Skip to content

Commit f2ea499

Browse files
committed
feat: improved HTMLElement display in inspector
1 parent 4f98811 commit f2ea499

4 files changed

Lines changed: 46 additions & 17 deletions

File tree

packages/api/src/api/component.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,22 @@ export interface ComponentPropState extends ComponentStateBase {
5252
export type ComponentBuiltinCustomStateTypes = 'function' | 'map' | 'set' | 'reference' | 'component' | 'component-definition' | 'router' | 'store'
5353

5454
export interface ComponentCustomState extends ComponentStateBase {
55-
value: {
56-
_custom: {
57-
type: ComponentBuiltinCustomStateTypes | string
58-
display?: string
59-
tooltip?: string
60-
value?: any
55+
value: CustomState
56+
}
57+
58+
export type CustomState = {
59+
_custom: {
60+
type: ComponentBuiltinCustomStateTypes | string
61+
display?: string
62+
tooltip?: string
63+
value?: any
64+
abstract?: boolean
65+
file?: string
66+
uid?: number
67+
readOnly?: boolean
68+
/** Configure immediate child fields */
69+
fields?: {
6170
abstract?: boolean
62-
file?: string
63-
uid?: number
64-
readOnly?: boolean
65-
/** Configure immediate child fields */
66-
fields?: {
67-
abstract?: boolean
68-
}
6971
}
7072
}
7173
}

packages/shared-utils/src/util.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import path from 'path'
2+
import { CustomState } from '@vue/devtools-api'
23
import { stringifyCircularAutoChunks, parseCircularAutoChunks } from './transfer'
34
import {
45
getInstanceMap,
56
getCustomInstanceDetails,
67
getCustomRouterDetails,
78
getCustomStoreDetails,
8-
isVueInstance,
9-
backendInjections
9+
isVueInstance
1010
} from './backend'
1111
import SharedData from './shared-data'
1212
import { isChrome, target } from './env'
@@ -196,6 +196,8 @@ function replacer (key) {
196196
return encodeCache.cache(val, () => getCustomComponentDefinitionDetails(val))
197197
} else if (val.constructor && val.constructor.name === 'VNode') {
198198
return `[native VNode <${val.tag}>]`
199+
} else if (val instanceof HTMLElement) {
200+
return encodeCache.cache(val, () => getCustomHTMLElementDetails(val))
199201
}
200202
} else if (Number.isNaN(val)) {
201203
return NAN
@@ -322,6 +324,26 @@ export function getCustomFunctionDetails (func) {
322324
}
323325
}
324326

327+
export function getCustomHTMLElementDetails (value: HTMLElement): CustomState {
328+
return {
329+
_custom: {
330+
type: 'HTMLElement',
331+
display: `<span class="opacity-30">&lt;</span><span class="text-blue-500">${value.tagName.toLowerCase()}</span><span class="opacity-30">&gt;</span>`,
332+
value: namedNodeMapToObject(value.attributes)
333+
}
334+
}
335+
}
336+
337+
function namedNodeMapToObject (map: NamedNodeMap) {
338+
const result: any = {}
339+
const l = map.length
340+
for (let i = 0; i < l; i++) {
341+
const node = map.item(i)
342+
result[node.name] = node.value
343+
}
344+
return result
345+
}
346+
325347
export function getCustomRefDetails (instance, key, ref) {
326348
let value
327349
if (Array.isArray(ref)) {

packages/shell-dev-vue3/src/NativeTypes.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
<div
66
id="aDiv"
77
ref="someDiv"
8+
class="foo bar"
9+
data-testid="some-div"
810
/>
911

1012
<p>
@@ -112,7 +114,8 @@ export default {
112114
multiLineParameterFunction: function (a,
113115
b,
114116
c) {},
115-
veryLongText
117+
veryLongText,
118+
someElement: null
116119
}
117120
},
118121
@@ -125,6 +128,7 @@ export default {
125128
126129
mounted () {
127130
this.testComponent = this.$refs.component
131+
this.someElement = this.$refs.someDiv
128132
},
129133
130134
methods: {

tailwind.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ module.exports = {
8484
path.resolve(__dirname, './packages/app-backend-core/src/**/*.{js,jsx,ts,tsx,vue}'),
8585
path.resolve(__dirname, './packages/app-backend-vue1/src/**/*.{js,jsx,ts,tsx,vue}'),
8686
path.resolve(__dirname, './packages/app-backend-vue2/src/**/*.{js,jsx,ts,tsx,vue}'),
87-
path.resolve(__dirname, './packages/app-backend-vue3/src/**/*.{js,jsx,ts,tsx,vue}')
87+
path.resolve(__dirname, './packages/app-backend-vue3/src/**/*.{js,jsx,ts,tsx,vue}'),
88+
path.resolve(__dirname, './packages/shared-utils/src/**/*.{js,jsx,ts,tsx,vue}')
8889
]
8990
}
9091
}

0 commit comments

Comments
 (0)