|
2 | 2 | import type { Asset as AssetInfo } from '@rolldown/debug' |
3 | 3 | import type { RolldownAssetInfo, RolldownChunkInfo, SessionContext } from '~~/shared/types' |
4 | 4 | import { useRpc } from '#imports' |
| 5 | +import { useAsyncState } from '@vueuse/core' |
5 | 6 | import { computed, ref } from 'vue' |
6 | 7 | import { settings } from '~~/app/state/settings' |
7 | 8 |
|
8 | | -const props = defineProps<{ |
9 | | - chunks: RolldownChunkInfo[] |
| 9 | +const props = withDefaults(defineProps<{ |
10 | 10 | session: SessionContext |
11 | 11 | asset: RolldownAssetInfo |
12 | | - importers: AssetInfo[] |
13 | | - imports: AssetInfo[] |
14 | | -}>() |
| 12 | + chunks?: RolldownChunkInfo[] |
| 13 | + importers?: AssetInfo[] |
| 14 | + imports?: AssetInfo[] |
| 15 | + lazy?: boolean |
| 16 | +}>(), { |
| 17 | + lazy: false, |
| 18 | +}) |
15 | 19 |
|
16 | 20 | const rpc = useRpc() |
17 | 21 | const showSource = ref(false) |
18 | | -const assetChunks = computed(() => props.chunks.filter(c => c.chunk_id === props.asset.chunk_id)) |
| 22 | +const { state } = useAsyncState( |
| 23 | + async () => { |
| 24 | + if (!props.lazy) |
| 25 | + return |
| 26 | + const res = await rpc.value!['vite:rolldown:get-asset-details']?.({ |
| 27 | + session: props.session.id, |
| 28 | + id: props.asset.filename, |
| 29 | + }) |
| 30 | + return { |
| 31 | + chunks: [{ ...res?.chunk, type: 'chunk' }], |
| 32 | + importers: res?.importers, |
| 33 | + imports: res?.imports, |
| 34 | + } satisfies { |
| 35 | + chunks: RolldownChunkInfo[] |
| 36 | + importers: AssetInfo[] |
| 37 | + imports: AssetInfo[] |
| 38 | + } |
| 39 | + }, |
| 40 | + null, |
| 41 | +) |
| 42 | +const assetChunks = computed(() => props.lazy ? state.value?.chunks : props.chunks?.filter(c => c.chunk_id === props.asset.chunk_id)) |
| 43 | +const _importers = computed(() => props.lazy ? state.value?.importers : props.importers) |
| 44 | +const _imports = computed(() => props.lazy ? state.value?.imports : props.imports) |
19 | 45 |
|
20 | 46 | function openInEditor() { |
21 | 47 | rpc.value |
@@ -81,14 +107,14 @@ function openInEditor() { |
81 | 107 | /> |
82 | 108 | </div> |
83 | 109 | </div> |
84 | | - <template v-if="importers.length || imports.length"> |
| 110 | + <template v-if="_importers?.length || _imports?.length"> |
85 | 111 | <div flex="~ col gap-2"> |
86 | 112 | <div op50> |
87 | 113 | Asset Relationships |
88 | 114 | </div> |
89 | 115 | <DataAssetRelationships |
90 | | - :importers="importers" |
91 | | - :imports="imports" |
| 116 | + :importers="_importers" |
| 117 | + :imports="_imports" |
92 | 118 | /> |
93 | 119 | </div> |
94 | 120 | </template> |
|
0 commit comments