({
projectId,
activeCompPath,
isMasterView,
compIdToSrc,
captionEditMode,
previewIframeRef,
timelineElements,
setSelectedTimelineElementId,
setRightCollapsed,
setRightPanelTab,
previewIframe,
refreshKey,
rightPanelTab,
}: UseDomSelectionParams)
| 102 | // ── Hook ── |
| 103 | |
| 104 | export function useDomSelection({ |
| 105 | projectId, |
| 106 | activeCompPath, |
| 107 | isMasterView, |
| 108 | compIdToSrc, |
| 109 | captionEditMode, |
| 110 | previewIframeRef, |
| 111 | timelineElements, |
| 112 | setSelectedTimelineElementId, |
| 113 | setRightCollapsed, |
| 114 | setRightPanelTab, |
| 115 | previewIframe, |
| 116 | refreshKey, |
| 117 | rightPanelTab, |
| 118 | }: UseDomSelectionParams): UseDomSelectionReturn { |
| 119 | // ── State ── |
| 120 | |
| 121 | const [domEditSelection, setDomEditSelection] = useState<DomEditSelection | null>(null); |
| 122 | const [domEditGroupSelections, setDomEditGroupSelections] = useState<DomEditSelection[]>([]); |
| 123 | const [domEditHoverSelection, setDomEditHoverSelection] = useState<DomEditSelection | null>(null); |
| 124 | // The data-hf-group wrapper the user has drilled into (null = top level). |
| 125 | const [activeGroupElement, setActiveGroupElementState] = useState<HTMLElement | null>(null); |
| 126 | |
| 127 | // ── Refs ── |
| 128 | |
| 129 | const domEditSelectionRef = useRef<DomEditSelection | null>(domEditSelection); |
| 130 | const domEditGroupSelectionsRef = useRef<DomEditSelection[]>(domEditGroupSelections); |
| 131 | const domEditHoverSelectionRef = useRef<DomEditSelection | null>(domEditHoverSelection); |
| 132 | const activeGroupElementRef = useRef<HTMLElement | null>(activeGroupElement); |
| 133 | |
| 134 | // Keep refs in sync with state |
| 135 | domEditSelectionRef.current = domEditSelection; |
| 136 | domEditGroupSelectionsRef.current = domEditGroupSelections; |
| 137 | domEditHoverSelectionRef.current = domEditHoverSelection; |
| 138 | activeGroupElementRef.current = activeGroupElement; |
| 139 | |
| 140 | // ── Callbacks ── |
| 141 | |
| 142 | const applyDomSelection = useCallback( |
| 143 | // fallow-ignore-next-line complexity |
| 144 | ( |
| 145 | selection: DomEditSelection | null, |
| 146 | options?: { |
| 147 | revealPanel?: boolean; |
| 148 | additive?: boolean; |
| 149 | preserveGroup?: boolean; |
| 150 | }, |
| 151 | ) => { |
| 152 | if (!selection) { |
| 153 | domEditSelectionRef.current = null; |
| 154 | domEditGroupSelectionsRef.current = []; |
| 155 | setDomEditSelection(null); |
| 156 | setDomEditGroupSelections([]); |
| 157 | setSelectedTimelineElementId(null); |
| 158 | return; |
| 159 | } |
| 160 | if (!STUDIO_INSPECTOR_PANELS_ENABLED) { |
| 161 | domEditSelectionRef.current = null; |
no test coverage detected