-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
Copy pathComponentsInspector.vue
264 lines (233 loc) · 6.24 KB
/
ComponentsInspector.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<script lang="ts">
import SplitPane from '@front/features/layout/SplitPane.vue'
import ComponentTreeNode from './ComponentTreeNode.vue'
import SelectedComponentPane from './SelectedComponentPane.vue'
import { onMounted, ref, provide, defineComponent } from 'vue'
import { onKeyDown } from '@front/util/keyboard'
import { useComponentPick, useComponents, loadComponent } from './composable'
export default defineComponent({
components: {
SplitPane,
ComponentTreeNode,
SelectedComponentPane,
},
setup () {
const {
rootInstances,
requestComponentTree,
treeFilter,
selectLastComponent,
subscribeToSelectedData,
selectedComponentId,
} = useComponents()
subscribeToSelectedData()
onMounted(() => {
requestComponentTree()
selectLastComponent()
})
const treeFilterInput = ref()
// Pick
const {
pickingComponent,
startPickingComponent,
stopPickingComponent,
} = useComponentPick()
onKeyDown(event => {
if (event.code === 'KeyF' && event.altKey) {
treeFilterInput.value.focus()
return false
} else if (event.code === 'KeyS' && event.altKey && !pickingComponent.value) {
startPickingComponent()
return false
} else if (event.key === 'Escape' && pickingComponent.value) {
stopPickingComponent()
return false
} else if (event.code === 'KeyR' && (event.ctrlKey || event.metaKey) && event.altKey) {
refresh()
return false
}
}, true)
// Refresh
const animateRefresh = ref(false)
let animateRefreshTimer
function refresh () {
requestComponentTree(null)
loadComponent(selectedComponentId.value)
// Animation
animateRefresh.value = false
clearTimeout(animateRefreshTimer)
requestAnimationFrame(() => {
animateRefresh.value = true
animateRefreshTimer = setTimeout(() => {
animateRefresh.value = false
}, 1000)
})
}
// Scroller
const treeScroller = ref()
provide('treeScroller', treeScroller)
return {
rootInstances,
treeFilter,
treeFilterInput,
pickingComponent,
startPickingComponent,
stopPickingComponent,
refresh,
animateRefresh,
treeScroller,
}
},
})
</script>
<template>
<div>
<SplitPane
save-id="components-inspector"
>
<template #left>
<div class="flex flex-col h-full">
<VueInput
ref="treeFilterInput"
v-model="treeFilter"
v-tooltip="{
content: $t('ComponentTree.filter.tooltip'),
html: true
}"
icon-left="search"
placeholder="Find components..."
select-all
class="search flat border-b border-gray-200 dark:border-gray-800 min-w-0"
/>
<div
ref="treeScroller"
class="flex-1 p-2 overflow-auto"
>
<ComponentTreeNode
v-for="instance of rootInstances"
:key="instance.id"
:instance="instance"
/>
</div>
</div>
</template>
<template #right>
<SelectedComponentPane />
</template>
</SplitPane>
<portal to="more-menu">
<div class="space-y-1 px-3 py-2 text-sm">
<div>Component names:</div>
<VueGroup
v-model="$shared.componentNameStyle"
>
<VueGroupButton
value="original"
label="Original"
/>
<VueGroupButton
value="class"
label="PascalCase"
/>
<VueGroupButton
value="kebab"
label="kebab-case"
/>
</VueGroup>
</div>
<div class="space-y-1 px-3 py-2 text-sm">
<VueSwitch v-model="$shared.editableProps">
Editable props
</VueSwitch>
<div class="flex items-center space-x-1 text-xs opacity-50">
<VueIcon
icon="warning"
class="w-4 h-4 flex-none"
/>
<span>May print warnings in the console</span>
</div>
</div>
<div class="space-y-1 px-3 py-2 text-sm">
<VueSwitch v-model="$shared.flashUpdates">
Highlight updates
</VueSwitch>
<div class="flex items-center space-x-1 text-xs opacity-50">
<VueIcon
icon="warning"
class="w-4 h-4 flex-none"
/>
<span>Don't enable if you are sensitive to flashing</span>
</div>
</div>
<div class="border-t border-gray-200 dark:border-gray-800 my-1" />
</portal>
<portal to="header-end">
<VueButton
v-tooltip="{
content: $t('ComponentTree.select.tooltip'),
html: true
}"
class="icon-button flat"
icon-left="gps_fixed"
@click="startPickingComponent()"
/>
<VueButton
v-tooltip="{
content: $t('ComponentTree.refresh.tooltip'),
html: true
}"
class="icon-button flat"
:class="{
'animate-icon': animateRefresh,
}"
icon-left="refresh"
@click="refresh()"
/>
</portal>
<portal to="root">
<div
v-if="pickingComponent"
class="absolute inset-0 bg-white bg-opacity-75 dark:bg-black dark:bg-opacity-75 z-100 flex items-center justify-center"
>
<div class="flex flex-col items-center justify-center space-y-4 px-8 py-6 rounded-lg shadow-lg bg-white dark:bg-gray-900">
<VueIcon
icon="gps_fixed"
class="w-8 h-8 text-green-500 animate-pulse"
/>
<div>
Click on a component on the page to select it
</div>
<div>
<VueButton
@click="stopPickingComponent()"
>
Cancel
</VueButton>
</div>
</div>
</div>
</portal>
</div>
</template>
<style lang="postcss" scoped>
.search {
>>> {
.input {
height: 39px !important;
}
.content {
border: none !important;
}
}
}
.animate-icon {
>>> .vue-ui-icon {
animation: refresh 1s ease-out;
}
}
@keyframes refresh {
100% {
transform: rotate(360deg);
}
}
</style>