Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Make props editable, closes #669 #813

Merged
merged 2 commits into from
Feb 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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