|
1 | 1 | <script setup lang="ts"> |
2 | 2 | import type { Component, NuxtLayout, NuxtPage } from 'nuxt/schema' |
3 | | -import type { Data, Node, Options } from 'vis-network' |
| 3 | +import type { Data, DataSetNodes, Node, Options } from 'vis-network' |
4 | 4 | import type { ComponentRelationship } from '~/../src/types' |
5 | 5 | import { useDebounce } from '@vueuse/core' |
| 6 | +import { DataSet } from 'vis-data' |
6 | 7 | import { Network } from 'vis-network' |
7 | 8 | import { computed, onMounted, ref, shallowRef, watch } from 'vue' |
8 | 9 | import { getColorMode } from '~/composables/client' |
@@ -67,7 +68,6 @@ const data = computed<Data>(() => { |
67 | 68 | const page = pages.value?.find(i => i.file === rel.id) |
68 | 69 | const layout = layouts.value?.find(i => i.file === rel.id) |
69 | 70 |
|
70 | | - const path = rel.id.replace(/\?.*$/, '').replace(/#.*$/, '') |
71 | 71 | const group = rel.id.includes('/node_modules/') |
72 | 72 | ? 'lib' |
73 | 73 | : component |
@@ -101,7 +101,7 @@ const data = computed<Data>(() => { |
101 | 101 |
|
102 | 102 | return { |
103 | 103 | id: rel.id, |
104 | | - label: path.split('/').splice(-1)[0].replace(/\.\w+$/, ''), |
| 104 | + label: getComponentName(rel.id), |
105 | 105 | group, |
106 | 106 | shape, |
107 | 107 | size: 15 + Math.min(rel.deps.length / 2, 8), |
@@ -132,7 +132,7 @@ const data = computed<Data>(() => { |
132 | 132 | }))) |
133 | 133 |
|
134 | 134 | return { |
135 | | - nodes, |
| 135 | + nodes: new DataSet(nodes), |
136 | 136 | edges, |
137 | 137 | } |
138 | 138 | }) |
@@ -193,16 +193,32 @@ onMounted(() => { |
193 | 193 |
|
194 | 194 | network.on('click', (e) => { |
195 | 195 | const id = e.nodes?.[0] |
196 | | - const node = (data.value.nodes as any[])?.find(i => i.id === id)?.extra |
197 | | - if (node) |
198 | | - selected.value = node |
| 196 | + const node = ((data.value.nodes as DataSetNodes).get(id) as any).extra |
| 197 | + selected.value = node |
199 | 198 | }) |
200 | 199 |
|
201 | 200 | watch(data, () => { |
202 | 201 | network.setData(data.value) |
203 | 202 | }) |
204 | 203 | }) |
205 | 204 |
|
| 205 | +function onCloseDrawer() { |
| 206 | + selected.value = undefined |
| 207 | +} |
| 208 | +
|
| 209 | +function getComponentName(path: string) { |
| 210 | + const component = props.components.find(i => i.filePath === path) |
| 211 | + if (component) |
| 212 | + return component.pascalName |
| 213 | + return path |
| 214 | + .replace(/.*\/components\//, '') |
| 215 | + .replace(/\.vue$/, '') |
| 216 | + .replace(/\/index$/, '') |
| 217 | + .split('/') |
| 218 | + .map(part => part.charAt(0).toUpperCase() + part.slice(1)) |
| 219 | + .join('') |
| 220 | +} |
| 221 | +
|
206 | 222 | function setFilter() { |
207 | 223 | selectedFilter.value = selected.value?.relationship |
208 | 224 | selected.value = undefined |
@@ -273,7 +289,7 @@ function setFilter() { |
273 | 289 | :model-value="!!(selected && selected.component)" |
274 | 290 | :top="navbar" |
275 | 291 | border="t l base" w-80 |
276 | | - @close="selected = undefined" |
| 292 | + @close="onCloseDrawer" |
277 | 293 | > |
278 | 294 | <div v-if="selected && selected.component" py4 pt4 flex="~ col"> |
279 | 295 | <ComponentDetails |
|
0 commit comments