forked from TanStack/table
-
Notifications
You must be signed in to change notification settings - Fork 0
/
render-component.ts
89 lines (83 loc) · 1.88 KB
/
render-component.ts
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
import type { ComponentType, ComponentProps } from 'svelte'
import {
SvelteComponent,
claim_component,
create_component,
destroy_component,
init,
mount_component,
noop,
safe_not_equal,
transition_in,
transition_out,
create_ssr_component,
validate_component,
} from 'svelte/internal'
function create_fragment(ctx: any, Comp: any, props: any) {
let c: any
let current: any
c = new Comp({ props, $$inline: true })
return {
c() {
create_component(c.$$.fragment)
},
l(nodes: any) {
claim_component(c.$$.fragment, nodes)
},
m(target: any, anchor: any) {
// @ts-ignore
mount_component(c, target, anchor)
current = true
},
p: noop,
i(local: any) {
if (current) return
transition_in(c.$$.fragment, local)
current = true
},
o(local: any) {
transition_out(c.$$.fragment, local)
current = false
},
d(detaching: any) {
destroy_component(c, detaching)
},
}
}
function renderClient<T>(
Comp: T,
props: T extends ComponentType<infer C> ? ComponentProps<C> : any
) {
return class WrapperComp extends SvelteComponent {
constructor(options: any) {
super()
init(
this,
options,
null,
(ctx: any) => create_fragment(ctx, Comp, props),
safe_not_equal,
{},
undefined
)
}
} as ComponentType
}
function renderServer<T>(
Comp: T,
props: T extends ComponentType<infer C> ? ComponentProps<C> : any
) {
const WrapperComp = create_ssr_component(
($$result: any, $$props: any, $$bindings: any, slots: any) => {
return `${validate_component(Comp, 'TableComponent').$$render(
$$result,
props,
{},
{}
)}`
}
)
return WrapperComp as unknown as ComponentType
}
export const renderComponent =
typeof window === 'undefined' ? renderServer : renderClient