1
1
<script setup lang="ts">
2
2
import type { InspectorCustomState , InspectorState , InspectorStateEditorPayload } from ' @vue/devtools-kit'
3
- import { sortByKey } from ' @vue/devtools-shared'
3
+ import { isArray , isObject , sortByKey } from ' @vue/devtools-shared'
4
4
import { formatInspectorStateValue , getInspectorStateValueType , getRawValue } from ' @vue/devtools-kit'
5
5
import { useDevToolsBridgeRpc } from ' @vue/devtools-core'
6
+ import { VueButton , VueIcon , VTooltip as vTooltip } from ' @vue/devtools-ui'
6
7
import Actions from ' ./InspectorDataField/Actions.vue'
7
8
import type { EditorAddNewPropType } from ' ~/composables/inspector'
8
9
@@ -15,6 +16,8 @@ const props = withDefaults(defineProps<{
15
16
depth: 0 ,
16
17
})
17
18
19
+ const STATE_FIELDS_LIMIT_SIZE = 30
20
+
18
21
const state = useStateEditorContext ()
19
22
const bridgeRpc = useDevToolsBridgeRpc ()
20
23
const value = computed (() => formatInspectorStateValue (props .data .value ))
@@ -49,11 +52,13 @@ const normalizedValue = computed(() => {
49
52
50
53
const rawValue = computed (() => getRawValue (props .data .value ))
51
54
55
+ const limit = ref (STATE_FIELDS_LIMIT_SIZE )
56
+
52
57
const normalizedChildField = computed (() => {
53
- let { value, inherit } = rawValue .value
54
- if ( Array . isArray ( value )) {
55
- // @TODO: show more
56
- const sliced = value .slice (0 , 20 )
58
+ const { value, inherit } = rawValue .value
59
+ let displayedValue : any []
60
+ if ( isArray ( value )) {
61
+ const sliced = value .slice (0 , limit . value )
57
62
return sliced .map ((item , i ) => ({
58
63
key: ` ${props .data .key }.${i } ` ,
59
64
value: item ,
@@ -62,22 +67,32 @@ const normalizedChildField = computed(() => {
62
67
creating: false ,
63
68
}))
64
69
}
65
- else if (value !== null && typeof value === ' object ' ) {
66
- value = Object .keys (value ).map (key => ({
70
+ else if (isObject ( value ) ) {
71
+ displayedValue = Object .keys (value ). slice ( 0 , limit . value ).map (key => ({
67
72
key: ` ${props .data .key }.${key } ` ,
68
73
value: value [key ],
69
74
... inherit ,
70
75
editable: props .data .editable ,
71
76
creating: false ,
72
77
}))
73
78
if (type .value !== ' custom' )
74
- value = sortByKey (value )
79
+ displayedValue = sortByKey (displayedValue )
75
80
}
76
81
else {
77
- value = []
82
+ displayedValue = []
78
83
}
79
84
80
- return value === props .data .value ? {} : value
85
+ return displayedValue === props .data .value ? {} : displayedValue
86
+ })
87
+
88
+ const fieldsCount = computed (() => {
89
+ const { value } = rawValue .value
90
+ if (isArray (value ))
91
+ return value .length
92
+ else if (isObject (value ))
93
+ return Object .keys (value ).length
94
+ else
95
+ return 0
81
96
})
82
97
83
98
const normalizedDisplayedKey = computed (() => {
@@ -150,8 +165,8 @@ function submitDrafting() {
150
165
resetDrafting ()
151
166
}
152
167
153
- const containerRef = ref ()
154
- const { isHovering } = useHover (containerRef )
168
+ const containerRef = ref < HTMLDivElement > ()
169
+ const { isHovering } = useHover (() => containerRef . value )
155
170
</script >
156
171
157
172
<template >
@@ -194,6 +209,11 @@ const { isHovering } = useHover(containerRef)
194
209
<InspectorStateField
195
210
v-for =" (field, index) in normalizedChildField" :key =" index" :data =" field" :depth =" depth + 1" :no =" no" :root-id =" rootId"
196
211
/>
212
+ <VueButton v-if =" fieldsCount > limit" v-tooltip =" 'Show more'" flat size =" mini" class =" ml-4" @click =" limit += STATE_FIELDS_LIMIT_SIZE" >
213
+ <template #icon >
214
+ <VueIcon icon =" i-material-symbols-more-horiz" />
215
+ </template >
216
+ </VueButton >
197
217
<div v-if =" draftingNewProp.enable" :style =" { paddingLeft: `${(depth + 1) * 15 + 4}px` }" >
198
218
<span overflow-hidden text-ellipsis whitespace-nowrap state-key >
199
219
<EditInput v-model =" draftingNewProp.key" type =" string" :show-actions =" false" />
0 commit comments