@@ -25,6 +25,7 @@ import {
2525 rootComponent ,
2626 showAttribute ,
2727 WsComponentMeta ,
28+ blockTemplateComponent ,
2829} from "@webstudio-is/react-sdk" ;
2930import { ROOT_INSTANCE_ID , type Instance } from "@webstudio-is/sdk" ;
3031import {
@@ -82,7 +83,70 @@ const $dropTarget = computed(
8283 ( dragAndDropState ) => dragAndDropState . dropTarget
8384) ;
8485
85- const $flatTree = computed (
86+ const $contentTree = computed (
87+ [ $selectedPage , $instances , $propValuesByInstanceSelector ] ,
88+ ( page , instances , propValuesByInstanceSelector ) => {
89+ const flatTree : TreeItem [ ] = [ ] ;
90+ if ( page === undefined ) {
91+ return flatTree ;
92+ }
93+ const traverse = (
94+ instanceId : Instance [ "id" ] ,
95+ selector : InstanceSelector ,
96+ parentComponent ?: Instance [ "component" ] ,
97+ isParentHidden = false ,
98+ isLastChild = false ,
99+ level = 0
100+ ) => {
101+ const instance = instances . get ( instanceId ) ;
102+ if ( instance === undefined ) {
103+ // log instead of failing navigator tree
104+ console . error ( `Unknown instance ${ instanceId } ` ) ;
105+ return ;
106+ }
107+ const propValues = propValuesByInstanceSelector . get (
108+ getInstanceKey ( selector )
109+ ) ;
110+ const isHidden =
111+ isParentHidden ||
112+ false === Boolean ( propValues ?. get ( showAttribute ) ?? true ) ;
113+ const treeItem : TreeItem = {
114+ level,
115+ selector,
116+ instance,
117+ isExpanded : undefined ,
118+ isLastChild,
119+ isHidden,
120+ isReusable : false ,
121+ } ;
122+ const isVisible =
123+ instance . component === blockComponent ||
124+ ( parentComponent === blockComponent &&
125+ instance . component !== blockTemplateComponent ) ;
126+ if ( isVisible ) {
127+ flatTree . push ( treeItem ) ;
128+ }
129+ for ( let index = 0 ; index < instance . children . length ; index += 1 ) {
130+ const child = instance . children [ index ] ;
131+ if ( child . type === "id" ) {
132+ const isLastChild = index === instance . children . length - 1 ;
133+ traverse (
134+ child . value ,
135+ [ child . value , ...selector ] ,
136+ instance . component ,
137+ isHidden ,
138+ isLastChild ,
139+ isVisible ? level + 1 : level
140+ ) ;
141+ }
142+ }
143+ } ;
144+ traverse ( page . rootInstanceId , [ page . rootInstanceId ] ) ;
145+ return flatTree ;
146+ }
147+ ) ;
148+
149+ export const $flatTree = computed (
86150 [
87151 $selectedPage ,
88152 $instances ,
@@ -480,7 +544,8 @@ const canDrop = (
480544} ;
481545
482546export const NavigatorTree = ( ) => {
483- const flatTree = useStore ( $flatTree ) ;
547+ const isContentMode = useStore ( $isContentMode ) ;
548+ const flatTree = useStore ( isContentMode ? $contentTree : $flatTree ) ;
484549 const selectedInstanceSelector = useStore ( $selectedInstanceSelector ) ;
485550 const selectedKey = selectedInstanceSelector ?. join ( ) ;
486551 const hoveredInstanceSelector = useStore ( $hoveredInstanceSelector ) ;
@@ -523,7 +588,7 @@ export const NavigatorTree = () => {
523588 } }
524589 >
525590 < TreeRoot >
526- { rootMeta && (
591+ { rootMeta && isContentMode === false && (
527592 < TreeNode
528593 level = { 0 }
529594 isSelected = { selectedKey === ROOT_INSTANCE_ID }
0 commit comments