Skip to content
Source
Sign inSign up
TanStack/devtools
Open History to see the last commit

panel.ts

35 lines909 Bytes

1import type { Component } from 'svelte'
2​
3export interface DevtoolsPanelProps {
4 theme?: 'dark' | 'light' | 'system'
5}
6​
7export function createSveltePanel<
8 TComponentProps extends DevtoolsPanelProps,
9 TCoreDevtoolsClass extends {
10 mount: (el: HTMLElement, theme?: DevtoolsPanelProps['theme']) => void
11 unmount: () => void
12 },
13>(
14 CoreClass: new (props: TComponentProps) => TCoreDevtoolsClass,
15): [Component<any>, Component<any>] {
16 const Panel: Component<any> = ((anchor: any, props: any) => {
17 const el = document.createElement('div')
18 el.style.height = '100%'
19 anchor.before(el)
20​
21 const instance = new CoreClass(props?.devtoolsProps as TComponentProps)
22 instance.mount(el, props?.theme)
23​
24 return {
25 destroy() {
26 instance.unmount()
27 el.remove()
28 },
29 }
30 }) as any
31​
32 const NoOpPanel: Component<any> = (() => ({})) as any
33​
34 return [Panel, NoOpPanel]