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

Commit 5b9ac05

Browse files
feat(popup): fallback notification (#250)
1 parent e3c5b45 commit 5b9ac05

File tree

4 files changed

+72
-28
lines changed

4 files changed

+72
-28
lines changed

packages/client/components/Notification.vue

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,22 @@ const icon = ref<string | undefined>()
44
const text = ref<string | undefined>()
55
const type = ref<'primary' | 'error' | 'warning' | undefined>()
66
const duration = ref<number>()
7+
const placement = ref<'top' | 'bottom'>('top')
78
let timer: ReturnType<typeof setTimeout> | undefined
89
910
provideNotification((opt: {
1011
text: string
1112
icon?: string
1213
type?: 'primary' | 'error' | 'warning'
1314
duration?: number
15+
placement?: 'top' | 'bottom'
1416
}) => {
1517
text.value = opt.text
1618
icon.value = opt.icon
1719
show.value = true
1820
type.value = opt.type
1921
duration.value = opt.duration || 1500
22+
placement.value = opt.placement || 'top'
2023
createTimer()
2124
})
2225
@@ -47,15 +50,26 @@ function createTimer() {
4750

4851
<template>
4952
<div
50-
fixed left-0 right-0 top-0 z-1000 text-center text-base
51-
:class="show ? '' : 'pointer-events-none overflow-hidden'"
53+
fixed z-1000 text-center text-base
54+
:class="[
55+
{
56+
'pointer-events-none overflow-hidden': !show,
57+
},
58+
[
59+
placement === 'top' ? 'top-0' : 'bottom-0',
60+
],
61+
]"
5262
>
5363
<div
5464
border="~ base"
5565
flex="~ inline gap2"
56-
m-3 inline-block items-center rounded px-4 py-1 transition-all duration-300 bg-base
57-
:style="show ? {} : { transform: 'translateY(-300%)' }"
58-
:class="[show ? 'shadow' : 'shadow-none', textColor]"
66+
m-3 inline-block items-center rounded px-4 py-1 transition-transform duration-300 bg-base
67+
:class="[
68+
show
69+
? 'shadow'
70+
: `shadow-none ${placement === 'top' ? 'translate-y--300%' : 'translate-y-300%'}`,
71+
textColor,
72+
]"
5973
@mouseenter="clearTimer"
6074
@mouseleave="createTimer"
6175
>

packages/client/components/PopupButton.vue

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,40 @@
11
<script setup lang="ts">
22
import { useDevToolsClient } from '~/logic/client'
33
4+
defineProps<{
5+
closePopover: () => void
6+
}>()
7+
48
const client = useDevToolsClient()
5-
// @ts-expect-error missing type
6-
const isSupported = typeof window !== 'undefined' && window.parent.documentPictureInPicture?.requestWindow
79
const showPopupUnsupported = ref(false)
810
const copy = useCopy()
911
12+
const isSupported = typeof window !== 'undefined'
13+
// @ts-expect-error experimental API
14+
&& window.parent?.documentPictureInPicture?.requestWindow
15+
&& checkIsSecurityContext()
16+
17+
const showNotification = useNotification()
18+
1019
function popup() {
1120
if (!isSupported) {
1221
showPopupUnsupported.value = true
1322
return
1423
}
15-
16-
client.value?.panel?.popup()
24+
const popupFn = client.value?.panel?.popup as (() => Promise<boolean>) | undefined
25+
if (popupFn) {
26+
popupFn().then((success) => {
27+
if (!success) {
28+
showNotification({
29+
text: 'Open popup mode failed, check console for more details.',
30+
icon: 'i-carbon-warning',
31+
type: 'error',
32+
duration: 3000,
33+
placement: 'bottom',
34+
})
35+
}
36+
})
37+
}
1738
}
1839
</script>
1940

packages/client/composables/context.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const [
1919
icon?: string
2020
type?: 'primary' | 'warning' | 'error'
2121
duration?: number
22+
placement?: 'top' | 'bottom'
2223
}) => void>()
2324

2425
export {

packages/node/src/views/composables.ts

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,14 @@ export function usePiPMode(iframeGetter: () => HTMLIFrameElement | undefined, ho
198198
const documentPictureInPicture = window.documentPictureInPicture
199199
async function popup() {
200200
const iframe = iframeGetter()
201-
const pip = popupWindow.value = await documentPictureInPicture.requestWindow({
202-
width: Math.round(window.innerWidth * state.value.width / 100),
203-
height: Math.round(window.innerHeight * state.value.height / 100),
204-
})
205-
const style = pip.document.createElement('style')
206-
style.innerHTML = `
201+
let isSuccess = true
202+
try {
203+
const pip = popupWindow.value = await documentPictureInPicture.requestWindow({
204+
width: Math.round(window.innerWidth * state.value.width / 100),
205+
height: Math.round(window.innerHeight * state.value.height / 100),
206+
})
207+
const style = pip.document.createElement('style')
208+
style.innerHTML = `
207209
body {
208210
margin: 0;
209211
padding: 0;
@@ -215,19 +217,25 @@ export function usePiPMode(iframeGetter: () => HTMLIFrameElement | undefined, ho
215217
outline: none;
216218
}
217219
`
218-
pip.__VUE_DEVTOOLS_GLOBAL_HOOK__ = hook
219-
pip.__VUE_DEVTOOLS_IS_POPUP__ = true
220-
pip.document.title = 'Vue DevTools'
221-
pip.document.head.appendChild(style)
222-
pip.document.body.appendChild(iframe)
223-
pip.addEventListener('resize', () => {
224-
state.value.width = Math.round(pip.innerWidth / window.innerWidth * 100)
225-
state.value.height = Math.round(pip.innerHeight / window.innerHeight * 100)
226-
})
227-
pip.addEventListener('pagehide', () => {
228-
popupWindow.value = null
229-
pip.close()
230-
})
220+
pip.__VUE_DEVTOOLS_GLOBAL_HOOK__ = hook
221+
pip.__VUE_DEVTOOLS_IS_POPUP__ = true
222+
pip.document.title = 'Vue DevTools'
223+
pip.document.head.appendChild(style)
224+
pip.document.body.appendChild(iframe)
225+
pip.addEventListener('resize', () => {
226+
state.value.width = Math.round(pip.innerWidth / window.innerWidth * 100)
227+
state.value.height = Math.round(pip.innerHeight / window.innerHeight * 100)
228+
})
229+
pip.addEventListener('pagehide', () => {
230+
popupWindow.value = null
231+
pip.close()
232+
})
233+
}
234+
catch (error) {
235+
isSuccess = false
236+
console.error(`[vite-plugin-vue-devtools] Open popup mode failed: ${(error as DOMException).message}`)
237+
}
238+
return isSuccess
231239
}
232240
return {
233241
popup,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy