-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
- Loading branch information
1 parent
77377bd
commit 56be5a7
Showing
21 changed files
with
1,742 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { activeAppRecord, connected } from '../setup/vue-devtools' | ||
|
||
export function useVueDevToolsState() { | ||
return { | ||
activeAppRecord, | ||
connected, | ||
} | ||
} | ||
|
||
export function onVueDevToolsConnected(callback: () => void) { | ||
if (connected.value) { | ||
callback() | ||
} | ||
else { | ||
const stop = watch(connected, (value) => { | ||
if (value) { | ||
stop() | ||
callback() | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<script setup lang="ts"> | ||
import { Pinia } from '@vue/devtools-applet' | ||
import '@vue/devtools-applet/style.css' | ||
const { connected } = useVueDevToolsState() | ||
definePageMeta({ | ||
icon: 'i-logos-pinia', | ||
title: 'Pinia', | ||
layout: 'full', | ||
show() { | ||
const configs = useServerConfig() | ||
return () => configs.value?.modules?.includes('@pinia/nuxt') | ||
}, | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div class="h-full w-full"> | ||
<Pinia v-if="connected" /> | ||
<NLoading v-else> | ||
Connecting.... | ||
</NLoading> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { HandShakeServer, getDevToolsState, initDevToolsSeparateWindow, initDevToolsSeparateWindowBridge, onDevToolsStateUpdated, setupDevToolsBridge } from '@vue/devtools-core' | ||
import type { AppRecord } from '@vue/devtools-kit' | ||
import { toggleHighPerfMode } from '@vue/devtools-kit' | ||
|
||
export type DevtoolsBridgeAppRecord = Pick<AppRecord, 'name' | 'id' | 'version' | 'routerId' | 'moduleDetectives'> | ||
|
||
const appConnected = ref(false) | ||
const clientConnected = ref(false) | ||
const appRecords = ref<Array<DevtoolsBridgeAppRecord>>([]) | ||
const activeAppRecordId = ref<string | null>(null) | ||
export const connected = computed(() => appConnected.value && clientConnected.value) | ||
export const activeAppRecord = computed(() => appRecords.value.find(r => r.id === activeAppRecordId.value)) | ||
|
||
export function initVueDevToolsState() { | ||
getDevToolsState().then((data) => { | ||
if (!data) | ||
return | ||
appConnected.value = data.connected | ||
clientConnected.value = data.clientConnected | ||
appRecords.value = data.appRecords | ||
activeAppRecordId.value = data.activeAppRecordId | ||
}) | ||
|
||
onDevToolsStateUpdated((data) => { | ||
if (!data) | ||
return | ||
appConnected.value = data.connected | ||
clientConnected.value = data.clientConnected | ||
appRecords.value = data.appRecords | ||
activeAppRecordId.value = data.activeAppRecordId | ||
}) | ||
|
||
return { | ||
appRecords, | ||
activeAppRecord, | ||
} | ||
} | ||
|
||
export function setupVueDevTools() { | ||
const state = useDevToolsFrameState() | ||
|
||
const isInPopup = window.__NUXT_DEVTOOLS_IS_POPUP__ | ||
|
||
watchEffect(() => { | ||
if (isInPopup) | ||
toggleHighPerfMode(false) | ||
else | ||
toggleHighPerfMode(!state.value?.open) | ||
}) | ||
|
||
initDevToolsSeparateWindow({ | ||
onConnected(channel) { | ||
const bridge = initDevToolsSeparateWindowBridge(channel) | ||
setupDevToolsBridge(bridge) | ||
new HandShakeServer(bridge).onnConnect().then(() => { | ||
bridge.emit('devtools:client-ready') | ||
initVueDevToolsState() | ||
}) | ||
bridge.on('disconnect', () => { | ||
channel.close() | ||
initDevToolsSeparateWindow() | ||
}) | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { addVitePlugin } from '@nuxt/kit' | ||
import { join } from 'pathe' | ||
import type { NuxtDevtoolsServerContext } from '../types' | ||
import { runtimeDir } from '../dirs' | ||
|
||
export function setup({ nuxt }: NuxtDevtoolsServerContext) { | ||
if (!nuxt.options.dev || nuxt.options.test) | ||
return | ||
|
||
addVitePlugin({ | ||
name: 'vue:devtools', | ||
async resolveId(importee: string) { | ||
if (importee.startsWith('virtual:vue-devtools-path:')) { | ||
const resolved = importee.replace('virtual:vue-devtools-path:', join(runtimeDir, 'vue-devtools/')) | ||
return resolved | ||
} | ||
}, | ||
transform(code, id) { | ||
const [filename] = id.split('?', 2) | ||
const appendTo = /\/entry\.m?js$/ | ||
|
||
if (appendTo.test(filename)) | ||
code = `import 'virtual:vue-devtools-path:overlay.mjs';\n${code}` | ||
|
||
return code | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { devtools } from '@vue/devtools-kit' | ||
import { initAppSeparateWindow } from '@vue/devtools-core' | ||
|
||
devtools.init() | ||
|
||
initAppSeparateWindow() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
shamefully-hoist=true | ||
strict-peer-dependencies=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<script setup lang="ts"> | ||
</script> | ||
|
||
<template> | ||
<NuxtLayout> | ||
<NuxtPage /> | ||
</NuxtLayout> | ||
</template> | ||
|
||
<style> | ||
html.dark { | ||
background: #050505; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@import '@exampledev/new.css'; |
Oops, something went wrong.