@@ -46,7 +46,11 @@ export function getInspectorStateValueType(value, raw = true) {
46
46
}
47
47
}
48
48
49
- export function formatInspectorStateValue ( value , quotes = false ) {
49
+ export function formatInspectorStateValue ( value , quotes = false , options ?: {
50
+ // Support more types if needed
51
+ customClass ?: Partial < Record < 'string' , string > >
52
+ } ) {
53
+ const { customClass } = options ?? { }
50
54
let result
51
55
const type = getInspectorStateValueType ( value , false )
52
56
if ( type !== 'custom' && value ?. _custom )
@@ -58,7 +62,7 @@ export function formatInspectorStateValue(value, quotes = false) {
58
62
}
59
63
else if ( type === 'custom' ) {
60
64
// For digging out nested custom name.
61
- const nestedName = value . _custom . value ?. _custom && formatInspectorStateValue ( value . _custom . value )
65
+ const nestedName = value . _custom . value ?. _custom && formatInspectorStateValue ( value . _custom . value , quotes , options )
62
66
return nestedName || value . _custom . displayText || value . _custom . display
63
67
}
64
68
else if ( type === 'array' ) {
@@ -72,21 +76,30 @@ export function formatInspectorStateValue(value, quotes = false) {
72
76
}
73
77
else if ( typeof value === 'string' ) {
74
78
const typeMatch = value . match ( rawTypeRE )
75
- if ( typeMatch )
76
- value = escape ( typeMatch [ 1 ] )
77
-
78
- else if ( quotes )
79
- value = `<span>"</span>${ escape ( value ) } <span>"</span>`
79
+ if ( typeMatch ) {
80
+ value = escapeString ( typeMatch [ 1 ] )
81
+ }
80
82
81
- else
82
- value = escape ( value )
83
+ else if ( quotes ) {
84
+ value = `<span>"</span>${
85
+ customClass ?. string ? `<span class=${ customClass . string } >${ escapeString ( value ) } </span>` : escapeString ( value )
86
+ } <span>"</span>`
87
+ }
83
88
84
- value = value . replace ( / / g, ' ' )
85
- . replace ( / \n / g, '<span>\\n</span>' )
89
+ else {
90
+ value = customClass ?. string
91
+ ? `<span class="${ customClass ?. string ?? '' } ">${ escapeString ( value ) } </span>`
92
+ : escapeString ( value )
93
+ }
86
94
}
87
95
return value
88
96
}
89
97
98
+ function escapeString ( value : string ) {
99
+ return escape ( value ) . replace ( / / g, ' ' )
100
+ . replace ( / \n / g, '<span>\\n</span>' )
101
+ }
102
+
90
103
export function getRaw ( value : InspectorState [ 'value' ] ) : {
91
104
value : object | string | number | boolean | null
92
105
inherit : { } | { abstract : true }
0 commit comments