@hyperframes/studio 0.9.37 → 0.9.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/dist/assets/{codec-BP7F-7Jx.js → codec-Dz2VdhdD.js} +1 -1
  2. package/dist/assets/{hyperframes-player-_QnPoHup.js → hyperframes-player-BkaWdGLq.js} +1 -1
  3. package/dist/assets/{index-D6ePWUpc.js → index-DONaC7VF.js} +1 -1
  4. package/dist/assets/{index-tjhfci4N.js → index-DsNxqAwr.js} +164 -164
  5. package/dist/assets/{pausedVideoDecoder-B7U86zDa.js → pausedVideoDecoder-BGN2jKrN.js} +1 -1
  6. package/dist/index.html +1 -1
  7. package/dist/index.js +58 -59
  8. package/package.json +8 -8
  9. package/src/components/editor/propertyPanelFlatMediaSection.test.tsx +7 -36
  10. package/src/components/editor/propertyPanelFlatMediaSection.tsx +9 -32
  11. package/src/components/editor/useVolumeAutomation.test.tsx +0 -69
  12. package/src/components/editor/useVolumeAutomation.ts +0 -4
  13. package/src/hooks/gsapScriptCommitTypes.ts +2 -6
  14. package/src/hooks/timelineEditingHelpers.test.ts +39 -0
  15. package/src/hooks/timelineEditingHelpers.ts +13 -0
  16. package/src/hooks/useDomEditCommits.ts +4 -9
  17. package/src/hooks/useDomEditPersist.ts +2 -12
  18. package/src/hooks/useGsapScriptCommits.test.tsx +21 -0
  19. package/src/hooks/useGsapScriptCommits.ts +7 -3
  20. package/src/player/components/Player.test.ts +15 -0
  21. package/src/player/components/Player.tsx +4 -4
  22. package/src/player/components/audioGainApply.test.ts +13 -0
  23. package/src/player/components/audioGainApply.ts +0 -3
  24. package/src/player/hooks/timelinePlayerTestHarness.ts +1 -0
  25. package/src/player/hooks/useShadowPreviewReload.ts +20 -5
  26. package/src/player/hooks/useTimelinePlayer.shadowReload.test.ts +46 -0
  27. package/src/utils/studioFileHistory.test.ts +29 -1
  28. package/src/utils/studioFileHistory.ts +24 -1
@@ -380,6 +380,23 @@ describe("persistTimelineBatchEdit", () => {
380
380
  expect(perMember).toContain('data-duration="9"');
381
381
  });
382
382
 
383
+ it("files the move under every clip it moved, by identity and by the name the clip wears", async () => {
384
+ stubReadFileContent(SOURCE);
385
+ const recordEdit = vi.fn(async () => {});
386
+ await persistTimelineBatchEdit({
387
+ ...batchInput([moveMember("a", 3, 0, 0), moveMember("b", 4, 1, 1)], []),
388
+ recordEdit,
389
+ });
390
+ expect(recordEdit).toHaveBeenCalledWith(
391
+ expect.objectContaining({
392
+ targets: [
393
+ { file: "index.html", id: "a", name: "a" },
394
+ { file: "index.html", id: "b", name: "b" },
395
+ ],
396
+ }),
397
+ );
398
+ });
399
+
383
400
  it("skips no-op members instead of aborting the batch (track-insert renumber)", async () => {
384
401
  // A track-insert renumber can include a member whose attributes already
385
402
  // hold the target values — its patch is string-identical. The batch must
@@ -492,6 +509,28 @@ describe("persistTimelineEdit", () => {
492
509
  expect([...pending]).toEqual(["index.html"]);
493
510
  });
494
511
 
512
+ it("files the edit under the clip it changed, by identity and by the name the clip wears", async () => {
513
+ vi.stubGlobal(
514
+ "fetch",
515
+ vi.fn(async () => ({ ok: true, json: async () => ({ content: SOURCE }) })),
516
+ );
517
+ const recordEdit = vi.fn(async () => {});
518
+ const element = el({ id: "a", tag: "video", domId: "a", start: 1, duration: 3 });
519
+ await persistTimelineEdit({
520
+ projectId: "p1",
521
+ element,
522
+ activeCompPath: "index.html",
523
+ label: "Move timeline clip",
524
+ buildPatches: (original, target) => buildTimelineMoveTimingPatch(original, target, 2, 3, 0),
525
+ writeProjectFile: async () => {},
526
+ recordEdit,
527
+ pendingTimelineEditPathRef: { current: new Set<string>() },
528
+ });
529
+ expect(recordEdit).toHaveBeenCalledWith(
530
+ expect.objectContaining({ targets: [{ file: "index.html", id: "a", name: "a" }] }),
531
+ );
532
+ });
533
+
495
534
  it("still throws for a clip the file does not hold", async () => {
496
535
  const { done, writes } = await runEdit("ghost", 2);
497
536
  await expect(done).rejects.toThrow("Unable to patch timeline element ghost in index.html");
@@ -23,8 +23,10 @@ import {
23
23
  } from "../player/lib/timelineElementHelpers";
24
24
  import { resolveTimelinePlaybackRate } from "../player/components/timelineGroupEditing";
25
25
  import {
26
+ editContextTarget,
26
27
  saveProjectFilesWithHistory,
27
28
  writeProjectFilesWithHistoryInQueue,
29
+ type EditContextTarget,
28
30
  type RecordEditInput,
29
31
  } from "../utils/studioFileHistory";
30
32
  import { serializeStudioFileMutations } from "../utils/studioFileMutationCoordinator";
@@ -140,6 +142,12 @@ export function buildPatchTarget(element: {
140
142
  return null;
141
143
  }
142
144
  export type PatchTarget = NonNullable<ReturnType<typeof buildPatchTarget>>;
145
+
146
+ /** A clip's entry in the history: how to find the element again, and the name the clip wears on the timeline. */
147
+ function timelineEditTarget(path: string, element: TimelineElement): EditContextTarget | null {
148
+ const patchTarget = buildPatchTarget(element);
149
+ return patchTarget && editContextTarget(path, { ...patchTarget, label: element.label });
150
+ }
143
151
  // The runtime re-reads data-start/data-duration from the DOM on each sync tick
144
152
  // (packages/core/src/runtime/init.ts:1324-1368), so attribute mutations here are
145
153
  // picked up automatically on the next frame without a rebind call.
@@ -354,6 +362,7 @@ export async function persistTimelineEdit(input: PersistTimelineEditInput): Prom
354
362
  await saveProjectFilesWithHistory({
355
363
  projectId: input.projectId,
356
364
  label: input.label,
365
+ targets: [editContextTarget(targetPath, { ...patchTarget, label: input.element.label })],
357
366
  coalesceKey: input.coalesceKey,
358
367
  coalesceMs: input.coalesceMs,
359
368
  files: {
@@ -457,6 +466,10 @@ export async function persistTimelineBatchEdit(
457
466
  await saveProjectFilesWithHistory({
458
467
  projectId: input.projectId,
459
468
  label: input.label,
469
+ targets: input.changes.flatMap((change) => {
470
+ const path = change.element.sourceFile || input.activeCompPath || "index.html";
471
+ return timelineEditTarget(path, change.element) ?? [];
472
+ }),
460
473
  coalesceKey: input.coalesceKey,
461
474
  coalesceMs: input.coalesceMs,
462
475
  files: Object.fromEntries([...changesByPath.keys()].map((path) => [path, buildFile(path)])),
@@ -1,4 +1,5 @@
1
1
  import { buildProjectApiPath } from "../utils/projectRouting";
2
+ import { editContextTarget } from "../utils/studioFileHistory";
2
3
  import { useCallback } from "react";
3
4
  import { findUnsafeDomPatchValues } from "@hyperframes/core/studio-api/finite-mutation";
4
5
  import { FONT_EXT } from "../utils/mediaTypes";
@@ -181,15 +182,9 @@ export function useDomEditCommits({
181
182
  targets: batches
182
183
  .filter((batch) => Object.hasOwn(files, batch.sourceFile))
183
184
  .flatMap((batch) =>
184
- batch.patches.map(({ target }) => ({
185
- file: batch.sourceFile,
186
- ...(target.id && { id: target.id }),
187
- ...(target.hfId && { hfId: target.hfId }),
188
- ...(target.selector && { selector: target.selector }),
189
- ...(target.selectorIndex !== undefined && {
190
- selectorIndex: target.selectorIndex,
191
- }),
192
- })),
185
+ batch.patches.map(({ target }) =>
186
+ editContextTarget(batch.sourceFile, target),
187
+ ),
193
188
  ),
194
189
  });
195
190
  }
@@ -20,7 +20,7 @@ import { countStudioManualEditSave } from "../components/editor/manualEditsDom";
20
20
  import type { CutoverResult } from "../utils/sdkCutover";
21
21
  import { reseekPreviewRuntime } from "./timelineTrackVisibility";
22
22
  import { serializeStudioFileMutations } from "../utils/studioFileMutationCoordinator";
23
- import { readProjectFileContent } from "../utils/studioFileHistory";
23
+ import { editContextTarget, readProjectFileContent } from "../utils/studioFileHistory";
24
24
 
25
25
  import type { RecordEditInput } from "../utils/studioFileHistory";
26
26
  export type { RecordEditInput } from "../utils/studioFileHistory";
@@ -160,17 +160,7 @@ export function useDomEditPersist({
160
160
 
161
161
  await editHistory.recordEdit({
162
162
  ...history,
163
- targets: [
164
- {
165
- file: targetPath,
166
- ...(selection.id && { id: selection.id }),
167
- ...(selection.hfId && { hfId: selection.hfId }),
168
- ...(selection.selector && { selector: selection.selector }),
169
- ...(selection.selectorIndex !== undefined && {
170
- selectorIndex: selection.selectorIndex,
171
- }),
172
- },
173
- ],
163
+ targets: [editContextTarget(targetPath, selection)],
174
164
  files: { [targetPath]: { before: originalContent, after: finalContent } },
175
165
  });
176
166
  return { patchData, patchedContent, finalContent };
@@ -898,6 +898,27 @@ describe("runCommit — instantPatch wiring", () => {
898
898
  expect(deps.reloadPreview).not.toHaveBeenCalled();
899
899
  });
900
900
 
901
+ it("files a gsap move under the layer it moved, by identity and by the name the person saw", async () => {
902
+ applySoftReload.mockReturnValue("applied");
903
+ mockFetchResult();
904
+ const deps = renderCommitHook();
905
+
906
+ await act(async () => {
907
+ await deps.api.commitMutation(
908
+ { ...selection, label: "Title" },
909
+ { x: 10 },
910
+ { label: "Move layer", softReload: true },
911
+ );
912
+ });
913
+
914
+ expect(deps.recordEdit).toHaveBeenCalledWith(
915
+ expect.objectContaining({
916
+ label: "Move layer",
917
+ targets: [{ file: "index.html", id: "a", selector: "#a", name: "Title" }],
918
+ }),
919
+ );
920
+ });
921
+
901
922
  it("batch capability posts ordered mutations and finalizes the result once", async () => {
902
923
  applySoftReload.mockReturnValue("applied");
903
924
  mockFetchResult();
@@ -1,6 +1,9 @@
1
1
  import { useCallback, useMemo, useRef } from "react";
2
2
  import { findUnsafeMutationValues } from "@hyperframes/core/studio-api/finite-mutation";
3
- import { readProjectFileContent as readSharedProjectFileContent } from "../utils/studioFileHistory";
3
+ import {
4
+ editContextTarget,
5
+ readProjectFileContent as readSharedProjectFileContent,
6
+ } from "../utils/studioFileHistory";
4
7
  import type { DomEditSelection } from "../components/editor/domEditingTypes";
5
8
  import { usePlayerStore } from "../player/store/playerStore";
6
9
  import {
@@ -323,12 +326,13 @@ export function useGsapScriptCommits({ projectIdRef, activeCompPath, previewIfra
323
326
  // the same animationId so their POSTs can't interleave. Held in a ref so the
324
327
  // chain survives re-renders.
325
328
  const serializerRef = useRef(createKeyedSerializer());
326
- const recordMutationEdit = useCallback(async (targetPath: string, result: MutationResult, options: CommitMutationOptions) => {
329
+ const recordMutationEdit = useCallback(async (targetPath: string, selection: DomEditSelection, result: MutationResult, options: CommitMutationOptions) => {
327
330
  if (result.before == null || result.after == null) return;
328
331
  await editHistory.recordEdit({
329
332
  label: options.label,
330
333
  coalesceKey: options.coalesceKey,
331
334
  coalesceMs: options.coalesceMs,
335
+ targets: [editContextTarget(targetPath, selection)],
332
336
  files: { [targetPath]: { before: result.before, after: result.after } },
333
337
  });
334
338
  }, [editHistory]);
@@ -348,7 +352,7 @@ export function useGsapScriptCommits({ projectIdRef, activeCompPath, previewIfra
348
352
  }
349
353
  return;
350
354
  }
351
- await recordMutationEdit(targetPath, result, options);
355
+ await recordMutationEdit(targetPath, selection, result, options);
352
356
  const nestedFiles = await settleNestedReads(
353
357
  result.scriptText
354
358
  ? readNestedFiles(previewIframeRef.current, result.scriptText, (path) =>
@@ -129,6 +129,21 @@ describe("preview errors", () => {
129
129
  root = null;
130
130
  });
131
131
 
132
+ it("leaves a callback ref alone on unmount, so a frame its owner made live since is kept", async () => {
133
+ // A shadow reload's promotion makes its frame the live one without calling the live Player's ref.
134
+ const ref = vi.fn();
135
+ const { player } = await mountPlayer({ ref } as Partial<PlayerProps>);
136
+ const frame = ref.mock.calls[0]?.[0] as HTMLIFrameElement;
137
+ player.shadowRoot!.append(frame); // where <hyperframes-player> keeps its frame
138
+ expect(frame.isConnected).toBe(true);
139
+
140
+ act(() => root?.unmount());
141
+ root = null;
142
+
143
+ expect(ref).toHaveBeenCalledTimes(1);
144
+ expect(frame.isConnected).toBe(false);
145
+ });
146
+
132
147
  it("puts the preview on the player's once-a-second paused heartbeat", async () => {
133
148
  const { player } = await mountPlayer();
134
149
  expect(player.hasAttribute("low-power-idle")).toBe(true);
@@ -377,11 +377,11 @@ export const Player = forwardRef<HTMLIFrameElement, PlayerProps>(
377
377
  // During crossfade refreshes the retiring Player unmounts after the
378
378
  // new Player has already assigned its iframe to the same ref — blindly
379
379
  // nulling it would break seeking in the new Player.
380
- // Callback refs are skipped — we can't read back the current value to
381
- // guard against clobbering a newer assignment. The mutable-ref branch
382
- // (the only path used today) is guarded by identity check.
380
+ // Callback refs are left alone: a shadow reload's promotion repoints
381
+ // the live frame without calling them, so a null here would wipe it.
382
+ // Their owners check `isConnected` instead (useShadowPreviewReload).
383
383
  if (typeof ref === "function") {
384
- // no-op: can't safely guard callback refs
384
+ // no-op
385
385
  } else if (ref) {
386
386
  const mutableRef = ref as React.MutableRefObject<HTMLIFrameElement | null>;
387
387
  if (mutableRef.current === iframe) {
@@ -52,6 +52,19 @@ describe("normalizeClipsLoudness", () => {
52
52
  });
53
53
 
54
54
  describe("writeClipGains", () => {
55
+ it("writes data-volume on a clip with a volume lane, which the gain stacks on", async () => {
56
+ const onSetElementAttributeQuiet = vi.fn(async () => ({ status: "saved" as const }));
57
+ await writeClipGains([{ element: clip("vo", { automation: volumeLane }), gain: 2 }], {
58
+ onSetElementAttributeQuiet,
59
+ });
60
+ expect(onSetElementAttributeQuiet).toHaveBeenCalledWith(
61
+ expect.objectContaining({ id: "vo" }),
62
+ "data-volume",
63
+ "2",
64
+ "Audio Gain",
65
+ );
66
+ });
67
+
55
68
  it("stops at the first refused single save", async () => {
56
69
  const onSetElementAttributeQuiet = vi.fn(async () => ({
57
70
  status: "refused" as const,
@@ -22,9 +22,6 @@ export async function writeClipGains(
22
22
  writers: VolumeWriters,
23
23
  label = AUDIO_GAIN_LABEL,
24
24
  ): Promise<void> {
25
- if (edits.some(({ element }) => volumeLaneOwnsGain(element))) {
26
- throw new Error(VOLUME_LANE_REFUSAL);
27
- }
28
25
  const values = edits.map(({ element, gain }) => ({ element, value: formatAudioGain(gain) }));
29
26
  if (values.length > 1 && writers.onSetElementsAttributeQuiet) {
30
27
  throwUnlessSaved(await writers.onSetElementsAttributeQuiet(values, "data-volume", label));
@@ -67,6 +67,7 @@ export function makeFakeIframe(iframeWindow: Record<string, unknown>): HTMLIFram
67
67
  value: document.implementation.createHTMLDocument("preview"),
68
68
  configurable: true,
69
69
  });
70
+ document.body.appendChild(iframe);
70
71
  return iframe;
71
72
  }
72
73
 
@@ -114,6 +114,7 @@ export function useShadowPreviewReload({
114
114
  const budgetsSpentRef = useRef(0);
115
115
  // The shadow still owed a wait budget, so a hidden tab can resume it when it becomes visible.
116
116
  const budgetGenRef = useRef<number | null>(null);
117
+ const shadowFrameLeftPageRef = useRef(false);
117
118
  const cancelPendingLoadRef = useRef<() => void>(() => {});
118
119
  const stopHoldRef = useRef<() => void>(() => {});
119
120
  const shadowUrlRef = useRef("");
@@ -127,6 +128,7 @@ export function useShadowPreviewReload({
127
128
  const stopPendingShadow = useCallback(() => {
128
129
  clearTimeout(readyTimerRef.current);
129
130
  budgetGenRef.current = null;
131
+ shadowFrameLeftPageRef.current = false;
130
132
  cancelPendingLoadRef.current();
131
133
  stopHoldRef.current();
132
134
  pendingCommitRef.current = null;
@@ -296,14 +298,10 @@ export function useShadowPreviewReload({
296
298
  [promoteWhenReady],
297
299
  );
298
300
 
299
- const setShadowIframeNode = useCallback((node: HTMLIFrameElement | null) => {
300
- shadowIframeRef.current = node;
301
- }, []);
302
-
303
301
  const armReadyTimer = useCallback(
304
302
  (gen: number) => {
305
303
  clearTimeout(readyTimerRef.current);
306
- if (isDocumentHidden()) return;
304
+ if (isDocumentHidden() || shadowFrameLeftPageRef.current) return;
307
305
  let drew = false;
308
306
  let starved = false;
309
307
  requestAnimationFrame(() => {
@@ -317,6 +315,12 @@ export function useShadowPreviewReload({
317
315
  logReload("shadow-starved", { gen });
318
316
  return;
319
317
  }
318
+ const frame = shadowIframeRef.current;
319
+ if (frame && !frame.isConnected) {
320
+ shadowFrameLeftPageRef.current = true;
321
+ logReload("shadow-detached", { gen });
322
+ return;
323
+ }
320
324
  budgetsSpentRef.current += 1;
321
325
  if (budgetsSpentRef.current < SHADOW_READY_BUDGETS) {
322
326
  logReload("shadow-slow", { budgetsSpent: budgetsSpentRef.current });
@@ -331,6 +335,17 @@ export function useShadowPreviewReload({
331
335
  const armReadyTimerRef = useRef(armReadyTimer);
332
336
  armReadyTimerRef.current = armReadyTimer;
333
337
 
338
+ const setShadowIframeNode = useCallback((node: HTMLIFrameElement | null) => {
339
+ shadowIframeRef.current = node;
340
+ const gen = budgetGenRef.current;
341
+ if (!node || !shadowFrameLeftPageRef.current || gen == null || gen !== shadowGenRef.current)
342
+ return;
343
+ shadowFrameLeftPageRef.current = false;
344
+ budgetsSpentRef.current = 0;
345
+ logReload("shadow-reattached", { gen });
346
+ armReadyTimerRef.current(gen);
347
+ }, []);
348
+
334
349
  const beginShadowReload = useCallback(
335
350
  (url: string) => {
336
351
  retry.started();
@@ -533,6 +533,52 @@ describe("shadow reload readiness and failure", () => {
533
533
  unmount(root);
534
534
  });
535
535
 
536
+ it("keeps a reload whose frame left the page, and promotes it once a new frame mounts", () => {
537
+ vi.useFakeTimers();
538
+ const onPreviewReloadFailed = vi.fn();
539
+ const { getApi, gen, live, root } = beginReload({ onPreviewReloadFailed });
540
+ const first = makeShadowWithSpies();
541
+ act(() => getApi().setShadowIframeNode(first.iframe));
542
+
543
+ // The pane holding the preview unmounts mid-reload: its Players remove their frames.
544
+ act(() => first.iframe.remove());
545
+ act(() => void vi.advanceTimersByTime(FULL_WAIT_MS * 2));
546
+ expect(onPreviewReloadFailed).not.toHaveBeenCalled();
547
+ expect(getApi().iframeRef.current).toBe(live);
548
+
549
+ // The pane comes back: a new Player for the same slot mounts a new frame, which loads.
550
+ const again = makeShadowWithSpies();
551
+ act(() => {
552
+ getApi().setShadowIframeNode(again.iframe);
553
+ getApi().onShadowIframeLoad(gen);
554
+ });
555
+ act(() => getApi().onShadowReadyChange(gen, true));
556
+ expect(getApi().iframeRef.current).toBe(again.iframe);
557
+ expect(onPreviewReloadFailed).not.toHaveBeenCalled();
558
+ unmount(root);
559
+ });
560
+
561
+ it("gives a frame that mounts again its full budgets, then drops it if it stays silent", () => {
562
+ vi.useFakeTimers();
563
+ vi.spyOn(console, "error").mockImplementation(() => {});
564
+ const onPreviewReloadFailed = vi.fn();
565
+ const { getApi, live, root } = beginReload({ onPreviewReloadFailed });
566
+ const first = makeShadowWithSpies();
567
+ act(() => getApi().setShadowIframeNode(first.iframe));
568
+ act(() => void vi.advanceTimersByTime(SHADOW_READY_TIMEOUT_MS + 1000));
569
+ act(() => first.iframe.remove());
570
+ act(() => void vi.advanceTimersByTime(FULL_WAIT_MS));
571
+ expect(onPreviewReloadFailed).not.toHaveBeenCalled();
572
+
573
+ act(() => getApi().setShadowIframeNode(makeShadowWithSpies().iframe));
574
+ act(() => void vi.advanceTimersByTime(FULL_WAIT_MS - 1));
575
+ expect(onPreviewReloadFailed).not.toHaveBeenCalled();
576
+ act(() => void vi.advanceTimersByTime(1));
577
+ expect(onPreviewReloadFailed).toHaveBeenCalledWith(expect.stringContaining("too long"));
578
+ expect(getApi().iframeRef.current).toBe(live);
579
+ unmount(root);
580
+ });
581
+
536
582
  it("does not spend the budget while the tab is hidden, and promotes once it is visible", () => {
537
583
  vi.useFakeTimers();
538
584
  const onPreviewReloadFailed = vi.fn();
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, it, vi } from "vitest";
2
- import { saveProjectFilesWithHistory } from "./studioFileHistory";
2
+ import { editContextTarget, saveProjectFilesWithHistory } from "./studioFileHistory";
3
3
  import { serializeStudioFileMutation } from "./studioFileMutationCoordinator";
4
4
 
5
5
  describe("saveProjectFilesWithHistory", () => {
@@ -235,3 +235,31 @@ describe("saveProjectFilesWithHistory", () => {
235
235
  );
236
236
  });
237
237
  });
238
+
239
+ describe("editContextTarget", () => {
240
+ it("names the element by identity and carries the layer name the person saw", () => {
241
+ expect(
242
+ editContextTarget("index.html", {
243
+ id: "title",
244
+ hfId: "hf-1",
245
+ selector: ".title",
246
+ selectorIndex: 0,
247
+ label: "Title",
248
+ }),
249
+ ).toEqual({
250
+ file: "index.html",
251
+ id: "title",
252
+ hfId: "hf-1",
253
+ selector: ".title",
254
+ selectorIndex: 0,
255
+ name: "Title",
256
+ });
257
+ });
258
+
259
+ it("leaves the name out when the layer has none", () => {
260
+ expect(editContextTarget("index.html", { id: "title", label: "" })).toEqual({
261
+ file: "index.html",
262
+ id: "title",
263
+ });
264
+ });
265
+ });
@@ -4,9 +4,24 @@ import type { MutableRefObject } from "react";
4
4
  import { serializeStudioFileMutations } from "./studioFileMutationCoordinator";
5
5
  import { createStudioSaveHttpError } from "./studioSaveDiagnostics";
6
6
  import { studioApiFetch } from "./studioApiFetch";
7
+ import type { PatchTarget } from "./sourcePatcher";
7
8
 
8
9
  export type EditContextTarget = HistoryTarget;
9
10
 
11
+ export function editContextTarget(
12
+ file: string,
13
+ target: PatchTarget & { label?: string },
14
+ ): EditContextTarget {
15
+ return {
16
+ file,
17
+ ...(target.id && { id: target.id }),
18
+ ...(target.hfId && { hfId: target.hfId }),
19
+ ...(target.selector && { selector: target.selector }),
20
+ ...(target.selectorIndex !== undefined && { selectorIndex: target.selectorIndex }),
21
+ ...(target.label && { name: target.label }),
22
+ };
23
+ }
24
+
10
25
  export interface RecordEditInput {
11
26
  targets?: EditContextTarget[];
12
27
  label: string;
@@ -31,6 +46,7 @@ type ProjectFileWriter = (path: string, content: string, expectedContent?: strin
31
46
  interface SaveProjectFilesWithHistoryInput {
32
47
  projectId: string;
33
48
  label: string;
49
+ targets?: EditContextTarget[];
34
50
  coalesceKey?: string;
35
51
  coalesceMs?: number;
36
52
  files: Record<string, (contentInsideFileQueue: string) => string>;
@@ -107,6 +123,7 @@ export async function saveServerRewriteWithHistory(input: {
107
123
 
108
124
  export async function writeProjectFilesWithHistoryInQueue({
109
125
  label,
126
+ targets,
110
127
  coalesceKey,
111
128
  coalesceMs,
112
129
  files,
@@ -134,7 +151,13 @@ export async function writeProjectFilesWithHistoryInQueue({
134
151
  writtenPaths.push(path);
135
152
  }
136
153
 
137
- await recordEdit({ label, coalesceKey, coalesceMs, files: snapshots });
154
+ await recordEdit({
155
+ label,
156
+ coalesceKey,
157
+ coalesceMs,
158
+ ...(targets?.length && { targets }),
159
+ files: snapshots,
160
+ });
138
161
  } catch (error) {
139
162
  try {
140
163
  for (const path of writtenPaths.reverse()) {