From 9f3c8bf147355b5b1c7435e8047432a0a47db4fb Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sun, 16 Feb 2025 15:01:24 +0800 Subject: [PATCH] feat: allow override component inspector with `__NUXT_INSPECTOR__` --- .../devtools/src/runtime/plugins/view/client.ts | 14 +++++++++----- packages/devtools/src/types/global.ts | 5 +++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/devtools/src/runtime/plugins/view/client.ts b/packages/devtools/src/runtime/plugins/view/client.ts index a170888950..5343da173b 100644 --- a/packages/devtools/src/runtime/plugins/view/client.ts +++ b/packages/devtools/src/runtime/plugins/view/client.ts @@ -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() @@ -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() diff --git a/packages/devtools/src/types/global.ts b/packages/devtools/src/types/global.ts index 09b663de31..e07d70c155 100644 --- a/packages/devtools/src/types/global.ts +++ b/packages/devtools/src/types/global.ts @@ -61,6 +61,11 @@ declare global { */ __VUE_INSPECTOR__?: VueInspectorClient + /** + * Vue Inspector client + */ + __NUXT_INSPECTOR__?: VueInspectorClient + /** * Experimental API: Picture-in-Picture mode *