Skip to content

Commit bbc62b0

Browse files
committed
fix: inspector interaction
1 parent af7da96 commit bbc62b0

7 files changed

Lines changed: 48 additions & 18 deletions

File tree

‎packages/devtools/src/runtime/plugins/view/client.ts‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { setIframeServerContext } from '@vue/devtools-kit'
1313
import{createHooks}from'hookable'
1414
import{debounce}from'perfect-debounce'
1515
import{eventsasinspectorEvents,hasDataasinspectorHasData,stateasinspectorState}from'vite-plugin-vue-tracer/client/overlay'
16-
import{computed,markRaw,reactive,ref,shallowReactive,shallowRef,toRef,watch}from'vue'
16+
import{computed,markRaw,nextTick,reactive,ref,shallowReactive,shallowRef,toRef,watch}from'vue'
1717

1818
import{initTimelineMetrics}from'../../function-metrics-helpers'
1919
import{settings}from'../../settings'
@@ -191,6 +191,7 @@ export async function setupDevToolsClient({
191191

192192
constprops=reactive<NuxtDevToolsInspectorProps>({
193193
mouse: {x: 0,y: 0},
194+
hasParent: false,
194195
matched: undefined,
195196
})
196197

@@ -203,33 +204,40 @@ export async function setupDevToolsClient({
203204
component.addEventListener('close',()=>{
204205
props.matched=undefined
205206
inspectorState.isEnabled=false
207+
inspectorState.isVisible=false
206208
})
207209
component.addEventListener('selectParent',()=>{
208210
constparent=inspectorState.main?.getParent()
209211
if(parent){
210212
inspectorState.main=parent
211213
props.matched=parent
214+
nextTick(()=>{
215+
props.hasParent=!!inspectorState.main?.getParent()
216+
})
212217
}
213218
})
214219
// eslint-disable-next-line ts/ban-ts-comment
215220
// @ts-ignore WebComponent types
216-
component.addEventListener('openInEditor',(e)=>{
221+
component.addEventListener('openInEditor',async(e)=>{
217222
consturl=(easany)?.detail?.[0]
218223
if(url)
219-
client.hooks.callHook('host:inspector:click',url)
224+
awaitclient.hooks.callHook('host:inspector:click',url)
220225
})
221226

222227
inspectorEvents.on('hover',()=>{
223228
inspectorState.isFocused=false
229+
props.hasParent=!!inspectorState.main?.getParent()
224230
})
225231
inspectorEvents.on('disabled',()=>{
226232
inspectorState.isVisible=false
227233
client?.hooks.callHook('host:inspector:close')
228234
})
229235
inspectorEvents.on('enabled',()=>{
230236
inspectorState.isVisible=true
237+
inspectorState.isEnabled=true
231238
})
232239
inspectorEvents.on('click',async(info,e)=>{
240+
inspectorState.isEnabled=false
233241
inspectorState.isFocused=true
234242
inspectorState.isVisible=true
235243

@@ -246,15 +254,18 @@ export async function setupDevToolsClient({
246254

247255
returninspector=markRaw({
248256
isAvailable,
249-
isEnabled: toRef(inspectorState,'isEnabled'),
257+
isEnabled: toRef(inspectorState,'isVisible'),
250258
enable: ()=>{
259+
inspectorState.isVisible=true
251260
inspectorState.isEnabled=true
252261
},
253262
disable: ()=>{
263+
inspectorState.isVisible=false
254264
inspectorState.isEnabled=false
255265
},
256266
toggle: ()=>{
257267
inspectorState.isEnabled=!inspectorState.isEnabled
268+
inspectorState.isVisible=inspectorState.isEnabled
258269
},
259270
})
260271
}

‎packages/devtools/src/webcomponents/.generated/css.ts‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
importtype{VueElementConstructor}from'vue'
2-
importtype{NuxtDevToolsInspectorProps}from'./Props'
32
import{defineCustomElement}from'vue'
43
importcssfrom'../.generated/css'
54
importComponentfrom'./NuxtDevtoolsFrame.vue'
65

7-
exportconstNuxtDevtoolsFrame=defineCustomElement({
8-
...Component,
9-
shadowRoot: true,
10-
styles: [css],
11-
}asany)asVueElementConstructor<{props: NuxtDevToolsInspectorProps}>
6+
exportconstNuxtDevtoolsFrame=defineCustomElement(
7+
Component,
8+
{
9+
shadowRoot: true,
10+
styles: [css],
11+
},
12+
)asVueElementConstructor
1213

1314
customElements.define('nuxt-devtools-frame',NuxtDevtoolsFrame)

‎packages/devtools/src/webcomponents/components/NuxtDevtoolsInspectPanel.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import { defineCustomElement } from 'vue'
44
importcssfrom'../.generated/css'
55
importComponentfrom'./NuxtDevtoolsInspectPanel.vue'
66

7-
exportconstNuxtDevtoolsInspectPanel=defineCustomElement({
8-
...Component,
9-
shadowRoot: true,
10-
styles: [css],
11-
}asany)asVueElementConstructor<{props: NuxtDevToolsInspectorProps}>
7+
exportconstNuxtDevtoolsInspectPanel=defineCustomElement(
8+
Component,
9+
{
10+
shadowRoot: true,
11+
styles: [css],
12+
},
13+
)asVueElementConstructor<{props: NuxtDevToolsInspectorProps}>
1214

1315
customElements.define('nuxt-devtools-inspect-panel',NuxtDevtoolsInspectPanel)

‎packages/devtools/src/webcomponents/components/NuxtDevtoolsInspectPanel.vue‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ async function openInEditor() {
9393
<divref="draggingEl"class="flex items-center gap-2 p2">
9494
<button
9595
title="Go to parent"
96-
class="flex items-center text-sm font-mono op50 hover:text-green6 hover:op100"
96+
class="flex items-center text-sm font-mono op50 disabled:pointer-events-none hover:text-green6 hover:op100 disabled:op10!"
97+
:disabled="!props.hasParent"
9798
@click="selectParent"
9899
>
99100
<divclass="i-ph-arrow-bend-left-up-duotone text-lg" />

‎packages/devtools/src/webcomponents/components/Props.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ import type { ElementTraceInfo } from 'vite-plugin-vue-tracer/client/record'
22

33
exportinterfaceNuxtDevToolsInspectorProps{
44
matched?: ElementTraceInfo
5+
hasParent?: boolean
56
mouse: {x: number,y: number}
67
}

‎playgrounds/empty/app.vue‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
1+
<script setup lang="ts">
2+
function handleClick() {
3+
// eslint-disable-next-line no-console
4+
console.log('clicked')
5+
}
6+
</script>
7+
18
<template>
2-
<div>Hello</div>
9+
<h1>Hello</h1>
10+
<p>
11+
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, quos.
12+
<ahref="https://nuxt.com">Nuxt</a>
13+
</p>
14+
<button@click="handleClick">
15+
Click me
16+
</button>
317
</template>
418

519
<style>

0 commit comments

Comments
 (0)