11import type { DomEditSelection } from "./domEditingTypes" ;
2- import { findPreviewElement } from "../../player/lib/timelineElementHelpers " ;
2+ import { findElementForSelection } from "./domEditingElement " ;
33
44/**
55 * Build the "live preview" callback the 3D-transform sub-view fires while a
@@ -9,17 +9,17 @@ import { findPreviewElement } from "../../player/lib/timelineElementHelpers";
99 * Extracted so the identical closure exists once — shared by the legacy
1010 * PropertyPanel Layout section and the flat Layout group (PropertyPanelFlat).
1111 */
12- // Resolve by id when unique, otherwise by selector + selectorIndex — a bare
13- // querySelector(selector) always hits the FIRST match, so dragging on the
14- // second of two same-selector siblings would animate the wrong element.
12+ // hf-ids and ids repeat across flattened sub-compositions and a selector's first match may be a sibling, so look in
13+ // the selection's own file first, then anywhere.
1514function resolvePreviewNode (
1615 doc : Document | null | undefined ,
1716 el : DomEditSelection ,
1817) : Element | null {
1918 if ( ! doc ) return null ;
20- if ( el . hfId || el . id ) return findPreviewElement ( doc , el ) ;
21- if ( ! el . selector ) return null ;
22- return doc . querySelectorAll ( el . selector ) [ el . selectorIndex ?? 0 ] ?? null ;
19+ return (
20+ findElementForSelection ( doc , el ) ??
21+ findElementForSelection ( doc , { ...el , sourceFile : undefined } )
22+ ) ;
2323}
2424
2525export function createGsapLivePreview ( iframeRef : { readonly current : HTMLIFrameElement | null } ) {
0 commit comments