Skip to content

Commit 3ab6600

Browse files
authoredMar 20, 2024··
feat(applet): enhance pinia panel nav (#285)
1 parent 8cd6092 commit 3ab6600

File tree

6 files changed

+48
-11
lines changed

6 files changed

+48
-11
lines changed
 

‎packages/applet/src/components/basic/DevToolsHeader.vue

+7-3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ const router = useVirtualRouter()
1010
</script>
1111

1212
<template>
13-
<div border="b base" class="h10 h40px flex items-center justify-between px-2">
14-
<i class="i-ep:back cursor-pointer op70 text-base hover:op100" @click="router.push('/')" />
13+
<div border="b base" class="h10 h40px flex items-center justify-between px3">
1514
<div>
16-
<a class="pr1" :href="docLink" target="_blank">
15+
<slot>
16+
<i class="i-ep:back cursor-pointer op70 text-base hover:op100" @click="router.push('/')" />
17+
</slot>
18+
</div>
19+
<div>
20+
<a class="pr2" :href="docLink" target="_blank">
1721
<i class="i-clarity:document-line cursor-pointer op70 text-base hover:op100" />
1822
</a>
1923
<a :href="githubRepoLink" target="_blank">

‎packages/applet/src/composables/virtual-router.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import type { Component, InjectionKey, Ref } from 'vue'
22
import { computed, defineComponent, h, inject, provide, ref } from 'vue'
33

44
const VirtualRouteKey: InjectionKey<Ref<{ path: string }>> = Symbol('VirtualRouteKey')
5+
const VirtualRoutesKey: InjectionKey<{ path: string, component: Component, icon?: string }[]> = Symbol('VirtualRoutesKey')
56

6-
export function registerVirtualRouter(routes: { path: string, component: Component }[]) {
7-
const route = ref<{ path: string }>({
7+
export function registerVirtualRouter(routes: { path: string, component: Component, icon?: string }[]) {
8+
const route = ref<{ path: string, icon?: string }>({
89
path: '/',
910
})
1011
const routePath = computed(() => route.value.path)
@@ -22,6 +23,7 @@ export function registerVirtualRouter(routes: { path: string, component: Compone
2223
})
2324

2425
provide(VirtualRouteKey, route)
26+
provide(VirtualRoutesKey, routes)
2527
return { VirtualRouterView }
2628
}
2729

@@ -34,3 +36,10 @@ export function useVirtualRouter() {
3436
},
3537
}
3638
}
39+
40+
export function useVirtualRoute() {
41+
const route = inject(VirtualRoutesKey)!
42+
return {
43+
routes: route,
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<script setup lang="ts">
2+
import { useVirtualRoute, useVirtualRouter } from '~/composables/virtual-router'
3+
4+
const { routes } = useVirtualRoute()
5+
const router = useVirtualRouter()
6+
</script>
7+
8+
<template>
9+
<ul class="flex gap3">
10+
<li
11+
v-for="(item, index) in routes"
12+
:key="index"
13+
cursor-pointer op70 hover:op100
14+
@click="router.push(item.path)"
15+
>
16+
<i :class="item.icon" />
17+
</li>
18+
</ul>
19+
</template>

‎packages/applet/src/pinia/components/store/Index.vue

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Pane, Splitpanes } from 'splitpanes'
44
import { getInspectorState, getInspectorTree, onInspectorStateUpdated, onInspectorTreeUpdated } from '@vue/devtools-core'
55
import { parse } from '@vue/devtools-kit'
66
import type { InspectorNodeTag, InspectorState } from '@vue/devtools-kit'
7+
import Navbar from '../Navbar.vue'
78
import SelectiveList from '~/components/basic/SelectiveList.vue'
89
import DevToolsHeader from '~/components/basic/DevToolsHeader.vue'
910
import Empty from '~/components/basic/Empty.vue'
@@ -77,7 +78,9 @@ onInspectorStateUpdated((data) => {
7778

7879
<template>
7980
<div class="h-full flex flex-col">
80-
<DevToolsHeader doc-link="https://pinia.vuejs.org/" github-repo-link="https://github.com/vuejs/pinia" />
81+
<DevToolsHeader doc-link="https://pinia.vuejs.org/" github-repo-link="https://github.com/vuejs/pinia">
82+
<Navbar />
83+
</DevToolsHeader>
8184
<Splitpanes class="flex-1">
8285
<Pane border="r base" size="40" h-full>
8386
<div h-full select-none overflow-scroll class="no-scrollbar">

‎packages/applet/src/pinia/components/timeline/Index.vue

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { onAddTimelineEvent } from '@vue/devtools-core'
44
55
import type { InspectorState, TimelineEvent } from '@vue/devtools-kit'
66
import { computed, ref } from 'vue'
7+
import Navbar from '../Navbar.vue'
78
import EventList from './EventList.vue'
89
import Empty from '~/components/basic/Empty.vue'
910
import RootStateViewer from '~/components/state/RootStateViewer.vue'
@@ -79,7 +80,9 @@ onAddTimelineEvent((payload) => {
7980

8081
<template>
8182
<div class="h-full flex flex-col">
82-
<DevToolsHeader doc-link="https://pinia.vuejs.org/" github-repo-link="https://github.com/vuejs/pinia" />
83+
<DevToolsHeader doc-link="https://pinia.vuejs.org/" github-repo-link="https://github.com/vuejs/pinia">
84+
<Navbar />
85+
</DevToolsHeader>
8386
<template v-if="eventList.length">
8487
<div class="flex-1 overflow-hidden">
8588
<Splitpanes class="h-full">

‎packages/applet/src/pinia/index.vue

+3-4
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,21 @@ const { VirtualRouterView } = registerVirtualRouter([
1313
{
1414
path: '/',
1515
component: Home,
16+
icon: 'i-logos-pinia',
1617
},
1718
{
1819
path: '/store',
1920
component: Store,
21+
icon: 'i-carbon-tree-view-alt',
2022
},
2123
{
2224
path: '/timeline',
2325
component: Timeline,
26+
icon: 'i-mdi:timeline-clock-outline',
2427
},
2528
])
2629
2730
const routePath = ref('/')
28-
29-
function toggleRoute(route: string) {
30-
routePath.value = route
31-
}
3231
</script>
3332

3433
<template>

0 commit comments

Comments
 (0)
Please sign in to comment.