(props: PiPProviderProps)
| 40 | * @returns The context provider. |
| 41 | */ |
| 42 | export const PiPProvider = (props: PiPProviderProps) => { |
| 43 | // Expose pipWindow that is currently active |
| 44 | const [pipWindow, setPipWindow] = createSignal<Window | null>(null) |
| 45 | |
| 46 | // Close pipWindow programmatically |
| 47 | const closePipWindow = () => { |
| 48 | const w = pipWindow() |
| 49 | if (w != null) { |
| 50 | w.close() |
| 51 | props.setLocalStore('pip_open', 'false') |
| 52 | setPipWindow(null) |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | // Open new pipWindow |
| 57 | const requestPipWindow = (width: number, height: number) => { |
| 58 | // We don't want to allow multiple requests. |
| 59 | if (pipWindow() != null) { |
| 60 | return |
| 61 | } |
| 62 | |
| 63 | const pip = window.open( |
| 64 | '', |
| 65 | 'TSQD-Devtools-Panel', |
| 66 | `width=${width},height=${height},popup`, |
| 67 | ) |
| 68 | |
| 69 | if (!pip) { |
| 70 | throw new PipOpenError( |
| 71 | 'Failed to open popup. Please allow popups for this site to view the devtools in picture-in-picture mode.', |
| 72 | ) |
| 73 | } |
| 74 | |
| 75 | // Remove existing styles and body. `replaceChildren` instead of |
| 76 | // `innerHTML = ''`, which Trusted Types block. |
| 77 | pip.document.head.replaceChildren() |
| 78 | pip.document.body.replaceChildren() |
| 79 | // Clear Delegated Events |
| 80 | clearDelegatedEvents(pip.document) |
| 81 | |
| 82 | pip.document.title = 'TanStack Query Devtools' |
| 83 | pip.document.body.style.margin = '0' |
| 84 | |
| 85 | // Detect when window is closed by user |
| 86 | pip.addEventListener('pagehide', () => { |
| 87 | props.setLocalStore('pip_open', 'false') |
| 88 | setPipWindow(null) |
| 89 | }) |
| 90 | |
| 91 | // It is important to copy all parent window styles. Otherwise, there would be no CSS available at all |
| 92 | // https://developer.chrome.com/docs/web-platform/document-picture-in-picture/#copy-style-sheets-to-the-picture-in-picture-window |
| 93 | ;[ |
| 94 | ...(useQueryDevtoolsContext().shadowDOMTarget || document).styleSheets, |
| 95 | ].forEach((styleSheet) => { |
| 96 | try { |
| 97 | const cssRules = [...styleSheet.cssRules] |
| 98 | .map((rule) => rule.cssText) |
| 99 | .join('') |
nothing calls this directly
no test coverage detected