Skip to content

Commit d7b6d3f

Browse files
emanuelmutschlechneriksim
authored and
iksim
committed
feat: Make props editable, closes vuejs#669 (vuejs#813)
* feat: Make props editable * feat: switch in settings
1 parent e27c663 commit d7b6d3f

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

src/backend/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { initEventsBackend } from './events'
77
import { initRouterBackend } from './router'
88
import { initPerfBackend } from './perf'
99
import { findRelatedComponent } from './utils'
10-
import { stringify, classify, camelize, set, parse, getComponentName, getCustomRefDetails } from '../util'
10+
import { stringify, classify, camelize, set, has, parse, getComponentName, getCustomRefDetails } from '../util'
1111
import ComponentSelector from './component-selector'
1212
import SharedData, { init as initSharedData } from 'src/shared-data'
1313
import { isBrowser, target } from 'src/devtools/env'
@@ -629,7 +629,8 @@ function processProps (instance) {
629629
required: !!prop.required
630630
} : {
631631
type: 'invalid'
632-
}
632+
},
633+
editable: SharedData.editableProps
633634
})
634635
}
635636
return propsData
@@ -959,7 +960,10 @@ function setStateValue ({ id, path, value, newKey, remove }) {
959960
$set: hook.Vue.set,
960961
$delete: hook.Vue.delete
961962
} : instance
962-
set(instance._data, path, parsedValue, (obj, field, value) => {
963+
const data = has(instance._props, path, newKey)
964+
? instance._props
965+
: instance._data
966+
set(data, path, parsedValue, (obj, field, value) => {
963967
(remove || newKey) && api.$delete(obj, field)
964968
!remove && api.$set(obj, newKey || field, value)
965969
})

src/devtools/views/settings/GlobalPreferences.vue

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div class="global-preferences preferences">
3-
<VueFormField title="Normalize Component Names">
3+
<VueFormField title="Normalize component names">
44
<VueGroup
55
:value="$shared.classifyComponents"
66
class="extend"
@@ -58,5 +58,19 @@
5858
/>
5959
</VueGroup>
6060
</VueFormField>
61+
62+
<VueFormField title="Editable props">
63+
<VueSwitch
64+
:value="$shared.editableProps"
65+
@input="$shared.editableProps = $event"
66+
>
67+
Enable <span class="dim">(may print warnings)</span>
68+
</VueSwitch>
69+
</VueFormField>
6170
</div>
6271
</template>
72+
73+
<style lang="stylus" scoped>
74+
.dim
75+
color $darkerGrey
76+
</style>

src/shared-data.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ const internalSharedData = {
88
cacheVuexSnapshotsEvery: 50,
99
cacheVuexSnapshotsLimit: 10,
1010
snapshotLoading: null,
11-
recordPerf: false
11+
recordPerf: false,
12+
editableProps: false
1213
}
1314

1415
const persisted = [
1516
'classifyComponents',
1617
'theme',
1718
'displayDensity',
18-
'recordVuex'
19+
'recordVuex',
20+
'editableProps'
1921
]
2022

2123
// ---- INTERNALS ---- //

src/util.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,15 @@ export function get (object, path) {
519519
return object
520520
}
521521

522+
export function has (object, path, parent = false) {
523+
const sections = path.split('.')
524+
const size = !parent ? 1 : 2
525+
while (sections.length > size) {
526+
object = object[sections.shift()]
527+
}
528+
return object != null && object.hasOwnProperty(sections[0])
529+
}
530+
522531
export function scrollIntoView (scrollParent, el, center = true) {
523532
const parentTop = scrollParent.scrollTop
524533
const parentHeight = scrollParent.offsetHeight

0 commit comments

Comments
 (0)