Skip to content

Commit d1dc299

Browse files
author
Guillaume Chau
committed
Improvements to CustomValue API
1 parent 4303b58 commit d1dc299

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

src/backend/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,11 @@ export function getCustomInstanceDetails (instance) {
377377
type: 'component',
378378
id: instance.__VUE_DEVTOOLS_UID__,
379379
display: getInstanceName(instance),
380-
state: reduceStateList(state),
381-
abstract: true
380+
expandable: true,
381+
value: reduceStateList(state),
382+
fields: {
383+
abstract: true
384+
}
382385
}
383386
}
384387
}

src/devtools/components/DataField.vue

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
@keyup.enter="submitEdit()"
2828
>
2929
</span>
30-
<span v-else class="key" :class="{ abstract: field.abstractField }">{{ field.key }}</span><span class="colon" v-if="!field.abstractField">:</span>
30+
<span v-else class="key" :class="{ abstract: fieldOptions.abstract }">{{ field.key }}</span><span class="colon" v-if="!fieldOptions.abstract">:</span>
3131

3232
<span
3333
v-if="editing"
@@ -266,13 +266,17 @@ export default {
266266
},
267267
isExpandableType () {
268268
const value = this.field.value
269-
return Array.isArray(value) ||
270-
(this.valueType === 'custom' && value._custom.state) ||
271-
(this.valueType !== 'custom' && isPlainObject(value))
269+
return (typeof this.fieldOptions.expandable === 'undefined' || this.fieldOptions.expandable) &&
270+
(
271+
Array.isArray(value) ||
272+
(this.valueType === 'custom' && value._custom.expandable) ||
273+
(this.valueType !== 'custom' && isPlainObject(value))
274+
)
272275
},
273276
isEditable () {
274277
return this.editable &&
275-
!this.field.abstractField &&
278+
!this.fieldOptions.abstract &&
279+
!this.fieldOptions.readOnly &&
276280
(
277281
typeof this.field.key !== 'string' ||
278282
this.field.key.charAt(0) !== '$'
@@ -294,7 +298,7 @@ export default {
294298
},
295299
formattedValue () {
296300
const value = this.field.value
297-
if (this.field.abstractField) {
301+
if (this.fieldOptions.abstract) {
298302
return ''
299303
} else if (value === null) {
300304
return 'null'
@@ -327,29 +331,40 @@ export default {
327331
},
328332
formattedSubFields () {
329333
let value = this.field.value
334+
335+
// CustomValue API
336+
const isCustom = this.valueType === 'custom'
337+
let inherit = {}
338+
if (isCustom) {
339+
inherit = value._custom.fields || {}
340+
value = value._custom.value
341+
}
342+
330343
if (Array.isArray(value)) {
331344
value = value.map((item, i) => ({
332345
key: i,
333-
value: item
346+
value: item,
347+
...inherit
334348
}))
335349
} else if (typeof value === 'object') {
336-
const isCustom = this.valueType === 'custom'
337-
let abstractField = false
338-
if (isCustom) {
339-
abstractField = !!value._custom.abstract
340-
value = value._custom.state
341-
}
342350
value = sortByKey(Object.keys(value).map(key => ({
343351
key,
344352
value: value[key],
345-
abstractField
353+
...inherit
346354
})))
347355
}
348356
return value
349357
},
350358
limitedSubFields () {
351359
return this.formattedSubFields.slice(0, this.limit)
352360
},
361+
fieldOptions () {
362+
if (this.valueType === 'custom') {
363+
return Object.assign({}, this.field, this.field.value._custom)
364+
} else {
365+
return this.field
366+
}
367+
},
353368
valueValid () {
354369
try {
355370
parse(this.transformSpecialTokens(this.editedValue, false))

0 commit comments

Comments
 (0)