-
-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathViewBuiltinSettings.vue
More file actions
323 lines (296 loc) · 12.5 KB
/
ViewBuiltinSettings.vue
File metadata and controls
323 lines (296 loc) · 12.5 KB
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
<script setup lang="ts">
import type { DevToolsViewBuiltin } from '@vitejs/devtools-kit'
import type { DocksContext } from '@vitejs/devtools-kit/client'
import { DEFAULT_STATE_USER_SETTINGS } from '@vitejs/devtools-kit/constants'
import { computed } from 'vue'
import { docksGroupByCategories } from '../state/dock-settings'
import { sharedStateToRef } from '../state/docks'
import DockIcon from './DockIcon.vue'
const props = defineProps<{
context: DocksContext
entry: DevToolsViewBuiltin
}>()
const settingsStore = props.context.docks.settings
const settings = sharedStateToRef(settingsStore)
const categories = computed(() => {
return docksGroupByCategories(props.context.docks.entries, settingsStore.value(), { includeHidden: true })
})
function getCategoryLabel(category: string): string {
const labels: Record<string, string> = {
'~viteplus': 'Vite+',
'default': 'Default',
'app': 'App',
'framework': 'Framework',
'web': 'Web',
'advanced': 'Advanced',
'~builtin': 'Built-in',
}
return labels[category] || category
}
function toggleDock(id: string, visible?: boolean) {
const hidden = settings.value.docksHidden
const isHidden = hidden.includes(id)
const shouldShow = visible ?? isHidden
if (shouldShow) {
settingsStore.mutate((state) => {
state.docksHidden = state.docksHidden.filter((i: string) => i !== id)
})
}
else {
settingsStore.mutate((state) => {
state.docksHidden = [...state.docksHidden, id]
})
}
}
function toggleCategory(category: string, visible?: boolean) {
const hidden = settings.value.docksCategoriesHidden
const isHidden = hidden.includes(category)
const shouldShow = visible ?? isHidden
if (shouldShow) {
settingsStore.mutate((state) => {
state.docksCategoriesHidden = state.docksCategoriesHidden.filter((i: string) => i !== category)
})
}
else {
settingsStore.mutate((state) => {
state.docksCategoriesHidden = [...state.docksCategoriesHidden, category]
})
}
}
function togglePin(id: string) {
const pinned = settings.value.docksPinned
if (pinned.includes(id)) {
settingsStore.mutate((state) => {
state.docksPinned = state.docksPinned.filter((i: string) => i !== id)
})
}
else {
settingsStore.mutate((state) => {
state.docksPinned = [...state.docksPinned, id]
})
}
}
function isInCustomOrder(id: string): boolean {
return settings.value.docksCustomOrder[id] !== undefined
}
function moveOrder(category: string, id: string, delta: number) {
const items = categories.value.find(([cat]) => cat === category)
if (!items)
throw new Error(`Category ${category} not found`)
const array = [...items[1]]
const index = array.findIndex(item => item.id === id)
const newIndex = index + delta
if (newIndex < 0 || newIndex >= array.length)
throw new Error(`Invalid new index ${newIndex} for category ${category}`)
array.splice(newIndex, 0, array.splice(index, 1)[0]!)
items[1] = array
settingsStore.mutate((state) => {
array.forEach((item, index) => {
state.docksCustomOrder[item.id] = index
})
})
}
function doesCategoryHaveCustomOrder(category: string): boolean {
const items = categories.value.find(([cat]) => cat === category)
if (!items)
return false
return items[1].some(item => isInCustomOrder(item.id))
}
function resetCustomOrderForCategory(category: string) {
const items = categories.value.find(([cat]) => cat === category)
if (!items)
return
settingsStore.mutate((state) => {
items[1].forEach((item) => {
delete state.docksCustomOrder[item.id]
})
})
}
function resetSettings() {
// eslint-disable-next-line no-alert
if (confirm('Reset all dock settings to defaults?')) {
settingsStore.mutate(() => {
return DEFAULT_STATE_USER_SETTINGS()
})
}
}
</script>
<template>
<div class="h-full w-full overflow-hidden">
<div class="h-full w-full overflow-auto p10">
<div class="max-w-200 mx-auto">
<h1 class="text-xl font-semibold mb-6 flex items-center gap-2 op85">
<div class="i-ph-gear-duotone text-2xl" />
DevTools Settings
</h1>
<section class="mb-8">
<h2 class="text-lg font-medium mb-4 op75">
Dock Entries
</h2>
<p class="text-sm op50 mb-4">
Manage visibility and order of dock entries. Hidden entries will not appear in the dock bar.
</p>
<div class="flex flex-col gap-4">
<template v-for="[category, entries] of categories" :key="category">
<div
class="border border-base rounded-lg overflow-hidden transition-opacity"
:class="settings.docksCategoriesHidden.includes(category) ? 'op40' : ''"
>
<!-- Category header -->
<div
class="flex items-center gap-2 px-4 py-3 bg-gray/5 cursor-pointer select-none border-b border-base"
>
<button
class="w-5 h-5 flex items-center justify-center rounded transition-colors"
:class="settings.docksCategoriesHidden.includes(category) ? 'bg-gray/20' : 'bg-lime/20 text-lime'"
@click="toggleCategory(category)"
>
<div
class="transition-transform"
:class="settings.docksCategoriesHidden.includes(category) ? 'i-ph-eye-slash text-sm op50' : 'i-ph-check-bold text-xs'"
/>
</button>
<span class="font-medium capitalize">{{ getCategoryLabel(category) }}</span>
<span class="text-xs op40">({{ entries.length }})</span>
<span class="flex-auto" />
<button
v-if="doesCategoryHaveCustomOrder(category)"
class="w-6 h-6 flex items-center justify-center rounded hover:bg-gray/20 transition-colors"
title="Reset custom order"
@click="resetCustomOrderForCategory(category)"
>
<div class="i-ph-arrows-counter-clockwise-duotone text-sm op60" />
</button>
</div>
<!-- Entries -->
<div>
<div
v-for="(dock, index) of entries"
:key="dock.id"
class="flex items-center gap-3 px-4 py-2.5 hover:bg-gray/5 transition-colors group border-b border-base border-t-0"
:class="settings.docksHidden.includes(dock.id) ? 'op40' : ''"
>
<!-- Visibility toggle -->
<button
class="w-6 h-6 flex items-center justify-center rounded border border-transparent hover:border-base transition-colors shrink-0"
:class="settings.docksHidden.includes(dock.id) ? 'op50' : ''"
:title="settings.docksHidden.includes(dock.id) ? 'Show' : 'Hide'"
@click="toggleDock(dock.id)"
>
<div
class="w-4 h-4 rounded flex items-center justify-center transition-colors"
:class="settings.docksHidden.includes(dock.id) ? 'bg-gray/30' : 'bg-lime/20 text-lime'"
>
<div
v-if="!settings.docksHidden.includes(dock.id)"
class="i-ph-check-bold text-xs"
/>
</div>
</button>
<!-- Icon & Title -->
<DockIcon
:icon="dock.icon"
:title="dock.title"
class="w-5 h-5 shrink-0"
:class="settings.docksHidden.includes(dock.id) ? 'saturate-0' : ''"
/>
<span
class="flex-1 truncate"
:class="settings.docksHidden.includes(dock.id) ? 'line-through op60' : ''"
>
{{ dock.title }}
</span>
<!-- Order controls -->
<div class="flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity">
<button
v-if="index > 0"
class="w-6 h-6 flex items-center justify-center rounded hover:bg-gray/20 transition-colors"
title="Move up (higher priority)"
@click="moveOrder(category, dock.id, -1)"
>
<div class="i-ph-caret-up text-sm op60" />
</button>
<button
v-if="index < entries.length - 1"
class="w-6 h-6 flex items-center justify-center rounded hover:bg-gray/20 transition-colors"
title="Move down (lower priority)"
@click="moveOrder(category, dock.id, 1)"
>
<div class="i-ph-caret-down text-sm op60" />
</button>
</div>
<!-- Pin toggle -->
<button
class="w-7 h-7 flex items-center justify-center rounded hover:bg-gray/20 transition-colors shrink-0"
:class="settings.docksPinned.includes(dock.id) ? 'text-amber' : 'op40 hover:op70'"
:title="settings.docksPinned.includes(dock.id) ? 'Unpin' : 'Pin'"
@click="togglePin(dock.id)"
>
<div
:class="settings.docksPinned.includes(dock.id) ? 'i-ph-push-pin-fill rotate--45' : 'i-ph-push-pin'"
class="text-base"
/>
</button>
</div>
</div>
</div>
</template>
</div>
</section>
<section class="border-t border-base pt-6 mb-8">
<h2 class="text-lg font-medium mb-4 op75">
Appearance
</h2>
<div class="flex flex-col gap-3">
<!-- Show iframe address bar toggle -->
<label class="flex items-center gap-3 cursor-pointer group">
<button
class="w-10 h-6 rounded-full transition-colors relative shrink-0"
:class="settings.showIframeAddressBar ? 'bg-lime' : 'bg-gray/30'"
@click="settingsStore.mutate((s) => { s.showIframeAddressBar = !s.showIframeAddressBar })"
>
<div
class="absolute top-1 w-4 h-4 rounded-full bg-white shadow transition-transform"
:class="settings.showIframeAddressBar ? 'translate-x-5' : 'translate-x-1'"
/>
</button>
<div class="flex flex-col">
<span class="text-sm">Show iframe address bar</span>
<span class="text-xs op50">Display navigation controls and URL bar for iframe views</span>
</div>
</label>
<!-- Close on outside click toggle -->
<label class="flex items-center gap-3 cursor-pointer group">
<button
class="w-10 h-6 rounded-full transition-colors relative shrink-0"
:class="settings.closeOnOutsideClick ? 'bg-lime' : 'bg-gray/30'"
@click="settingsStore.mutate((s) => { s.closeOnOutsideClick = !s.closeOnOutsideClick })"
>
<div
class="absolute top-1 w-4 h-4 rounded-full bg-white shadow transition-transform"
:class="settings.closeOnOutsideClick ? 'translate-x-5' : 'translate-x-1'"
/>
</button>
<div class="flex flex-col">
<span class="text-sm">Close panel on outside click</span>
<span class="text-xs op50">Close the DevTools panel when clicking outside of it (embedded mode only)</span>
</div>
</label>
</div>
</section>
<section class="border-t border-base pt-6">
<h2 class="text-lg font-medium mb-4 op75">
Reset
</h2>
<button
class="px-4 py-2 rounded bg-red/10 text-red hover:bg-red/20 transition-colors flex items-center gap-2"
@click="resetSettings"
>
<div class="i-ph-arrow-counter-clockwise" />
Reset Dock Settings
</button>
</section>
</div>
</div>
</div>
</template>