@hamur/adapter-svelte 0.0.2 → 0.0.3
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/dist/src/index.js +1 -1
- package/dist/types/src/Announcer.svelte +26 -0
- package/dist/types/src/Await.svelte +43 -0
- package/dist/types/src/AwaitAsync.svelte +42 -0
- package/dist/types/src/BodyAttrs.svelte +7 -0
- package/dist/types/src/Caught.svelte +41 -0
- package/dist/types/src/ClientComponent.svelte +35 -0
- package/dist/types/src/ClientFallback.svelte +46 -0
- package/dist/types/src/ClientOnly.svelte +22 -0
- package/dist/types/src/DefaultErrorPage.svelte +15 -0
- package/dist/types/src/DevOnly.svelte +12 -0
- package/dist/types/src/ErrorBoundary.svelte +14 -0
- package/dist/types/src/FallbackEffect.svelte +9 -0
- package/dist/types/src/Form.svelte +96 -0
- package/dist/types/src/HeadLink.svelte +7 -0
- package/dist/types/src/HeadMeta.svelte +7 -0
- package/dist/types/src/HeadScript.svelte +7 -0
- package/dist/types/src/HeadStyle.svelte +7 -0
- package/dist/types/src/HeadTitle.svelte +6 -0
- package/dist/types/src/HtmlAttrs.svelte +7 -0
- package/dist/types/src/HttpHeader.svelte +7 -0
- package/dist/types/src/HttpStatusCode.svelte +7 -0
- package/dist/types/src/Island.svelte +59 -0
- package/dist/types/src/IslandChildren.svelte +7 -0
- package/dist/types/src/KeptOutlet.svelte +46 -0
- package/dist/types/src/KeptPage.svelte +55 -0
- package/dist/types/src/LazyHydration.svelte +54 -0
- package/dist/types/src/Link.svelte +209 -0
- package/dist/types/src/LoadingIndicator.svelte +18 -0
- package/dist/types/src/MarkdownNodes.svelte +36 -0
- package/dist/types/src/MarkdownRenderer.svelte +20 -0
- package/dist/types/src/MarkdownSlots.svelte +33 -0
- package/dist/types/src/Navigate.svelte +10 -0
- package/dist/types/src/Nest.svelte +83 -0
- package/dist/types/src/Outlet.svelte +31 -0
- package/dist/types/src/Rethrow.svelte +7 -0
- package/dist/types/src/Root.svelte +29 -0
- package/dist/types/src/RouteAnnouncer.svelte +47 -0
- package/dist/types/src/Scoped.svelte +11 -0
- package/dist/types/src/ServerComponent.svelte +19 -0
- package/dist/types/src/ServerComponentClient.svelte +64 -0
- package/dist/types/src/ServerIsland.svelte +26 -0
- package/dist/types/src/Slotted.svelte +11 -0
- package/dist/types/src/Thrown.svelte +9 -0
- package/dist/types/src/Time.svelte +23 -0
- package/dist/types/src/index.d.ts +7 -7
- package/package.json +2 -2
- package/src/index.ts +8 -7
package/dist/src/index.js
CHANGED
|
@@ -683,7 +683,7 @@ function useSearch(select) {
|
|
|
683
683
|
return {
|
|
684
684
|
get value() {
|
|
685
685
|
const search = read().route.search;
|
|
686
|
-
if (shown
|
|
686
|
+
if (shown && shown.search === search)
|
|
687
687
|
return shown.value;
|
|
688
688
|
const next = select ? select(search) : search;
|
|
689
689
|
shown = { search, value: shown && equalSearch(shown.value, next) ? shown.value : next };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { ANNOUNCER_ASSERTIVE_ID, ANNOUNCER_POLITE_ID, createAnnouncer, hideAnnouncer } from "hamur/adapter"
|
|
3
|
+
import { onMount } from "svelte"
|
|
4
|
+
import { createSubscriber } from "svelte/reactivity"
|
|
5
|
+
import { useApp } from "./index.ts"
|
|
6
|
+
|
|
7
|
+
const store = createAnnouncer(useApp())
|
|
8
|
+
const subscribe = createSubscriber((update) => store.subscribe(update))
|
|
9
|
+
const regions = $derived.by(() => {
|
|
10
|
+
subscribe()
|
|
11
|
+
return store.get().regions
|
|
12
|
+
})
|
|
13
|
+
let polite: HTMLElement | undefined = $state()
|
|
14
|
+
let assertive: HTMLElement | undefined = $state()
|
|
15
|
+
onMount(() => {
|
|
16
|
+
for (const element of [polite, assertive]) if (element) hideAnnouncer(element)
|
|
17
|
+
return store.mount()
|
|
18
|
+
})
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<div bind:this={polite} id={ANNOUNCER_POLITE_ID} aria-live="polite" aria-atomic="true" role="status"
|
|
22
|
+
>{regions.polite}</div
|
|
23
|
+
>
|
|
24
|
+
<div bind:this={assertive} id={ANNOUNCER_ASSERTIVE_ID} aria-live="assertive" aria-atomic="true" role="alert"
|
|
25
|
+
>{regions.assertive}</div
|
|
26
|
+
>
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
<script lang="ts" generics="T">
|
|
2
|
+
import { settledOf } from "hamur/adapter"
|
|
3
|
+
import type { Snippet } from "svelte"
|
|
4
|
+
import Rethrow from "./Rethrow.svelte"
|
|
5
|
+
|
|
6
|
+
let {
|
|
7
|
+
resolve,
|
|
8
|
+
children,
|
|
9
|
+
fallback,
|
|
10
|
+
error,
|
|
11
|
+
}: { resolve: T; children?: Snippet<[Awaited<T>]>; fallback?: Snippet; error?: Snippet<[Error]> } = $props()
|
|
12
|
+
|
|
13
|
+
const isThenable = (value: unknown): value is PromiseLike<unknown> =>
|
|
14
|
+
typeof (value as { then?: unknown } | null)?.then === "function"
|
|
15
|
+
const settled = $derived(
|
|
16
|
+
isThenable(resolve) ? settledOf(resolve) : ({ status: "fulfilled", value: resolve } as const),
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
if ((import.meta as { dev?: boolean }).dev === true && !children)
|
|
20
|
+
console.warn("Await has nothing to render for its value")
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
{#if settled?.status === "fulfilled"}
|
|
24
|
+
{@render children?.(settled.value as Awaited<T>)}
|
|
25
|
+
{:else if settled?.status === "rejected"}
|
|
26
|
+
{#if error}
|
|
27
|
+
{@render error(settled.reason as Error)}
|
|
28
|
+
{:else}
|
|
29
|
+
<Rethrow error={settled.reason} />
|
|
30
|
+
{/if}
|
|
31
|
+
{:else}
|
|
32
|
+
{#await resolve}
|
|
33
|
+
{@render fallback?.()}
|
|
34
|
+
{:then value}
|
|
35
|
+
{@render children?.(value as Awaited<T>)}
|
|
36
|
+
{:catch reason}
|
|
37
|
+
{#if error}
|
|
38
|
+
{@render error(reason as Error)}
|
|
39
|
+
{:else}
|
|
40
|
+
<Rethrow error={reason} />
|
|
41
|
+
{/if}
|
|
42
|
+
{/await}
|
|
43
|
+
{/if}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
<script lang="ts" generics="T">
|
|
2
|
+
import { settledOf } from "hamur/adapter"
|
|
3
|
+
import type { Snippet } from "svelte"
|
|
4
|
+
import Rethrow from "./Rethrow.svelte"
|
|
5
|
+
|
|
6
|
+
let {
|
|
7
|
+
resolve,
|
|
8
|
+
children,
|
|
9
|
+
error,
|
|
10
|
+
}: { resolve: T; children?: Snippet<[Awaited<T>]>; fallback?: Snippet; error?: Snippet<[Error]> } = $props()
|
|
11
|
+
|
|
12
|
+
const isThenable = (value: unknown): value is PromiseLike<unknown> =>
|
|
13
|
+
typeof (value as { then?: unknown } | null)?.then === "function"
|
|
14
|
+
const settled = $derived(
|
|
15
|
+
isThenable(resolve) ? settledOf(resolve) : ({ status: "fulfilled", value: resolve } as const),
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
if ((import.meta as { dev?: boolean }).dev === true && !children)
|
|
19
|
+
console.warn("Await has nothing to render for its value")
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
{#if settled?.status === "fulfilled"}
|
|
23
|
+
{@render children?.(settled.value as Awaited<T>)}
|
|
24
|
+
{:else if settled?.status === "rejected"}
|
|
25
|
+
{#if error}
|
|
26
|
+
{@render error(settled.reason as Error)}
|
|
27
|
+
{:else}
|
|
28
|
+
<Rethrow error={settled.reason} />
|
|
29
|
+
{/if}
|
|
30
|
+
{:else}
|
|
31
|
+
<!-- a `pending` snippet would be rendered instead of the content on the server, so the boundary has none and the fallback is not shown -->
|
|
32
|
+
<svelte:boundary>
|
|
33
|
+
{@render children?.((await resolve) as Awaited<T>)}
|
|
34
|
+
{#snippet failed(reason)}
|
|
35
|
+
{#if error}
|
|
36
|
+
{@render error(reason as Error)}
|
|
37
|
+
{:else}
|
|
38
|
+
<Rethrow error={reason} />
|
|
39
|
+
{/if}
|
|
40
|
+
{/snippet}
|
|
41
|
+
</svelte:boundary>
|
|
42
|
+
{/if}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { untrack } from "svelte"
|
|
3
|
+
import type { Component as SvelteComponent } from "svelte"
|
|
4
|
+
import { routeBoundary } from "hamur/adapter"
|
|
5
|
+
import type { RenderEntry } from "hamur/adapter"
|
|
6
|
+
import { isRedirect, type ClearErrorOptions, type ErrorPageProps } from "hamur/app"
|
|
7
|
+
import { isFailure, originalOf, reviveError } from "./boundary-error.ts"
|
|
8
|
+
import { useAppState } from "./context.ts"
|
|
9
|
+
import Rethrow from "./Rethrow.svelte"
|
|
10
|
+
import Scoped from "./Scoped.svelte"
|
|
11
|
+
|
|
12
|
+
let { entry, error, reset, thrown }: { entry: RenderEntry; error: unknown; reset: () => void; thrown: boolean } =
|
|
13
|
+
$props()
|
|
14
|
+
|
|
15
|
+
const read = useAppState("Boundary")
|
|
16
|
+
const first = untrack(() => entry)
|
|
17
|
+
const clearError = (options?: ClearErrorOptions) => read().app.error?.clear(options) ?? Promise.resolve()
|
|
18
|
+
const caught = untrack(() => {
|
|
19
|
+
if (thrown)
|
|
20
|
+
return { component: entry.component, error: entry.props?.error as ErrorPageProps, props: entry.props ?? {} }
|
|
21
|
+
const revived = reviveError(error)
|
|
22
|
+
if (isFailure(revived) || isRedirect(revived)) throw revived
|
|
23
|
+
const result = routeBoundary(read().context, entry, originalOf(error) ?? revived)
|
|
24
|
+
if (!result) throw revived
|
|
25
|
+
return { component: result.component, error: result.error, props: { error: result.error, clearError } }
|
|
26
|
+
})
|
|
27
|
+
const Boundary = caught.component as SvelteComponent<any>
|
|
28
|
+
|
|
29
|
+
$effect(() => {
|
|
30
|
+
if (entry !== first) untrack(reset)
|
|
31
|
+
})
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<svelte:boundary>
|
|
35
|
+
<Scoped error={caught.error}>
|
|
36
|
+
<Boundary {...caught.props} />
|
|
37
|
+
</Scoped>
|
|
38
|
+
{#snippet failed(thrown)}
|
|
39
|
+
<Rethrow error={thrown} />
|
|
40
|
+
{/snippet}
|
|
41
|
+
</svelte:boundary>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { getContext, onMount } from "svelte"
|
|
3
|
+
import type { Component } from "svelte"
|
|
4
|
+
import { CLIENT_ONLY } from "./client-only.ts"
|
|
5
|
+
import type { ClientOnlyScope } from "./client-only.ts"
|
|
6
|
+
|
|
7
|
+
let {
|
|
8
|
+
server,
|
|
9
|
+
...rest
|
|
10
|
+
}: { server: { load?: () => Promise<{ default: Component<Record<string, unknown>> }> } } & Record<string, unknown> =
|
|
11
|
+
$props()
|
|
12
|
+
const scope = getContext<ClientOnlyScope | undefined>(CLIENT_ONLY)
|
|
13
|
+
let Loaded = $state.raw<Component<Record<string, unknown>>>()
|
|
14
|
+
let failure = $state.raw<{ error: unknown }>()
|
|
15
|
+
onMount(() => {
|
|
16
|
+
server.load?.().then(
|
|
17
|
+
(module) => {
|
|
18
|
+
Loaded = module.default
|
|
19
|
+
},
|
|
20
|
+
(error: unknown) => {
|
|
21
|
+
failure = { error }
|
|
22
|
+
},
|
|
23
|
+
)
|
|
24
|
+
})
|
|
25
|
+
// An effect's throw reaches the nearest boundary; a promise callback's does not.
|
|
26
|
+
$effect(() => {
|
|
27
|
+
if (failure) throw failure.error
|
|
28
|
+
})
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
{#if Loaded}
|
|
32
|
+
<Loaded {...rest} />
|
|
33
|
+
{:else if scope?.fallback}
|
|
34
|
+
{@render scope.fallback()}
|
|
35
|
+
{/if}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { untrack } from "svelte"
|
|
3
|
+
import type { Snippet } from "svelte"
|
|
4
|
+
import { clientFallback } from "hamur/adapter"
|
|
5
|
+
import { originalOf, reviveError } from "./boundary-error.ts"
|
|
6
|
+
import { useAppState } from "./context.ts"
|
|
7
|
+
import FallbackEffect from "./FallbackEffect.svelte"
|
|
8
|
+
|
|
9
|
+
let {
|
|
10
|
+
children,
|
|
11
|
+
fallback,
|
|
12
|
+
onSsrError,
|
|
13
|
+
}: { children?: Snippet; fallback?: Snippet; keepFallback?: boolean; onSsrError?: (error: unknown) => unknown } =
|
|
14
|
+
$props()
|
|
15
|
+
|
|
16
|
+
const id = $props.id()
|
|
17
|
+
const read = useAppState("ClientFallback")
|
|
18
|
+
const server = typeof window === "undefined"
|
|
19
|
+
const ids = server
|
|
20
|
+
? undefined
|
|
21
|
+
: untrack(() => (read().context.payload as { clientFallback?: unknown }).clientFallback)
|
|
22
|
+
let retry = Array.isArray(ids) && ids.includes(id)
|
|
23
|
+
|
|
24
|
+
const report = (error: unknown) => {
|
|
25
|
+
if (server)
|
|
26
|
+
clientFallback(
|
|
27
|
+
untrack(() => read().app),
|
|
28
|
+
id,
|
|
29
|
+
originalOf(error) ?? reviveError(error),
|
|
30
|
+
onSsrError,
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
const render = (reset: () => void) => () => {
|
|
34
|
+
if (!retry) return
|
|
35
|
+
retry = false
|
|
36
|
+
reset()
|
|
37
|
+
}
|
|
38
|
+
</script>
|
|
39
|
+
|
|
40
|
+
<svelte:boundary>
|
|
41
|
+
{@render children?.()}
|
|
42
|
+
{#snippet failed(error, reset)}
|
|
43
|
+
<FallbackEffect run={() => report(error)} after={render(reset)} />
|
|
44
|
+
{@render fallback?.()}
|
|
45
|
+
{/snippet}
|
|
46
|
+
</svelte:boundary>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onMount, setContext } from "svelte"
|
|
3
|
+
import type { Snippet } from "svelte"
|
|
4
|
+
import { CLIENT_ONLY } from "./client-only.ts"
|
|
5
|
+
|
|
6
|
+
let { children, fallback }: { children?: Snippet; fallback?: Snippet } = $props()
|
|
7
|
+
let hydrated = $state(false)
|
|
8
|
+
setContext(CLIENT_ONLY, {
|
|
9
|
+
get fallback() {
|
|
10
|
+
return fallback
|
|
11
|
+
},
|
|
12
|
+
})
|
|
13
|
+
onMount(() => {
|
|
14
|
+
hydrated = true
|
|
15
|
+
})
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
{#if hydrated}
|
|
19
|
+
{@render children?.()}
|
|
20
|
+
{:else}
|
|
21
|
+
{@render fallback?.()}
|
|
22
|
+
{/if}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { ErrorPageProps } from "hamur/app"
|
|
3
|
+
import { diagnosticURL, type DiagnosticCode } from "hamur/adapter"
|
|
4
|
+
import Link from "./Link.svelte"
|
|
5
|
+
|
|
6
|
+
let { error }: { error: ErrorPageProps } = $props()
|
|
7
|
+
const isDev = (import.meta as { dev?: boolean }).dev === true
|
|
8
|
+
const codeURL = isDev ? (code: string) => diagnosticURL(code as DiagnosticCode) : () => ""
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<main style="font-family:system-ui,sans-serif;text-align:center;padding:4rem 1rem"
|
|
12
|
+
><h1 style="font-size:4rem;margin:0">{error.status}</h1><p>{error.message}</p>{#if isDev && error.code}<p
|
|
13
|
+
><a href={codeURL(error.code)} target="_blank" rel="noopener">{error.code}</a></p
|
|
14
|
+
>{/if}{#if error.stack}<pre>{error.stack}</pre>{/if}<Link to="/">Back home</Link></main
|
|
15
|
+
>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from "svelte"
|
|
3
|
+
|
|
4
|
+
let { children, fallback }: { children?: Snippet; fallback?: Snippet } = $props()
|
|
5
|
+
const isDev = (import.meta as { dev?: boolean }).dev === true
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
{#if isDev}
|
|
9
|
+
{@render children?.()}
|
|
10
|
+
{:else}
|
|
11
|
+
{@render fallback?.()}
|
|
12
|
+
{/if}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from "svelte"
|
|
3
|
+
import type { ErrorBoundaryFallbackProps } from "hamur/adapter"
|
|
4
|
+
import { reviveError } from "./boundary-error.ts"
|
|
5
|
+
|
|
6
|
+
let { children, fallback }: { children?: Snippet; fallback?: Snippet<[ErrorBoundaryFallbackProps]> } = $props()
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<svelte:boundary>
|
|
10
|
+
{@render children?.()}
|
|
11
|
+
{#snippet failed(error, reset)}
|
|
12
|
+
{@render fallback?.({ error: reviveError(error), reset })}
|
|
13
|
+
{/snippet}
|
|
14
|
+
</svelte:boundary>
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { getContext, onMount, setContext, type Snippet } from "svelte"
|
|
3
|
+
import type { HTMLFormAttributes } from "svelte/elements"
|
|
4
|
+
import { enhance, type FormSubmitArgs, type RouteLocation } from "hamur/app"
|
|
5
|
+
import { assertFormMethod, createFormStatus, functionFormAction, runFunctionForm } from "hamur/adapter"
|
|
6
|
+
import { APP_KEY, FORM_STATUS_KEY, detachedHref, type AppState } from "./context.ts"
|
|
7
|
+
import { track, type Source } from "./store.ts"
|
|
8
|
+
|
|
9
|
+
interface Props extends Omit<HTMLFormAttributes, "action" | "method" | "enctype" | "children"> {
|
|
10
|
+
action?: string | RouteLocation | (((...args: never[]) => unknown) & { readonly url: string })
|
|
11
|
+
method?: "get" | "post"
|
|
12
|
+
encType?: "application/x-www-form-urlencoded" | "multipart/form-data"
|
|
13
|
+
replace?: boolean
|
|
14
|
+
reset?: boolean
|
|
15
|
+
reloadDocument?: boolean
|
|
16
|
+
refresh?: boolean
|
|
17
|
+
instance?: string | number
|
|
18
|
+
restore?: boolean
|
|
19
|
+
onSubmit?: (args: FormSubmitArgs) => void
|
|
20
|
+
children?: Snippet
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let {
|
|
24
|
+
action,
|
|
25
|
+
method,
|
|
26
|
+
encType,
|
|
27
|
+
replace = false,
|
|
28
|
+
reset = false,
|
|
29
|
+
reloadDocument = false,
|
|
30
|
+
refresh,
|
|
31
|
+
instance,
|
|
32
|
+
restore = true,
|
|
33
|
+
onSubmit,
|
|
34
|
+
children,
|
|
35
|
+
...rest
|
|
36
|
+
}: Props = $props()
|
|
37
|
+
const source = getContext<Source<AppState> | undefined>(APP_KEY)
|
|
38
|
+
const read = source && track(source)
|
|
39
|
+
let element: HTMLFormElement | undefined = $state()
|
|
40
|
+
assertFormMethod(action, method)
|
|
41
|
+
const target = $derived(
|
|
42
|
+
typeof action === "function"
|
|
43
|
+
? functionFormAction(
|
|
44
|
+
action as never,
|
|
45
|
+
read ? read().href(read().route.fullPath.replace(/#.*$/, "")) : "/",
|
|
46
|
+
instance,
|
|
47
|
+
)
|
|
48
|
+
: action !== undefined
|
|
49
|
+
? read
|
|
50
|
+
? read().href(action)
|
|
51
|
+
: detachedHref(action)
|
|
52
|
+
: read
|
|
53
|
+
? read().href(read().route.fullPath.replace(/#.*$/, ""))
|
|
54
|
+
: undefined,
|
|
55
|
+
)
|
|
56
|
+
const status = createFormStatus()
|
|
57
|
+
setContext(FORM_STATUS_KEY, status)
|
|
58
|
+
onMount(() =>
|
|
59
|
+
enhance(element!, {
|
|
60
|
+
onSubmit: (args) => {
|
|
61
|
+
status.submitted(args.formData)
|
|
62
|
+
onSubmit?.(args)
|
|
63
|
+
},
|
|
64
|
+
...(typeof action === "function" && source
|
|
65
|
+
? {
|
|
66
|
+
call: (input: Record<string, unknown>, formData: FormData) =>
|
|
67
|
+
runFunctionForm(
|
|
68
|
+
source.get().app,
|
|
69
|
+
action as never,
|
|
70
|
+
input,
|
|
71
|
+
formData,
|
|
72
|
+
() => source.get().router.refresh(),
|
|
73
|
+
status,
|
|
74
|
+
{ refresh, instance },
|
|
75
|
+
),
|
|
76
|
+
}
|
|
77
|
+
: {}),
|
|
78
|
+
}),
|
|
79
|
+
)
|
|
80
|
+
</script>
|
|
81
|
+
|
|
82
|
+
<form
|
|
83
|
+
{...rest}
|
|
84
|
+
bind:this={element}
|
|
85
|
+
method={typeof action === "function" ? "post" : "get"}
|
|
86
|
+
action={target}
|
|
87
|
+
enctype={encType}
|
|
88
|
+
data-hamur-form=""
|
|
89
|
+
data-hamur-replace={replace ? "" : undefined}
|
|
90
|
+
data-hamur-reset={reset ? "" : undefined}
|
|
91
|
+
data-hamur-reload={reloadDocument ? "" : undefined}
|
|
92
|
+
data-hamur-refresh={refresh === false ? "false" : undefined}
|
|
93
|
+
data-hamur-restore={restore === false ? "false" : undefined}
|
|
94
|
+
>
|
|
95
|
+
{@render children?.()}
|
|
96
|
+
</form>
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { getContext } from "svelte"
|
|
3
|
+
import type { Component, Snippet } from "svelte"
|
|
4
|
+
import { ISLAND_ELEMENT, renderIsland } from "hamur/adapter"
|
|
5
|
+
import type { IslandOn } from "hamur/adapter"
|
|
6
|
+
import { APP_KEY, PENDING_ISLANDS_KEY } from "./context.ts"
|
|
7
|
+
import type { AppState } from "./context.ts"
|
|
8
|
+
import type { Source } from "./store.ts"
|
|
9
|
+
import { keptServerHTML } from "./hydrating.ts"
|
|
10
|
+
import { settledIsland } from "./island-html.ts"
|
|
11
|
+
import IslandChildren from "./IslandChildren.svelte"
|
|
12
|
+
|
|
13
|
+
let {
|
|
14
|
+
component,
|
|
15
|
+
props = {},
|
|
16
|
+
on,
|
|
17
|
+
fallback,
|
|
18
|
+
children,
|
|
19
|
+
persist,
|
|
20
|
+
persistProps,
|
|
21
|
+
}: {
|
|
22
|
+
component: Component<any>
|
|
23
|
+
props?: Record<string, unknown>
|
|
24
|
+
on?: IslandOn
|
|
25
|
+
fallback?: Snippet
|
|
26
|
+
children?: Snippet
|
|
27
|
+
persist?: string
|
|
28
|
+
persistProps?: boolean
|
|
29
|
+
} = $props()
|
|
30
|
+
const id = $props.id()
|
|
31
|
+
const app = getContext<Source<AppState> | undefined>(APP_KEY)?.get().app
|
|
32
|
+
if (!app) throw new Error("Island must be rendered inside a Hamur app")
|
|
33
|
+
// In the browser an Island only runs inside an island that hydrates and keeps the inner element's server nodes; Svelte reads an `on` attribute there as an event handler, so the spread is empty.
|
|
34
|
+
const island =
|
|
35
|
+
typeof document === "undefined"
|
|
36
|
+
? renderIsland(
|
|
37
|
+
app,
|
|
38
|
+
id,
|
|
39
|
+
component,
|
|
40
|
+
props,
|
|
41
|
+
on,
|
|
42
|
+
children ? { component: IslandChildren, props: { slot: children } } : undefined,
|
|
43
|
+
{ persist, persistProps },
|
|
44
|
+
)
|
|
45
|
+
: undefined
|
|
46
|
+
const attributes = island?.attributes ?? {}
|
|
47
|
+
const html = island?.html
|
|
48
|
+
? (settledIsland(island.html, getContext<Promise<void>[] | undefined>(PENDING_ISLANDS_KEY)) ?? "")
|
|
49
|
+
: keptServerHTML()
|
|
50
|
+
</script>
|
|
51
|
+
|
|
52
|
+
{#if on === "only"}
|
|
53
|
+
<svelte:element this={ISLAND_ELEMENT} {...attributes}>{@render fallback?.()}</svelte:element>
|
|
54
|
+
{:else}
|
|
55
|
+
<svelte:element this={ISLAND_ELEMENT} {...attributes}>
|
|
56
|
+
<!-- svelte-ignore hydration_html_changed -->
|
|
57
|
+
{@html html}
|
|
58
|
+
</svelte:element>
|
|
59
|
+
{/if}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Component } from "svelte"
|
|
3
|
+
import type { KeptUnit, RenderEntry, RenderTree, RouteValue } from "hamur/adapter"
|
|
4
|
+
import type { KeepAliveBase } from "./keepalive.ts"
|
|
5
|
+
import KeptPage from "./KeptPage.svelte"
|
|
6
|
+
|
|
7
|
+
const SHOWN = "\0shown"
|
|
8
|
+
|
|
9
|
+
let {
|
|
10
|
+
kept,
|
|
11
|
+
entry,
|
|
12
|
+
components,
|
|
13
|
+
index,
|
|
14
|
+
route,
|
|
15
|
+
Nest,
|
|
16
|
+
base,
|
|
17
|
+
}: {
|
|
18
|
+
kept: KeptUnit[]
|
|
19
|
+
entry?: RenderEntry
|
|
20
|
+
components: RenderTree["components"]
|
|
21
|
+
index: number
|
|
22
|
+
route?: RouteValue
|
|
23
|
+
Nest: Component<any>
|
|
24
|
+
base: KeepAliveBase
|
|
25
|
+
} = $props()
|
|
26
|
+
const places = $derived.by(() => {
|
|
27
|
+
const list: Array<{ key: string; unit?: KeptUnit }> = kept.map((unit) => ({ key: unit.key, unit }))
|
|
28
|
+
if (entry) list.push({ key: entry.keepalive ?? SHOWN })
|
|
29
|
+
return list
|
|
30
|
+
})
|
|
31
|
+
</script>
|
|
32
|
+
|
|
33
|
+
{#each places as place (place.key)}
|
|
34
|
+
{#if place.key === SHOWN}
|
|
35
|
+
<Nest {components} {index} {route} bare />
|
|
36
|
+
{:else}
|
|
37
|
+
<KeptPage name={place.key} unit={place.unit} {base}>
|
|
38
|
+
<Nest
|
|
39
|
+
components={place.unit ? place.unit.tree.components : components}
|
|
40
|
+
index={place.unit ? 0 : index}
|
|
41
|
+
route={place.unit ? undefined : route}
|
|
42
|
+
bare
|
|
43
|
+
/>
|
|
44
|
+
</KeptPage>
|
|
45
|
+
{/if}
|
|
46
|
+
{/each}
|