@@ -2,19 +2,28 @@ import { StudioFeature, type StudioHost, type TreeItem } from '../types'
22import { ref , computed } from 'vue'
33import type { useDraftDocuments } from './useDraftDocuments'
44import type { useDraftMedias } from './useDraftMedias'
5- import { buildTree , findItemFromId , findItemFromRoute , ROOT_ITEM , findParentFromId } from '../utils/tree'
5+ import { buildTree , findItemFromId , findItemFromRoute , findParentFromId , TreeRootId } from '../utils/tree'
66import type { RouteLocationNormalized } from 'vue-router'
77import { useHooks } from './useHooks'
88import type { useUI } from './useUI'
99
1010export const useTree = ( type : StudioFeature , host : StudioHost , ui : ReturnType < typeof useUI > , draft : ReturnType < typeof useDraftDocuments | typeof useDraftMedias > ) => {
1111 const hooks = useHooks ( )
1212
13+ const rootItem = computed < TreeItem > ( ( ) => {
14+ return {
15+ id : type === StudioFeature . Content ? TreeRootId . Content : TreeRootId . Media ,
16+ name : type === StudioFeature . Content ? 'content' : 'media' ,
17+ type : 'root' ,
18+ fsPath : '/' ,
19+ } as TreeItem
20+ } )
21+
1322 const tree = ref < TreeItem [ ] > ( [ ] )
14- const currentItem = ref < TreeItem > ( ROOT_ITEM )
23+ const currentItem = ref < TreeItem > ( rootItem . value )
1524
1625 const currentTree = computed < TreeItem [ ] > ( ( ) => {
17- if ( currentItem . value . id === ROOT_ITEM . id ) {
26+ if ( currentItem . value . id === rootItem . value . id ) {
1827 return tree . value
1928 }
2029
@@ -31,15 +40,8 @@ export const useTree = (type: StudioFeature, host: StudioHost, ui: ReturnType<ty
3140 return subTree
3241 } )
3342
34- // const parentItem = computed<TreeItem | null>(() => {
35- // if (currentItem.value.id === ROOT_ITEM.id) return null
36-
37- // const parent = findParentFromId(tree.value, currentItem.value.id)
38- // return parent || ROOT_ITEM
39- // })
40-
4143 async function select ( item : TreeItem ) {
42- currentItem . value = item || ROOT_ITEM
44+ currentItem . value = item || rootItem . value
4345 if ( item ?. type === 'file' ) {
4446 if ( type === StudioFeature . Content && ui . config . value . syncEditorAndRoute ) {
4547 host . app . navigateTo ( item . routePath ! )
@@ -103,6 +105,7 @@ export const useTree = (type: StudioFeature, host: StudioHost, ui: ReturnType<ty
103105
104106 return {
105107 root : tree ,
108+ rootItem,
106109 current : currentTree ,
107110 currentItem,
108111 // parentItem,
0 commit comments