Skip to content

Commit 3e2d40b

Browse files
authoredMay 3, 2024··
fix(applet): make sure a.b property displays/edits as expected (#353)
1 parent ae68355 commit 3e2d40b

File tree

4 files changed

+13
-17
lines changed

4 files changed

+13
-17
lines changed
 

Diff for: ‎packages/applet/src/components/state/StateFieldEditor.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const buttonClass = computed(() => ({
4646
4747
function quickEdit(v: unknown, remove: boolean = false) {
4848
editInspectorState({
49-
path: props.data.key.split('.'),
49+
path: props.data.path || [props.data.key],
5050
inspectorId: state.value.inspectorId,
5151
type: props.data.stateType!,
5252
nodeId: state.value.nodeId,

Diff for: ‎packages/applet/src/components/state/StateFieldViewer.vue

+8-14
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,9 @@ const fieldsCount = computed(() => {
4545
else
4646
return 0
4747
})
48-
48+
const normalizedPath = computed(() => props.data.path || [props.data.key])
4949
// normalized display key
50-
const normalizedDisplayedKey = computed(() => {
51-
const key = props.data.key
52-
const lastDotIndex = key.lastIndexOf('.')
53-
if (lastDotIndex === -1)
54-
return key
55-
return key.slice(lastDotIndex + 1)
56-
})
50+
const normalizedDisplayedKey = computed(() => normalizedPath.value[normalizedPath.value.length - 1])
5751
5852
// normalized display value
5953
const normalizedDisplayedValue = computed(() => {
@@ -90,7 +84,8 @@ const normalizedDisplayedChildren = computed(() => {
9084
if (isArray(value)) {
9185
const sliced = value.slice(0, limit.value)
9286
return sliced.map((item, i) => ({
93-
key: `${props.data.key}.${i}`,
87+
key: i.toString(),
88+
path: [...normalizedPath.value, i.toString()],
9489
value: item,
9590
...inherit,
9691
editable: props.data.editable && !isUneditableType,
@@ -99,7 +94,8 @@ const normalizedDisplayedChildren = computed(() => {
9994
}
10095
else if (isObject(value)) {
10196
displayedChildren = Object.keys(value).slice(0, limit.value).map(key => ({
102-
key: `${props.data.key}.${key}`,
97+
key,
98+
path: [...normalizedPath.value, key],
10399
value: value[key],
104100
...inherit,
105101
editable: props.data.editable && !isUneditableType,
@@ -137,7 +133,7 @@ watch(() => editing.value, (v) => {
137133
function submit() {
138134
const data = props.data
139135
editInspectorState({
140-
path: data.key.split('.'),
136+
path: normalizedPath.value,
141137
inspectorId: state.value.inspectorId,
142138
type: data.stateType!,
143139
nodeId,
@@ -163,10 +159,8 @@ function addNewProp(type: EditorAddNewPropType) {
163159
164160
function submitDrafting() {
165161
const data = props.data
166-
const path = data.key.split('.')
167-
path.push(draftingNewProp.value.key)
168162
editInspectorState({
169-
path,
163+
path: [...normalizedPath.value, draftingNewProp.value.key],
170164
inspectorId: state.value.inspectorId,
171165
type: data.stateType!,
172166
nodeId,

Diff for: ‎packages/devtools-kit/src/core/component/types/state.ts

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface InspectorState {
1717
key: string
1818
value: string | number | boolean | null | Record<string, unknown> | InspectorCustomState | Array<unknown>
1919
type: string
20+
path: string[]
2021
stateType?: string
2122
stateTypeName?: string
2223
meta?: Record<string, boolean | string>

Diff for: ‎packages/playground/basic/src/stores/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ import { computed, ref } from 'vue'
33

44
export const useAppStore = defineStore('app', () => {
55
const count = ref(120)
6-
const map = ref(new Map([['a', 1], ['b', 2]]))
6+
const map = ref(new Map([['a', 1], ['b', 2], ['c.test', 3]]))
77
const set = ref(new Set([1, 2, 3]))
8+
const obj = ref({ 'foo.test': 1 })
89
function increment() {
910
count.value++
1011
}
1112
const doubledCount = computed(() => count.value * 2)
1213

13-
return { count, doubledCount, increment, map, set }
14+
return { count, doubledCount, increment, map, set, obj }
1415
})
1516

1617
export const useCounterStore = defineStore('counter', () => {

0 commit comments

Comments
 (0)
Please sign in to comment.