Skip to content

Commit 7868342

Browse files
authored
feat: SharedData: classifyComponent, openInEditorHost (#575)
* Shared-data: classifyComponent, openInEditorHost * Fix SharedData on user page refresh * Change config to `window.VUE_DEVTOOLS_CONFIG` * Wrap example in dev-only condition
1 parent af618a9 commit 7868342

File tree

14 files changed

+156
-68
lines changed

14 files changed

+156
-68
lines changed

docs/open-in-editor.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,17 @@ openInEditor('code')
3535
## Node.js
3636

3737
You can use the [launch-editor](https://github.com/yyx990803/launch-editor#usage) package to setup an HTTP route with the `/__open-in-editor` path. It will receive `file` as an URL variable.
38+
39+
## Customize request
40+
41+
You can change the request host (default `/`) with the following code in your frontend app:
42+
43+
```js
44+
if (process.env.NODE_ENV !== 'production')
45+
// App served from port 4000
46+
// Webpack dev server on port 9000
47+
window.VUE_DEVTOOLS_CONFIG = {
48+
openInEditorHost: 'http://localhost:9000/'
49+
}
50+
}
51+
```

shells/dev/target/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import MyClass from './MyClass.js'
99
import Router from './Router.vue'
1010
import router from './router'
1111

12+
window.VUE_DEVTOOLS_CONFIG = {
13+
openInEditorHost: '/'
14+
}
15+
1216
const items = []
1317
for (var i = 0; i < 100; i++) {
1418
items.push({ id: i })

src/backend/config.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/backend/highlighter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { inDoc, classify } from '../util'
22
import { getInstanceName } from './index'
3-
import { claissifyComponents } from './config'
3+
import SharedData from 'src/shared-data'
44

55
const overlay = document.createElement('div')
66
overlay.style.backgroundColor = 'rgba(104, 182, 255, 0.35)'
@@ -32,7 +32,7 @@ export function highlight (instance) {
3232
if (rect) {
3333
let content = ''
3434
let name = getInstanceName(instance)
35-
if (claissifyComponents) name = classify(name)
35+
if (SharedData.classifyComponents) name = classify(name)
3636
if (name) content = `<span style="opacity: .6;">&lt;</span>${name}<span style="opacity: .6;">&gt;</span>`
3737
showOverlay(rect, content)
3838
}

src/backend/index.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { initEventsBackend } from './events'
77
import { findRelatedComponent } from './utils'
88
import { stringify, classify, camelize, set, parse, getComponentName } from '../util'
99
import ComponentSelector from './component-selector'
10-
import config from './config'
10+
import SharedData, { init as initSharedData } from 'src/shared-data'
1111

1212
// hook should have been injected before this executes.
1313
const hook = window.__VUE_DEVTOOLS_GLOBAL_HOOK__
@@ -32,12 +32,15 @@ export function initBackend (_bridge) {
3232
hook.once('init', connect)
3333
}
3434

35-
config(bridge)
36-
3735
initRightClick()
3836
}
3937

4038
function connect () {
39+
initSharedData({
40+
bridge,
41+
Vue: hook.Vue
42+
})
43+
4144
hook.currentTab = 'components'
4245
bridge.on('switch-tab', tab => {
4346
hook.currentTab = tab
@@ -118,6 +121,16 @@ function connect () {
118121

119122
window.__VUE_DEVTOOLS_INSPECT__ = inspectInstance
120123

124+
// User project devtools config
125+
if (window.hasOwnProperty('VUE_DEVTOOLS_CONFIG')) {
126+
const config = window.VUE_DEVTOOLS_CONFIG
127+
128+
// Open in editor
129+
if (config.hasOwnProperty('openInEditorHost')) {
130+
SharedData.openInEditorHost = config.openInEditorHost
131+
}
132+
}
133+
121134
bridge.log('backend ready.')
122135
bridge.send('ready', hook.Vue.version)
123136
console.log(

src/devtools/index.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import store from './store'
55
import './plugins'
66
import { parse } from '../util'
77
import { isChrome, initEnv } from './env'
8+
import SharedData, { init as initSharedData, destroy as destroySharedData } from 'src/shared-data'
9+
import storage from './storage'
810

911
// UI
1012

@@ -80,6 +82,23 @@ function initApp (shell) {
8082
shell.connect(bridge => {
8183
window.bridge = bridge
8284

85+
if (Vue.prototype.hasOwnProperty('$shared')) {
86+
destroySharedData()
87+
} else {
88+
Object.defineProperty(Vue.prototype, '$shared', {
89+
get: () => SharedData
90+
})
91+
}
92+
93+
initSharedData({
94+
bridge,
95+
Vue,
96+
storage,
97+
persist: [
98+
'classifyComponents'
99+
]
100+
})
101+
83102
bridge.once('ready', version => {
84103
store.commit(
85104
'SHOW_MESSAGE',
@@ -157,8 +176,6 @@ function initApp (shell) {
157176
}
158177
}
159178
}).$mount('#app')
160-
161-
store.dispatch('init')
162179
})
163180
}
164181

src/devtools/views/components/ComponentInspector.vue

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
</template>
4545

4646
<script>
47-
import { mapState } from 'vuex'
4847
import ScrollPane from 'components/ScrollPane.vue'
4948
import ActionHeader from 'components/ActionHeader.vue'
5049
import StateInspector from 'components/StateInspector.vue'
@@ -66,14 +65,11 @@ export default {
6665
}
6766
},
6867
computed: {
69-
...mapState('components', [
70-
'classifyComponents'
71-
]),
7268
hasTarget () {
7369
return this.target.id != null
7470
},
7571
targetName () {
76-
return this.classifyComponents ? classify(this.target.name) : this.target.name
72+
return this.$shared.classifyComponents ? classify(this.target.name) : this.target.name
7773
},
7874
filteredState () {
7975
return groupBy(sortByKey(this.target.state.filter(el => {

src/devtools/views/components/ComponentInstance.vue

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
</template>
8383

8484
<script>
85-
import { mapState } from 'vuex'
8685
import { classify, scrollIntoView, UNDEFINED } from '../../../util'
8786
8887
export default {
@@ -101,10 +100,6 @@ export default {
101100
},
102101
103102
computed: {
104-
...mapState('components', [
105-
'classifyComponents'
106-
]),
107-
108103
scrollToExpanded () {
109104
return this.$store.state.components.scrollToExpanded
110105
},
@@ -126,7 +121,7 @@ export default {
126121
},
127122
128123
displayName () {
129-
return this.classifyComponents ? classify(this.instance.name) : this.instance.name
124+
return this.$shared.classifyComponents ? classify(this.instance.name) : this.instance.name
130125
},
131126
132127
componentHasKey () {

src/devtools/views/components/ComponentTree.vue

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
<span>Select</span>
2323
</a>
2424
<a class="button classify-names"
25-
:class="{ active: classifyComponents }"
25+
:class="{ active: $shared.classifyComponents }"
2626
v-tooltip="'Format component names'"
27-
@click="toggleClassifyComponents"
27+
@click="$shared.classifyComponents = !$shared.classifyComponents"
2828
>
2929
<VueIcon icon="text_fields"/>
3030
<span>Format</span>
@@ -43,8 +43,6 @@
4343
</template>
4444

4545
<script>
46-
import { mapState, mapActions } from 'vuex'
47-
4846
import ScrollPane from 'components/ScrollPane.vue'
4947
import ActionHeader from 'components/ActionHeader.vue'
5048
import ComponentInstance from './ComponentInstance.vue'
@@ -129,12 +127,6 @@ export default {
129127
}
130128
},
131129
132-
computed: {
133-
...mapState('components', [
134-
'classifyComponents'
135-
])
136-
},
137-
138130
mounted () {
139131
bridge.on('instance-selected', () => {
140132
this.setSelecting(false)
@@ -146,10 +138,6 @@ export default {
146138
},
147139
148140
methods: {
149-
...mapActions('components', [
150-
'toggleClassifyComponents'
151-
]),
152-
153141
filterInstances (e) {
154142
bridge.send('filter-instances', classify(e.target.value))
155143
},

src/devtools/views/components/module.js

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
import Vue from 'vue'
2-
import storage from '../../storage'
3-
4-
const CLASSIFY_COMPONENTS_KEY = 'CLASSIFY_COMPONENTS'
5-
const classifyComponents = storage.get(CLASSIFY_COMPONENTS_KEY)
62

73
const state = {
84
selected: null,
@@ -11,8 +7,7 @@ const state = {
117
instancesMap: {},
128
expansionMap: {},
139
events: [],
14-
scrollToExpanded: null,
15-
classifyComponents: classifyComponents == null ? true : classifyComponents
10+
scrollToExpanded: null
1611
}
1712

1813
const mutations = {
@@ -54,19 +49,10 @@ const mutations = {
5449
TOGGLE_INSTANCE (state, { id, expanded, scrollTo = null } = {}) {
5550
Vue.set(state.expansionMap, id, expanded)
5651
state.scrollToExpanded = scrollTo
57-
},
58-
CLASSIFY_COMPONENTS (state, value) {
59-
state.classifyComponents = value
6052
}
6153
}
6254

6355
const actions = {
64-
init: {
65-
handler ({ state }) {
66-
bridge.send('config:classifyComponents', state.classifyComponents)
67-
},
68-
root: true
69-
},
7056
toggleInstance ({ commit, dispatch, state }, { instance, expanded, recursive, parent = false } = {}) {
7157
const id = instance.id
7258

@@ -98,13 +84,6 @@ const actions = {
9884
})
9985
}
10086
}
101-
},
102-
103-
toggleClassifyComponents ({ state, commit }) {
104-
const newValue = !state.classifyComponents
105-
commit('CLASSIFY_COMPONENTS', newValue)
106-
storage.set(CLASSIFY_COMPONENTS_KEY, newValue)
107-
bridge.send('config:classifyComponents', newValue)
10887
}
10988
}
11089

src/devtools/views/events/EventsHistory.vue

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,6 @@ export default {
116116
'filteredEvents'
117117
]),
118118
119-
...mapState('components', [
120-
'classifyComponents'
121-
]),
122-
123119
filter: {
124120
get () {
125121
return this.$store.state.events.filter
@@ -138,7 +134,7 @@ export default {
138134
}),
139135
140136
displayComponentName (name) {
141-
return this.classifyComponents ? classify(name) : name
137+
return this.$shared.classifyComponents ? classify(name) : name
142138
}
143139
},
144140

src/devtools/views/events/module.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import storage from '../../storage'
22
import { classify } from 'src/util'
3+
import SharedData from 'src/shared-data'
34

45
const ENABLED_KEY = 'EVENTS_ENABLED'
56
const enabled = storage.get(ENABLED_KEY)
@@ -48,7 +49,7 @@ const getters = {
4849
return state.events[state.inspectedIndex]
4950
},
5051
filteredEvents: (state, getters, rootState) => {
51-
const classifyComponents = rootState.components.classifyComponents
52+
const classifyComponents = SharedData.classifyComponents
5253
let searchText = state.filter.toLowerCase()
5354
const searchComponent = /<|>/g.test(searchText)
5455
if (searchComponent) {

0 commit comments

Comments
 (0)