Skip to content

Commit ecc650d

Browse files
committed
chore: update
2 parents 206ceb9 + fe353ef commit ecc650d

File tree

11 files changed

+176
-271
lines changed

11 files changed

+176
-271
lines changed

packages/rolldown/src/app/pages/session/[session].vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
import type { ModuleListItem, SessionContext } from '~~/shared/types'
33
import { useRoute, useRouter } from '#app/composables/router'
44
import { useRpc } from '#imports'
5+
import PanelSideNav from '@vitejs/devtools-ui/components/PanelSideNav.vue'
6+
import { useSideNav } from '@vitejs/devtools-ui/composables/nav'
57
import { onKeyDown } from '@vueuse/core'
68
import { computed, onMounted, reactive, ref, shallowRef } from 'vue'
7-
import { useSideNav } from '~/state/nav'
89
import { getFileTypeFromName } from '~/utils/icon'
910
1011
const params = useRoute().params as {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import type { SessionContext } from '~~/shared/types'
33
import DisplayBadge from '@vitejs/devtools-ui/components/DisplayBadge.vue'
44
import DisplayDuration from '@vitejs/devtools-ui/components/DisplayDuration.vue'
55
import DisplayNumberBadge from '@vitejs/devtools-ui/components/DisplayNumberBadge.vue'
6+
import { sideNavItems } from '@vitejs/devtools-ui/composables/nav'
67
import { computed } from 'vue'
7-
import { sideNavItems } from '~~/app/state/nav'
88
99
const props = defineProps<{
1010
session: SessionContext

packages/ui/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"module": "./src/index.ts",
4646
"peerDependencies": {
4747
"@vueuse/core": "*",
48+
"nuxt": "*",
4849
"unocss": "*",
4950
"vue": "*",
5051
"vue-virtual-scroller": ">=2.0.0-beta.0"

packages/rolldown/src/app/components/panel/SideNav.vue renamed to packages/ui/src/components/PanelSideNav.vue

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
11
<script setup lang="ts">
2-
import type { SideNavItem } from '~/state/nav'
2+
import type { SideNavItem } from '../composables/nav'
33
import { NuxtLink } from '#components'
4-
import { toggleDark } from '@vitejs/devtools-ui/composables/dark'
54
import { computed } from 'vue'
6-
import { sideNavItems } from '~/state/nav'
5+
import { toggleDark } from '../composables/dark'
6+
import { sideNavItems } from '../composables/nav'
77
8-
const items = computed<SideNavItem[]>(() => [
9-
...sideNavItems.value,
10-
{
11-
title: 'Toggle dark mode',
12-
icon: 'i-ph-sun-duotone dark:i-ph-moon-duotone',
13-
action: toggleDark,
14-
},
15-
])
8+
const props = withDefaults(defineProps<{
9+
items?: SideNavItem[]
10+
showDarkModeToggle?: boolean
11+
}>(), {
12+
showDarkModeToggle: true,
13+
})
14+
15+
const items = computed<SideNavItem[]>(() => {
16+
const navItems = props.items ?? sideNavItems.value
17+
if (!props.showDarkModeToggle) {
18+
return navItems
19+
}
20+
return [
21+
...navItems,
22+
{
23+
title: 'Toggle dark mode',
24+
icon: 'i-ph-sun-duotone dark:i-ph-moon-duotone',
25+
action: toggleDark,
26+
},
27+
]
28+
})
1629
</script>
1730

1831
<template>
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,28 @@ export interface SideNavItem {
99
action?: () => void
1010
}
1111

12-
let __id = 0
12+
let id = 0
1313
const sideNavItemsMap = reactive(new Map<number, SideNavItem[]>())
1414

1515
export const sideNavItems = computed(() => Array.from(sideNavItemsMap.values()).flat())
1616

1717
export function useSideNav(items: MaybeRefOrGetter<SideNavItem[]>) {
18-
const r = toRef(items)
18+
const itemsRef = toRef(items)
1919

2020
let clear = () => {}
21-
function add(items: SideNavItem[]) {
21+
function add(nextItems: SideNavItem[]) {
2222
clear()
23-
const id = __id++
24-
sideNavItemsMap.set(id, items)
23+
const currentId = id++
24+
sideNavItemsMap.set(currentId, nextItems)
2525
clear = () => {
26-
sideNavItemsMap.delete(id)
26+
sideNavItemsMap.delete(currentId)
2727
}
28-
return id
2928
}
3029

3130
watch(
32-
r,
33-
(items) => {
34-
add(items)
31+
itemsRef,
32+
(nextItems) => {
33+
add(nextItems)
3534
},
3635
{ immediate: true },
3736
)
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import type {} from '@vitejs/devtools'
2+
import type { DevToolsRpcClient } from '@vitejs/devtools-kit/client'
3+
import type {} from '../../node/rpc'
4+
import { useRuntimeConfig } from '#app/nuxt'
5+
import { getDevToolsRpcClient } from '@vitejs/devtools-kit/client'
6+
import { reactive, shallowRef } from 'vue'
7+
8+
export const rpcConnectionState = reactive<{
9+
connected: boolean
10+
error: Error | null
11+
}>({
12+
connected: false,
13+
error: null,
14+
})
15+
16+
const rpc = shallowRef<DevToolsRpcClient>(undefined!)
17+
18+
export async function connect() {
19+
const runtimeConfig = useRuntimeConfig()
20+
try {
21+
rpc.value = await getDevToolsRpcClient({
22+
baseURL: [
23+
'/.devtools/',
24+
runtimeConfig.app.baseURL,
25+
],
26+
connectionMeta: runtimeConfig.app.connection,
27+
wsOptions: {
28+
onConnected: () => {
29+
rpcConnectionState.connected = true
30+
},
31+
onError: (e) => {
32+
rpcConnectionState.error = e
33+
},
34+
onDisconnected: () => {
35+
rpcConnectionState.connected = false
36+
},
37+
},
38+
rpcOptions: {
39+
onGeneralError: (e, name) => {
40+
rpcConnectionState.error = e
41+
console.error(`[vite-devtools] RPC error on executing "${name}":`)
42+
},
43+
onFunctionError: (e, name) => {
44+
rpcConnectionState.error = e
45+
console.error(`[vite-devtools] RPC error on executing "${name}":`)
46+
},
47+
},
48+
})
49+
50+
rpcConnectionState.connected = true
51+
}
52+
catch (e) {
53+
rpcConnectionState.error = e as Error
54+
}
55+
}
56+
57+
export function useRpc() {
58+
return rpc
59+
}

packages/vite/src/modules/rpc.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { addVitePlugin, defineNuxtModule } from '@nuxt/kit'
2+
import { DevToolsServer } from '../../../core/src/node/plugins/server'
3+
import { rpcFunctions } from '../node/rpc'
4+
5+
export default defineNuxtModule({
6+
meta: {
7+
name: 'devtools-rpc',
8+
configKey: 'devtoolsRpc',
9+
},
10+
setup() {
11+
addVitePlugin({
12+
name: 'vite:devtools:vite',
13+
devtools: {
14+
setup(ctx) {
15+
for (const fn of rpcFunctions) {
16+
ctx.rpc.register(fn)
17+
}
18+
},
19+
},
20+
})
21+
22+
addVitePlugin(DevToolsServer())
23+
},
24+
})
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { defineRpcFunction } from '@vitejs/devtools-kit'
2+
3+
export const viteHi = defineRpcFunction({
4+
name: 'vite:hi',
5+
type: 'query',
6+
setup: (context) => {
7+
return {
8+
handler: async () => {
9+
return {
10+
message: 'Hi from server.',
11+
cwd: context.cwd,
12+
timestamp: Date.now(),
13+
}
14+
},
15+
}
16+
},
17+
})
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { RpcDefinitionsToFunctions } from '@vitejs/devtools-kit'
2+
import { viteHi } from './functions/hi'
3+
import '@vitejs/devtools-kit'
4+
5+
export const rpcFunctions = [
6+
viteHi,
7+
] as const
8+
9+
export type ServerFunctions = RpcDefinitionsToFunctions<typeof rpcFunctions>
10+
11+
declare module '@vitejs/devtools-kit' {
12+
export interface DevToolsRpcServerFunctions extends ServerFunctions {}
13+
}

packages/vite/src/nuxt.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default defineNuxtConfig({
1414
'@unocss/nuxt',
1515
'@nuxt/eslint',
1616
'nuxt-eslint-auto-explicit-import',
17+
'./modules/rpc',
1718
],
1819

1920
alias,

0 commit comments

Comments
 (0)