@@ -12,8 +12,13 @@ import { useDispatch } from "core/dispatch";
1212export function EditorLayerHierarchy ( ) {
1313 const [ state ] = useEditorState ( ) ;
1414 const dispatch = useDispatch ( ) ;
15- const root = state . design ?. current ?. entry ;
16- const layers = root ? flatten ( root , [ "origin" ] ) : [ ] ;
15+ const root = state . selectedPage
16+ ? state . design . pages . find ( ( p ) => p . id == state . selectedPage ) . children
17+ : [ state . design ?. input ?. entry ] ;
18+
19+ const layers : FlattenedNode [ ] [ ] = root
20+ ? root . filter ( ( l ) => ! ! l ) . map ( ( layer ) => flatten ( layer ) )
21+ : [ ] ;
1722
1823 const renderItem = useCallback (
1924 ( { id, name, depth, type } ) => {
@@ -48,14 +53,14 @@ export function EditorLayerHierarchy() {
4853
4954 const haschildren = useCallback (
5055 ( id : string ) => {
51- return layers . some ( ( layer ) => layer . parent === id ) ;
56+ return layers . some ( ( l ) => l . some ( ( layer ) => layer . parent === id ) ) ;
5257 } ,
53- [ layers . length ]
58+ [ layers ]
5459 ) ;
5560
5661 return (
5762 < TreeView . Root
58- data = { layers }
63+ data = { layers . flat ( ) }
5964 keyExtractor = { useCallback ( ( item : any ) => item . id , [ ] ) }
6065 renderItem = { renderItem }
6166 />
@@ -79,11 +84,14 @@ interface FlattenedNode {
7984
8085const flatten = < T extends ITreeNode > (
8186 tree : T ,
82- properties ?: string [ ] ,
8387 parent ?: string ,
8488 depth : number = 0
8589) : FlattenedNode [ ] => {
86- const convert = ( node : T , properties , depth : number , parent ?: string ) => {
90+ const convert = ( node : T , depth : number , parent ?: string ) => {
91+ if ( ! node ) {
92+ return ;
93+ }
94+
8795 const result : FlattenedNode = {
8896 id : node . id ,
8997 name : node . name ,
@@ -92,17 +100,13 @@ const flatten = <T extends ITreeNode>(
92100 parent,
93101 } ;
94102
95- properties ?. forEach ( ( property ) => {
96- ( result as object ) [ property ] = node [ property ] ;
97- } ) ;
98-
99103 return result ;
100104 } ;
101105
102106 const final = [ ] ;
103- final . push ( convert ( tree , properties , depth , parent ) ) ;
104- for ( const child of tree . children || [ ] ) {
105- final . push ( ...flatten ( child , null , tree . id , depth + 1 ) ) ;
107+ final . push ( convert ( tree , depth , parent ) ) ;
108+ for ( const child of tree ? .children || [ ] ) {
109+ final . push ( ...flatten ( child , tree . id , depth + 1 ) ) ;
106110 }
107111 return final ;
108112} ;
0 commit comments