@tanstack/svelte-table 8.0.0-alpha.76 → 8.0.0-alpha.79

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tanstack/svelte-table",
3
3
  "author": "Tanner Linsley",
4
- "version": "8.0.0-alpha.76",
4
+ "version": "8.0.0-alpha.79",
5
5
  "description": "Composables for building lightweight, fast and extendable datagrids for Vue",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/tanstack/react-table#readme",
@@ -34,7 +34,7 @@
34
34
  "src"
35
35
  ],
36
36
  "dependencies": {
37
- "@tanstack/table-core": "8.0.0-alpha.76"
37
+ "@tanstack/table-core": "8.0.0-alpha.79"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "svelte": "^3.48.0"
package/src/index.ts CHANGED
@@ -7,6 +7,7 @@ import {
7
7
  TableOptions,
8
8
  } from '@tanstack/table-core'
9
9
  import Placeholder from './placeholder.svelte'
10
+ import { SvelteComponent } from 'svelte/internal'
10
11
  import { readable, writable, derived, Readable, get } from 'svelte/store'
11
12
  import { renderComponent } from './render-component'
12
13
 
@@ -14,17 +15,48 @@ export { renderComponent } from './render-component'
14
15
 
15
16
  export * from '@tanstack/table-core'
16
17
 
17
- export function render(Comp: any, props: any) {
18
- if (!Comp) return null
18
+ function isSvelteServerComponent(component: any) {
19
+ return (
20
+ typeof component === 'object' &&
21
+ typeof component.$$render === 'function' &&
22
+ typeof component.render === 'function'
23
+ )
24
+ }
25
+
26
+ function isSvelteClientComponent(component: any) {
27
+ return component.prototype instanceof SvelteComponent
28
+ }
19
29
 
20
- if (Comp instanceof Function) {
21
- let res = Comp(props)
22
- return res
30
+ function isSvelteComponent(component: any) {
31
+ if (typeof document === 'undefined') {
32
+ return isSvelteServerComponent(component)
23
33
  } else {
24
- return renderComponent(Placeholder, { content: Comp })
34
+ return isSvelteClientComponent(component)
35
+ }
36
+ }
37
+
38
+ function wrapInPlaceholder(content: any) {
39
+ return renderComponent(Placeholder, { content })
40
+ }
41
+
42
+ export function render(component: any, props: any) {
43
+ if (!component) return null
44
+
45
+ if (isSvelteComponent(component)) {
46
+ return renderComponent(component, props)
47
+ }
48
+
49
+ if (typeof component === 'function') {
50
+ const result = component(props)
51
+
52
+ if (isSvelteComponent(result)) {
53
+ return result
54
+ }
55
+
56
+ return wrapInPlaceholder(result)
25
57
  }
26
58
 
27
- // return Comp
59
+ return wrapInPlaceholder(component)
28
60
  }
29
61
 
30
62
  export const createTable = createTableFactory({ render })