forked from inertiajs/inertia
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[inertiajs#1866] Merge pull request #8 (with improvements)
Merge punyflash/inertia with some tweaks and fixes
- Loading branch information
Showing
28 changed files
with
1,374 additions
and
389 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
dist | ||
types | ||
node_modules | ||
package-lock.json | ||
yarn.lock | ||
.svelte-kit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<script lang="ts"> | ||
import Render, { h } from './Render.svelte' | ||
import store from '../store' | ||
$: child = $store.component?.default && h($store.component.default, $store.page?.props) | ||
$: layout = $store.component && $store.component.layout | ||
$: components = layout | ||
? Array.isArray(layout) | ||
? layout | ||
.concat(child) | ||
.reverse() | ||
.reduce((child, layout) => h(layout, $store.page?.props, [child])) | ||
: h(layout, $store.page?.props, child ? [child] : []) | ||
: child | ||
</script> | ||
|
||
<Render {...components} /> |
25 changes: 13 additions & 12 deletions
25
packages/svelte/src/Link.svelte → ...ges/svelte/src/lib/components/Link.svelte
100755 → 100644
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<script context="module" lang="ts"> | ||
import type { PageProps } from '@inertiajs/core' | ||
import type { ComponentType } from 'svelte' | ||
type RenderProps = { | ||
component: ComponentType | ||
props?: PageProps | ||
children?: RenderProps[] | ||
} | null | ||
export const h = (component: ComponentType, props?: PageProps, children?: RenderProps[]): RenderProps => { | ||
return { | ||
component, | ||
...(props ? { props } : {}), | ||
...(children ? { children } : {}), | ||
} | ||
} | ||
</script> | ||
|
||
<script lang="ts"> | ||
import store from '../store' | ||
export let component: ComponentType | ||
export let props: PageProps = {} | ||
export let children: RenderProps[] = [] | ||
let prevComponent: ComponentType | ||
let key: number | ||
$: { | ||
if (prevComponent !== component) { | ||
key = Date.now() | ||
prevComponent = component | ||
} | ||
} | ||
</script> | ||
|
||
{#if $store.component} | ||
{#key key} | ||
<svelte:component this={component} {...props}> | ||
{#each children as child, index (component && component.length === index ? $store.key : null)} | ||
<svelte:self {...child} /> | ||
{/each} | ||
</svelte:component> | ||
{/key} | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<script context="module" lang="ts"> | ||
import type { Page } from '@inertiajs/core' | ||
export type SSRProps = { id: string; initialPage: Page } | ||
</script> | ||
<script lang="ts"> | ||
import App from './App.svelte' | ||
interface $$Props extends SSRProps {} | ||
export let id: $$Props['id'] | ||
export let initialPage: $$Props['initialPage'] | ||
</script> | ||
|
||
<div data-server-rendered="true" {id} data-page={JSON.stringify(initialPage)}> | ||
<App /> | ||
</div> |
Oops, something went wrong.