Skip to content

Commit d681b7a

Browse files
committed
feat(studio): cap by the clips an edit would change, and cut the added comments
The 3-clip rule counts the clips a move or trim would write to: a locked clip swept into a move stays put, and a trim some member cannot take edits only the grabbed clip. Comment share is back at or under the base in every changed file.
1 parent 87a97fa commit d681b7a

11 files changed

Lines changed: 54 additions & 42 deletions

‎packages/studio-server/src/helpers/compositionInputs.ts‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,11 @@ function closureOf(read: SourceReader, compPath: string): Set<string> {
5454
const inputSignatures = new Map<string, { projectSignature: string; inputSignature: string }>();
5555

5656
interface RootMemo {
57-
/** Hash of the whole root file this memo answers for. */
5857
root: string;
5958
head: string;
60-
/** What `compositionsAffectedBy` told every subscriber for that root content. */
6159
affected: string[] | null;
6260
}
6361

64-
/** Per project, the last root content announced to watchers; thumbnail requests only seed it. */
6562
const rootMemos = new Map<string, RootMemo>();
6663

6764
const sha1 = (text: string) => createHash("sha1").update(text).digest("hex");
@@ -72,8 +69,7 @@ function rootHashes(read: SourceReader) {
7269
}
7370

7471
// What a thumbnail of `compPath` renders from: the project minus the compositions the root
75-
// mounts that `compPath` does not. A scene's page borrows only the root's head, so for a scene
76-
// the root counts as its head alone; the root's own thumbnail renders all of it.
72+
// mounts that `compPath` does not; for a scene the root counts as its head alone.
7773
export function compositionInputSignature(
7874
projectDir: string,
7975
compPath: string,
@@ -103,8 +99,7 @@ export function compositionInputSignature(
10399
/**
104100
* Compositions whose rendered frames a write at `changedPath` can change, or `null` for all
105101
* of them: assets, a root head edit, and any file the root does not mount reach every
106-
* composition. A root write that leaves the head as it was changes only the root's own frames.
107-
* Every subscriber asking about the same root content gets the same answer.
102+
* composition. A head-preserving root write changes only the root's own frames.
108103
*/
109104
export function compositionsAffectedBy(projectDir: string, changedPath: string): string[] | null {
110105
const changed = changedPath.replace(/\\/g, "/");

‎packages/studio-server/src/helpers/subComposition.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ function tagRootCompositionFile(bodyHtml: string, compPath: string): string {
236236
);
237237
}
238238

239-
/** The root document's `<head>` content: the only part of the root a sub-composition page borrows. */
240239
export function rootHeadContent(rootHtml: string): string {
241240
return rootHtml.match(/<head[^>]*>([\s\S]*?)<\/head>/i)?.[1] ?? "";
242241
}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ export function readFileChangeAffectedCompositions(payload: unknown): readonly s
4444
return value.map(normalizeStudioFileChangePath);
4545
}
4646

47-
/**
48-
* `incoming` replacing a `waiting` change must not forget what `waiting` invalidated: the
49-
* result carries both lists, or "all" when either said so.
50-
*/
5147
export function mergeFileChangeAffectedCompositions(waiting: unknown, incoming: unknown): unknown {
5248
const before = readFileChangeAffectedCompositions(waiting);
5349
const after = readFileChangeAffectedCompositions(incoming);

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ interface PendingProbe {
77
resolve: (exists: boolean) => void;
88
}
99

10-
/** Probes asked for in the same tick, one batch per project file. */
1110
const pending = new Map<string, PendingProbe[]>();
1211

1312
async function sendBatch(projectId: string, sourceFile: string, probes: PendingProbe[]) {
14-
// Any failure reads as "exists": a probe that cannot answer must not strip capabilities.
1513
let exists: boolean[] = [];
1614
try {
1715
const response = await fetch(
@@ -29,16 +27,10 @@ async function sendBatch(projectId: string, sourceFile: string, probes: PendingP
2927
const data = await response.json();
3028
if (Array.isArray(data?.exists)) exists = data.exists;
3129
}
32-
} catch {
33-
// Network failure reads as "exists" too.
34-
}
30+
} catch {}
3531
probes.forEach((probe, index) => probe.resolve(exists[index] !== false));
3632
}
3733

38-
/**
39-
* Whether the element still exists in its source file. A selection of N elements asks N times
40-
* in one tick; the asks for one file leave as a single request.
41-
*/
4234
export function probeSourceElement(
4335
projectId: string,
4436
sourceFile: string,

‎packages/studio/src/hooks/keyframeCacheAstLoad.ts‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,8 @@ async function requestParsedAnimations(
8181
try {
8282
const res = await fetch(
8383
`/api/projects/${encodeURIComponent(projectId)}/gsap-animations/${encodeURIComponent(sourceFile)}`,
84-
// Always revalidate against the source; the server answers 304 for a file that did not
85-
// change, so a write elsewhere costs no re-parse here. No per-call timestamp (a
86-
// deterministic-render no-no).
84+
// Always revalidate; an unchanged file answers 304. No per-call timestamp
85+
// (a deterministic-render no-no).
8786
{ cache: "no-cache" },
8887
);
8988
if (!res.ok) return null;
@@ -99,8 +98,8 @@ async function requestParsedAnimations(
9998
}
10099

101100
/**
102-
* Read one composition file's tweens into the keyframe cache; false when the read failed.
103-
* Split out of the hook so the effect can run it per file without re-nesting the whole body.
101+
* Read one composition file's tweens into the keyframe cache. Split out of the
102+
* hook so the effect can run it per file without re-nesting the whole body.
104103
*/
105104
// fallow-ignore-next-line complexity
106105
export async function populateKeyframeCacheFromAst(

‎packages/studio/src/hooks/useGsapTweenCache.ts‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,6 @@ export function usePopulateKeyframeCacheForFile(
290290
const domClipChildrenKey = usePlayerStore((s) =>
291291
s.domClipChildren.map((c) => `${c.id}<${c.hostId}`).join("|"),
292292
);
293-
// What each file's cache entries were last loaded for. Switching `sourceFile` to a
294-
// file that is already loaded for the current data must not refetch the others.
295293
const loadedRef = useRef<{ dataKey: string; files: Set<string> }>({
296294
dataKey: "",
297295
files: new Set(),
@@ -311,8 +309,6 @@ export function usePopulateKeyframeCacheForFile(
311309
);
312310
const sameData = loadedRef.current.dataKey === dataKey;
313311
const stale = sameData ? files.filter((sf) => !loadedRef.current.files.has(sf)) : files;
314-
// Flipping `sourceFile` among files already covered keeps all of them; only new data
315-
// (another composition, a write) narrows the set back to what is on screen.
316312
const covered = sameData ? new Set([...loadedRef.current.files, ...files]) : new Set(files);
317313
loadedRef.current = { dataKey, files: covered };
318314
// Everything the previous scan cached for a file this one no longer covers
@@ -323,7 +319,6 @@ export function usePopulateKeyframeCacheForFile(
323319
const doc = iframeRef?.current?.contentDocument;
324320
for (const sf of stale) {
325321
void populateKeyframeCacheFromAst(projectId, sf, doc).then((loaded) => {
326-
// A failed read is not loaded: the next selection flip asks for it again.
327322
if (!loaded && loadedRef.current.dataKey === dataKey) loadedRef.current.files.delete(sf);
328323
});
329324
}

‎packages/studio/src/player/components/timelineClipGestureHandlers.test.ts‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,19 @@ afterEach(() => usePlayerStore.getState().reset());
1010

1111
const clips: TimelineElement[] = Array.from({ length: 6 }, (_, i) => ({
1212
id: `clip-${i}`,
13+
domId: `clip-${i}`,
1314
tag: "div",
1415
start: i,
1516
duration: 1,
1617
track: i,
1718
}));
1819
const capabilities = { canMove: true, canTrimStart: true, canTrimEnd: true, readOnly: false };
1920

20-
function grabFirstClip(count: number, gesture: "move" | "resize") {
21+
function grabFirstClip(count: number, gesture: "move" | "resize", locked: number[] = []) {
2122
const store = usePlayerStore.getState();
22-
store.setElements(clips);
23+
store.setElements(
24+
clips.map((clip, i) => (locked.includes(i) ? { ...clip, timelineLocked: true } : clip)),
25+
);
2326
store.setSelectedElementIds(new Set(clips.slice(0, count).map((c) => c.id)));
2427
const setDraggedClip = vi.fn();
2528
const setResizingClip = vi.fn();
@@ -75,4 +78,17 @@ describe("hand-editing a multi-selection", () => {
7578
expect(setResizingClip).not.toHaveBeenCalled();
7679
expect(blockedClipRef.current?.intent).toBe("edit-many");
7780
});
81+
82+
it("counts the clips a move would change: locked ones in the selection stay put", () => {
83+
const allowed = grabFirstClip(MAX_HAND_EDIT_CLIPS + 2, "move", [3, 4]);
84+
expect(allowed.setDraggedClip).toHaveBeenCalledOnce();
85+
const refused = grabFirstClip(MAX_HAND_EDIT_CLIPS + 2, "move", [4]);
86+
expect(refused.setDraggedClip).not.toHaveBeenCalled();
87+
});
88+
89+
it("counts the clips a trim would change: a locked member leaves a trim of the grabbed clip alone", () => {
90+
const allowed = grabFirstClip(MAX_HAND_EDIT_CLIPS + 1, "resize", [3]);
91+
expect(allowed.setResizingClip).toHaveBeenCalledOnce();
92+
expect(allowed.blockedClipRef.current).toBeNull();
93+
});
7894
});

‎packages/studio/src/player/components/timelineClipGestureHandlers.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ function resolvePointerDownAction(
9898
}
9999

100100
if (!onMoveElement || !capabilities.canMove) return { kind: "ignore" };
101-
if (exceedsHandEditLimit(grabbed, e.altKey)) return { kind: "block", intent: "edit-many", rect };
101+
if (exceedsHandEditLimit(grabbed, e.altKey, null))
102+
return { kind: "block", intent: "edit-many", rect };
102103
return { kind: "move", rect };
103104
}
104105

@@ -135,7 +136,7 @@ export function createClipGestureHandlers(
135136
const onResizeStart = (edge: "start" | "end", e: ReactPointerEvent): void => {
136137
if (!canStartResize(edge, e, capabilities, onResizeElement)) return;
137138
e.stopPropagation();
138-
if (exceedsHandEditLimit(el, e.altKey)) {
139+
if (exceedsHandEditLimit(el, e.altKey, edge)) {
139140
blockedClipRef.current = {
140141
pointerId: e.pointerId,
141142
element: el,

‎packages/studio/src/player/components/timelineEditing.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ export interface TimelinePromptElement {
250250

251251
export type BlockedTimelineEditIntent = "move" | "edit-many" | "resize-start" | "resize-end";
252252

253-
/** Most clips a hand drag moves or resizes at once; a larger selection goes through the prompt box. */
254253
export const MAX_HAND_EDIT_CLIPS = 3;
255254

256255
export interface TimelineRangeSelection {

‎packages/studio/src/player/components/timelineLinkSelection.ts‎

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { usePlayerStore, type TimelineElement } from "../store/playerStore";
2-
import { expandToLinkedMembers, linkedGestureKeys, linkedMembersOf } from "./audioClipLink";
2+
import {
3+
dropMisalignedTrimPartners,
4+
expandToLinkedMembers,
5+
linkedGestureKeys,
6+
linkedMembersOf,
7+
} from "./audioClipLink";
8+
import { buildTimelineGroupResizeMembers } from "./timelineGroupEditing";
9+
import { resolveGroupMovers } from "./timelineMultiDragPreview";
310
import { MAX_HAND_EDIT_CLIPS } from "./timelineEditing";
411
import { isLinkedSelectionOn } from "../../utils/linkedClipPreferences";
512

@@ -41,15 +48,28 @@ export function toggleClipWithLinks(key: string, altKey: boolean): TimelineEleme
4148
return state.elements.find((el) => (el.key ?? el.id) === primary) ?? null;
4249
}
4350

44-
/** Whether grabbing `grabbed` would move or resize more clips by hand than a hand drag allows. */
45-
export function exceedsHandEditLimit(grabbed: TimelineElement, altKey: boolean): boolean {
51+
/** Whether a hand drag grabbing `grabbed` (trimming `edge`, or null for a move) would change more clips than allowed. */
52+
export function exceedsHandEditLimit(
53+
grabbed: TimelineElement,
54+
altKey: boolean,
55+
edge: "start" | "end" | null,
56+
): boolean {
4657
const { selectedElementIds, elements } = usePlayerStore.getState();
47-
const moved = linkedGestureKeys(
58+
const grabbedKey = grabbed.key ?? grabbed.id;
59+
const keys = linkedGestureKeys(
4860
selectedElementIds,
4961
grabbed,
5062
elements,
5163
altKey,
5264
isLinkedSelectionOn(),
5365
);
54-
return moved.size > MAX_HAND_EDIT_CLIPS;
66+
const changed = edge
67+
? buildTimelineGroupResizeMembers(
68+
elements,
69+
dropMisalignedTrimPartners(keys, grabbed, elements, edge),
70+
grabbedKey,
71+
edge,
72+
)
73+
: resolveGroupMovers(elements, keys, grabbedKey);
74+
return (changed?.length ?? 1) > MAX_HAND_EDIT_CLIPS;
5575
}

0 commit comments

Comments
 (0)