11<script setup lang="ts">
22import { computed } from ' vue'
33import { useStudio } from ' ../composables/useStudio'
4+ import type { TreeItem } from ' ../types'
45import { StudioItemActionId , TreeStatus } from ' ../types'
56
67const { documentTree, context } = useStudio ()
@@ -22,6 +23,48 @@ const showFileForm = computed(() => {
2223 context .actionInProgress .value ?.id === StudioItemActionId .RenameItem
2324 && context .actionInProgress .value ?.item ?.type === ' file' )
2425})
26+
27+ function fileIcon(id : string ) {
28+ return {
29+ md: ' i-ph-markdown-logo' ,
30+ yaml: ' i-fluent-document-yml-20-regular' ,
31+ yml: ' i-fluent-document-yml-20-regular' ,
32+ json: ' i-lucide-file-json' ,
33+ }[id .split (' .' ).pop () as string ] || ' i-lucide-file-text'
34+ }
35+
36+ function mapTreeToItem(tree : TreeItem []) {
37+ return tree .map ((treeItem ) => {
38+ if (treeItem .type === ' file' ) {
39+ return {
40+ type: ' file' ,
41+ label: treeItem .name ,
42+ icon: fileIcon (treeItem .id ),
43+ onSelect : () => context .activeTree .value .select (treeItem ),
44+ }
45+ }
46+ return {
47+ type: ' directory' ,
48+ label: treeItem .name ,
49+ icon: ' i-lucide-folder' ,
50+ // onSelect: () => context.activeTree.value.select(treeItem),
51+ children: treeItem .children ? mapTreeToItem (treeItem .children ) : [],
52+ }
53+ }).sort ((a ) => {
54+ // sort by directory first
55+ if (a .type === ' directory' ) {
56+ return - 1
57+ }
58+ return 1
59+ })
60+ }
61+
62+ const items = computed (() => {
63+ if (documentTree .currentItem .value .type === ' file' ) {
64+ return []
65+ }
66+ return mapTreeToItem (documentTree .current .value )
67+ })
2568 </script >
2669
2770<template >
@@ -36,21 +79,12 @@ const showFileForm = computed(() => {
3679 :read-only =" documentTree .currentItem .value .status === TreeStatus .Deleted "
3780 />
3881 <div
39- v-else
40- class =" flex flex-col p-4 "
82+ v-show = " documentTree.currentItem.value.type !== 'file' "
83+ class =" flex flex-col p-1.5 text-default "
4184 >
42- <ItemTree
43- v-if =" folderTree ?.length > 0 || showFolderForm "
44- class="mb-2"
45- :tree =" folderTree "
46- :show-form =" showFolderForm "
47- type="directory"
48- />
49- <ItemTree
50- v-if =" fileTree ?.length > 0 || showFileForm "
51- :tree =" fileTree "
52- :show-form =" showFileForm "
53- type="file"
85+ <UTree
86+ :items =" items "
87+ color="neutral"
5488 />
5589 </div >
5690 </div >
0 commit comments