1- import React , { useEffect , useState } from "react" ;
1+ import { useEffect , useState } from "react" ;
22import type { ReflectSceneNode } from "@design-sdk/core" ;
3+ import type { DesignInput } from "@designto/config/input" ;
34import { useEditorState } from "core/states" ;
4- import { DesignInput } from "@designto/config/input" ;
5-
6- import { utils as _design_utils } from "@design-sdk/core" ;
7- const designq = _design_utils . query ;
5+ import { getTargetContainer } from "utils/get-target-node" ;
86
97export function useTargetContainer ( ) {
108 const [ t , setT ] = useState < { target : ReflectSceneNode ; root : DesignInput } > ( {
@@ -13,36 +11,8 @@ export function useTargetContainer() {
1311 } ) ;
1412 const [ state ] = useEditorState ( ) ;
1513
16- //
1714 useEffect ( ( ) => {
18- const thisPageNodes = state . selectedPage
19- ? state . design . pages . find ( ( p ) => p . id == state . selectedPage ) . children
20- : null ;
21-
22- const targetId =
23- state ?. selectedNodes ?. length === 1 ? state . selectedNodes [ 0 ] : null ;
24-
25- const container_of_target =
26- designq . find_node_by_id_under_inpage_nodes ( targetId , thisPageNodes ) ||
27- null ;
28-
29- const root = thisPageNodes
30- ? container_of_target &&
31- ( container_of_target . origin === "COMPONENT"
32- ? DesignInput . forMasterComponent ( {
33- master : container_of_target ,
34- all : state . design . pages ,
35- components : state . design . components ,
36- } )
37- : DesignInput . fromDesignWithComponents ( {
38- design : container_of_target ,
39- components : state . design . components ,
40- } ) )
41- : state . design ?. input ;
42-
43- const target =
44- designq . find_node_by_id_under_entry ( targetId , root ?. entry ) ?? root ?. entry ;
45-
15+ const { root, target } = getTargetContainer ( state ) ;
4616 setT ( { target, root } ) ;
4717 } , [ state ?. selectedNodes , state ?. selectedPage , state ?. design ?. pages ] ) ;
4818
0 commit comments