Skip to content

Commit

Permalink
feat: allow override component inspector with __NUXT_INSPECTOR__
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Feb 16, 2025
1 parent 13f6fd0 commit 9f3c8bf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/devtools/src/runtime/plugins/view/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,22 +182,26 @@ export async function setupDevToolsClient({
})
}

function getInspector() {
return window.__NUXT_INSPECTOR__ || window.__VUE_INSPECTOR__
}

function enableComponentInspector() {
window.__VUE_INSPECTOR__?.enable()
getInspector()?.enable()
isInspecting.value = true
}

function disableComponentInspector() {
if (!window.__VUE_INSPECTOR__?.enabled)
if (!getInspector()?.enabled)
return

window.__VUE_INSPECTOR__?.disable()
getInspector()?.disable()
client?.hooks.callHook('host:inspector:close')
isInspecting.value = false
}

function getInspectorInstance(): NuxtDevtoolsHostClient['inspector'] {
const componentInspector = window.__VUE_INSPECTOR__
const componentInspector = getInspector()
if (componentInspector) {
componentInspector.openInEditor = async (url) => {
disableComponentInspector()
Expand All @@ -218,7 +222,7 @@ export async function setupDevToolsClient({
toggle: () => {
if (!state.value.open)
client.devtools.open()
if (window.__VUE_INSPECTOR__?.enabled)
if (getInspector()?.enabled)
disableComponentInspector()
else
enableComponentInspector()
Expand Down
5 changes: 5 additions & 0 deletions packages/devtools/src/types/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ declare global {
*/
__VUE_INSPECTOR__?: VueInspectorClient

/**
* Vue Inspector client
*/
__NUXT_INSPECTOR__?: VueInspectorClient

/**
* Experimental API: Picture-in-Picture mode
*
Expand Down

0 comments on commit 9f3c8bf

Please sign in to comment.