Skip to content

Commit 6f3532e

Browse files
committed
feat: support editing nested custom values
1 parent f64b1c7 commit 6f3532e

File tree

5 files changed

+33
-16
lines changed

5 files changed

+33
-16
lines changed

packages/app-backend-vue3/src/components/data.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ export function getCustomObjectDetails (object: any, proto: string): CustomState
202202
_custom: {
203203
type: objectType.toLowerCase(),
204204
objectType,
205-
readOnly: true,
206205
value,
207206
...raw ? { tooltip: `<span class="font-mono">${raw}</span>` } : {},
208207
},

packages/app-frontend/src/features/inspector/DataField.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,15 @@ export default defineComponent({
6868
return valueType(this.field.value)
6969
},
7070
71+
interpretedValueType (): string {
72+
return valueType(this.field.value, false)
73+
},
74+
7175
valueDetails (): string {
7276
return valueDetails(this.field.value)
7377
},
7478
75-
rawValueType (): string {
79+
nativeValueType (): string {
7680
return typeof this.field.value
7781
},
7882
@@ -190,7 +194,7 @@ export default defineComponent({
190194
},
191195
192196
valueClass (): string[] {
193-
const cssClass = [this.valueType, `raw-${this.rawValueType}`]
197+
const cssClass = [this.valueType, `raw-${this.nativeValueType}`]
194198
if (this.valueType === 'custom') {
195199
const value = this.field.value
196200
value._custom.type && cssClass.push(`type-${value._custom.type}`)

packages/app-frontend/src/mixins/data-field-edit.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export default {
7171
},
7272

7373
isValueEditable () {
74-
const type = this.valueType
74+
const type = this.interpretedValueType
7575
return this.isEditable &&
7676
(
7777
type === 'null' ||
@@ -83,7 +83,7 @@ export default {
8383
},
8484

8585
isSubfieldsEditable () {
86-
return this.isEditable && (this.valueType === 'array' || this.valueType === 'plain-object')
86+
return this.isEditable && (this.interpretedValueType === 'array' || this.interpretedValueType === 'plain-object')
8787
},
8888

8989
valueValid () {
@@ -145,7 +145,12 @@ export default {
145145
if (currentEditedField && currentEditedField !== this) {
146146
currentEditedField.cancelEdit()
147147
}
148-
this.editedValue = this.transformSpecialTokens(JSON.stringify(this.field.value), true)
148+
let valueToEdit = this.field.value
149+
// Edit custom value (we don't want to edit the whole custom value data object)
150+
if (this.valueType === 'custom') {
151+
valueToEdit = valueToEdit._custom.value
152+
}
153+
this.editedValue = this.transformSpecialTokens(JSON.stringify(valueToEdit), true)
149154
this.editedKey = this.field.key
150155
this.editing = true
151156
currentEditedField = this
@@ -166,7 +171,16 @@ export default {
166171
submitEdit () {
167172
if (this.editValid) {
168173
this.editing = false
169-
const value = this.transformSpecialTokens(this.editedValue, false)
174+
let value = this.transformSpecialTokens(this.editedValue, false)
175+
// We need to send the entire custom value data object
176+
if (this.valueType === 'custom') {
177+
value = JSON.stringify({
178+
_custom: {
179+
...this.field.value._custom,
180+
value: JSON.parse(value), // Input
181+
},
182+
})
183+
}
170184
const newKey = this.editedKey !== this.field.key ? this.editedKey : undefined
171185
this.sendEdit({ value, newKey })
172186
this.$emit('submit-edit')
@@ -212,9 +226,9 @@ export default {
212226

213227
addNewValue () {
214228
let key
215-
if (this.valueType === 'array') {
229+
if (this.interpretedValueType === 'array') {
216230
key = this.field.value.length
217-
} else if (this.valueType === 'plain-object') {
231+
} else if (this.interpretedValueType === 'plain-object') {
218232
let i = 1
219233
while (this.field.value.hasOwnProperty(key = `prop${i}`)) i++
220234
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ const double = computed(() => count.value * 2)
1212
1313
const answer = 42
1414
15+
const state2 = reactive({
16+
n: ref(0),
17+
})
18+
1519
function onClick () {
1620
count.value++
1721
}
@@ -26,4 +30,6 @@ function onClick () {
2630
</button>
2731

2832
<Child />
33+
34+
<pre>{{ state2 }}</pre>
2935
</template>

packages/shell-dev-vue3/src/devtools-plugin/index.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,7 @@ export default {
108108
type: 'fail',
109109
key: 'state',
110110
editable: true,
111-
value: {
112-
_custom: {
113-
type: null,
114-
readOnly: false,
115-
value: reactive({ n: ref(0) }),
116-
},
117-
},
111+
value: reactive({ n: ref(0) }),
118112
})
119113

120114
return api.getComponentBounds(payload.componentInstance).then(bounds => {

0 commit comments

Comments
 (0)