This repository was archived by the owner on Jan 6, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathcomponent-docs.vue
92 lines (85 loc) · 2.77 KB
/
component-docs.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<script setup lang="ts">
import { Pane, Splitpanes } from 'splitpanes'
import Fuse from 'fuse.js'
import JsonEditorVue from 'json-editor-vue'
import 'vanilla-jsoneditor/themes/jse-theme-dark.css'
import { rpc } from '../logic/rpc'
const colorMode = useColorMode()
const keywords = ref('')
const activeFileIndex = ref(0)
const files = ref<string[]>([])
const content = ref({})
const list = computed(() => {
const fuse = new Fuse(files.value, {
shouldSort: true,
})
const result = keywords.value
? fuse.search(keywords.value).map(i => i.item)
: (files.value || [])
return result
})
async function getFileList() {
files.value = await rpc.getVueSFCList()
getComponentInfo()
}
async function getComponentInfo() {
if (!list.value.length)
return
const info = await rpc.getComponentInfo(list.value[activeFileIndex.value])
content.value = info
}
function toggle(index: number) {
activeFileIndex.value = index
getComponentInfo()
}
getFileList()
watch(keywords, () => {
activeFileIndex.value = 0
getComponentInfo()
})
</script>
<template>
<div relative h-full of-hidden n-panel-grids>
<div border="b base" flex="~ col gap1" px4 py3 navbar-glass>
<VTextInput v-model="keywords" font-mono icon="carbon:search" placeholder="Filter Files" op50 />
</div>
<Splitpanes :style="{ height: 'calc(100% - 60px)' }">
<Pane border="r base">
<div h-full select-none overflow-scroll p-2 class="no-scrollbar">
<ul v-if="list.length">
<li
v-for="(file, index) in list" :key="index" :class="[activeFileIndex === index ? 'op100' : 'op60']"
hover="op100" h-8 cursor-pointer of-hidden text-ellipsis lh-8 @click="toggle(index)"
>
{{ file }}
</li>
</ul>
<div v-else h-full flex items-center justify-center>
<VCard flex="~ col gap2" min-w-30 items-center p3>
<h1 text-sm italic op50>
No Files
</h1>
</VCard>
</div>
</div>
</Pane>
<Pane min-size="8">
<div h-full select-none overflow-scroll p-2 class="no-scrollbar">
<JsonEditorVue
v-show="list.length" v-model="content" h-full class="json-editor-vue" :class="[
colorMode === 'dark' ? 'jse-theme-dark' : '',
]" :main-menu-bar="false" :navigation-bar="false" :status-bar="false" :read-only="true" :indentation="2"
:tab-size="2"
/>
<div v-show="!list.length" h-full flex items-center justify-center>
<VCard flex="~ col gap2" min-w-30 items-center p3>
<h1 text-sm italic op50>
No Data
</h1>
</VCard>
</div>
</div>
</Pane>
</Splitpanes>
</div>
</template>