import type { Dispatch, MutableRefObject, SetStateAction } from "react"; import type { DomEditSelection } from "../components/editor/domEditing"; import type { PreviewElement } from "../player/lib/previewElements"; import type { SelectElementOptions, TimelineElement } from "../player"; import type { RightPanelTab } from "../utils/studioHelpers"; import type { MarqueeSelectionMode } from "../utils/marqueeGeometry"; export interface DomSelectionResult { changed: boolean; count: number; } export interface ApplyDomSelectionOptions { revealPanel?: boolean; additive?: boolean; preserveGroup?: boolean; // A clear that came FROM the timeline must not be echoed back, or picking a // clip with no canvas node would deselect the clip you just picked. announce?: boolean; } export interface ResolveDomSelectionOptions { preferClipAncestor?: boolean; skipSourceProbe?: boolean; activeGroupElement?: HTMLElement | null; /** Resolve this node itself instead of applying human group-capture behavior. */ exactTarget?: boolean; previous?: DomEditSelection | null; } // Shared by every hook that needs the project/timeline/panel context a DOM // edit session is built around — useDomEditSession has its own superset. export interface DomEditTimelineParams { projectId: string | null; activeCompPath: string | null; compIdToSrc: Map; captionEditMode: boolean; previewIframeRef: MutableRefObject; timelineElements: TimelineElement[]; getTimelineSelectionSet: () => ReadonlySet; setSelectedTimelineElementId: (id: string | null, options?: SelectElementOptions) => void; /** Publishes a whole multi-selection to the timeline; the anchor is set separately. */ setTimelineSelectionSet: (ids: Set) => void; setRightCollapsed: (collapsed: boolean) => void; setRightPanelTab: (tab: RightPanelTab) => void; } export interface UseDomSelectionParams extends DomEditTimelineParams { isMasterView: boolean; previewIframe: HTMLIFrameElement | null; refreshKey: number; rightPanelTab: RightPanelTab; } export interface UseDomSelectionReturn { // State domEditSelection: DomEditSelection | null; domEditGroupSelections: DomEditSelection[]; domEditHoverSelection: DomEditSelection | null; activeGroupElement: HTMLElement | null; // Refs domEditSelectionRef: MutableRefObject; domEditGroupSelectionsRef: MutableRefObject; domEditHoverSelectionRef: MutableRefObject; activeGroupElementRef: MutableRefObject; // State setters (needed by useDomEditSession for agent-prompt reset flows) setDomEditSelection: Dispatch>; setDomEditGroupSelections: Dispatch>; setActiveGroupElement: (el: HTMLElement | null) => void; // Callbacks applyDomSelection: ( selection: DomEditSelection | null, options?: ApplyDomSelectionOptions, ) => void; clearDomSelection: () => void; buildDomSelectionFromTarget: ( target: HTMLElement | PreviewElement, options?: ResolveDomSelectionOptions, ) => Promise; resolveDomSelectionFromPreviewPoint: ( clientX: number, clientY: number, options?: ResolveDomSelectionOptions, ) => Promise; resolveAllDomSelectionsFromPreviewPoint: ( clientX: number, clientY: number, ) => Promise; updateDomEditHoverSelection: (selection: DomEditSelection | null) => void; buildDomSelectionForTimelineElement: ( element: TimelineElement, ) => Promise; handleTimelineElementSelect: (element: TimelineElement | null) => Promise; refreshDomEditSelectionFromPreview: ( selection: DomEditSelection, iframe?: HTMLIFrameElement | null, ) => Promise; applyMarqueeSelection: ( selections: DomEditSelection[], mode: MarqueeSelectionMode, ) => DomSelectionResult; }