added WIP, recursive children in children render
This commit is contained in:
parent
f060090b0c
commit
613053c062
@ -1,12 +1,18 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import Composite from './Composite.svelte'; // Recursive import
|
||||||
import components from '$lib/components.ts';
|
import components from '$lib/components.ts';
|
||||||
import { getContextStore } from '$lib/stores/contextStore.ts';
|
import { getContextStore } from '$lib/stores/contextStore.ts';
|
||||||
export let componentsData = [];
|
|
||||||
|
|
||||||
// For each component, get or create its context store
|
export let componentsData = {
|
||||||
|
layout: '',
|
||||||
|
children: []
|
||||||
|
};
|
||||||
|
|
||||||
|
$: if (componentsData && componentsData.children) {
|
||||||
componentsData.children.forEach((child) => {
|
componentsData.children.forEach((child) => {
|
||||||
child.store = getContextStore(child.componentName);
|
child.store = getContextStore(child.componentName);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async function getComponent(componentName) {
|
async function getComponent(componentName) {
|
||||||
if (components[componentName]) {
|
if (components[componentName]) {
|
||||||
@ -37,6 +43,11 @@
|
|||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
<!-- Recursive rendering of children -->
|
||||||
|
{#if component.children && component.children.length}
|
||||||
|
<Composite componentsData={component} />
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
<p>Component {component.componentName} not found.</p>
|
<p>Component {component.componentName} not found.</p>
|
||||||
|
1
src/lib/components/HelloEarth.svelte
Normal file
1
src/lib/components/HelloEarth.svelte
Normal file
@ -0,0 +1 @@
|
|||||||
|
<div class="p-12 bg-blue-400">Hello Earth</div>
|
Loading…
x
Reference in New Issue
Block a user