Skip to content

Commit

Permalink
feat: Make props editable, closes #669 (#813)
Browse files Browse the repository at this point in the history
* feat: Make props editable

* feat: switch in settings
  • Loading branch information
emanuelmutschlechner authored and Akryum committed Feb 3, 2019
1 parent 8167e3c commit bcb165d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { initEventsBackend } from './events'
import { initRouterBackend } from './router'
import { initPerfBackend } from './perf'
import { findRelatedComponent } from './utils'
import { stringify, classify, camelize, set, parse, getComponentName, getCustomRefDetails } from '../util'
import { stringify, classify, camelize, set, has, parse, getComponentName, getCustomRefDetails } from '../util'
import ComponentSelector from './component-selector'
import SharedData, { init as initSharedData } from 'src/shared-data'
import { isBrowser, target } from 'src/devtools/env'
Expand Down Expand Up @@ -629,7 +629,8 @@ function processProps (instance) {
required: !!prop.required
} : {
type: 'invalid'
}
},
editable: SharedData.editableProps
})
}
return propsData
Expand Down Expand Up @@ -959,7 +960,10 @@ function setStateValue ({ id, path, value, newKey, remove }) {
$set: hook.Vue.set,
$delete: hook.Vue.delete
} : instance
set(instance._data, path, parsedValue, (obj, field, value) => {
const data = has(instance._props, path, newKey)
? instance._props
: instance._data
set(data, path, parsedValue, (obj, field, value) => {
(remove || newKey) && api.$delete(obj, field)
!remove && api.$set(obj, newKey || field, value)
})
Expand Down
16 changes: 15 additions & 1 deletion src/devtools/views/settings/GlobalPreferences.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="global-preferences preferences">
<VueFormField title="Normalize Component Names">
<VueFormField title="Normalize component names">
<VueGroup
:value="$shared.classifyComponents"
class="extend"
Expand Down Expand Up @@ -58,5 +58,19 @@
/>
</VueGroup>
</VueFormField>

<VueFormField title="Editable props">
<VueSwitch
:value="$shared.editableProps"
@input="$shared.editableProps = $event"
>
Enable <span class="dim">(may print warnings)</span>
</VueSwitch>
</VueFormField>
</div>
</template>

<style lang="stylus" scoped>
.dim
color $darkerGrey
</style>
6 changes: 4 additions & 2 deletions src/shared-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ const internalSharedData = {
cacheVuexSnapshotsEvery: 50,
cacheVuexSnapshotsLimit: 10,
snapshotLoading: null,
recordPerf: false
recordPerf: false,
editableProps: false
}

const persisted = [
'classifyComponents',
'theme',
'displayDensity',
'recordVuex'
'recordVuex',
'editableProps'
]

// ---- INTERNALS ---- //
Expand Down
9 changes: 9 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,15 @@ export function get (object, path) {
return object
}

export function has (object, path, parent = false) {
const sections = path.split('.')
const size = !parent ? 1 : 2
while (sections.length > size) {
object = object[sections.shift()]
}
return object != null && object.hasOwnProperty(sections[0])
}

export function scrollIntoView (scrollParent, el, center = true) {
const parentTop = scrollParent.scrollTop
const parentHeight = scrollParent.offsetHeight
Expand Down

0 comments on commit bcb165d

Please sign in to comment.