@hyperframes/studio 0.9.14 → 0.9.16
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.
- package/dist/assets/{hyperframes-player-CfYFgHV8.js → hyperframes-player-Bb-Fbf5k.js} +1 -1
- package/dist/assets/{index-COfhX0Gz.js → index-BZuKog_A.js} +139 -139
- package/dist/assets/{index-RUPGNyct.css → index-CNZk2EFC.css} +1 -1
- package/dist/assets/{index-Cj5x3rVD.js → index-Cap2SGKw.js} +1 -1
- package/dist/index.d.ts +17 -7
- package/dist/index.html +2 -2
- package/dist/index.js +112 -55
- package/dist/styles.css +1 -1
- package/package.json +8 -8
- package/src/components/editor/DomEditOverlay.tsx +3 -1
- package/src/components/editor/MarqueeOverlay.tsx +12 -4
- package/src/components/editor/marqueeCommit.test.tsx +137 -4
- package/src/components/editor/marqueeCommit.ts +30 -16
- package/src/components/editor/previewReadOnly.overlay.test.tsx +1 -1
- package/src/components/panels/motionBlurPanelModel.test.ts +1 -0
- package/src/editorGesturesExports.test.tsx +10 -4
- package/src/hooks/useDomSelection.test.ts +90 -9
- package/src/hooks/useDomSelection.ts +21 -9
- package/src/hooks/useDomSelectionTypes.ts +5 -1
- package/src/hooks/useStudioUrlState.ts +3 -2
- package/src/hooks/useTimelineSelectionPreviewSync.test.tsx +6 -2
- package/src/hooks/useTimelineSelectionPreviewSync.ts +3 -2
- package/src/index.ts +6 -1
- package/src/player/components/TimelineCanvas.tsx +11 -3
- package/src/player/components/TimelineProvider.tsx +2 -2
- package/src/player/components/timelineMarquee.test.ts +68 -0
- package/src/player/components/timelineMarquee.ts +17 -5
- package/src/player/components/timelineMarqueeCommit.ts +74 -0
- package/src/player/components/useTimelineRangeSelection.test.tsx +98 -4
- package/src/player/components/useTimelineRangeSelection.ts +53 -103
- package/src/styles/theme.css +1 -0
- package/src/utils/marqueeGeometry.test.ts +18 -1
- package/src/utils/marqueeGeometry.ts +20 -0
- package/src/utils/studioUrlState.test.ts +1 -1
|
@@ -22,6 +22,7 @@ import { reapplyPositionEditsAfterSeek } from "../components/editor/manualEdits"
|
|
|
22
22
|
import { holdScenesOf } from "../utils/sceneHold";
|
|
23
23
|
import { useStudioTestHooks } from "./useStudioTestHooks";
|
|
24
24
|
import { logSelect } from "../utils/selectDebug";
|
|
25
|
+
import type { MarqueeSelectionMode } from "../utils/marqueeGeometry";
|
|
25
26
|
import { announceTimelineSelection as announceSelectionToTimeline } from "./domSelectionTimelineMirror";
|
|
26
27
|
import type {
|
|
27
28
|
ApplyDomSelectionOptions,
|
|
@@ -490,30 +491,41 @@ export function useDomSelection({
|
|
|
490
491
|
|
|
491
492
|
const applyMarqueeSelection = useCallback(
|
|
492
493
|
// fallow-ignore-next-line complexity
|
|
493
|
-
(selections: DomEditSelection[],
|
|
494
|
-
logSelect("marquee", { hits: selections.length,
|
|
494
|
+
(selections: DomEditSelection[], mode: MarqueeSelectionMode) => {
|
|
495
|
+
logSelect("marquee", { hits: selections.length, mode });
|
|
495
496
|
const current = domEditSelectionRef.current;
|
|
496
497
|
const currentGroup = domEditGroupSelectionsRef.current;
|
|
498
|
+
const previous = seedDomEditGroupWithSelection(currentGroup, current);
|
|
499
|
+
const replace = mode === "replace";
|
|
497
500
|
if (selections.length === 0) {
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
return { changed: !additive && count > 0, count: additive ? count : 0 };
|
|
501
|
+
if (replace) applyDomSelection(null, { revealPanel: false });
|
|
502
|
+
return { changed: replace && previous.length > 0, count: replace ? 0 : previous.length };
|
|
501
503
|
}
|
|
502
504
|
let nextGroup: DomEditSelection[];
|
|
503
|
-
|
|
504
|
-
|
|
505
|
+
let nextSelection: DomEditSelection | undefined;
|
|
506
|
+
if (mode === "add") {
|
|
507
|
+
nextGroup = previous;
|
|
505
508
|
for (const s of selections) {
|
|
506
509
|
if (!domEditSelectionInGroup(nextGroup, s)) nextGroup = [...nextGroup, s];
|
|
507
510
|
}
|
|
511
|
+
nextSelection = current ?? selections[0];
|
|
512
|
+
} else if (mode === "subtract") {
|
|
513
|
+
nextGroup = previous.filter((entry) => !domEditSelectionInGroup(selections, entry));
|
|
514
|
+
if (nextGroup.length === 0) {
|
|
515
|
+
applyDomSelection(null, { revealPanel: false });
|
|
516
|
+
return { changed: previous.length > 0, count: 0 };
|
|
517
|
+
}
|
|
518
|
+
// Subtracting the primary re-anchors on the first survivor.
|
|
519
|
+
nextSelection =
|
|
520
|
+
current && domEditSelectionInGroup(nextGroup, current) ? current : nextGroup[0];
|
|
508
521
|
} else {
|
|
509
522
|
// Dedupe by target: select-as-unit collapses marquee'd members to one group.
|
|
510
523
|
nextGroup = [];
|
|
511
524
|
for (const s of selections) {
|
|
512
525
|
if (!domEditSelectionInGroup(nextGroup, s)) nextGroup.push(s);
|
|
513
526
|
}
|
|
527
|
+
nextSelection = selections[0];
|
|
514
528
|
}
|
|
515
|
-
const nextSelection = additive && current ? current : selections[0];
|
|
516
|
-
const previous = seedDomEditGroupWithSelection(currentGroup, current);
|
|
517
529
|
const changed =
|
|
518
530
|
previous.length !== nextGroup.length ||
|
|
519
531
|
nextGroup.some((selection) => !domEditSelectionInGroup(previous, selection)) ||
|
|
@@ -2,6 +2,7 @@ import type { Dispatch, MutableRefObject, SetStateAction } from "react";
|
|
|
2
2
|
import type { DomEditSelection } from "../components/editor/domEditing";
|
|
3
3
|
import type { SelectElementOptions, TimelineElement } from "../player";
|
|
4
4
|
import type { RightPanelTab } from "../utils/studioHelpers";
|
|
5
|
+
import type { MarqueeSelectionMode } from "../utils/marqueeGeometry";
|
|
5
6
|
|
|
6
7
|
export interface DomSelectionResult {
|
|
7
8
|
changed: boolean;
|
|
@@ -93,5 +94,8 @@ export interface UseDomSelectionReturn {
|
|
|
93
94
|
selection: DomEditSelection,
|
|
94
95
|
iframe?: HTMLIFrameElement | null,
|
|
95
96
|
) => Promise<void>;
|
|
96
|
-
applyMarqueeSelection: (
|
|
97
|
+
applyMarqueeSelection: (
|
|
98
|
+
selections: DomEditSelection[],
|
|
99
|
+
mode: MarqueeSelectionMode,
|
|
100
|
+
) => DomSelectionResult;
|
|
97
101
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
2
|
import { usePlayerStore } from "../player";
|
|
3
3
|
import { findElementForSelection, type DomEditSelection } from "../components/editor/domEditing";
|
|
4
|
+
import type { MarqueeSelectionMode } from "../utils/marqueeGeometry";
|
|
4
5
|
import { clampNumber, type RightPanelTab } from "../utils/studioHelpers";
|
|
5
6
|
import { parseProjectIdFromHash } from "../utils/projectRouting";
|
|
6
7
|
import {
|
|
@@ -24,7 +25,7 @@ interface UseStudioUrlStateParams {
|
|
|
24
25
|
activeCompPathHydrated: boolean;
|
|
25
26
|
domEditSelection: DomEditSelection | null;
|
|
26
27
|
domEditGroupSelections: DomEditSelection[];
|
|
27
|
-
applyMarqueeSelection: (selections: DomEditSelection[],
|
|
28
|
+
applyMarqueeSelection: (selections: DomEditSelection[], mode: MarqueeSelectionMode) => void;
|
|
28
29
|
buildDomSelectionFromTarget: (
|
|
29
30
|
target: HTMLElement,
|
|
30
31
|
options?: { preferClipAncestor?: boolean; skipSourceProbe?: boolean },
|
|
@@ -252,7 +253,7 @@ export function useStudioUrlState({
|
|
|
252
253
|
if (!primary) return applyDomSelection(null, { revealPanel: false });
|
|
253
254
|
if (group.length === 0) return applyDomSelection(primary, { revealPanel: false });
|
|
254
255
|
// Missing group members are dropped without failing the rest.
|
|
255
|
-
applyMarqueeSelection(members,
|
|
256
|
+
applyMarqueeSelection(members, "replace");
|
|
256
257
|
});
|
|
257
258
|
return true;
|
|
258
259
|
},
|
|
@@ -5,6 +5,7 @@ import { createRoot } from "react-dom/client";
|
|
|
5
5
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
6
6
|
import type { TimelineElement } from "../player";
|
|
7
7
|
import type { DomEditSelection } from "../components/editor/domEditing";
|
|
8
|
+
import type { MarqueeSelectionMode } from "../utils/marqueeGeometry";
|
|
8
9
|
import { installReactActEnvironment, makeSelection } from "./domSelectionTestHarness";
|
|
9
10
|
import { useTimelineSelectionPreviewSync } from "./useTimelineSelectionPreviewSync";
|
|
10
11
|
|
|
@@ -23,7 +24,7 @@ interface HarnessProps {
|
|
|
23
24
|
selection: DomEditSelection | null,
|
|
24
25
|
options?: { revealPanel?: boolean; additive?: boolean; preserveGroup?: boolean },
|
|
25
26
|
) => void;
|
|
26
|
-
applyMarqueeSelection: (selections: DomEditSelection[],
|
|
27
|
+
applyMarqueeSelection: (selections: DomEditSelection[], mode: MarqueeSelectionMode) => void;
|
|
27
28
|
onSelectionNotFound: () => void;
|
|
28
29
|
}
|
|
29
30
|
|
|
@@ -100,7 +101,10 @@ describe("useTimelineSelectionPreviewSync", () => {
|
|
|
100
101
|
onSelectionNotFound: vi.fn(),
|
|
101
102
|
});
|
|
102
103
|
|
|
103
|
-
expect(applyMarqueeSelection).toHaveBeenCalledWith(
|
|
104
|
+
expect(applyMarqueeSelection).toHaveBeenCalledWith(
|
|
105
|
+
[secondSelection, firstSelection],
|
|
106
|
+
"replace",
|
|
107
|
+
);
|
|
104
108
|
expect(applyDomSelection).not.toHaveBeenCalled();
|
|
105
109
|
harness.cleanup();
|
|
106
110
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useEffect, useMemo, useRef } from "react";
|
|
2
2
|
import type { TimelineElement } from "../player";
|
|
3
3
|
import type { DomEditSelection } from "../components/editor/domEditing";
|
|
4
|
+
import type { MarqueeSelectionMode } from "../utils/marqueeGeometry";
|
|
4
5
|
import { resolveTimelineIdForSelection } from "../utils/studioHelpers";
|
|
5
6
|
import { logSelect } from "../utils/selectDebug";
|
|
6
7
|
import { recordRetryAttempt, type RetryBudgetState } from "../utils/retryBudget";
|
|
@@ -24,7 +25,7 @@ interface UseTimelineSelectionPreviewSyncParams {
|
|
|
24
25
|
announce?: boolean;
|
|
25
26
|
},
|
|
26
27
|
) => void;
|
|
27
|
-
applyMarqueeSelection: (selections: DomEditSelection[],
|
|
28
|
+
applyMarqueeSelection: (selections: DomEditSelection[], mode: MarqueeSelectionMode) => void;
|
|
28
29
|
onSelectionNotFound: () => void;
|
|
29
30
|
}
|
|
30
31
|
|
|
@@ -96,7 +97,7 @@ function applyResolvedSelections(
|
|
|
96
97
|
} else if (selections.length === 1) {
|
|
97
98
|
applyDomSelection(selections[0]);
|
|
98
99
|
} else {
|
|
99
|
-
applyMarqueeSelection(selections,
|
|
100
|
+
applyMarqueeSelection(selections, "replace");
|
|
100
101
|
}
|
|
101
102
|
}
|
|
102
103
|
|
package/src/index.ts
CHANGED
|
@@ -282,7 +282,12 @@ export { useMarqueeGestures } from "./components/editor/marqueeCommit";
|
|
|
282
282
|
export type { MarqueeGestures, MarqueeGesturesDeps } from "./components/editor/marqueeCommit";
|
|
283
283
|
export { MarqueeOverlay } from "./components/editor/MarqueeOverlay";
|
|
284
284
|
export type { MarqueeOverlayProps } from "./components/editor/MarqueeOverlay";
|
|
285
|
-
export type {
|
|
285
|
+
export type {
|
|
286
|
+
Rect as MarqueeRect,
|
|
287
|
+
MarqueeBand,
|
|
288
|
+
MarqueeSelectionMode,
|
|
289
|
+
} from "./utils/marqueeGeometry";
|
|
290
|
+
export { resolveMarqueeMode } from "./utils/marqueeGeometry";
|
|
286
291
|
|
|
287
292
|
export { buildStudioTools } from "./webmcp/useStudioAgentTools";
|
|
288
293
|
export type { StudioAgentToolsDeps } from "./webmcp/useStudioAgentTools";
|
|
@@ -226,18 +226,26 @@ export const TimelineCanvas = memo(function TimelineCanvas() {
|
|
|
226
226
|
/>
|
|
227
227
|
|
|
228
228
|
{/* Marquee (rubber-band) multi-select rectangle — mirrors the canvas
|
|
229
|
-
MarqueeOverlay look:
|
|
229
|
+
MarqueeOverlay look: dashed accent border, danger-coloured while subtracting. */}
|
|
230
230
|
{props.marqueeRect && (
|
|
231
231
|
<div
|
|
232
232
|
aria-hidden="true"
|
|
233
|
+
data-marquee-mode={props.marqueeRect.mode}
|
|
233
234
|
className="absolute pointer-events-none"
|
|
234
235
|
style={{
|
|
235
236
|
left: props.marqueeRect.left,
|
|
236
237
|
top: props.marqueeRect.top,
|
|
237
238
|
width: props.marqueeRect.width,
|
|
238
239
|
height: props.marqueeRect.height,
|
|
239
|
-
|
|
240
|
-
|
|
240
|
+
...(props.marqueeRect.mode === "subtract"
|
|
241
|
+
? {
|
|
242
|
+
background: "var(--timeline-danger-fill)",
|
|
243
|
+
border: "1px dashed var(--timeline-danger)",
|
|
244
|
+
}
|
|
245
|
+
: {
|
|
246
|
+
background: "var(--timeline-accent-fill)",
|
|
247
|
+
border: "1px dashed var(--timeline-accent-border)",
|
|
248
|
+
}),
|
|
241
249
|
borderRadius: 2,
|
|
242
250
|
zIndex: 70,
|
|
243
251
|
}}
|
|
@@ -16,7 +16,7 @@ import type { TimelineEmptyState } from "./TimelineEmptyState";
|
|
|
16
16
|
import type { TimelineProps } from "./TimelineTypes";
|
|
17
17
|
import type { TimelineRangeSelection } from "./timelineEditing";
|
|
18
18
|
import type { TimelineDropPlacement } from "./timelineCallbacks";
|
|
19
|
-
import type {
|
|
19
|
+
import type { MarqueeBand } from "../../utils/marqueeGeometry";
|
|
20
20
|
import type { ResizingClipState } from "./useTimelineClipDrag";
|
|
21
21
|
import type { TimelineLaneBaseProps } from "./timelineLaneProps";
|
|
22
22
|
import type { TimelineLaneGapStrips } from "./useTimelineGapHighlights";
|
|
@@ -50,7 +50,7 @@ export type TimelineCanvasState = Omit<
|
|
|
50
50
|
majorTickInterval: number;
|
|
51
51
|
tickFrameRate: number | undefined;
|
|
52
52
|
rangeSelection: TimelineRangeSelection | null;
|
|
53
|
-
marqueeRect:
|
|
53
|
+
marqueeRect: MarqueeBand | null;
|
|
54
54
|
resizingClip: ResizingClipState | null;
|
|
55
55
|
isScrubbing: boolean;
|
|
56
56
|
playheadRef: React.RefObject<HTMLDivElement | null>;
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
getTimelineClipRect,
|
|
8
8
|
getMarqueeClipCandidates,
|
|
9
9
|
computeMarqueeSelection,
|
|
10
|
+
survivingPrimary,
|
|
10
11
|
} from "./timelineMarquee";
|
|
11
12
|
import { createTimelineClipIndex } from "../lib/timelineClipIndex";
|
|
12
13
|
import type { TimelineElement } from "../store/playerStore";
|
|
@@ -242,6 +243,61 @@ describe("computeMarqueeSelection", () => {
|
|
|
242
243
|
expect(primaryId).toBe("c");
|
|
243
244
|
});
|
|
244
245
|
|
|
246
|
+
it("subtracts the hits from the base selection and names no new primary", () => {
|
|
247
|
+
const marquee = { left: ORIGIN, top: row0Top, width: 50, height: 10 };
|
|
248
|
+
const { ids, primaryId } = computeMarqueeSelection({
|
|
249
|
+
clips,
|
|
250
|
+
rowGeometry,
|
|
251
|
+
pps,
|
|
252
|
+
contentOrigin: ORIGIN,
|
|
253
|
+
marquee,
|
|
254
|
+
baseSelection: ["a", "b", "c"],
|
|
255
|
+
mode: "subtract",
|
|
256
|
+
});
|
|
257
|
+
expect(ids).toEqual(new Set(["b", "c"]));
|
|
258
|
+
expect(primaryId).toBeNull();
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it("subtracting from an empty or unrelated base selects nothing", () => {
|
|
262
|
+
const marquee = { left: ORIGIN, top: row0Top, width: 50, height: 10 };
|
|
263
|
+
expect(
|
|
264
|
+
computeMarqueeSelection({
|
|
265
|
+
clips,
|
|
266
|
+
rowGeometry,
|
|
267
|
+
pps,
|
|
268
|
+
contentOrigin: ORIGIN,
|
|
269
|
+
marquee,
|
|
270
|
+
mode: "subtract",
|
|
271
|
+
}).ids,
|
|
272
|
+
).toEqual(new Set());
|
|
273
|
+
expect(
|
|
274
|
+
computeMarqueeSelection({
|
|
275
|
+
clips,
|
|
276
|
+
rowGeometry,
|
|
277
|
+
pps,
|
|
278
|
+
contentOrigin: ORIGIN,
|
|
279
|
+
marquee,
|
|
280
|
+
baseSelection: ["b"],
|
|
281
|
+
mode: "subtract",
|
|
282
|
+
}).ids,
|
|
283
|
+
).toEqual(new Set(["b"]));
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
it("add mode is the default when a base is given", () => {
|
|
287
|
+
const marquee = { left: ORIGIN, top: row0Top, width: 50, height: 10 };
|
|
288
|
+
const explicit = computeMarqueeSelection({
|
|
289
|
+
clips,
|
|
290
|
+
rowGeometry,
|
|
291
|
+
pps,
|
|
292
|
+
contentOrigin: ORIGIN,
|
|
293
|
+
marquee,
|
|
294
|
+
baseSelection: ["b"],
|
|
295
|
+
mode: "add",
|
|
296
|
+
});
|
|
297
|
+
expect(explicit.ids).toEqual(new Set(["a", "b"]));
|
|
298
|
+
expect(explicit.primaryId).toBe("a");
|
|
299
|
+
});
|
|
300
|
+
|
|
245
301
|
it("shrinking the rect live drops clips it no longer covers", () => {
|
|
246
302
|
const wide = { left: ORIGIN, top: row0Top, width: 320, height: 10 };
|
|
247
303
|
const narrow = { left: ORIGIN, top: row0Top, width: 80, height: 10 };
|
|
@@ -268,6 +324,18 @@ describe("computeMarqueeSelection", () => {
|
|
|
268
324
|
});
|
|
269
325
|
});
|
|
270
326
|
|
|
327
|
+
describe("survivingPrimary", () => {
|
|
328
|
+
it("keeps the pre-drag primary while it is still selected", () => {
|
|
329
|
+
expect(survivingPrimary(new Set(["a", "b"]), "b")).toBe("b");
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it("falls back to any remaining id, or null when nothing is left", () => {
|
|
333
|
+
expect(survivingPrimary(new Set(["a", "b"]), "c")).toBe("a");
|
|
334
|
+
expect(survivingPrimary(new Set(), "c")).toBeNull();
|
|
335
|
+
expect(survivingPrimary(new Set(["a"]), null)).toBe("a");
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
|
|
271
339
|
describe("getMarqueeClipCandidates", () => {
|
|
272
340
|
it("queries only the intersecting rows and time span", () => {
|
|
273
341
|
const rowGeometry = createTimelineRowGeometry([0, 1, 2], [TRACK_H, TRACK_H, TRACK_H]);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RULER_H, CLIP_Y, TRACK_H, type TimelineRowGeometry } from "./timelineLayout";
|
|
2
|
-
import { rectsOverlap, type Rect } from "../../utils/marqueeGeometry";
|
|
2
|
+
import { rectsOverlap, type MarqueeSelectionMode, type Rect } from "../../utils/marqueeGeometry";
|
|
3
3
|
import { queryTimelineClipIndex, type TimelineClipIndex } from "../lib/timelineClipIndex";
|
|
4
4
|
import type { TimelineElement } from "../store/playerStore";
|
|
5
5
|
|
|
@@ -84,10 +84,10 @@ export function getTimelineClipRect(
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
export interface MarqueeSelectionResult {
|
|
87
|
-
/**
|
|
87
|
+
/** The marquee's hits, unioned with or removed from the base selection. */
|
|
88
88
|
ids: Set<string>;
|
|
89
89
|
/** The last marquee-hit clip in element order — the primary selection.
|
|
90
|
-
* Null when the marquee
|
|
90
|
+
* Null when the marquee selects nothing new (caller keeps its current primary). */
|
|
91
91
|
primaryId: string | null;
|
|
92
92
|
}
|
|
93
93
|
|
|
@@ -125,9 +125,16 @@ export function getMarqueeClipCandidates(input: {
|
|
|
125
125
|
return candidates;
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
+
/** The primary after a subtract: the pre-drag primary if it survived, else any survivor. */
|
|
129
|
+
export function survivingPrimary(ids: Set<string>, basePrimary: string | null): string | null {
|
|
130
|
+
if (basePrimary && ids.has(basePrimary)) return basePrimary;
|
|
131
|
+
for (const id of ids) return id;
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
|
|
128
135
|
/**
|
|
129
136
|
* Live marquee selection: every clip whose rendered rect intersects the marquee.
|
|
130
|
-
* `baseSelection`
|
|
137
|
+
* `baseSelection` gains the hits in `add` mode and loses them in `subtract` mode.
|
|
131
138
|
*/
|
|
132
139
|
export function computeMarqueeSelection(input: {
|
|
133
140
|
clips: MarqueeClipInput[];
|
|
@@ -136,12 +143,17 @@ export function computeMarqueeSelection(input: {
|
|
|
136
143
|
contentOrigin: number;
|
|
137
144
|
marquee: Rect;
|
|
138
145
|
baseSelection?: Iterable<string>;
|
|
146
|
+
mode?: MarqueeSelectionMode;
|
|
139
147
|
}): MarqueeSelectionResult {
|
|
148
|
+
const subtract = input.mode === "subtract";
|
|
140
149
|
const ids = new Set<string>(input.baseSelection ?? []);
|
|
141
150
|
let primaryId: string | null = null;
|
|
142
151
|
for (const clip of input.clips) {
|
|
143
152
|
const rect = getTimelineClipRect(clip, input.rowGeometry, input.pps, input.contentOrigin);
|
|
144
|
-
if (rect
|
|
153
|
+
if (!rect || !rectsOverlap(rect, input.marquee)) continue;
|
|
154
|
+
if (subtract) {
|
|
155
|
+
ids.delete(clip.id);
|
|
156
|
+
} else {
|
|
145
157
|
ids.add(clip.id);
|
|
146
158
|
primaryId = clip.id;
|
|
147
159
|
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { TimelineRowGeometry } from "./timelineLayout";
|
|
2
|
+
import type { TimelineClipIndex } from "../lib/timelineClipIndex";
|
|
3
|
+
import { usePlayerStore, type TimelineElement } from "../store/playerStore";
|
|
4
|
+
import type { MarqueeSelectionMode, Rect } from "../../utils/marqueeGeometry";
|
|
5
|
+
import {
|
|
6
|
+
computeMarqueeSelection,
|
|
7
|
+
getMarqueeClipCandidates,
|
|
8
|
+
survivingPrimary,
|
|
9
|
+
type MarqueeClipInput,
|
|
10
|
+
} from "./timelineMarquee";
|
|
11
|
+
|
|
12
|
+
export interface MarqueeDragState {
|
|
13
|
+
originX: number;
|
|
14
|
+
originY: number;
|
|
15
|
+
/** Pre-drag selection, restored on Escape-cancel. */
|
|
16
|
+
baseIds: Set<string>;
|
|
17
|
+
basePrimary: string | null;
|
|
18
|
+
/** Base mode (cmd/ctrl at pointerdown adds); Shift or Alt held on the pointer override it. */
|
|
19
|
+
mode: MarqueeSelectionMode;
|
|
20
|
+
/** True once the pointer travelled past the click threshold. */
|
|
21
|
+
active: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function snapshotSelection(): { ids: Set<string>; primary: string | null } {
|
|
25
|
+
const s = usePlayerStore.getState();
|
|
26
|
+
const ids = new Set(s.selectedElementIds);
|
|
27
|
+
if (s.selectedElementId) ids.add(s.selectedElementId);
|
|
28
|
+
return { ids, primary: s.selectedElementId };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function toMarqueeClips(elements: TimelineElement[]): MarqueeClipInput[] {
|
|
32
|
+
return elements.map((el) => ({
|
|
33
|
+
id: el.key ?? el.id,
|
|
34
|
+
start: el.start,
|
|
35
|
+
duration: el.duration,
|
|
36
|
+
track: el.track,
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Computes the live selection for a marquee rect against the pre-drag base and commits it. */
|
|
41
|
+
export function commitMarqueeSelection(
|
|
42
|
+
rect: Rect,
|
|
43
|
+
mode: MarqueeSelectionMode,
|
|
44
|
+
marquee: MarqueeDragState,
|
|
45
|
+
clipIndex: TimelineClipIndex,
|
|
46
|
+
rowGeometry: TimelineRowGeometry,
|
|
47
|
+
pps: number,
|
|
48
|
+
contentOrigin: number,
|
|
49
|
+
): void {
|
|
50
|
+
const candidates = getMarqueeClipCandidates({
|
|
51
|
+
clipIndex,
|
|
52
|
+
rowGeometry,
|
|
53
|
+
marquee: rect,
|
|
54
|
+
pps,
|
|
55
|
+
contentOrigin,
|
|
56
|
+
});
|
|
57
|
+
const { ids, primaryId } = computeMarqueeSelection({
|
|
58
|
+
clips: toMarqueeClips([...candidates]),
|
|
59
|
+
rowGeometry,
|
|
60
|
+
pps,
|
|
61
|
+
contentOrigin,
|
|
62
|
+
marquee: rect,
|
|
63
|
+
baseSelection: mode === "replace" ? undefined : marquee.baseIds,
|
|
64
|
+
mode,
|
|
65
|
+
});
|
|
66
|
+
const store = usePlayerStore.getState();
|
|
67
|
+
let primary = primaryId;
|
|
68
|
+
if (mode === "add") primary ??= marquee.basePrimary;
|
|
69
|
+
if (mode === "subtract") primary = survivingPrimary(ids, marquee.basePrimary);
|
|
70
|
+
// Primary FIRST: setSelectedElementId collapses the multi-select set, so the set
|
|
71
|
+
// must be written after it or the marquee selection would be wiped every frame.
|
|
72
|
+
store.setSelectedElementId(primary);
|
|
73
|
+
store.setSelectedElementIds(ids);
|
|
74
|
+
}
|
|
@@ -103,20 +103,31 @@ function renderHarness(sessionEpoch = 1) {
|
|
|
103
103
|
|
|
104
104
|
function dragMarquee(
|
|
105
105
|
view: ReturnType<typeof renderHarness>,
|
|
106
|
-
options: {
|
|
106
|
+
options: {
|
|
107
|
+
secondPointer?: boolean;
|
|
108
|
+
release?: boolean;
|
|
109
|
+
down?: Partial<React.PointerEvent>;
|
|
110
|
+
move?: Partial<React.PointerEvent>;
|
|
111
|
+
} = {},
|
|
107
112
|
): void {
|
|
108
113
|
act(() => {
|
|
109
|
-
view.api.handlePointerDown(pointer(view.scroll, 7, 0, FIRST_ROW_Y));
|
|
114
|
+
view.api.handlePointerDown(pointer(view.scroll, 7, 0, FIRST_ROW_Y, options.down));
|
|
110
115
|
if (options.secondPointer) {
|
|
111
116
|
view.api.handlePointerDown(pointer(view.scroll, 8, 500, FIRST_ROW_Y));
|
|
112
117
|
}
|
|
113
|
-
view.api.handlePointerMove(pointer(view.scroll, 7, 400, OFFSCREEN_ROW_Y));
|
|
118
|
+
view.api.handlePointerMove(pointer(view.scroll, 7, 400, OFFSCREEN_ROW_Y, options.move));
|
|
114
119
|
if (options.release) {
|
|
115
|
-
view.api.handlePointerUp(pointer(view.scroll, 7, 400, OFFSCREEN_ROW_Y));
|
|
120
|
+
view.api.handlePointerUp(pointer(view.scroll, 7, 400, OFFSCREEN_ROW_Y, options.move));
|
|
116
121
|
}
|
|
117
122
|
});
|
|
118
123
|
}
|
|
119
124
|
|
|
125
|
+
function selectIds(primary: string, ...others: string[]): void {
|
|
126
|
+
const store = usePlayerStore.getState();
|
|
127
|
+
store.setSelectedElementId(primary);
|
|
128
|
+
store.setSelectedElementIds(new Set([primary, ...others]));
|
|
129
|
+
}
|
|
130
|
+
|
|
120
131
|
function expectSelectedIds(...ids: string[]): void {
|
|
121
132
|
expect(usePlayerStore.getState().selectedElementIds).toEqual(new Set(ids));
|
|
122
133
|
}
|
|
@@ -190,6 +201,89 @@ describe("useTimelineRangeSelection", () => {
|
|
|
190
201
|
unmountHarness(view);
|
|
191
202
|
});
|
|
192
203
|
|
|
204
|
+
it("replaces the selection with the covered clips when no modifier is held", () => {
|
|
205
|
+
selectIds("base");
|
|
206
|
+
const view = renderHarness();
|
|
207
|
+
dragMarquee(view, { release: true });
|
|
208
|
+
|
|
209
|
+
expectSelectedIds("first", "offscreen");
|
|
210
|
+
expect(view.api.marqueeRect).toBeNull();
|
|
211
|
+
unmountHarness(view);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("adds the covered clips to the selection while Shift is held", () => {
|
|
215
|
+
selectIds("base");
|
|
216
|
+
const view = renderHarness();
|
|
217
|
+
dragMarquee(view, { move: { shiftKey: true } });
|
|
218
|
+
|
|
219
|
+
expect(view.api.marqueeRect?.mode).toBe("add");
|
|
220
|
+
expectSelectedIds("base", "first", "offscreen");
|
|
221
|
+
unmountHarness(view);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it("removes the covered clips from the selection while Alt is held", () => {
|
|
225
|
+
selectIds("first", "offscreen", "base");
|
|
226
|
+
const view = renderHarness();
|
|
227
|
+
dragMarquee(view, { down: { altKey: true }, move: { altKey: true }, release: true });
|
|
228
|
+
|
|
229
|
+
expectSelectedIds("base");
|
|
230
|
+
expect(usePlayerStore.getState().selectedElementId).toBe("base");
|
|
231
|
+
unmountHarness(view);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it("re-anchors on a survivor when Alt removes the primary", () => {
|
|
235
|
+
selectIds("first", "base");
|
|
236
|
+
const view = renderHarness();
|
|
237
|
+
dragMarquee(view, { move: { altKey: true } });
|
|
238
|
+
|
|
239
|
+
expect(view.api.marqueeRect?.mode).toBe("subtract");
|
|
240
|
+
expectSelectedIds("base");
|
|
241
|
+
expect(usePlayerStore.getState().selectedElementId).toBe("base");
|
|
242
|
+
unmountHarness(view);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it("Alt pressed mid-drag flips a Shift add into a subtract", () => {
|
|
246
|
+
selectIds("first", "base");
|
|
247
|
+
const view = renderHarness();
|
|
248
|
+
dragMarquee(view, { move: { shiftKey: true } });
|
|
249
|
+
expectSelectedIds("first", "base", "offscreen");
|
|
250
|
+
|
|
251
|
+
act(() => {
|
|
252
|
+
view.api.handlePointerMove(
|
|
253
|
+
pointer(view.scroll, 7, 400, OFFSCREEN_ROW_Y, { shiftKey: true, altKey: true }),
|
|
254
|
+
);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
expect(view.api.marqueeRect?.mode).toBe("subtract");
|
|
258
|
+
expectSelectedIds("base");
|
|
259
|
+
unmountHarness(view);
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it("the modifiers held at release decide: letting go of Alt turns the subtract into a replace", () => {
|
|
263
|
+
selectIds("first", "base");
|
|
264
|
+
const view = renderHarness();
|
|
265
|
+
dragMarquee(view, { down: { altKey: true }, move: { altKey: true } });
|
|
266
|
+
expectSelectedIds("base");
|
|
267
|
+
|
|
268
|
+
act(() => view.api.handlePointerUp(pointer(view.scroll, 7, 400, OFFSCREEN_ROW_Y)));
|
|
269
|
+
|
|
270
|
+
expectSelectedIds("first", "offscreen");
|
|
271
|
+
expect(usePlayerStore.getState().selectedElementId).toBe("offscreen");
|
|
272
|
+
unmountHarness(view);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it("restores the pre-drag selection when an Alt marquee is cancelled", () => {
|
|
276
|
+
selectIds("first", "base");
|
|
277
|
+
const view = renderHarness();
|
|
278
|
+
dragMarquee(view, { move: { altKey: true } });
|
|
279
|
+
expectSelectedIds("base");
|
|
280
|
+
|
|
281
|
+
act(() => view.api.handlePointerCancel(pointer(view.scroll, 7, 400, OFFSCREEN_ROW_Y)));
|
|
282
|
+
expectSelectedIds("first", "base");
|
|
283
|
+
expect(usePlayerStore.getState().selectedElementId).toBe("first");
|
|
284
|
+
unmountHarness(view);
|
|
285
|
+
});
|
|
286
|
+
|
|
193
287
|
it("cancels a live marquee when the project session changes", () => {
|
|
194
288
|
usePlayerStore.getState().setSelectedElementId("base");
|
|
195
289
|
const view = renderHarness(1);
|