Skip to content
This repository was archived by the owner on Jan 6, 2024. It is now read-only.

Commit 34d514b

Browse files
authored
refactor: popup button (#114)
1 parent c7c3e25 commit 34d514b

File tree

6 files changed

+16
-50
lines changed

6 files changed

+16
-50
lines changed

src/client/components.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ declare module 'vue' {
2222
Logo: typeof import('./components/Logo.vue')['default']
2323
Navbar: typeof import('./components/Navbar.vue')['default']
2424
Notification: typeof import('./components/Notification.vue')['default']
25-
PanelPosition: typeof import('./components/PanelPosition.vue')['default']
25+
PopupButton: typeof import('./components/PopupButton.vue')['default']
2626
RoutePathItem: typeof import('./components/RoutePathItem.vue')['default']
2727
RouterLink: typeof import('vue-router')['RouterLink']
2828
RouterView: typeof import('vue-router')['RouterView']

src/client/components/DockingPanel.vue

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,11 @@ import { isInPopup } from '../logic/state'
44

55
<template>
66
<div>
7-
<div v-if="!isInPopup" px3 py2 border="b base" flex="~ col gap-1">
8-
<div text-sm op50>
9-
Dock devtools to
10-
</div>
11-
<PanelPosition />
12-
</div>
137
<div px3 py2 border="b base" flex="~ gap-2">
8+
<PopupButton v-if="!isInPopup" />
149
<VDarkToggle v-slot="{ toggle, isDark }">
1510
<VButton n="sm primary" @click="toggle">
16-
<div carbon-sun translate-y--1px dark:carbon-moon />
11+
<div carbon-sun dark:carbon-moon translate-y--1px />
1712
{{ isDark.value ? "Dark" : "Light" }}
1813
</VButton>
1914
</VDarkToggle>

src/client/components/PanelPosition.vue renamed to src/client/components/PopupButton.vue

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,27 @@
11
<script setup lang="ts">
22
import { useDevtoolsClient } from '../logic/client'
33
4-
const { position: _position } = useFrameState()
5-
6-
const frameState = computed(() => ({ position: _position.value }))
7-
84
const client = useDevtoolsClient()
5+
// @ts-expect-error missing type
6+
const isSupported = typeof window !== 'undefined' && window.parent.documentPictureInPicture?.requestWindow
97
const showPopupUnsupported = ref(false)
108
const copy = useCopy()
119
12-
const dockButton = [
13-
{
14-
position: 'popup',
15-
icon: 'i-carbon-launch',
16-
},
17-
]
18-
19-
function toggle(position: string) {
20-
if (position === 'popup') {
21-
// @ts-expect-error missing type
22-
if (!window.parent.documentPictureInPicture?.requestWindow) {
23-
showPopupUnsupported.value = true
24-
return
25-
}
26-
}
27-
else {
28-
_position.value = position
10+
function popup() {
11+
if (!isSupported) {
12+
showPopupUnsupported.value = true
13+
return
2914
}
3015
31-
client.value?.panel?.togglePosition(position)
16+
client.value?.panel?.popup()
3217
}
3318
</script>
3419

3520
<template>
36-
<div flex="~ gap-1" text-lg>
37-
<button
38-
v-for="item in dockButton" :key="item.position"
39-
:class="[frameState.position === item.position ? 'text-primary' : 'op50', item.icon]"
40-
@click="toggle(item.position)"
41-
/>
21+
<div flex="~ gap-1">
22+
<VButton n="sm primary" @click="popup">
23+
<i carbon-launch /> Popup <span v-if="!isSupported" op50>(not supported)</span>
24+
</VButton>
4225
</div>
4326

4427
<!-- popup mode not supported message -->

src/client/pages/settings.vue

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<script setup lang="ts">
2-
import { isInPopup } from '../logic/state'
32
import { getSortedTabs } from '../store'
43
54
const {
@@ -98,14 +97,6 @@ const showTabGroup = ref(false)
9897
<TabGroup v-else />
9998
</div>
10099
<div>
101-
<div v-if="!isInPopup" py3 flex="~ col gap-1" border="b base">
102-
<h3 mb1 text-lg>
103-
Position
104-
</h3>
105-
<div>
106-
<PanelPosition />
107-
</div>
108-
</div>
109100
<div py3 flex="~ col gap-1" border="b base">
110101
<h3 mb1 text-lg>
111102
Appearance

src/node/views/Main.vue

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,7 @@ async function setupClient(iframe: HTMLIFrameElement) {
109109
panelState.value.viewMode = 'xs'
110110
},
111111
toggle: togglePanelVisible,
112-
togglePosition(position) {
113-
if (position === 'popup')
114-
popup()
115-
},
112+
popup,
116113
},
117114
openInEditor: openInEditor.value ?? (() => {
118115
warn('Unable to load inspector, open-in-editor is not available.')

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export interface VueDevtoolsHostClient {
6868
markClientLoaded: () => void
6969
panel?: {
7070
toggleViewMode: (mode?: 'xs' | 'default') => void
71-
togglePosition: (position: string) => void
71+
popup: () => void
7272
toggle: () => void
7373
}
7474
hook: {

0 commit comments

Comments
 (0)