Skip to content

Commit 80ae1dc

Browse files
fix(client/bridge): enable deletion of property on Map/Set (#163)
1 parent f96ec04 commit 80ae1dc

File tree

2 files changed

+10
-5
lines changed
  • packages
    • client/src/components/inspector/InspectorDataField
    • devtools-kit/src/core/component/state

2 files changed

+10
-5
lines changed

packages/client/src/components/inspector/InspectorDataField/Actions.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script setup lang="ts">
2+
import { toRaw } from 'vue'
23
import { VueButton, VueDropdown, VueDropdownButton, VueIcon, VTooltip as vTooltip } from '@vue/devtools-ui'
34
import { getRawValue } from '@vue/devtools-kit'
45
import type { InspectorState, InspectorStateEditorPayload } from '@vue/devtools-kit'
@@ -49,7 +50,7 @@ function quickEdit(v: unknown, remove: boolean = false) {
4950
nodeId: state.value.nodeId,
5051
state: {
5152
newKey: null!,
52-
value: v,
53+
value: toRaw(v),
5354
type: dataType.value,
5455
remove,
5556
},
@@ -95,20 +96,20 @@ function quickEdit(v: unknown, remove: boolean = false) {
9596
</VueButton>
9697
<!-- increment/decrement button, numeric value only -->
9798
<template v-else-if="dataType === 'number'">
98-
<VueButton v-bind="iconButtonProps" :class="buttonClass" @click="quickEdit((rawValue as number) + 1)">
99+
<VueButton v-bind="iconButtonProps" :class="buttonClass" @click.stop="quickEdit((rawValue as number) + 1)">
99100
<template #icon>
100101
<VueIcon icon="i-carbon-add" />
101102
</template>
102103
</VueButton>
103-
<VueButton v-bind="iconButtonProps" :class="buttonClass" @click="quickEdit((rawValue as number) - 1)">
104+
<VueButton v-bind="iconButtonProps" :class="buttonClass" @click.stop="quickEdit((rawValue as number) - 1)">
104105
<template #icon>
105106
<VueIcon icon="i-carbon-subtract" />
106107
</template>
107108
</VueButton>
108109
</template>
109110
</template>
110111
<!-- delete prop, only appear if depth > 0 -->
111-
<VueButton v-if="!props.disableEdit && depth > 0" v-bind="iconButtonProps" :class="buttonClass" @click="quickEdit(rawValue, true)">
112+
<VueButton v-if="!props.disableEdit && depth > 0" v-bind="iconButtonProps" :class="buttonClass" @click.stop="quickEdit(rawValue, true)">
112113
<template #icon>
113114
<VueIcon icon="i-material-symbols-delete-rounded" />
114115
</template>

packages/devtools-kit/src/core/component/state/editor.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { MaybeRef, Ref } from 'vue'
2-
import { isReactive, isRef } from 'vue'
2+
import { isReactive, isRef, toRaw } from 'vue'
33
import { getComponentInstance } from '../general'
44
import { devtoolsContext } from '../../general'
55

@@ -70,6 +70,10 @@ export class StateEditor {
7070
if (state.remove || state.newKey) {
7171
if (Array.isArray(object))
7272
object.splice(field as number, 1)
73+
else if (toRaw(object) instanceof Map && typeof value === 'object' && value && 'key' in value)
74+
object.delete(value.key)
75+
else if (toRaw(object) instanceof Set)
76+
object.delete(value)
7377
else
7478
Reflect.deleteProperty(object, field)
7579
}

0 commit comments

Comments
 (0)