Skip to content

Commit 7330625

Browse files
committed
feat: new content tree
1 parent 9ce979c commit 7330625

2 files changed

Lines changed: 49 additions & 15 deletions

File tree

src/app/src/components/shared/item/ItemBreadcrumb.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const items = computed<BreadcrumbItem[]>(() => {
4242
const allItems = [rootItem, ...breadcrumbItems]
4343
4444
// Handle ellipsis dropdown
45-
if (allItems.length > 3) {
45+
if (allItems.length > 5) {
4646
const firstItem = allItems[0]
4747
const lastItem = allItems[allItems.length - 1]
4848
const hiddenItems = allItems.slice(1, -1)

src/app/src/pages/content.vue

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script setup lang="ts">
22
import { computed } from 'vue'
33
import { useStudio } from '../composables/useStudio'
4+
import type { TreeItem } from '../types'
45
import { StudioItemActionId, TreeStatus } from '../types'
56
67
const { 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

Comments
 (0)