@typed/svelte 1.0.0-beta.7
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/README.md +130 -0
- package/dist/AsyncData.d.ts +23 -0
- package/dist/AsyncData.d.ts.map +1 -0
- package/dist/AsyncData.js +28 -0
- package/dist/Attachment.d.ts +16 -0
- package/dist/Attachment.d.ts.map +1 -0
- package/dist/Attachment.js +56 -0
- package/dist/Reactive.d.ts +44 -0
- package/dist/Reactive.d.ts.map +1 -0
- package/dist/Reactive.js +184 -0
- package/dist/Router.d.ts +100 -0
- package/dist/Router.d.ts.map +1 -0
- package/dist/Router.js +89 -0
- package/dist/Runtime.d.ts +22 -0
- package/dist/Runtime.d.ts.map +1 -0
- package/dist/Runtime.js +53 -0
- package/dist/Source.d.ts +6 -0
- package/dist/Source.d.ts.map +1 -0
- package/dist/Source.js +12 -0
- package/dist/Store.d.ts +26 -0
- package/dist/Store.d.ts.map +1 -0
- package/dist/Store.js +58 -0
- package/dist/Typed.client.js +77 -0
- package/dist/Typed.d.ts +13 -0
- package/dist/Typed.d.ts.map +1 -0
- package/dist/Typed.js +1 -0
- package/dist/Typed.server.js +70 -0
- package/dist/TypedComponent.d.ts +7 -0
- package/dist/TypedComponent.d.ts.map +1 -0
- package/dist/TypedComponent.js +1 -0
- package/dist/ViewOptions.d.ts +21 -0
- package/dist/ViewOptions.d.ts.map +1 -0
- package/dist/ViewOptions.js +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/internal/Bridge.client.js +17 -0
- package/dist/internal/Bridge.server.js +18 -0
- package/dist/internal/Dom.d.ts +7 -0
- package/dist/internal/Dom.d.ts.map +1 -0
- package/dist/internal/Dom.js +47 -0
- package/dist/internal/Html.d.ts +6 -0
- package/dist/internal/Html.d.ts.map +1 -0
- package/dist/internal/Html.js +25 -0
- package/dist/internal/RenderSnapshot.client.d.ts +3 -0
- package/dist/internal/RenderSnapshot.client.d.ts.map +1 -0
- package/dist/internal/RenderSnapshot.client.js +4 -0
- package/dist/internal/RenderSnapshot.server.d.ts +7 -0
- package/dist/internal/RenderSnapshot.server.d.ts.map +1 -0
- package/dist/internal/RenderSnapshot.server.js +8 -0
- package/dist/view.d.ts +11 -0
- package/dist/view.d.ts.map +1 -0
- package/dist/view.js +52 -0
- package/package.json +99 -0
package/dist/Router.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import * as AsyncData from "@typed/async-data";
|
|
2
|
+
import * as Fx from "@typed/fx/Fx";
|
|
3
|
+
import { Navigation, CurrentPath } from "@typed/navigation/Navigation";
|
|
4
|
+
import { CurrentRoute } from "@typed/router/CurrentRoute";
|
|
5
|
+
import * as Matcher from "@typed/router/Matcher";
|
|
6
|
+
import * as Route from "@typed/router/Route";
|
|
7
|
+
import * as Context from "effect/Context";
|
|
8
|
+
import * as Effect from "effect/Effect";
|
|
9
|
+
import * as Option from "effect/Option";
|
|
10
|
+
import { derived, get } from "svelte/store";
|
|
11
|
+
import { useService, useSource } from "./Reactive.js";
|
|
12
|
+
import { asReadable, provideRuntime, useRuntime, } from "./Runtime.js";
|
|
13
|
+
/** Follows committed entries from browser, server memory, or test Navigation. */
|
|
14
|
+
export function useLocation(options = {}) {
|
|
15
|
+
return useSource(Navigation.currentEntry, options);
|
|
16
|
+
}
|
|
17
|
+
/** Follows the canonical pathname plus query used by Typed's Matcher. */
|
|
18
|
+
export function useCurrentPath(options = {}) {
|
|
19
|
+
return useSource(CurrentPath, options);
|
|
20
|
+
}
|
|
21
|
+
/** Reads the structural route owner; navigation does not rewrite this tree. */
|
|
22
|
+
export function useCurrentRoute(options = {}) {
|
|
23
|
+
return useService(CurrentRoute, options);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Native state plus promise commands using the closest Navigation service.
|
|
27
|
+
* Commands use the latest provider after runtime replacement.
|
|
28
|
+
*/
|
|
29
|
+
export function useNavigation(options = {}) {
|
|
30
|
+
const runtime = options.runtime ? asReadable(options.runtime) : useRuntime();
|
|
31
|
+
return {
|
|
32
|
+
location: useLocation({ ...options, runtime }),
|
|
33
|
+
entries: useSource(Navigation.entries, { runtime }),
|
|
34
|
+
transition: useSource(Navigation.transition.asComputed(), {
|
|
35
|
+
runtime,
|
|
36
|
+
initial: AsyncData.success(Option.none()),
|
|
37
|
+
}),
|
|
38
|
+
canGoBack: useSource(Navigation.canGoBack, { runtime, initial: AsyncData.success(false) }),
|
|
39
|
+
canGoForward: useSource(Navigation.canGoForward, {
|
|
40
|
+
runtime,
|
|
41
|
+
initial: AsyncData.success(false),
|
|
42
|
+
}),
|
|
43
|
+
navigate: (...args) => get(runtime).runPromise(Navigation.navigate(...args)),
|
|
44
|
+
back: (...args) => get(runtime).runPromise(Navigation.back(...args)),
|
|
45
|
+
forward: (...args) => get(runtime).runPromise(Navigation.forward(...args)),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Decodes reactive route parameters with Typed's matcher. By default, leaving
|
|
50
|
+
* the ambient mount yields None. An explicit root confines the wildcard to that
|
|
51
|
+
* root, so paths outside it retain the native RouteNotFound failure.
|
|
52
|
+
*/
|
|
53
|
+
export function useRoute(route, options = {}) {
|
|
54
|
+
const matcher = Matcher.match(route, (params) => Fx.map(params, Option.some));
|
|
55
|
+
if (options.currentRoute !== undefined) {
|
|
56
|
+
const matches = derived(asReadable(options.currentRoute), (owner) => matcher
|
|
57
|
+
.match(Route.Wildcard, Option.none())
|
|
58
|
+
.pipe(Fx.provideService(CurrentRoute, owner)));
|
|
59
|
+
return useSource(matches, options);
|
|
60
|
+
}
|
|
61
|
+
const matches = Fx.gen(function* () {
|
|
62
|
+
const owner = yield* CurrentRoute;
|
|
63
|
+
return matcher
|
|
64
|
+
.prefix(owner.route)
|
|
65
|
+
.match(Route.Wildcard, Option.none())
|
|
66
|
+
.pipe(Fx.provideService(CurrentRoute, { route: Route.Slash }));
|
|
67
|
+
});
|
|
68
|
+
return useSource(matches, options);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Extends the structural CurrentRoute for descendants, including nested Typed
|
|
72
|
+
* content. Pass the full mount route, as with CurrentRoute.extend.
|
|
73
|
+
*/
|
|
74
|
+
export function provideCurrentRoute(route, runtime = useRuntime()) {
|
|
75
|
+
return provideRuntime(derived(asReadable(runtime), (parent) => {
|
|
76
|
+
const contextEffect = Effect.map(parent.contextEffect, (services) => Context.add(services, CurrentRoute, {
|
|
77
|
+
route,
|
|
78
|
+
parent: Context.getOrUndefined(services, CurrentRoute),
|
|
79
|
+
}));
|
|
80
|
+
const provide = (effect) => Effect.flatMap(contextEffect, (services) => Effect.provideContext(effect, services));
|
|
81
|
+
return {
|
|
82
|
+
contextEffect,
|
|
83
|
+
runFork: (effect, options) => parent.runFork(provide(effect), options),
|
|
84
|
+
runPromise: (effect, options) => parent.runPromise(provide(effect), options),
|
|
85
|
+
runPromiseExit: (effect, options) => parent.runPromiseExit(provide(effect), options),
|
|
86
|
+
runSync: (effect) => parent.runSync(provide(effect)),
|
|
87
|
+
};
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as Context from "effect/Context";
|
|
2
|
+
import type * as ManagedRuntime from "effect/ManagedRuntime";
|
|
3
|
+
import { type Readable } from "svelte/store";
|
|
4
|
+
/** A borrowed execution boundary. ManagedRuntime implements this contract. */
|
|
5
|
+
export type Runtime<R, ER = never> = Pick<ManagedRuntime.ManagedRuntime<R, ER>, "runFork" | "runPromise" | "runPromiseExit" | "runSync" | "contextEffect">;
|
|
6
|
+
export type RuntimeSource<R, ER = never> = Runtime<R, ER> | Readable<Runtime<R, ER>>;
|
|
7
|
+
export declare function asReadable<A>(value: A | Readable<A>): Readable<A>;
|
|
8
|
+
/** Carries an existing Effect context into Svelte without acquiring a Layer. */
|
|
9
|
+
export declare function fromContext<R>(services: Context.Context<R>): Runtime<R>;
|
|
10
|
+
/** Produces a native Svelte mount/render context map. */
|
|
11
|
+
export declare function runtimeContext<R, ER>(runtime: RuntimeSource<R, ER>): Map<unknown, unknown>;
|
|
12
|
+
/** Call during component initialization; the caller retains runtime ownership. */
|
|
13
|
+
export declare function provideRuntime<R, ER>(runtime: RuntimeSource<R, ER>): Readable<Runtime<R, ER>>;
|
|
14
|
+
/** Optional lookup used by framework adapters during component initialization. */
|
|
15
|
+
export declare function getRuntime<R = never, ER = never>(): Readable<Runtime<R, ER>> | undefined;
|
|
16
|
+
/** Reads the closest runtime provider. Its store follows runtime replacements. */
|
|
17
|
+
export declare function useRuntime<R = never, ER = never>(): Readable<Runtime<R, ER>>;
|
|
18
|
+
/** Shadows services while keeping the parent's remaining services and lifetime. */
|
|
19
|
+
export declare function withServices<R, ER, R2>(runtime: Runtime<R, ER>, services: Context.Context<R2>): Runtime<R | R2, ER>;
|
|
20
|
+
/** Provides reactive service overrides to this component's descendants. */
|
|
21
|
+
export declare function provideServices<R2, R = never, ER = never>(services: Context.Context<R2> | Readable<Context.Context<R2>>, runtime?: RuntimeSource<R, ER>): Readable<Runtime<R | R2, ER>>;
|
|
22
|
+
//# sourceMappingURL=Runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Runtime.d.ts","sourceRoot":"","sources":["../src/Runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAE1C,OAAO,KAAK,KAAK,cAAc,MAAM,uBAAuB,CAAC;AAE7D,OAAO,EAAqB,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAEhE,8EAA8E;AAC9E,MAAM,MAAM,OAAO,CAAC,CAAC,EAAE,EAAE,GAAG,KAAK,IAAI,IAAI,CACvC,cAAc,CAAC,cAAc,CAAC,CAAC,EAAE,EAAE,CAAC,EACpC,SAAS,GAAG,YAAY,GAAG,gBAAgB,GAAG,SAAS,GAAG,eAAe,CAC1E,CAAC;AAEF,MAAM,MAAM,aAAa,CAAC,CAAC,EAAE,EAAE,GAAG,KAAK,IAAI,OAAO,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAIrF,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAIjE;AAED,gFAAgF;AAChF,wBAAgB,WAAW,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAQvE;AAID,yDAAyD;AACzD,wBAAgB,cAAc,CAAC,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAE1F;AAED,kFAAkF;AAClF,wBAAgB,cAAc,CAAC,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAE7F;AAED,kFAAkF;AAClF,wBAAgB,UAAU,CAAC,CAAC,GAAG,KAAK,EAAE,EAAE,GAAG,KAAK,KAAK,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,SAAS,CAExF;AAED,kFAAkF;AAClF,wBAAgB,UAAU,CAAC,CAAC,GAAG,KAAK,EAAE,EAAE,GAAG,KAAK,KAAK,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAI5E;AAED,mFAAmF;AACnF,wBAAgB,YAAY,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EACpC,OAAO,EAAE,OAAO,CAAC,CAAC,EAAE,EAAE,CAAC,EACvB,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,GAC5B,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,EAAE,CAAC,CAUrB;AAED,2EAA2E;AAC3E,wBAAgB,eAAe,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,EAAE,EAAE,GAAG,KAAK,EACvD,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,EAC7D,OAAO,GAAE,aAAa,CAAC,CAAC,EAAE,EAAE,CAAuB,GAClD,QAAQ,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC,CAM/B"}
|
package/dist/Runtime.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as Context from "effect/Context";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import { getContext, setContext } from "svelte";
|
|
4
|
+
import { derived, readable } from "svelte/store";
|
|
5
|
+
const key = Symbol.for("@typed/svelte/Runtime");
|
|
6
|
+
export function asReadable(value) {
|
|
7
|
+
return value !== null && typeof value === "object" && "subscribe" in value
|
|
8
|
+
? value
|
|
9
|
+
: readable(value);
|
|
10
|
+
}
|
|
11
|
+
/** Carries an existing Effect context into Svelte without acquiring a Layer. */
|
|
12
|
+
export function fromContext(services) {
|
|
13
|
+
return {
|
|
14
|
+
contextEffect: Effect.succeed(services),
|
|
15
|
+
runFork: Effect.runForkWith(services),
|
|
16
|
+
runPromise: Effect.runPromiseWith(services),
|
|
17
|
+
runPromiseExit: Effect.runPromiseExitWith(services),
|
|
18
|
+
runSync: Effect.runSyncWith(services),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const fallbackRuntime = readable(fromContext(Context.empty()));
|
|
22
|
+
/** Produces a native Svelte mount/render context map. */
|
|
23
|
+
export function runtimeContext(runtime) {
|
|
24
|
+
return new Map([[key, asReadable(runtime)]]);
|
|
25
|
+
}
|
|
26
|
+
/** Call during component initialization; the caller retains runtime ownership. */
|
|
27
|
+
export function provideRuntime(runtime) {
|
|
28
|
+
return setContext(key, asReadable(runtime));
|
|
29
|
+
}
|
|
30
|
+
/** Optional lookup used by framework adapters during component initialization. */
|
|
31
|
+
export function getRuntime() {
|
|
32
|
+
return getContext(key);
|
|
33
|
+
}
|
|
34
|
+
/** Reads the closest runtime provider. Its store follows runtime replacements. */
|
|
35
|
+
export function useRuntime() {
|
|
36
|
+
// Context lookup is the boundary where a native component declares its
|
|
37
|
+
// required services. Absent application services fail through Effect normally.
|
|
38
|
+
return getRuntime() ?? fallbackRuntime;
|
|
39
|
+
}
|
|
40
|
+
/** Shadows services while keeping the parent's remaining services and lifetime. */
|
|
41
|
+
export function withServices(runtime, services) {
|
|
42
|
+
return {
|
|
43
|
+
contextEffect: Effect.map(runtime.contextEffect, (parent) => Context.merge(parent, services)),
|
|
44
|
+
runFork: (effect, options) => runtime.runFork(Effect.provideContext(effect, services), options),
|
|
45
|
+
runPromise: (effect, options) => runtime.runPromise(Effect.provideContext(effect, services), options),
|
|
46
|
+
runPromiseExit: (effect, options) => runtime.runPromiseExit(Effect.provideContext(effect, services), options),
|
|
47
|
+
runSync: (effect) => runtime.runSync(Effect.provideContext(effect, services)),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/** Provides reactive service overrides to this component's descendants. */
|
|
51
|
+
export function provideServices(services, runtime = useRuntime()) {
|
|
52
|
+
return provideRuntime(derived([asReadable(runtime), asReadable(services)], ([parent, context]) => withServices(parent, context)));
|
|
53
|
+
}
|
package/dist/Source.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Stream from "effect/Stream";
|
|
3
|
+
import * as Fx from "@typed/fx/Fx";
|
|
4
|
+
export type Source<A, E = never, R = never> = A | Effect.Effect<A, E, R> | Stream.Stream<A, E, R> | Fx.Fx<A, E, R>;
|
|
5
|
+
export declare function toFx<A, E, R>(source: Source<A, E, R>): Fx.Fx<A, E, R>;
|
|
6
|
+
//# sourceMappingURL=Source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Source.d.ts","sourceRoot":"","sources":["../src/Source.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,EAAE,MAAM,cAAc,CAAC;AAEnC,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,KAAK,IACtC,CAAC,GACD,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GACtB,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GACtB,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAEnB,wBAAgB,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAKrE"}
|
package/dist/Source.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Stream from "effect/Stream";
|
|
3
|
+
import * as Fx from "@typed/fx/Fx";
|
|
4
|
+
export function toFx(source) {
|
|
5
|
+
if (Fx.isFx(source))
|
|
6
|
+
return source;
|
|
7
|
+
if (Effect.isEffect(source))
|
|
8
|
+
return Fx.fromEffect(source);
|
|
9
|
+
if (Stream.isStream(source))
|
|
10
|
+
return Fx.fromStream(source);
|
|
11
|
+
return Fx.succeed(source);
|
|
12
|
+
}
|
package/dist/Store.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Fx from "@typed/fx/Fx";
|
|
3
|
+
import * as RefSubject from "@typed/fx/RefSubject";
|
|
4
|
+
import type { Readable } from "svelte/store";
|
|
5
|
+
/**
|
|
6
|
+
* Exposes a non-failing Fx as a Svelte readable store. Its subscription belongs
|
|
7
|
+
* to the current Effect Scope. Svelte stores have no error channel; handle
|
|
8
|
+
* failures in the Fx before converting, or use the AsyncData integration.
|
|
9
|
+
*/
|
|
10
|
+
export declare const toReadable: <A, R>(source: Fx.Fx<A, never, R>, initial: A) => Effect.Effect<{
|
|
11
|
+
subscribe: (this: void, run: import("svelte/store").Subscriber<A>, invalidate?: () => void) => import("svelte/store").Unsubscriber;
|
|
12
|
+
}, never, R | import("effect/Scope").Scope>;
|
|
13
|
+
/** Converts a Svelte readable into an Fx, unsubscribing on interruption. */
|
|
14
|
+
export declare function fromReadable<A>(store: Readable<A>): Fx.Fx<A>;
|
|
15
|
+
/**
|
|
16
|
+
* Exposes a non-failing RefSubject as a writable Svelte store. Writes are
|
|
17
|
+
* synchronous for Svelte subscribers and applied to the RefSubject in the
|
|
18
|
+
* captured Effect context. Both observation and writes belong to the current
|
|
19
|
+
* Scope. After it closes, set/update are inert.
|
|
20
|
+
*/
|
|
21
|
+
export declare const toWritable: <A, R>(ref: RefSubject.RefSubject<A, never, R>) => Effect.Effect<{
|
|
22
|
+
subscribe: (this: void, run: import("svelte/store").Subscriber<A>, invalidate?: () => void) => import("svelte/store").Unsubscriber;
|
|
23
|
+
set: (value: A) => void;
|
|
24
|
+
update: (f: (value: A) => A) => void;
|
|
25
|
+
}, never, R | import("effect/Scope").Scope>;
|
|
26
|
+
//# sourceMappingURL=Store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Store.d.ts","sourceRoot":"","sources":["../src/Store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,KAAK,UAAU,MAAM,sBAAsB,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG7C;;;;GAIG;AACH,eAAO,MAAM,UAAU,GAAwB,CAAC,EAAE,CAAC;;2CAKjD,CAAC;AAEH,4EAA4E;AAC5E,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAK5D;AAED;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAwB,CAAC,EAAE,CAAC;;iBAoB7B,CAAC,KAAG,IAAI;gBAWd,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC;2CAI7B,CAAC"}
|
package/dist/Store.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Fiber from "effect/Fiber";
|
|
3
|
+
import * as Fx from "@typed/fx/Fx";
|
|
4
|
+
import * as RefSubject from "@typed/fx/RefSubject";
|
|
5
|
+
import { writable } from "svelte/store";
|
|
6
|
+
/**
|
|
7
|
+
* Exposes a non-failing Fx as a Svelte readable store. Its subscription belongs
|
|
8
|
+
* to the current Effect Scope. Svelte stores have no error channel; handle
|
|
9
|
+
* failures in the Fx before converting, or use the AsyncData integration.
|
|
10
|
+
*/
|
|
11
|
+
export const toReadable = Effect.fn(function* (source, initial) {
|
|
12
|
+
const store = writable(initial);
|
|
13
|
+
yield* Fx.observe(source, store.set).pipe(Effect.forkScoped);
|
|
14
|
+
return { subscribe: store.subscribe };
|
|
15
|
+
});
|
|
16
|
+
/** Converts a Svelte readable into an Fx, unsubscribing on interruption. */
|
|
17
|
+
export function fromReadable(store) {
|
|
18
|
+
return Fx.callback((emit) => {
|
|
19
|
+
const unsubscribe = store.subscribe((value) => emit.succeed(value));
|
|
20
|
+
return Effect.sync(unsubscribe);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Exposes a non-failing RefSubject as a writable Svelte store. Writes are
|
|
25
|
+
* synchronous for Svelte subscribers and applied to the RefSubject in the
|
|
26
|
+
* captured Effect context. Both observation and writes belong to the current
|
|
27
|
+
* Scope. After it closes, set/update are inert.
|
|
28
|
+
*/
|
|
29
|
+
export const toWritable = Effect.fn(function* (ref) {
|
|
30
|
+
let current = yield* ref;
|
|
31
|
+
let closed = false;
|
|
32
|
+
const store = writable(current);
|
|
33
|
+
const services = yield* Effect.context();
|
|
34
|
+
const scope = yield* Effect.scope;
|
|
35
|
+
const runFork = Effect.runForkWith(services);
|
|
36
|
+
yield* Effect.addFinalizer(() => Effect.sync(() => {
|
|
37
|
+
closed = true;
|
|
38
|
+
}));
|
|
39
|
+
yield* Fx.observe(ref, (value) => {
|
|
40
|
+
current = value;
|
|
41
|
+
store.set(value);
|
|
42
|
+
}).pipe(Effect.forkScoped);
|
|
43
|
+
const set = (value) => {
|
|
44
|
+
if (closed)
|
|
45
|
+
return;
|
|
46
|
+
current = value;
|
|
47
|
+
store.set(value);
|
|
48
|
+
runFork(RefSubject.set(ref, value), { onFiberStart: Fiber.runIn(scope) });
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
subscribe: store.subscribe,
|
|
52
|
+
set,
|
|
53
|
+
update: (f) => {
|
|
54
|
+
if (!closed)
|
|
55
|
+
set(f(current));
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import 'svelte/internal/disclose-version';
|
|
2
|
+
import 'svelte/internal/flags/async';
|
|
3
|
+
import * as $ from 'svelte/internal/client';
|
|
4
|
+
import { attachment } from "./Attachment.js";
|
|
5
|
+
import { useRuntime } from "./Runtime.js";
|
|
6
|
+
import { renderSnapshot } from "./internal/RenderSnapshot.client.js";
|
|
7
|
+
import { rootEvents } from "@typed/template/RootEvents";
|
|
8
|
+
import { Cause, Exit, Layer } from "effect";
|
|
9
|
+
|
|
10
|
+
var root_1 = $.from_html(`<div style="display: contents"><!></div>`);
|
|
11
|
+
|
|
12
|
+
export default function Typed($$anchor, $$props) {
|
|
13
|
+
const componentId = $.props_id();
|
|
14
|
+
|
|
15
|
+
$.push($$props, true);
|
|
16
|
+
|
|
17
|
+
const $inherited = () => $.store_get(inherited, '$inherited', $$stores);
|
|
18
|
+
const [$$stores, $$cleanup] = $.setup_stores();
|
|
19
|
+
const inherited = useRuntime();
|
|
20
|
+
|
|
21
|
+
// $inherited subscribes to the runtime store and follows provider replacements.
|
|
22
|
+
const selectedRuntime = $.derived(() => $$props.runtime ?? $inherited());
|
|
23
|
+
|
|
24
|
+
const report = (root, cause) => {
|
|
25
|
+
if ($$props.onError) $$props.onError(cause); else root.dispatchEvent(new CustomEvent("typed:error", { detail: cause }));
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const render = $.derived(() => {
|
|
29
|
+
const selected = $.get(selectedRuntime);
|
|
30
|
+
const current = $$props.view;
|
|
31
|
+
|
|
32
|
+
return (root) => attachment(selected, current, {
|
|
33
|
+
stopPropagation: false,
|
|
34
|
+
onError: (cause) => report(root, cause),
|
|
35
|
+
onReady: () => $$props.onReady?.()
|
|
36
|
+
})(root);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const events = $.derived(() => {
|
|
40
|
+
const selected = $.get(selectedRuntime);
|
|
41
|
+
const policy = $$props.stopPropagation;
|
|
42
|
+
|
|
43
|
+
return (root) => {
|
|
44
|
+
const fiber = selected.runFork(rootEvents(root, policy).pipe(Layer.effectDiscard, Layer.launch));
|
|
45
|
+
|
|
46
|
+
fiber.addObserver((exit) => {
|
|
47
|
+
if (Exit.isFailure(exit) && !Cause.hasInterruptsOnly(exit.cause)) report(root, exit.cause);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
return () => fiber.interruptUnsafe();
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
var // The host separates Typed's output from the surrounding Svelte component.
|
|
55
|
+
// Keep the server snapshot fixed; subsequent updates belong to Typed.
|
|
56
|
+
// svelte-ignore state_referenced_locally
|
|
57
|
+
initialHtml;
|
|
58
|
+
|
|
59
|
+
var $$promises = $.run([
|
|
60
|
+
async () => initialHtml = await renderSnapshot($.get(selectedRuntime), $$props.view)
|
|
61
|
+
]);
|
|
62
|
+
|
|
63
|
+
var div = root_1();
|
|
64
|
+
var node = $.child(div);
|
|
65
|
+
|
|
66
|
+
$.async(node, [$$promises[0]], void 0, (node) => {
|
|
67
|
+
$.html(node, () => initialHtml);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
$.reset(div);
|
|
71
|
+
$.attach(div, () => $.get(render));
|
|
72
|
+
$.attach(div, () => $.get(events));
|
|
73
|
+
$.template_effect(() => $.set_attribute(div, 'id', $$props.id ?? componentId));
|
|
74
|
+
$.append($$anchor, div);
|
|
75
|
+
$.pop();
|
|
76
|
+
$$cleanup();
|
|
77
|
+
}
|
package/dist/Typed.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Renderable } from "@typed/template/Renderable";
|
|
2
|
+
import type { RenderTemplate } from "@typed/template/RenderTemplate";
|
|
3
|
+
import type { Runtime } from "./Runtime.js";
|
|
4
|
+
import type * as Scope from "effect/Scope";
|
|
5
|
+
import type { AttachmentOptions } from "./Attachment.js";
|
|
6
|
+
/** Props for the Svelte component that embeds a Typed renderable. */
|
|
7
|
+
export interface TypedProps<V extends Renderable.Any, ER = never> extends AttachmentOptions<Renderable.Error<V> | ER> {
|
|
8
|
+
readonly runtime?: Runtime<Exclude<Exclude<Renderable.Services<V>, RenderTemplate>, Scope.Scope>, ER>;
|
|
9
|
+
readonly view: V;
|
|
10
|
+
/** Optional host id; defaults to Svelte $props.id(), stable during SSR and hydration. */
|
|
11
|
+
readonly id?: string;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=Typed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Typed.d.ts","sourceRoot":"","sources":["../src/Typed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,qEAAqE;AACrE,MAAM,WAAW,UAAU,CAAC,CAAC,SAAS,UAAU,CAAC,GAAG,EAAE,EAAE,GAAG,KAAK,CAAE,SAAQ,iBAAiB,CACzF,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE,CACzB;IACC,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CACxB,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,cAAc,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,EACrE,EAAE,CACH,CAAC;IACF,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IAEjB,yFAAyF;IACzF,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;CACtB"}
|
package/dist/Typed.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import 'svelte/internal/flags/async';
|
|
2
|
+
import * as $ from 'svelte/internal/server';
|
|
3
|
+
import { attachment } from "./Attachment.js";
|
|
4
|
+
import { useRuntime } from "./Runtime.js";
|
|
5
|
+
import { renderSnapshot } from "./internal/RenderSnapshot.server.js";
|
|
6
|
+
import { rootEvents } from "@typed/template/RootEvents";
|
|
7
|
+
import { Cause, Exit, Layer } from "effect";
|
|
8
|
+
|
|
9
|
+
export default function Typed($$renderer, $$props) {
|
|
10
|
+
$$renderer.component(($$renderer) => {
|
|
11
|
+
const componentId = $.props_id($$renderer);
|
|
12
|
+
var $$store_subs;
|
|
13
|
+
let { runtime, view, id, onError, onReady, stopPropagation } = $$props;
|
|
14
|
+
const inherited = useRuntime();
|
|
15
|
+
|
|
16
|
+
// $inherited subscribes to the runtime store and follows provider replacements.
|
|
17
|
+
const selectedRuntime = $.derived(() => runtime ?? $.store_get($$store_subs ??= {}, '$inherited', inherited));
|
|
18
|
+
|
|
19
|
+
const report = (root, cause) => {
|
|
20
|
+
if (onError) onError(cause); else root.dispatchEvent(new CustomEvent("typed:error", { detail: cause }));
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const render = $.derived(() => {
|
|
24
|
+
const selected = selectedRuntime();
|
|
25
|
+
const current = view;
|
|
26
|
+
|
|
27
|
+
return (root) => attachment(selected, current, {
|
|
28
|
+
stopPropagation: false,
|
|
29
|
+
onError: (cause) => report(root, cause),
|
|
30
|
+
onReady: () => onReady?.()
|
|
31
|
+
})(root);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const events = $.derived(() => {
|
|
35
|
+
const selected = selectedRuntime();
|
|
36
|
+
const policy = stopPropagation;
|
|
37
|
+
|
|
38
|
+
return (root) => {
|
|
39
|
+
const fiber = selected.runFork(rootEvents(root, policy).pipe(Layer.effectDiscard, Layer.launch));
|
|
40
|
+
|
|
41
|
+
fiber.addObserver((exit) => {
|
|
42
|
+
if (Exit.isFailure(exit) && !Cause.hasInterruptsOnly(exit.cause)) report(root, exit.cause);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return () => fiber.interruptUnsafe();
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
var // The host separates Typed's output from the surrounding Svelte component.
|
|
50
|
+
// Keep the server snapshot fixed; subsequent updates belong to Typed.
|
|
51
|
+
// svelte-ignore state_referenced_locally
|
|
52
|
+
initialHtml;
|
|
53
|
+
|
|
54
|
+
var $$promises = $$renderer.run([
|
|
55
|
+
async () => initialHtml = await renderSnapshot(selectedRuntime(), view)
|
|
56
|
+
]);
|
|
57
|
+
|
|
58
|
+
$$renderer.push(`<div${$.attr('id', id ?? componentId)} style="display: contents">`);
|
|
59
|
+
|
|
60
|
+
$$renderer.async_block([$$promises[0]], ($$renderer) => {
|
|
61
|
+
$$renderer.push($.html(initialHtml));
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
$$renderer.push(`</div>`);
|
|
65
|
+
|
|
66
|
+
$$renderer.on_destroy(() => {
|
|
67
|
+
if ($$store_subs) $.unsubscribe_stores($$store_subs);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Component } from "svelte";
|
|
2
|
+
import type { Renderable } from "@typed/template/Renderable";
|
|
3
|
+
import type { TypedProps } from "./Typed.js";
|
|
4
|
+
/** A Svelte 5 component that server-renders and hydrates a Typed view. */
|
|
5
|
+
declare const Typed: <const V extends Renderable.Any, ER = never>(internals: Parameters<Component<TypedProps<V, ER>>>[0], props: TypedProps<V, ER>) => ReturnType<Component<TypedProps<V, ER>>>;
|
|
6
|
+
export default Typed;
|
|
7
|
+
//# sourceMappingURL=TypedComponent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypedComponent.d.ts","sourceRoot":"","sources":["../src/TypedComponent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,0EAA0E;AAC1E,OAAO,CAAC,MAAM,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,SAAS,UAAU,CAAC,GAAG,EAAE,EAAE,GAAG,KAAK,EAC9D,SAAS,EAAE,UAAU,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EACtD,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,KACrB,UAAU,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;eAC/B,KAAK"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default Typed;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { RootEventOptions } from "@typed/template/RootEvents";
|
|
2
|
+
/** Svelte mount, hydration and SSR options for one island. */
|
|
3
|
+
export interface ViewOptions {
|
|
4
|
+
/** Stable, nonempty host id, unique among islands in the rendered page. Use the same id on server and client. */
|
|
5
|
+
readonly id: string;
|
|
6
|
+
/** Per-event bubbling policy at the automatic host. Inherits CurrentRootEvents when omitted. */
|
|
7
|
+
readonly stopPropagation?: RootEventOptions;
|
|
8
|
+
readonly context?: Map<any, any>;
|
|
9
|
+
readonly idPrefix?: string;
|
|
10
|
+
readonly intro?: boolean;
|
|
11
|
+
readonly recover?: boolean;
|
|
12
|
+
readonly transformError?: (error: unknown) => unknown;
|
|
13
|
+
/** Receives Svelte's native head output when this island is server-rendered. */
|
|
14
|
+
readonly onHead?: (head: string) => void;
|
|
15
|
+
readonly outro?: boolean;
|
|
16
|
+
readonly csp?: {
|
|
17
|
+
readonly nonce?: string;
|
|
18
|
+
readonly hash?: boolean;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=ViewOptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ViewOptions.d.ts","sourceRoot":"","sources":["../src/ViewOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,8DAA8D;AAC9D,MAAM,WAAW,WAAW;IAC1B,iHAAiH;IACjH,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,gGAAgG;IAChG,QAAQ,CAAC,eAAe,CAAC,EAAE,gBAAgB,CAAC;IAC5C,QAAQ,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IACjC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;IACtD,gFAAgF;IAChF,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,GAAG,CAAC,EAAE;QACb,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;KACzB,CAAC;CACH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import 'svelte/internal/disclose-version';
|
|
2
|
+
import 'svelte/internal/flags/async';
|
|
3
|
+
import * as $ from 'svelte/internal/client';
|
|
4
|
+
|
|
5
|
+
export default function Bridge($$anchor, $$props) {
|
|
6
|
+
const $values = () => $.store_get($$props.values, '$values', $$stores);
|
|
7
|
+
const [$$stores, $$cleanup] = $.setup_stores();
|
|
8
|
+
var fragment = $.comment();
|
|
9
|
+
var node = $.first_child(fragment);
|
|
10
|
+
|
|
11
|
+
$.component(node, () => $$props.component, ($$anchor, Component_1) => {
|
|
12
|
+
Component_1($$anchor, $.spread_props($values));
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
$.append($$anchor, fragment);
|
|
16
|
+
$$cleanup();
|
|
17
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import 'svelte/internal/flags/async';
|
|
2
|
+
import * as $ from 'svelte/internal/server';
|
|
3
|
+
|
|
4
|
+
export default function Bridge($$renderer, $$props) {
|
|
5
|
+
var $$store_subs;
|
|
6
|
+
let { component: Component, values } = $$props;
|
|
7
|
+
|
|
8
|
+
if (Component) {
|
|
9
|
+
$$renderer.push('<!--[-->');
|
|
10
|
+
Component($$renderer, $.spread_props([$.store_get($$store_subs ??= {}, '$values', values)]));
|
|
11
|
+
$$renderer.push('<!--]-->');
|
|
12
|
+
} else {
|
|
13
|
+
$$renderer.push('<!--[!-->');
|
|
14
|
+
$$renderer.push('<!--]-->');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if ($$store_subs) $.unsubscribe_stores($$store_subs);
|
|
18
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as Deferred from "effect/Deferred";
|
|
2
|
+
import * as Layer from "effect/Layer";
|
|
3
|
+
import * as Fx from "@typed/fx/Fx";
|
|
4
|
+
import { type Component } from "svelte";
|
|
5
|
+
import type { ViewOptions } from "../ViewOptions.js";
|
|
6
|
+
export declare const mountComponent: <Props extends Record<string, any>, E, R>(element: HTMLElement, component: Component<Props, {}, string>, props: Fx.Fx<Props, E, R>, options: ViewOptions, ready: Deferred.Deferred<void, E>, hydrate: boolean) => Layer.Layer<never, E, Exclude<R, import("effect/Scope").Scope>>;
|
|
7
|
+
//# sourceMappingURL=Dom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Dom.d.ts","sourceRoot":"","sources":["../../src/internal/Dom.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAC;AAC5C,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAqD,KAAK,SAAS,EAAE,MAAM,QAAQ,CAAC;AAI3F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD,eAAO,MAAM,cAAc,GAAwB,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,yOAwDnE,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Deferred from "effect/Deferred";
|
|
3
|
+
import * as Layer from "effect/Layer";
|
|
4
|
+
import * as Fx from "@typed/fx/Fx";
|
|
5
|
+
import { hydrate as hydrateComponent, mount, tick, unmount } from "svelte";
|
|
6
|
+
import { writable } from "svelte/store";
|
|
7
|
+
import { rootEvents } from "@typed/template/RootEvents";
|
|
8
|
+
import { fromContext, runtimeContext } from "../Runtime.js";
|
|
9
|
+
import Bridge from "./Bridge.client.js";
|
|
10
|
+
export const mountComponent = Effect.fn(function* (element, component, props, options, ready, hydrate) {
|
|
11
|
+
yield* rootEvents(element, options.stopPropagation);
|
|
12
|
+
const services = yield* Effect.context();
|
|
13
|
+
const context = new Map([...runtimeContext(fromContext(services)), ...(options.context ?? [])]);
|
|
14
|
+
let instance;
|
|
15
|
+
let values;
|
|
16
|
+
const committed = yield* Deferred.make();
|
|
17
|
+
yield* Effect.addFinalizer(() => Effect.suspend(() => {
|
|
18
|
+
const mounted = instance;
|
|
19
|
+
return mounted === undefined
|
|
20
|
+
? Effect.void
|
|
21
|
+
: Effect.promise(() => unmount(mounted, { outro: options.outro }));
|
|
22
|
+
}));
|
|
23
|
+
const update = Effect.fn(function* (next) {
|
|
24
|
+
if (values !== undefined) {
|
|
25
|
+
const store = values;
|
|
26
|
+
yield* Deferred.await(committed);
|
|
27
|
+
return yield* Effect.sync(() => store.set(next));
|
|
28
|
+
}
|
|
29
|
+
values = writable(next);
|
|
30
|
+
const common = {
|
|
31
|
+
target: element,
|
|
32
|
+
props: { component, values },
|
|
33
|
+
context,
|
|
34
|
+
intro: options.intro,
|
|
35
|
+
transformError: options.transformError,
|
|
36
|
+
};
|
|
37
|
+
yield* Effect.sync(() => {
|
|
38
|
+
instance = hydrate
|
|
39
|
+
? hydrateComponent(Bridge, { ...common, recover: options.recover })
|
|
40
|
+
: mount(Bridge, common);
|
|
41
|
+
});
|
|
42
|
+
// Publication follows native Typed ref timing; Svelte schedules its own commit.
|
|
43
|
+
yield* Deferred.succeed(ready, undefined);
|
|
44
|
+
yield* Effect.promise(tick).pipe(Effect.onExit((exit) => Deferred.done(committed, exit)));
|
|
45
|
+
});
|
|
46
|
+
return yield* Fx.observe(props, update).pipe(Effect.andThen(Deferred.succeed(ready, undefined)));
|
|
47
|
+
}, Layer.effectDiscard);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Fx from "@typed/fx/Fx";
|
|
3
|
+
import { type Component } from "svelte";
|
|
4
|
+
import type { ViewOptions } from "../ViewOptions.js";
|
|
5
|
+
export declare const render: <Props extends Record<string, any>, E, R>(component: Component<Props, {}, string>, props: Fx.Fx<Props, E, R>, options: ViewOptions) => Effect.Effect<string, E, R>;
|
|
6
|
+
//# sourceMappingURL=Html.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Html.d.ts","sourceRoot":"","sources":["../../src/internal/Html.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,QAAQ,CAAC;AAGxC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGrD,eAAO,MAAM,MAAM,GAAwB,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,0HAwBhF,CAAC"}
|