@@ -201,14 +201,11 @@ export function NodeHierarchyList() {
201201 const node = editor . state . document . nodes [ currentId ] ;
202202 if ( ! node ) break ;
203203
204- // Find the parent of this node
205- const parentId = Object . keys (
206- editor . state . document_ctx . lu_children
207- ) . find ( ( parentId ) =>
208- editor . state . document_ctx . lu_children [ parentId ] ?. includes ( currentId )
209- ) ;
204+ // Find the parent of this node using the context lookup
205+ const parentId = editor . state . document_ctx . lu_parent [ currentId ] ;
210206
211- if ( parentId && parentId !== "<root>" ) {
207+ // Stop at the scene (root) level - don't include the scene itself
208+ if ( parentId && parentId !== id ) {
212209 parentIds . push ( parentId ) ;
213210 currentId = parentId ;
214211 } else {
@@ -228,8 +225,9 @@ export function NodeHierarchyList() {
228225 return Array . from ( expandedItems ) ;
229226 } , [
230227 selection ,
228+ id ,
231229 editor . state . document . nodes ,
232- editor . state . document_ctx . lu_children ,
230+ editor . state . document_ctx . lu_parent ,
233231 ] ) ;
234232
235233 // Combine user's manual expansions with required expansions
@@ -238,9 +236,9 @@ export function NodeHierarchyList() {
238236 return Array . from ( combined ) ;
239237 } , [ userExpandedItems , requiredExpandedItems ] ) ;
240238
241- // root item id must be "< root>"
239+ // Use the scene id as root (scenes are now part of the nodes tree)
242240 const tree = useTree < grida . program . nodes . Node > ( {
243- rootItemId : "<root>" ,
241+ rootItemId : id ,
244242 canReorder : true ,
245243 initialState : {
246244 selectedItems : selection ,
@@ -258,14 +256,12 @@ export function NodeHierarchyList() {
258256 setUserExpandedItems ( items ) ;
259257 } ,
260258 getItemName : ( item ) => {
261- if ( item . getId ( ) === "<root>" ) {
262- return name ;
263- }
264259 return item . getItemData ( ) . name ;
265260 } ,
266261 isItemFolder : ( item ) => {
267262 const node = item . getItemData ( ) ;
268263 return (
264+ node . type === "scene" ||
269265 node . type === "container" ||
270266 node . type === "group" ||
271267 node . type === "boolean"
@@ -278,13 +274,13 @@ export function NodeHierarchyList() {
278274 target,
279275 draggedItemIds : ids ,
280276 getActualChildren : ( parentId ) => {
281- if ( parentId === "<root>" ) {
282- return children ?? [ ] ;
283- }
284- return editor . state . document_ctx . lu_children [ parentId ] ;
277+ return editor . state . document_ctx . lu_children [ parentId ] ?? [ ] ;
285278 } ,
286279 inversed : true ,
287280 } ) ;
281+
282+ // TODO: introduce a new mv command, where it preserves the absolute position of the moving node, while entering/exiting the parent
283+ // simplu calling mv will only change the hierarchy, causing its location to change visually, not the expected ux when working with the tree ui.
288284 editor . commands . mv ( ids , target_id , index ) ;
289285 } ,
290286 indent : 6 ,
@@ -293,9 +289,6 @@ export function NodeHierarchyList() {
293289 return editor . state . document . nodes [ itemId ] ;
294290 } ,
295291 getChildren : ( itemId ) => {
296- if ( itemId === "<root>" ) {
297- return toReversedCopy ( children ) ;
298- }
299292 return toReversedCopy ( editor . state . document_ctx . lu_children [ itemId ] ) ;
300293 } ,
301294 } ,
0 commit comments