Skip to content

Commit e604b41

Browse files
authored
feat(vite): introducing component inspector option (#214)
1 parent e65ba84 commit e604b41

File tree

13 files changed

+46
-15
lines changed

13 files changed

+46
-15
lines changed

packages/client/src/App.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ const eyeDropper = useEyeDropper({})
7474
7575
bridgeRpc?.isVueInspectorDetected?.()?.then(({ data }) => {
7676
if (data) {
77+
vueInspectorDetected.value = true
7778
registerCommands(() =>
7879
[{
7980
id: 'action:vue-inspector',

packages/client/src/components/assets/AssetDetails.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const state = useDevToolsState()
1616
const asset = useVModel(props, 'modelValue', emit, { passive: true })
1717
1818
const _openInEditor = openInEditor
19-
19+
const _vueInspectorDetected = computed(() => vueInspectorDetected.value)
2020
const imageMeta = computedAsync(() => {
2121
if (asset.value.type !== 'image')
2222
return undefined
@@ -132,7 +132,7 @@ const supportsPreview = computed(() => {
132132
<div flex="~ gap-1" w-full items-center>
133133
<FilepathItem :filepath="asset.filePath" text-left />
134134
<VueIcon
135-
v-if="state.vitePluginDetected.value"
135+
v-if="state.vitePluginDetected.value && _vueInspectorDetected"
136136
v-tooltip="'Open in Editor'"
137137
title="Open in Editor"
138138
icon="i-carbon-launch"

packages/client/src/components/graph/GraphDrawer.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const filterId = graphFilterNodeId
1212
const state = useDevToolsState()
1313
1414
const _openInEditor = (path: string) => {
15-
if (state.vitePluginDetected.value) {
15+
if (state.vitePluginDetected.value && vueInspectorDetected.value) {
1616
openInEditor(path)
1717
return
1818
}

packages/client/src/components/pages/RoutesTable.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const sorted = computed(() => {
1818
})
1919
2020
const _openInEditor = openInEditor
21+
const _vueInspectorDetected = computed(() => vueInspectorDetected.value)
2122
const state = useDevToolsState()
2223
</script>
2324

@@ -63,7 +64,7 @@ const state = useDevToolsState()
6364
/>
6465
<div op0 group-hover:op100 flex="~ gap1">
6566
<button
66-
v-if="(item.file || item.meta?.file) && state.vitePluginDetected.value"
67+
v-if="(item.file || item.meta?.file) && state.vitePluginDetected.value && _vueInspectorDetected"
6768
text-sm op40 hover="op100 text-primary-400"
6869
title="Open in editor"
6970
@click="_openInEditor((item.file || item.meta?.file) as string)"

packages/client/src/composables/open-in-editor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useDevToolsBridgeRpc } from '@vue/devtools-core'
22

3+
export const vueInspectorDetected = ref(false)
34
export function openInEditor(file: string) {
45
const bridgeRpc = useDevToolsBridgeRpc()
56
return bridgeRpc.openInEditor({

packages/client/src/pages/components.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const treeNode = ref<ComponentTreeNode[]>([])
1111
const activeComponentId = ref('')
1212
1313
const _openInEditor = openInEditor
14+
const _vueInspectorDetected = computed(() => vueInspectorDetected.value)
1415
1516
// UX related state
1617
const loaded = ref(false)
@@ -281,7 +282,7 @@ const devtoolsState = useDevToolsState()
281282
/>
282283

283284
<VueIcon
284-
v-if="selectedComponentFilePath && devtoolsState.vitePluginDetected.value"
285+
v-if="selectedComponentFilePath && devtoolsState.vitePluginDetected.value && _vueInspectorDetected"
285286
v-tooltip="'Open in Editor'"
286287
title="Open in Editor"
287288
icon="i-carbon-launch"

packages/devtools-kit/src/core/vue-inspector/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ export interface VueInspector {
1919
onUpdated: () => void
2020
}
2121

22+
target.__VUE_DEVTOOLS_COMPONENT_INSPECTOR_ENABLED__ ??= true
23+
export function toggleComponentInspectorEnabled(enabled: boolean) {
24+
target.__VUE_DEVTOOLS_COMPONENT_INSPECTOR_ENABLED__ = enabled
25+
}
26+
2227
function waitForInspectorInit(cb: () => void) {
2328
let total = 0
2429
const timer = setInterval(() => {
@@ -41,8 +46,11 @@ function setupInspector() {
4146
}
4247
}
4348

44-
export function getVueInspector(): Promise<VueInspector> {
49+
export function getVueInspector(): Promise<VueInspector | null> {
4550
return new Promise((resolve) => {
51+
if (!target.__VUE_DEVTOOLS_COMPONENT_INSPECTOR_ENABLED__)
52+
resolve(null)
53+
4654
function setup() {
4755
setupInspector()
4856
resolve(target.__VUE_INSPECTOR__)

packages/devtools-kit/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { devtoolsContext, devtoolsState, hook, initDevTools, onDevToolsClientCon
22
import { addCustomTab } from './core/custom-tab'
33
import { addCustomCommand, removeCustomCommand } from './core/custom-command'
44
import { setupDevToolsPlugin } from './api/plugin'
5+
import { toggleComponentInspectorEnabled } from './core/vue-inspector'
56

67
export type * from './core/component/types'
78
export type * from './core/timeline/types'
@@ -31,4 +32,5 @@ export {
3132
addCustomCommand,
3233
removeCustomCommand,
3334
setupDevToolsPlugin,
35+
toggleComponentInspectorEnabled,
3436
}

packages/devtools-kit/src/shared/util.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ export function stringify<T extends object = Record<string, unknown>>(data: T) {
77
}
88

99
export function parse(data: string, revive = false) {
10-
if (!data)
10+
// eslint-disable-next-line eqeqeq
11+
if (data == undefined)
1112
return {}
1213

1314
return revive

packages/overlay/src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ const { iframe, getIframe } = useIframe(clientUrl, async () => {
121121
<path fill="#35495E" d="M50.56 0L128 133.12L204.8 0h-47.36L128 51.2L97.92 0H50.56Z" />
122122
</svg>
123123
</div>
124-
<template v-if="devtools.state.vitePluginDetected">
124+
<template v-if="devtools.state.vitePluginDetected && vueInspectorEnabled">
125125
<div class="vue-devtools__panel-content vue-devtools__panel-divider" />
126126
<div
127127
class="vue-devtools__anchor-btn vue-devtools__panel-content vue-devtools__inspector-button"

0 commit comments

Comments
 (0)