@hyperframes/studio 0.8.79 → 0.8.81

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 (86) hide show
  1. package/dist/assets/hyperframes-player-C68UawR3.js +464 -0
  2. package/dist/assets/{index-ORZXYB0k.js → index-CMzPGv9P.js} +1 -1
  3. package/dist/assets/{index-CJP92F4-.js → index-CS5SImRT.js} +1 -1
  4. package/dist/assets/{index-DBKySIo7.js → index-hNVM9Pd2.js} +200 -197
  5. package/dist/index.d.ts +18 -1
  6. package/dist/index.html +1 -1
  7. package/dist/index.js +1673 -1348
  8. package/dist/index.js.map +1 -1
  9. package/package.json +8 -8
  10. package/src/App.tsx +13 -10
  11. package/src/components/StudioRightPanels.tsx +4 -48
  12. package/src/components/editor/TimelineFxPopover.test.tsx +1 -1
  13. package/src/components/editor/TimelineFxPopover.tsx +1 -1
  14. package/src/components/editor/manualEdits.ts +1 -0
  15. package/src/components/editor/manualEditsParsing.ts +4 -0
  16. package/src/components/editor/useFxAudition.ts +3 -3
  17. package/src/components/nle/useTimelineEditCallbacks.ts +4 -0
  18. package/src/components/panels/VariablesOtherCompositions.tsx +4 -4
  19. package/src/components/panels/VariablesPanel.test.tsx +86 -0
  20. package/src/components/panels/VariablesPanel.tsx +3 -3
  21. package/src/components/sidebar/SidebarLintButton.test.tsx +29 -0
  22. package/src/components/sidebar/SidebarLintButton.tsx +4 -0
  23. package/src/components/studioColorGradingScope.ts +5 -7
  24. package/src/contexts/DomEditContext.tsx +4 -0
  25. package/src/contexts/TimelineEditContext.tsx +2 -0
  26. package/src/hooks/liveLanes.ts +147 -0
  27. package/src/hooks/timelineAudioGroupVolume.ts +81 -47
  28. package/src/hooks/timelineEditPermission.ts +9 -1
  29. package/src/hooks/timelineEditingHelpers.test.ts +16 -0
  30. package/src/hooks/timelineEditingHelpers.ts +69 -43
  31. package/src/hooks/timelineElementFxAttribute.ts +82 -36
  32. package/src/hooks/useAppHotkeys.ts +1 -1
  33. package/src/hooks/useApplyColorGradingScope.test.tsx +53 -0
  34. package/src/hooks/useApplyColorGradingScope.ts +54 -0
  35. package/src/hooks/useAutomationSelectionKeyboard.test.tsx +125 -21
  36. package/src/hooks/useAutomationSelectionKeyboard.ts +21 -25
  37. package/src/hooks/useBlockHandlers.test.tsx +65 -0
  38. package/src/hooks/useBlockHandlers.ts +7 -4
  39. package/src/hooks/useDomEditAttributeCommits.ts +3 -17
  40. package/src/hooks/useDomEditSession.ts +1 -0
  41. package/src/hooks/useEditHistoryActions.ts +4 -3
  42. package/src/hooks/useExternalFileChangeCoordinator.test.tsx +49 -0
  43. package/src/hooks/useExternalFileChangeCoordinator.ts +15 -6
  44. package/src/hooks/useLintModal.test.tsx +15 -0
  45. package/src/hooks/useLintModal.ts +5 -2
  46. package/src/hooks/useProjectCompositionVariables.ts +3 -3
  47. package/src/hooks/useTimelineEditing.ts +19 -16
  48. package/src/hooks/useTimelineGroupEditing.ts +2 -1
  49. package/src/hooks/useToast.ts +2 -1
  50. package/src/player/components/ImageThumbnail.tsx +3 -12
  51. package/src/player/components/Player.test.ts +23 -0
  52. package/src/player/components/Player.tsx +4 -2
  53. package/src/player/components/TimelineAutomationLane.test.tsx +38 -0
  54. package/src/player/components/TimelineAutomationLane.tsx +18 -13
  55. package/src/player/components/TimelineAutomationLaneSlot.test.tsx +0 -2
  56. package/src/player/components/TimelineClipFades.test.tsx +24 -3
  57. package/src/player/components/TimelineClipFades.tsx +5 -2
  58. package/src/player/components/TimelineFxButton.tsx +1 -1
  59. package/src/player/components/TimelineGroupHeader.tsx +1 -1
  60. package/src/player/components/TimelineGroupRow.test.tsx +0 -1
  61. package/src/player/components/TimelineGroupRow.tsx +17 -11
  62. package/src/player/components/TimelineTrackHeader.tsx +21 -6
  63. package/src/player/components/groupAutomationElement.ts +9 -1
  64. package/src/player/components/timelineCallbacks.ts +2 -0
  65. package/src/player/components/timelineClipDragPreview.test.ts +41 -0
  66. package/src/player/components/timelineClipDragPreview.ts +15 -24
  67. package/src/player/components/timelineEditing.test.ts +99 -1
  68. package/src/player/components/timelineEditing.ts +5 -8
  69. package/src/player/components/timelineGroupEditing.test.ts +27 -0
  70. package/src/player/components/timelineGroupEditing.ts +18 -15
  71. package/src/player/components/timelineStackingSync.ts +5 -5
  72. package/src/player/components/timelineZones.ts +2 -3
  73. package/src/player/components/useAutomationEdgeStretch.ts +4 -4
  74. package/src/player/components/useAutomationLaneGestures.ts +1 -1
  75. package/src/player/components/useAutomationLanes.save.test.tsx +1406 -0
  76. package/src/player/components/useAutomationLanes.ts +58 -74
  77. package/src/player/lib/automationStoreSync.ts +30 -3
  78. package/src/player/lib/thumbnailImageDecoder.test.ts +82 -0
  79. package/src/player/lib/thumbnailImageDecoder.ts +73 -0
  80. package/src/player/lib/timelineDOM.test.ts +28 -8
  81. package/src/player/lib/timelineElementHelpers.ts +3 -4
  82. package/src/player/lib/timelineGroupInfo.ts +23 -23
  83. package/src/utils/studioFileHistory.ts +36 -30
  84. package/dist/assets/hyperframes-player-Bx_Kw4Ey.js +0 -464
  85. package/src/player/components/automationGestureKeys.test.ts +0 -49
  86. package/src/player/components/automationGestureKeys.ts +0 -49
@@ -7,18 +7,25 @@
7
7
  * shared core `setAudioGroupAttribute` also uses.
8
8
  */
9
9
 
10
- import { useCallback, useRef } from "react";
10
+ import { useCallback } from "react";
11
11
  import type { TimelineElement } from "../player";
12
12
  import {
13
13
  buildPatchTarget,
14
14
  findTimelineElementInIframe,
15
15
  persistElementAttribute,
16
+ readSavedAttribute,
16
17
  } from "./timelineEditingHelpers";
18
+ import { useLiveLanes, type LiveLaneRestore, type LiveLaneSource } from "./liveLanes";
17
19
  import type {
18
20
  MutableRef,
19
21
  UseTimelineElementVisibilityEditingInput,
20
22
  } from "./timelineTrackVisibility";
21
- import { projectForTimelineSave, type TimelineEditOutcome } from "./timelineEditPermission";
23
+ import {
24
+ failedTimelineSave,
25
+ projectForTimelineSave,
26
+ type TimelineEditOutcome,
27
+ } from "./timelineEditPermission";
28
+ import { syncStoredElementAttribute } from "../player/lib/automationStoreSync";
22
29
 
23
30
  function patchLiveElementAttribute(
24
31
  iframe: HTMLIFrameElement | null,
@@ -41,6 +48,22 @@ function elementAttributeLiveKey(
41
48
  return `${element.sourceFile || activeCompPath || "index.html"}\0${element.key ?? element.domId ?? element.id}\0${attr}`;
42
49
  }
43
50
 
51
+ function elementSaveTarget(element: TimelineElement, activeCompPath: string | null) {
52
+ return {
53
+ targetPath: element.sourceFile || activeCompPath || "index.html",
54
+ patchTarget: buildPatchTarget(element),
55
+ };
56
+ }
57
+
58
+ function elementLiveSource(
59
+ element: TimelineElement,
60
+ activeCompPath: string | null,
61
+ attr: string,
62
+ ): LiveLaneSource {
63
+ const { targetPath, patchTarget } = elementSaveTarget(element, activeCompPath);
64
+ return { path: targetPath, target: patchTarget, attr };
65
+ }
66
+
44
67
  interface SetElementAttributeInput {
45
68
  projectId: string;
46
69
  activeCompPath: string | null;
@@ -48,7 +71,8 @@ interface SetElementAttributeInput {
48
71
  attr: string;
49
72
  value: string | null;
50
73
  label: string;
51
- previewIframe: HTMLIFrameElement | null;
74
+ patchLive: (value: string | null) => void;
75
+ onFileRead: (value: string | null) => void;
52
76
  writeProjectFile: (path: string, content: string) => Promise<void>;
53
77
  recordEdit: Parameters<typeof persistElementAttribute>[0]["recordEdit"];
54
78
  pendingTimelineEditPathRef: MutableRef<Set<string>>;
@@ -61,13 +85,13 @@ async function setElementAttribute({
61
85
  attr,
62
86
  value,
63
87
  label,
64
- previewIframe,
88
+ patchLive,
89
+ onFileRead,
65
90
  writeProjectFile,
66
91
  recordEdit,
67
92
  pendingTimelineEditPathRef,
68
93
  }: SetElementAttributeInput): Promise<string[] | null> {
69
- const targetPath = element.sourceFile || activeCompPath || "index.html";
70
- const patchTarget = buildPatchTarget(element);
94
+ const { targetPath, patchTarget } = elementSaveTarget(element, activeCompPath);
71
95
  if (!patchTarget) return null;
72
96
 
73
97
  return persistElementAttribute({
@@ -80,7 +104,8 @@ async function setElementAttribute({
80
104
  writeProjectFile,
81
105
  recordEdit,
82
106
  pendingTimelineEditPathRef,
83
- patchLive: (v) => patchLiveElementAttribute(previewIframe, element, attr, v, activeCompPath),
107
+ patchLive,
108
+ onFileRead,
84
109
  });
85
110
  }
86
111
 
@@ -102,33 +127,46 @@ export function useSetElementAttribute({
102
127
  label: string,
103
128
  ) => Promise<TimelineEditOutcome>;
104
129
  revertLive: (element: TimelineElement, attr: string) => void;
130
+ restoreLive: (restore: LiveLaneRestore) => void;
105
131
  } {
106
- const liveBeforeRef = useRef(new Map<string, string | null>());
132
+ const liveLanes = useLiveLanes(projectIdRef, activeCompPath);
107
133
  const setLive = useCallback(
108
134
  (element: TimelineElement, attr: string, value: string | null) => {
109
135
  const key = elementAttributeLiveKey(element, activeCompPath, attr);
110
136
  const target = findTimelineElementInIframe(previewIframeRef.current, element, activeCompPath);
111
- if (!liveBeforeRef.current.has(key)) {
112
- liveBeforeRef.current.set(key, target?.getAttribute(attr) ?? null);
113
- }
137
+ liveLanes.preview(
138
+ key,
139
+ () => target?.getAttribute(attr) ?? null,
140
+ elementLiveSource(element, activeCompPath, attr),
141
+ );
114
142
  patchLiveElementAttribute(previewIframeRef.current, element, attr, value, activeCompPath);
115
143
  },
144
+ [liveLanes, previewIframeRef, activeCompPath],
145
+ );
146
+ const laneApply = useCallback(
147
+ (element: TimelineElement, attr: string) => ({
148
+ preview: (value: string | null) =>
149
+ patchLiveElementAttribute(previewIframeRef.current, element, attr, value, activeCompPath),
150
+ store: (value: string | null) => syncStoredElementAttribute(element, attr, value),
151
+ }),
116
152
  [previewIframeRef, activeCompPath],
117
153
  );
154
+ const claimLive = useCallback(
155
+ (element: TimelineElement, attr: string) =>
156
+ liveLanes.claim(
157
+ elementAttributeLiveKey(element, activeCompPath, attr),
158
+ laneApply(element, attr),
159
+ elementLiveSource(element, activeCompPath, attr),
160
+ ),
161
+ [liveLanes, laneApply, activeCompPath],
162
+ );
118
163
  const revertLive = useCallback(
119
- (element: TimelineElement, attr: string) => {
120
- const key = elementAttributeLiveKey(element, activeCompPath, attr);
121
- if (!liveBeforeRef.current.has(key)) return;
122
- patchLiveElementAttribute(
123
- previewIframeRef.current,
124
- element,
125
- attr,
126
- liveBeforeRef.current.get(key) ?? null,
127
- activeCompPath,
128
- );
129
- liveBeforeRef.current.delete(key);
130
- },
131
- [previewIframeRef, activeCompPath],
164
+ (element: TimelineElement, attr: string) =>
165
+ liveLanes.revert(
166
+ elementAttributeLiveKey(element, activeCompPath, attr),
167
+ laneApply(element, attr),
168
+ ),
169
+ [liveLanes, laneApply, activeCompPath],
132
170
  );
133
171
  const setQuiet = useCallback(
134
172
  async (
@@ -137,9 +175,17 @@ export function useSetElementAttribute({
137
175
  value: string | null,
138
176
  label: string,
139
177
  ): Promise<TimelineEditOutcome> => {
140
- const pid = projectForTimelineSave(isRecordingRef?.current, projectIdRef.current, showToast);
141
- if (typeof pid !== "string") return pid;
142
- const liveKey = elementAttributeLiveKey(element, activeCompPath, attr);
178
+ const project = projectIdRef.current;
179
+ const pid = projectForTimelineSave(isRecordingRef?.current, project, showToast);
180
+ const live = claimLive(element, attr);
181
+ const unsaved = async (outcome: TimelineEditOutcome): Promise<TimelineEditOutcome> => {
182
+ const { targetPath, patchTarget } = elementSaveTarget(element, activeCompPath);
183
+ live.settle(
184
+ await readSavedAttribute(project, targetPath, patchTarget, attr, writeProjectFile),
185
+ );
186
+ return outcome;
187
+ };
188
+ if (typeof pid !== "string") return unsaved(pid);
143
189
  try {
144
190
  const written = await setElementAttribute({
145
191
  projectId: pid,
@@ -148,25 +194,25 @@ export function useSetElementAttribute({
148
194
  attr,
149
195
  value,
150
196
  label,
151
- previewIframe: previewIframeRef.current,
197
+ patchLive: live.preview,
198
+ onFileRead: live.read,
152
199
  writeProjectFile,
153
200
  recordEdit,
154
201
  pendingTimelineEditPathRef,
155
202
  });
156
- liveBeforeRef.current.delete(liveKey);
157
- if (written) return { status: "saved" };
158
- return { status: "failed", reason: "This clip has no id to save it by" };
203
+ if (!written)
204
+ return unsaved(failedTimelineSave("This clip has no id to save it by", showToast));
205
+ live.settle(value);
206
+ return { status: "saved" };
159
207
  } catch (error) {
160
208
  console.error("[Timeline] Failed to set element attribute", error);
161
209
  const message = error instanceof Error ? error.message : "Failed to update effect";
162
- showToast(message);
163
- liveBeforeRef.current.delete(liveKey);
164
- return { status: "failed", reason: message };
210
+ return unsaved(failedTimelineSave(message, showToast));
165
211
  }
166
212
  },
167
213
  [
214
+ claimLive,
168
215
  activeCompPath,
169
- previewIframeRef,
170
216
  writeProjectFile,
171
217
  recordEdit,
172
218
  pendingTimelineEditPathRef,
@@ -175,5 +221,5 @@ export function useSetElementAttribute({
175
221
  projectIdRef,
176
222
  ],
177
223
  );
178
- return { setLive, setQuiet, revertLive };
224
+ return { setLive, setQuiet, revertLive, restoreLive: liveLanes.restore };
179
225
  }
@@ -93,7 +93,7 @@ interface UseAppHotkeysParams {
93
93
  handleDuplicate: () => Promise<boolean>;
94
94
  onResetKeyframes: () => boolean;
95
95
  onDeleteSelectedKeyframes: () => void;
96
- onAfterUndoRedo?: () => void;
96
+ onAfterUndoRedo?: UseEditHistoryActionsOptions["onAfterUndoRedo"];
97
97
  onToggleRecording?: () => void;
98
98
  /** Group the current multi-selection into a data-hf-group wrapper (⌘G). */
99
99
  onGroupSelection?: () => void;
@@ -0,0 +1,53 @@
1
+ // @vitest-environment happy-dom
2
+
3
+ import React, { act } from "react";
4
+ import { createRoot } from "react-dom/client";
5
+ import { expect, it, vi } from "vitest";
6
+ import { useApplyColorGradingScope } from "./useApplyColorGradingScope";
7
+
8
+ (globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
9
+
10
+ const readProjectFile = vi.fn(async (_path: string) => "<html><body></body></html>");
11
+
12
+ vi.mock("../contexts/StudioContext", () => ({
13
+ useStudioShellContext: () => ({
14
+ projectId: "demo",
15
+ activeCompPath: "index.html",
16
+ showToast: vi.fn(),
17
+ waitForPendingDomEditSaves: async () => {},
18
+ }),
19
+ }));
20
+ vi.mock("../contexts/DomEditContext", () => ({
21
+ useDomEditContext: () => ({ domEditSelection: null }),
22
+ }));
23
+ vi.mock("../contexts/FileManagerContext", () => ({
24
+ useFileManagerContext: () => ({
25
+ readProjectFile,
26
+ writeProjectFile: vi.fn(),
27
+ fileTree: ["index.html", "scene.html", ".hyperframes/preview/4884df6e.html"],
28
+ compositions: ["index.html", "scene.html"],
29
+ }),
30
+ }));
31
+
32
+ it("grades the project's compositions, not Studio's generated preview documents", async () => {
33
+ let apply: ReturnType<typeof useApplyColorGradingScope> | null = null;
34
+ function Probe() {
35
+ apply = useApplyColorGradingScope(
36
+ vi.fn(async () => {}),
37
+ vi.fn(),
38
+ );
39
+ return null;
40
+ }
41
+ const root = createRoot(document.createElement("div"));
42
+ act(() => root.render(<Probe />));
43
+
44
+ await act(async () => {
45
+ await apply!("project", null);
46
+ });
47
+
48
+ expect(readProjectFile.mock.calls.map(([path]) => path).sort()).toEqual([
49
+ "index.html",
50
+ "scene.html",
51
+ ]);
52
+ act(() => root.unmount());
53
+ });
@@ -0,0 +1,54 @@
1
+ import { useCallback } from "react";
2
+ import { useStudioShellContext } from "../contexts/StudioContext";
3
+ import { useDomEditContext } from "../contexts/DomEditContext";
4
+ import { useFileManagerContext } from "../contexts/FileManagerContext";
5
+ import {
6
+ applyColorGradingScopeUpdate,
7
+ EMPTY_COLOR_GRADING_SCOPE_RESULT,
8
+ type ColorGradingScope,
9
+ } from "../components/studioColorGradingScope";
10
+ import type { StudioRightPanelsProps } from "../components/StudioRightPanels.types";
11
+
12
+ export function useApplyColorGradingScope(
13
+ recordEdit: StudioRightPanelsProps["recordEdit"],
14
+ reloadPreview: StudioRightPanelsProps["reloadPreview"],
15
+ ) {
16
+ const { projectId, activeCompPath, showToast, waitForPendingDomEditSaves } =
17
+ useStudioShellContext();
18
+ const { domEditSelection } = useDomEditContext();
19
+ const { readProjectFile, writeProjectFile, compositions } = useFileManagerContext();
20
+ return useCallback(
21
+ async (scope: ColorGradingScope, value: string | null) =>
22
+ applyColorGradingScopeUpdate({
23
+ scope,
24
+ value,
25
+ selectedSourceFile: domEditSelection?.sourceFile || activeCompPath || "index.html",
26
+ compositionPaths: compositions,
27
+ projectId,
28
+ waitForPendingDomEditSaves,
29
+ readProjectFile,
30
+ writeProjectFile,
31
+ recordEdit,
32
+ reloadPreview,
33
+ showToast,
34
+ }).catch((error) => {
35
+ showToast(
36
+ `Couldn't apply color grading: ${error instanceof Error ? error.message : String(error)}`,
37
+ "error",
38
+ );
39
+ return EMPTY_COLOR_GRADING_SCOPE_RESULT;
40
+ }),
41
+ [
42
+ activeCompPath,
43
+ compositions,
44
+ domEditSelection?.sourceFile,
45
+ projectId,
46
+ readProjectFile,
47
+ recordEdit,
48
+ reloadPreview,
49
+ showToast,
50
+ waitForPendingDomEditSaves,
51
+ writeProjectFile,
52
+ ],
53
+ );
54
+ }
@@ -77,7 +77,7 @@ describe("useAutomationSelectionKeyboard", () => {
77
77
  });
78
78
 
79
79
  const setup = (binding: Partial<AutomationLaneBinding>) => {
80
- const onCommit = vi.fn();
80
+ const onCommit = vi.fn().mockResolvedValue(undefined);
81
81
  const automation = {
82
82
  version: 1,
83
83
  lanes: [
@@ -102,7 +102,6 @@ describe("useAutomationSelectionKeyboard", () => {
102
102
  onCommit,
103
103
  onSelect: vi.fn(),
104
104
  readOnly: false,
105
- commitTargetKey: "bgm",
106
105
  selection: null,
107
106
  onRangeSelect: vi.fn(),
108
107
  onRangeClear: vi.fn(),
@@ -230,7 +229,7 @@ describe("useAutomationSelectionKeyboard", () => {
230
229
  expect(entry?.points.map((p) => p.t)).toEqual([0, 2]);
231
230
  });
232
231
 
233
- it("Cmd+V with no selection pastes at the playhead and selects the pasted span", () => {
232
+ it("Cmd+V with no selection pastes at the playhead and selects the pasted span", async () => {
234
233
  clearAutomationClipboard();
235
234
  // Duration wide enough that the playhead (5s) is not clamped down by the
236
235
  // 0..duration-span bound — this is a paste-at-playhead test, not a
@@ -255,6 +254,7 @@ describe("useAutomationSelectionKeyboard", () => {
255
254
  expect(times).toContain(7); // + clipboard span 2
256
255
 
257
256
  // Pasting again immediately should land right after the first paste.
257
+ await act(async () => {});
258
258
  expect(usePlayerStore.getState().automationSelection).toEqual({
259
259
  elementKey: "bgm",
260
260
  target: "volume",
@@ -268,7 +268,124 @@ describe("useAutomationSelectionKeyboard", () => {
268
268
  });
269
269
  });
270
270
 
271
- it("chains a second Cmd+V after the first instead of overwriting it", () => {
271
+ it("marks nothing when the paste's save is refused, even for two quick presses", async () => {
272
+ clearAutomationClipboard();
273
+ usePlayerStore.setState({
274
+ elements: [{ ...bgmElement, duration: 10 }],
275
+ selectedElementId: "bgm",
276
+ });
277
+ const original = wholeAxis({ elementKey: "bgm", target: "volume", t0: 2, t1: 4 });
278
+ usePlayerStore.getState().setAutomationSelection(original);
279
+ const onCommit = vi.fn().mockResolvedValue({ status: "refused", reason: "Locked" });
280
+ setup({ onCommit });
281
+ combo("c");
282
+ combo("v");
283
+ combo("v");
284
+ await act(async () => {});
285
+ expect(usePlayerStore.getState().automationSelection).toEqual(original);
286
+ combo("v");
287
+ const again = (onCommit.mock.calls.at(-1)?.[0]?.lanes?.[0]?.points ?? []).map(
288
+ (p: { t: number }) => p.t,
289
+ );
290
+ expect(again).toContain(2);
291
+ expect(again).not.toContain(6);
292
+ });
293
+
294
+ it.each([{ status: "saved" as const }, { status: "refused" as const, reason: "Locked" }])(
295
+ "keeps a selection drawn while a paste was saving ($status)",
296
+ async (outcome) => {
297
+ clearAutomationClipboard();
298
+ usePlayerStore.setState({
299
+ elements: [{ ...bgmElement, duration: 10 }],
300
+ selectedElementId: "bgm",
301
+ });
302
+ usePlayerStore
303
+ .getState()
304
+ .setAutomationSelection(wholeAxis({ elementKey: "bgm", target: "volume", t0: 2, t1: 4 }));
305
+ let land = () => {};
306
+ const onCommit = vi.fn(
307
+ () =>
308
+ new Promise<typeof outcome>((resolve) => {
309
+ land = () => resolve(outcome);
310
+ }),
311
+ );
312
+ setup({ onCommit });
313
+ combo("c");
314
+ combo("v");
315
+ const drawn = wholeAxis({ elementKey: "bgm", target: "volume", t0: 6, t1: 8 });
316
+ usePlayerStore.getState().setAutomationSelection(drawn);
317
+ land();
318
+ await act(async () => {});
319
+ expect(usePlayerStore.getState().automationSelection).toEqual(drawn);
320
+ },
321
+ );
322
+
323
+ it.each(["in order", "reversed"])(
324
+ "marks the latest paste when pastes on two clips resolve %s",
325
+ async (order) => {
326
+ clearAutomationClipboard();
327
+ usePlayerStore.setState({
328
+ elements: [
329
+ { ...bgmElement, duration: 10 },
330
+ { ...bgmElement, id: "vo", key: "vo", duration: 10 },
331
+ ],
332
+ selectedElementId: "bgm",
333
+ currentTime: 1,
334
+ });
335
+ usePlayerStore
336
+ .getState()
337
+ .setAutomationSelection(wholeAxis({ elementKey: "bgm", target: "volume", t0: 2, t1: 4 }));
338
+ const lands: Array<() => void> = [];
339
+ const onCommit = vi.fn(
340
+ () =>
341
+ new Promise<{ status: "saved" }>((resolve) =>
342
+ lands.push(() => resolve({ status: "saved" })),
343
+ ),
344
+ );
345
+ setup({ onCommit });
346
+ combo("c");
347
+ usePlayerStore.getState().clearAutomationSelection();
348
+ combo("v");
349
+ usePlayerStore.setState({ selectedElementId: "vo" });
350
+ combo("v");
351
+ const order_ = order === "in order" ? [0, 1] : [1, 0];
352
+ for (const i of order_) lands[i]?.();
353
+ await act(async () => {});
354
+ expect(usePlayerStore.getState().automationSelection?.elementKey).toBe("vo");
355
+ },
356
+ );
357
+
358
+ it("does not mark a paste whose clip was left before it landed", async () => {
359
+ clearAutomationClipboard();
360
+ usePlayerStore.setState({
361
+ elements: [
362
+ { ...bgmElement, duration: 10 },
363
+ { ...bgmElement, id: "vo", key: "vo", duration: 10 },
364
+ ],
365
+ selectedElementId: "bgm",
366
+ currentTime: 1,
367
+ });
368
+ usePlayerStore
369
+ .getState()
370
+ .setAutomationSelection(wholeAxis({ elementKey: "bgm", target: "volume", t0: 2, t1: 4 }));
371
+ let land = () => {};
372
+ const onCommit = vi.fn(
373
+ () =>
374
+ new Promise<{ status: "saved" }>((resolve) => {
375
+ land = () => resolve({ status: "saved" });
376
+ }),
377
+ );
378
+ setup({ onCommit });
379
+ combo("c");
380
+ usePlayerStore.getState().clearAutomationSelection();
381
+ combo("v");
382
+ usePlayerStore.setState({ selectedElementId: "vo" });
383
+ land();
384
+ await act(async () => {});
385
+ expect(usePlayerStore.getState().automationSelection).toBeNull();
386
+ });
387
+
388
+ it("chains a second Cmd+V after the first instead of overwriting it", async () => {
272
389
  // The regression this pins: paste leaves its own span selected, so anchoring
273
390
  // at sel.t0 unconditionally made every later press recompute the same atT.
274
391
  clearAutomationClipboard();
@@ -288,6 +405,7 @@ describe("useAutomationSelectionKeyboard", () => {
288
405
  );
289
406
  expect(first).toContain(2);
290
407
  expect(first).toContain(4);
408
+ await act(async () => {});
291
409
 
292
410
  combo("v");
293
411
  const second = (onCommit.mock.calls.at(-1)?.[0]?.lanes?.[0]?.points ?? []).map(
@@ -295,6 +413,7 @@ describe("useAutomationSelectionKeyboard", () => {
295
413
  );
296
414
  expect(second).toContain(4);
297
415
  expect(second).toContain(6);
416
+ await act(async () => {});
298
417
  expect(usePlayerStore.getState().automationSelection).toEqual({
299
418
  elementKey: "bgm",
300
419
  target: "volume",
@@ -308,7 +427,7 @@ describe("useAutomationSelectionKeyboard", () => {
308
427
  });
309
428
  });
310
429
 
311
- it("Cmd+V at a selection near the clip's end clamps the paste inside its duration", () => {
430
+ it("Cmd+V at a selection near the clip's end clamps the paste inside its duration", async () => {
312
431
  // The playhead branch already clamps to duration - span; the
313
432
  // selection-start branch didn't, so pasting a 2s clip at a selection
314
433
  // sitting at t0=5.5 on a 6s clip used to write points out to t=7.5 —
@@ -334,6 +453,7 @@ describe("useAutomationSelectionKeyboard", () => {
334
453
  expect(t).toBeLessThanOrEqual(bgmElement.duration);
335
454
  }
336
455
  // Clamped to duration (6) - span (2) = 4, not the unclamped 5.5.
456
+ await act(async () => {});
337
457
  expect(usePlayerStore.getState().automationSelection).toEqual({
338
458
  elementKey: "bgm",
339
459
  target: "volume",
@@ -347,22 +467,6 @@ describe("useAutomationSelectionKeyboard", () => {
347
467
  });
348
468
  });
349
469
 
350
- it("refuses to paste when the dom-edit layer would write to a different clip", () => {
351
- // selectedElementId says "bgm" but the commit channel is still on the
352
- // previously selected clip — writing here would serialize bgm's automation
353
- // onto that other clip and leave bgm untouched.
354
- clearAutomationClipboard();
355
- copyRange(null, { target: "volume", points: [{ t: 0, v: 0.5 }] }, VOLUME_RANGE, 0, 2);
356
- usePlayerStore.setState({ elements: [bgmElement], selectedElementId: "bgm" });
357
- usePlayerStore
358
- .getState()
359
- .setAutomationSelection(wholeAxis({ elementKey: "bgm", target: "volume", t0: 2, t1: 4 }));
360
- const { onCommit } = setup({ commitTargetKey: "some-other-clip" });
361
- const e = combo("v");
362
- expect(e.defaultPrevented).toBe(false);
363
- expect(onCommit).not.toHaveBeenCalled();
364
- });
365
-
366
470
  it("does not paste from a playhead outside the clip", () => {
367
471
  // No selection on this clip, and the playhead is past its end — there is no
368
472
  // anchor. This used to collapse to the clip's own t=0.
@@ -108,7 +108,7 @@ function resolveDeleteWrite(
108
108
  state: PlayerState,
109
109
  lanes: UseAutomationLanesResult,
110
110
  sel: AutomationSelection,
111
- ): { onCommit(next: HfAutomation): void; next: HfAutomation } | null {
111
+ ): { onCommit: AutomationLaneBinding["onCommit"]; next: HfAutomation } | null {
112
112
  const ctx = resolveSelectionContext(state, lanes, sel);
113
113
  if (!ctx) return null;
114
114
  const points = ctx.lane.points.filter((p) => !pointInSelection(p, sel));
@@ -139,18 +139,7 @@ function pasteTargetName(
139
139
 
140
140
  /**
141
141
  * Where Cmd+V lands, or null when nothing is selected, the clip's lanes are
142
- * read-only, it has no automation lane to fall back to, or the dom-edit layer
143
- * would write the result to a DIFFERENT clip.
144
- *
145
- * That last guard is the one with teeth. `binding.onCommit` persists through
146
- * handleDomAttributeQuietCommit, which targets whatever the dom-edit layer
147
- * currently has selected — not the element `bind()` was handed (see the
148
- * doc-comment on `onSelect` in useAutomationLanes). Selecting a clip in the
149
- * timeline sets `selectedElementId` synchronously but resolves the dom-edit
150
- * selection asynchronously, so clicking clip B and immediately pressing Cmd+V
151
- * would serialize B's automation onto A. Every other lane path is a pointer
152
- * gesture on the lane itself, which cannot run before the selection lands;
153
- * paste is the only one that can, so it refuses rather than write blind.
142
+ * read-only, or it has no automation lane to fall back to.
154
143
  */
155
144
  function resolvePasteTarget(
156
145
  state: PlayerState,
@@ -169,7 +158,6 @@ function resolvePasteTarget(
169
158
  const elementKey = elementKeyOf(element);
170
159
  const binding = lanes.bind(element, true);
171
160
  if (binding.readOnly) return null;
172
- if (binding.commitTargetKey !== elementKey) return null;
173
161
  const target = pasteTargetName(binding, elementKey, sel);
174
162
  if (!target) return null;
175
163
  const range = resolveAutomationRange(target, binding.chain ?? undefined);
@@ -225,6 +213,8 @@ function pasteAnchor(
225
213
  return clampNumber(raw, 0, element.duration - span);
226
214
  }
227
215
 
216
+ let latestPaste = 0;
217
+
228
218
  /**
229
219
  * Cmd/Ctrl+V: paste the clipboard onto the selected clip's lane, at the active
230
220
  * selection or the playhead. Returns false (untouched event) when the chord
@@ -252,12 +242,10 @@ function handlePaste(
252
242
 
253
243
  e.preventDefault();
254
244
  e.stopImmediatePropagation();
255
- paste.binding.onCommit(withLane(paste.binding.automation, { target: paste.target, points }));
256
- // Select the pasted span — the only feedback that it landed — and mark it, so
257
- // an immediate second Cmd+V recognises this selection as the paste's own and
258
- // chains right after it instead of overwriting it.
259
- // Full-height box over the pasted span: everything that landed is selected, so
260
- // Delete straight after a paste undoes it in one press.
245
+ const saved = paste.binding.onCommit(
246
+ withLane(paste.binding.automation, { target: paste.target, points }),
247
+ );
248
+ const seq = ++latestPaste;
261
249
  const mark = {
262
250
  elementKey: paste.elementKey,
263
251
  target: paste.target,
@@ -266,8 +254,17 @@ function handlePaste(
266
254
  v0: paste.range.min,
267
255
  v1: paste.range.max,
268
256
  };
269
- state.setAutomationSelection(mark);
270
- markLastPaste(mark);
257
+ // Once the latest paste lands, and only over the selection it was pasted at, select
258
+ // and mark its full-height span: the feedback that it landed, what a second Cmd+V
259
+ // chains after, and what Delete takes back in one press.
260
+ void saved.then((outcome) => {
261
+ if (outcome && outcome.status !== "saved") return;
262
+ const current = usePlayerStore.getState();
263
+ const moved = current.selectedElementId !== state.selectedElementId;
264
+ if (seq !== latestPaste || moved || current.automationSelection !== sel) return;
265
+ current.setAutomationSelection(mark);
266
+ markLastPaste(mark);
267
+ });
271
268
  return true;
272
269
  }
273
270
 
@@ -300,8 +297,7 @@ function handleCopy(
300
297
  *
301
298
  * Store and clipboard only, no lane binding, so the dispatcher can call it
302
299
  * without holding the binding factory. That leaves one accepted residual: the
303
- * predicate cannot see a read-only lane, an unresolvable target, or the
304
- * dom-edit target mismatch `resolvePasteTarget` guards, so in those rare cases
300
+ * predicate cannot see a read-only lane or an unresolvable target, so in those rare cases
305
301
  * the keystroke is a no-op instead of falling through to clip copy/paste. A
306
302
  * dead key beats today's double write.
307
303
  */
@@ -333,7 +329,7 @@ function handleDelete(
333
329
  if (!write) return false;
334
330
  e.preventDefault();
335
331
  e.stopImmediatePropagation();
336
- write.onCommit(write.next);
332
+ void write.onCommit(write.next);
337
333
  return true;
338
334
  }
339
335