Skip to content

Commit 5807c07

Browse files
feat(kit): editable component props (#674)
1 parent bf8ad74 commit 5807c07

File tree

6 files changed

+69
-6
lines changed

6 files changed

+69
-6
lines changed

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,22 @@ export async function editComponentState(payload: InspectorStateEditorPayload, s
160160

161161
let target: Record<string, unknown> | undefined
162162

163-
// TODO: props
164-
165-
// 1. check if is setup
166-
if (instance.devtoolsRawSetupState && Object.keys(instance.devtoolsRawSetupState).includes(path[0]))
163+
// 1. check if is props
164+
if (Object.keys(instance.props).includes(path[0])) {
165+
target = instance.props
166+
}
167+
// 2. check if is setup
168+
else if (instance.devtoolsRawSetupState && Object.keys(instance.devtoolsRawSetupState).includes(path[0])) {
167169
target = instance.devtoolsRawSetupState
168-
// 2. check if is options
169-
if (instance.data && Object.keys(instance.data).includes(path[0]))
170+
}
171+
// 3. check if is options
172+
else if (instance.data && Object.keys(instance.data).includes(path[0])) {
170173
target = instance.data
174+
}
175+
else {
176+
// 4. fallback
177+
target = instance.proxy
178+
}
171179

172180
if (target && targetPath) {
173181
if (state.type === 'object' && type === 'reactive') {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ function processProps(instance: VueAppInstance) {
7070
type: 'props',
7171
key: camelizeKey,
7272
value: returnError(() => instance.props[key]),
73+
editable: true,
7374
meta: propDefinition
7475
? {
7576
type: propDefinition.type ? getPropType(propDefinition.type) : 'any',

packages/playground/basic/src/App.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626
/hey/123123
2727
</span>
2828
</RouterLink>
29+
|
30+
<RouterLink to="/prop-mutation">
31+
<span>
32+
Prop mutation
33+
</span>
34+
</RouterLink>
2935
</div>
3036
</div>
3137
</template>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<script setup lang="ts">
2+
const props = defineProps<{
3+
bool: boolean
4+
num: number
5+
str: string
6+
obj: Record<string, any>
7+
}>()
8+
</script>
9+
10+
<template>
11+
<div>
12+
<div>bool: {{ props.bool }}</div>
13+
<div>num: {{ props.num }}</div>
14+
<div>str: {{ props.str }}</div>
15+
<div>obj: {{ props.obj }}</div>
16+
</div>
17+
</template>

packages/playground/basic/src/main.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ const routes: RouteRecordRaw[] = [
6666
component: () => import('./pages/IntervalUpdate.vue'),
6767
name: 'interval-update',
6868
},
69+
{
70+
path: '/prop-mutation',
71+
component: () => import('./pages/PropMutation.vue'),
72+
name: 'prop-mutation',
73+
},
6974
]
7075

7176
const router = createRouter({
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<script setup lang="ts">
2+
import PropChild from '../components/PropChild.vue'
3+
4+
const props = {
5+
bool: ref(false),
6+
num: ref(0),
7+
str: ref('hey'),
8+
obj: ref({
9+
foo: 'bar',
10+
}),
11+
}
12+
</script>
13+
14+
<template>
15+
<div>
16+
<div>Prop Page</div>
17+
<PropChild
18+
v-bind="{
19+
bool: props.bool.value,
20+
num: props.num.value,
21+
str: props.str.value,
22+
obj: props.obj.value,
23+
}"
24+
/>
25+
</div>
26+
</template>

0 commit comments

Comments
 (0)