Skip to content

Commit c1ed725

Browse files
committed
feat: preserve UI state
1 parent 193fec6 commit c1ed725

File tree

7 files changed

+151
-62
lines changed

7 files changed

+151
-62
lines changed

packages/devtools/src/app/components/flowmap/Expandable.vue

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
<script setup lang="ts">
2-
import { ref } from 'vue'
3-
42
defineProps<{
53
expandable?: boolean
64
classRootNode?: string
75
activeStart?: boolean
86
activeEnd?: boolean
97
}>()
108
11-
const isExpanded = ref(true)
9+
const expanded = defineModel<boolean>('expanded', { required: false, default: true })
1210
</script>
1311

1412
<template>
1513
<FlowmapNode
16-
:lines="{ top: true, bottom: !expandable || !isExpanded }" pl6 pt4
14+
:lines="{ top: true, bottom: !expandable || !expanded }" pl6 pt4
1715
:class-node-outer="classRootNode"
1816
:active="activeStart"
1917
>
@@ -24,13 +22,13 @@ const isExpanded = ref(true)
2422
<template v-if="expandable" #inline-before>
2523
<button
2624
w-6 h-6 mr1 ml--7 mya rounded-full hover="bg-active" flex="~ items-center justify-center"
27-
@click="isExpanded = !isExpanded"
25+
@click="expanded = !expanded"
2826
>
29-
<div i-ph-caret-right text-sm op50 transition duration-300 :class="{ 'rotate-90': isExpanded }" />
27+
<div i-ph-caret-right text-sm op50 transition duration-300 :class="{ 'rotate-90': expanded }" />
3028
</button>
3129
</template>
3230

33-
<template v-if="expandable && isExpanded" #after>
31+
<template v-if="expandable && expanded" #after>
3432
<div>
3533
<svg
3634
ml-1em w-27px h-30px

packages/devtools/src/app/components/flowmap/ModuleFlow.vue

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<script setup lang="ts">
2-
import type { ModuleInfo, RolldownModuleFlowNode, RolldownModuleLoadNoChanges, RolldownModuleTransformInfo, RolldownModuleTransformNoChanges, SessionContext } from '~~/shared/types'
2+
import type { ModuleInfo, RolldownModuleFlowNode, RolldownModuleNoChanges, RolldownModuleNoChangesHide, RolldownModuleTransformInfo, SessionContext } from '~~/shared/types'
33
import { Menu as VMenu } from 'floating-vue'
4-
import { computed, ref, shallowRef, toRefs, watch } from 'vue'
4+
import { computed, shallowRef, toRefs, watch } from 'vue'
5+
import { settingsRefs } from '~/state/settings'
56
import PluginName from '../display/PluginName.vue'
67
78
const props = defineProps<{
@@ -13,51 +14,85 @@ const emit = defineEmits<{
1314
(e: 'select', v: boolean): void
1415
}>()
1516
const { info } = toRefs(props)
16-
const expandNoChangesTransform = ref(false)
17-
const expandNoChangesLoad = ref(false)
17+
18+
const {
19+
flowShowAllTransforms,
20+
flowShowAllLoads,
21+
flowExpandTransforms,
22+
flowExpandLoads,
23+
flowExpandResolveId,
24+
} = settingsRefs
25+
1826
const selected = shallowRef<RolldownModuleFlowNode | null>(null)
1927
2028
const resolveIds = computed(() => info?.value?.resolve_ids ?? [])
2129
22-
const transforms = computed((): (RolldownModuleTransformNoChanges | RolldownModuleTransformInfo)[] => {
23-
if (expandNoChangesTransform.value)
24-
return info?.value?.transforms ?? []
25-
30+
const transforms = computed((): (RolldownModuleNoChanges | RolldownModuleNoChangesHide | RolldownModuleTransformInfo)[] => {
2631
const unchanged = info?.value?.transforms?.filter(t => t.content_from === t.content_to)
2732
const changed = info?.value?.transforms?.filter(t => t.content_from !== t.content_to)
2833
34+
if (flowShowAllTransforms.value && !unchanged?.length)
35+
return info?.value?.transforms ?? []
36+
37+
if (flowShowAllTransforms.value && unchanged?.length) {
38+
return [
39+
...(info.value.transforms ?? []),
40+
({
41+
type: 'no_changes_hide',
42+
id: 'no_changes_hide',
43+
count: unchanged?.length ?? 0,
44+
duration: unchanged?.reduce((acc, t) => acc + t.duration, 0) ?? 0,
45+
} satisfies RolldownModuleNoChangesHide),
46+
]
47+
}
48+
2949
if (!unchanged?.length)
3050
return changed ?? []
51+
3152
return [
3253
({
33-
type: 'transform_no_changes',
34-
id: 'transform_no_changes',
54+
type: 'no_changes_collapsed',
55+
id: 'no_changes_collapsed',
3556
count: unchanged?.length ?? 0,
3657
duration: unchanged?.reduce((acc, t) => acc + t.duration, 0) ?? 0,
37-
} satisfies RolldownModuleTransformNoChanges),
58+
} satisfies RolldownModuleNoChanges),
3859
...(changed ?? []),
3960
]
4061
})
4162
4263
const loads = computed(() => {
43-
if (expandNoChangesLoad.value)
44-
return info?.value?.loads ?? []
45-
4664
const unchanged = info?.value?.loads?.filter(l => !l.content)
4765
const changed = info?.value?.loads?.filter(l => l.content)
4866
67+
if (flowShowAllLoads.value && !unchanged?.length)
68+
return info?.value?.loads ?? []
69+
70+
if (flowShowAllLoads.value && unchanged?.length) {
71+
return [
72+
...(info.value.loads ?? []),
73+
({
74+
type: 'no_changes_hide',
75+
id: 'no_changes_hide',
76+
count: unchanged?.length ?? 0,
77+
duration: unchanged?.reduce((acc, t) => acc + t.duration, 0) ?? 0,
78+
} satisfies RolldownModuleNoChangesHide),
79+
]
80+
}
81+
4982
if (!unchanged?.length)
5083
return changed ?? []
84+
5185
return [
5286
({
53-
type: 'load_no_changes',
54-
id: 'load_no_changes',
87+
type: 'no_changes_collapsed',
88+
id: 'no_changes_collapsed',
5589
count: unchanged?.length ?? 0,
5690
duration: unchanged?.reduce((acc, t) => acc + t.duration, 0) ?? 0,
57-
} satisfies RolldownModuleLoadNoChanges),
91+
} satisfies RolldownModuleNoChanges),
5892
...(changed ?? []),
5993
]
6094
})
95+
6196
const nodes = computed(() => [
6297
...resolveIds.value,
6398
...loads.value,
@@ -82,13 +117,6 @@ watch(selected, (v) => {
82117
emit('select', !!v)
83118
})
84119
85-
function activate(node: RolldownModuleFlowNode) {
86-
if (node.type === 'transform_no_changes')
87-
expandNoChangesTransform.value = !expandNoChangesTransform.value
88-
else if (node.type === 'load_no_changes')
89-
expandNoChangesLoad.value = !expandNoChangesLoad.value
90-
}
91-
92120
const codeDisplay = computed(() => {
93121
if (!selected.value)
94122
return null
@@ -189,9 +217,10 @@ const codeDisplay = computed(() => {
189217
</VMenu>
190218
</template>
191219
</div>
192-
<div flex="~ gap-10">
220+
<div flex="~ gap-10" min-w-300>
193221
<div select-none w-max>
194222
<FlowmapExpandable
223+
v-model:expanded="flowExpandResolveId"
195224
:expandable="resolveIds.length > 0"
196225
:class-root-node="resolveIds.length === 0 ? 'border-dashed' : ''"
197226
:active-start="isSelectedAncestor(resolveIds[0] || loads[0])"
@@ -211,13 +240,13 @@ const codeDisplay = computed(() => {
211240
:active="isSelectedAncestor(item)"
212241
:class="index > 0 ? 'pt-2' : ''"
213242
@select="select"
214-
@activate="activate"
215243
/>
216244
</div>
217245
</template>
218246
</FlowmapExpandable>
219247

220248
<FlowmapExpandable
249+
v-model:expanded="flowExpandLoads"
221250
:expandable="loads.length > 0"
222251
:class-root-node="loads.length === 0 ? 'border-dashed' : ''"
223252
:active-start="isSelectedAncestor(loads[0])"
@@ -237,13 +266,14 @@ const codeDisplay = computed(() => {
237266
:active="isSelectedAncestor(item)"
238267
:class="index > 0 ? 'pt-2' : ''"
239268
@select="select"
240-
@activate="activate"
269+
@toggle-show-all="flowShowAllLoads = !flowShowAllLoads"
241270
/>
242271
</div>
243272
</template>
244273
</FlowmapExpandable>
245274

246275
<FlowmapExpandable
276+
v-model:expanded="flowExpandTransforms"
247277
:expandable="transforms.length > 0"
248278
:class-root-node="transforms.length === 0 ? 'border-dashed' : ''"
249279
:active-start="isSelectedAncestor(transforms[0])"
@@ -264,7 +294,7 @@ const codeDisplay = computed(() => {
264294
:active="isSelectedAncestor(item)"
265295
:class="index > 0 ? 'pt-2' : ''"
266296
@select="select"
267-
@activate="activate"
297+
@toggle-show-all="flowShowAllTransforms = !flowShowAllTransforms"
268298
/>
269299
</div>
270300
</template>

packages/devtools/src/app/components/flowmap/NodeModuleInfo.vue

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const props = defineProps<{
1111
1212
const emit = defineEmits<{
1313
(e: 'select', item: RolldownModuleFlowNode): void
14-
(e: 'activate', item: RolldownModuleFlowNode): void
14+
(e: 'toggleShowAll', item: RolldownModuleFlowNode): void
1515
}>()
1616
1717
const isDashed = computed(() => {
@@ -44,7 +44,7 @@ const importterModule = computed(() => {
4444
</script>
4545

4646
<template>
47-
<div v-if="item.type === 'transform_no_changes' || item.type === 'load_no_changes'" pl10>
47+
<div v-if="item.type === 'no_changes_collapsed'" pl10>
4848
<div
4949
flex="~ gap-2 items-center" text-sm border="l" py1
5050
:class="active ? 'border-flow-line-active' : 'border-flow-line'"
@@ -58,12 +58,32 @@ const importterModule = computed(() => {
5858
<span op50 flex-shrink-0>in total</span>
5959
<button
6060
border="~ base rounded-full" px2 py-px op50 hover="op100"
61-
@click="emit('activate', item)"
61+
@click="emit('toggleShowAll', item)"
6262
>
6363
Expand
6464
</button>
6565
</div>
6666
</div>
67+
<div v-else-if="item.type === 'no_changes_hide'" pl10>
68+
<div
69+
flex="~ gap-2 items-center" text-sm border="l" py1
70+
:class="active ? 'border-flow-line-active' : 'border-flow-line'"
71+
>
72+
<div
73+
w-2 h-2 border="4" rounded-full ml--1 translate-x--0.5px
74+
:class="active ? 'border-flow-line-active' : 'border-flow-line'"
75+
/>
76+
<span op50>{{ item.count }} plugins did not change the content but cost</span>
77+
<DisplayDuration :duration="item.duration" :color="true" :factor="5" text-xs />
78+
<span op50 flex-shrink-0>in total</span>
79+
<button
80+
border="~ base rounded-full" px2 py-px op50 hover="op100"
81+
@click="emit('toggleShowAll', item)"
82+
>
83+
Hide
84+
</button>
85+
</div>
86+
</div>
6787
<FlowmapNode
6888
v-else
6989
:lines="{ top: true }"
@@ -92,7 +112,7 @@ const importterModule = computed(() => {
92112
<template #inline-after>
93113
<DisplayDuration :duration="item.duration" :color="true" :factor="5" text-xs />
94114
<template v-if="item.type === 'transform'">
95-
<div v-if="item.content_from === item.content_to" text-xs op50>
115+
<div v-if="item.content_from === item.content_to" text-xs op25>
96116
no changes
97117
</div>
98118
<div v-else>

packages/devtools/src/app/pages/session/[session]/graph/index.vue

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { useRoute, useRouter } from '#app/composables/router'
44
import { clearUndefined } from '@antfu/utils'
55
import { computedWithControl, debouncedWatch } from '@vueuse/core'
66
import Fuse from 'fuse.js'
7-
import { computed, reactive, ref } from 'vue'
7+
import { computed, reactive } from 'vue'
8+
import { settings } from '~/state/settings'
89
import { parseReadablePath } from '~/utils/filepath'
910
import { getFileTypeFromModuleId, getFileTypeFromName } from '~/utils/icon'
1011
@@ -118,13 +119,11 @@ const searched = computed(() => {
118119
.map(r => r.item)
119120
})
120121
121-
const display = ref<'list' | 'graph'>('list')
122-
123122
function toggleDisplay() {
124123
if (route.query.module) {
125124
router.replace({ query: { ...route.query, module: undefined } })
126125
}
127-
display.value = display.value === 'list' ? 'graph' : 'list'
126+
settings.value.flowModuleGraphView = settings.value.flowModuleGraphView === 'list' ? 'graph' : 'list'
128127
}
129128
</script>
130129

@@ -165,18 +164,18 @@ function toggleDisplay() {
165164
btn-action
166165
@click="toggleDisplay"
167166
>
168-
<div v-if="display === 'graph'" i-ph-graph-duotone />
167+
<div v-if="settings.flowModuleGraphView === 'graph'" i-ph-graph-duotone />
169168
<div v-else i-ph-list-duotone />
170-
{{ display === 'list' ? 'List' : 'Graph' }}
169+
{{ settings.flowModuleGraphView === 'list' ? 'List' : 'Graph' }}
171170
</button>
172171
</div>
173172
<!-- TODO: should we add filters for node_modules? -->
174173
<!-- {{ allNodeModules }} -->
175174
</div>
176-
<template v-if="display === 'list'">
175+
<template v-if="settings.flowModuleGraphView === 'list'">
177176
<div of-scroll max-h-screen pt-45 relative>
178177
<ModulesFlatList
179-
v-if="display === 'list'"
178+
v-if="settings.flowModuleGraphView === 'list'"
180179
:session="session"
181180
:modules="searched"
182181
/>

packages/devtools/src/app/pages/session/[session]/index.vue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,14 @@ const dataTable = computed<DataTableItem[]>(() => {
6060

6161
<template>
6262
<div flex="~ col gap-2" p6>
63-
<div op50>
63+
<div flex="~ gap-2">
64+
<NuxtLink btn-action :to="{ path: `/` }">
65+
<div i-ph-arrow-bend-up-left-duotone />
66+
Re-select Session
67+
</NuxtLink>
68+
</div>
69+
70+
<div op50 mt-10>
6471
Meta Info
6572
</div>
6673
<div border="~ base rounded" p4 grid="~ cols-[max-content_160px_2fr] gap-2 items-center">
@@ -99,12 +106,5 @@ const dataTable = computed<DataTableItem[]>(() => {
99106
</NuxtLink>
100107
</template>
101108
</div>
102-
103-
<div flex="~ gap-2" mt-10>
104-
<NuxtLink btn-action :to="{ path: `/` }">
105-
<div i-ph-arrow-left-duotone />
106-
Re-select Session
107-
</NuxtLink>
108-
</div>
109109
</div>
110110
</template>

0 commit comments

Comments
 (0)