2020-11-13 16:42:32 +01:00
|
|
|
<script>
|
|
|
|
import { componentStore } from "../store"
|
2020-11-17 13:08:24 +01:00
|
|
|
import { getValidProps } from "../utils"
|
2020-11-13 16:42:32 +01:00
|
|
|
|
2020-11-17 13:08:24 +01:00
|
|
|
export let definition = {}
|
2020-11-13 16:42:32 +01:00
|
|
|
|
2020-11-17 13:08:24 +01:00
|
|
|
$: componentProps = getValidProps(definition)
|
|
|
|
$: children = definition._children
|
|
|
|
$: componentName = extractComponentName(definition._component)
|
|
|
|
$: constructor = componentStore.actions.getComponent(componentName)
|
|
|
|
$: id = `${componentName}-${definition._id}`
|
|
|
|
$: styles = { ...definition._styles, id }
|
|
|
|
|
|
|
|
// Extracts the actual component name from the library name
|
|
|
|
function extractComponentName(name) {
|
|
|
|
const split = name.split("/")
|
|
|
|
return split[split.length - 1]
|
|
|
|
}
|
|
|
|
|
|
|
|
$: console.log("Rendering: " + componentName)
|
2020-11-13 16:42:32 +01:00
|
|
|
</script>
|
|
|
|
|
2020-11-17 13:08:24 +01:00
|
|
|
{#if constructor}
|
|
|
|
<svelte:component this={constructor} {...componentProps} {styles}>
|
|
|
|
{#if children && children.length}
|
|
|
|
{#each children as child}
|
|
|
|
<svelte:self definition={child} />
|
|
|
|
{/each}
|
|
|
|
{/if}
|
|
|
|
</svelte:component>
|
2020-11-13 16:42:32 +01:00
|
|
|
{/if}
|