@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.
Files changed (54) hide show
  1. package/README.md +130 -0
  2. package/dist/AsyncData.d.ts +23 -0
  3. package/dist/AsyncData.d.ts.map +1 -0
  4. package/dist/AsyncData.js +28 -0
  5. package/dist/Attachment.d.ts +16 -0
  6. package/dist/Attachment.d.ts.map +1 -0
  7. package/dist/Attachment.js +56 -0
  8. package/dist/Reactive.d.ts +44 -0
  9. package/dist/Reactive.d.ts.map +1 -0
  10. package/dist/Reactive.js +184 -0
  11. package/dist/Router.d.ts +100 -0
  12. package/dist/Router.d.ts.map +1 -0
  13. package/dist/Router.js +89 -0
  14. package/dist/Runtime.d.ts +22 -0
  15. package/dist/Runtime.d.ts.map +1 -0
  16. package/dist/Runtime.js +53 -0
  17. package/dist/Source.d.ts +6 -0
  18. package/dist/Source.d.ts.map +1 -0
  19. package/dist/Source.js +12 -0
  20. package/dist/Store.d.ts +26 -0
  21. package/dist/Store.d.ts.map +1 -0
  22. package/dist/Store.js +58 -0
  23. package/dist/Typed.client.js +77 -0
  24. package/dist/Typed.d.ts +13 -0
  25. package/dist/Typed.d.ts.map +1 -0
  26. package/dist/Typed.js +1 -0
  27. package/dist/Typed.server.js +70 -0
  28. package/dist/TypedComponent.d.ts +7 -0
  29. package/dist/TypedComponent.d.ts.map +1 -0
  30. package/dist/TypedComponent.js +1 -0
  31. package/dist/ViewOptions.d.ts +21 -0
  32. package/dist/ViewOptions.d.ts.map +1 -0
  33. package/dist/ViewOptions.js +1 -0
  34. package/dist/index.d.ts +8 -0
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +7 -0
  37. package/dist/internal/Bridge.client.js +17 -0
  38. package/dist/internal/Bridge.server.js +18 -0
  39. package/dist/internal/Dom.d.ts +7 -0
  40. package/dist/internal/Dom.d.ts.map +1 -0
  41. package/dist/internal/Dom.js +47 -0
  42. package/dist/internal/Html.d.ts +6 -0
  43. package/dist/internal/Html.d.ts.map +1 -0
  44. package/dist/internal/Html.js +25 -0
  45. package/dist/internal/RenderSnapshot.client.d.ts +3 -0
  46. package/dist/internal/RenderSnapshot.client.d.ts.map +1 -0
  47. package/dist/internal/RenderSnapshot.client.js +4 -0
  48. package/dist/internal/RenderSnapshot.server.d.ts +7 -0
  49. package/dist/internal/RenderSnapshot.server.d.ts.map +1 -0
  50. package/dist/internal/RenderSnapshot.server.js +8 -0
  51. package/dist/view.d.ts +11 -0
  52. package/dist/view.d.ts.map +1 -0
  53. package/dist/view.js +52 -0
  54. package/package.json +99 -0
@@ -0,0 +1,25 @@
1
+ import * as Effect from "effect/Effect";
2
+ import * as Option from "effect/Option";
3
+ import * as Fx from "@typed/fx/Fx";
4
+ import { readable } from "svelte/store";
5
+ import { fromContext, runtimeContext } from "../Runtime.js";
6
+ import Bridge from "./Bridge.server.js";
7
+ export const render = Effect.fn(function* (component, props, options) {
8
+ const initial = yield* Fx.first(props);
9
+ if (Option.isNone(initial))
10
+ return "";
11
+ const services = yield* Effect.context();
12
+ const output = yield* Effect.promise(async () => {
13
+ const { render } = await import("svelte/server");
14
+ const values = readable(initial.value);
15
+ return await render(Bridge, {
16
+ props: { component, values },
17
+ context: new Map([...runtimeContext(fromContext(services)), ...(options.context ?? [])]),
18
+ idPrefix: options.idPrefix ?? options.id,
19
+ csp: options.csp,
20
+ transformError: options.transformError,
21
+ });
22
+ });
23
+ options.onHead?.(output.head);
24
+ return output.body;
25
+ });
@@ -0,0 +1,3 @@
1
+ /** Svelte's opaque HTML hydration retains server nodes; CSR starts empty. */
2
+ export declare function renderSnapshot(..._args: ReadonlyArray<unknown>): string;
3
+ //# sourceMappingURL=RenderSnapshot.client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RenderSnapshot.client.d.ts","sourceRoot":"","sources":["../../src/internal/RenderSnapshot.client.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,wBAAgB,cAAc,CAAC,GAAG,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,GAAG,MAAM,CAEvE"}
@@ -0,0 +1,4 @@
1
+ /** Svelte's opaque HTML hydration retains server nodes; CSR starts empty. */
2
+ export function renderSnapshot(..._args) {
3
+ return "";
4
+ }
@@ -0,0 +1,7 @@
1
+ import type * as Scope from "effect/Scope";
2
+ import type { Renderable } from "@typed/template/Renderable";
3
+ import type { RenderTemplate } from "@typed/template/RenderTemplate";
4
+ import type { Runtime } from "../Runtime.js";
5
+ /** Runs within Svelte's native request render; only the observation scope closes. */
6
+ export declare function renderSnapshot<V extends Renderable.Any, ER>(runtime: Runtime<Exclude<Exclude<Renderable.Services<V>, RenderTemplate>, Scope.Scope>, ER>, view: V): Promise<string>;
7
+ //# sourceMappingURL=RenderSnapshot.server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RenderSnapshot.server.d.ts","sourceRoot":"","sources":["../../src/internal/RenderSnapshot.server.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAC;AAE3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAG7C,qFAAqF;AACrF,wBAAgB,cAAc,CAAC,CAAC,SAAS,UAAU,CAAC,GAAG,EAAE,EAAE,EACzD,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,cAAc,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,EAC3F,IAAI,EAAE,CAAC,GACN,OAAO,CAAC,MAAM,CAAC,CAIjB"}
@@ -0,0 +1,8 @@
1
+ import * as Effect from "effect/Effect";
2
+ import { HtmlRenderTemplate, renderToHtmlString } from "@typed/template/Html";
3
+ import { getAbortSignal } from "svelte";
4
+ /** Runs within Svelte's native request render; only the observation scope closes. */
5
+ export function renderSnapshot(runtime, view) {
6
+ const snapshot = renderToHtmlString(view).pipe(Effect.provide(HtmlRenderTemplate), Effect.scoped);
7
+ return runtime.runPromise(snapshot, { signal: getAbortSignal() });
8
+ }
package/dist/view.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import * as Scope from "effect/Scope";
2
+ import * as Fx from "@typed/fx/Fx";
3
+ import { type RenderEvent } from "@typed/template/RenderEvent";
4
+ import { type RenderTemplate } from "@typed/template/RenderTemplate";
5
+ import type { Component } from "svelte";
6
+ import { type Source } from "./Source.js";
7
+ import type { ViewOptions } from "./ViewOptions.js";
8
+ export type { ViewOptions } from "./ViewOptions.js";
9
+ /** A native Typed template that mounts or serializes a Svelte component. */
10
+ export declare function view<Props extends Record<string, any>, E = never, R = never>(component: Component<Props>, props: Source<NoInfer<Props>, E, R>, options: ViewOptions): Fx.Fx<RenderEvent, E, R | Scope.Scope | RenderTemplate>;
11
+ //# sourceMappingURL=view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../src/view.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAIL,KAAK,WAAW,EACjB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAQ,KAAK,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAQ,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,4EAA4E;AAC5E,wBAAgB,IAAI,CAAC,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,KAAK,EAC1E,SAAS,EAAE,SAAS,CAAC,KAAK,CAAC,EAC3B,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EACnC,OAAO,EAAE,WAAW,GACnB,EAAE,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,KAAK,GAAG,cAAc,CAAC,CAgEzD"}
package/dist/view.js ADDED
@@ -0,0 +1,52 @@
1
+ import * as Cause from "effect/Cause";
2
+ import * as Deferred from "effect/Deferred";
3
+ import * as Effect from "effect/Effect";
4
+ import * as Exit from "effect/Exit";
5
+ import * as Layer from "effect/Layer";
6
+ import * as Option from "effect/Option";
7
+ import * as Scope from "effect/Scope";
8
+ import * as Fx from "@typed/fx/Fx";
9
+ import { DomRenderEvent, HtmlRenderEvent, isDomRenderEvent, } from "@typed/template/RenderEvent";
10
+ import { HydrateContext } from "@typed/template/HydrateContext";
11
+ import { html } from "@typed/template/RenderTemplate";
12
+ import { toFx } from "./Source.js";
13
+ /** A native Typed template that mounts or serializes a Svelte component. */
14
+ export function view(component, props, options) {
15
+ return Fx.gen(function* () {
16
+ if (typeof options?.id !== "string" || options.id.trim() === "") {
17
+ throw new TypeError("Svelte view requires a nonempty id, unique within the rendered page");
18
+ }
19
+ const source = toFx(props);
20
+ const scope = yield* Scope.fork(yield* Effect.scope);
21
+ const ready = yield* Deferred.make();
22
+ let published = false;
23
+ let target;
24
+ const ref = (element) => {
25
+ target = element;
26
+ };
27
+ const content = Fx.gen(function* () {
28
+ if (target === undefined) {
29
+ const { render } = yield* Effect.promise(() => import("./internal/Html.js"));
30
+ return Fx.fromEffect(render(component, source, options)).pipe(Fx.map((html) => HtmlRenderEvent(html, true)));
31
+ }
32
+ const hydration = yield* Effect.serviceOption(HydrateContext);
33
+ const hydrate = Option.isSome(hydration) && hydration.value.where._tag === "hole";
34
+ if (hydrate) {
35
+ // Transfer the exact marker-owned range to Svelte, then publish one DOM event for the host.
36
+ hydration.value.where.startComment.remove();
37
+ hydration.value.where.endComment.remove();
38
+ }
39
+ const element = target;
40
+ const mount = Effect.promise(() => import("./internal/Dom.js")).pipe(Effect.flatMap(({ mountComponent }) => Layer.launch(mountComponent(element, component, source, options, ready, hydrate))), Effect.onExit((exit) => Deferred.done(ready, exit)));
41
+ return Fx.fromEffect(mount).pipe(Fx.prepend(DomRenderEvent([])));
42
+ });
43
+ return html `<div id=${options.id} style="display: contents" ref=${ref}>${content}</div>`.pipe(Fx.provideService(Scope.Scope, scope), Fx.concatMap((event) => isDomRenderEvent(event)
44
+ ? Fx.fromEffect(Deferred.await(ready)).pipe(Fx.map(() => {
45
+ published = true;
46
+ return event;
47
+ }))
48
+ : Fx.succeed(event)), Fx.onExit((exit) => published && (Exit.isSuccess(exit) || Cause.hasInterruptsOnly(exit.cause))
49
+ ? Effect.void
50
+ : Scope.close(scope, exit)), Fx.catchCause((cause) => Cause.hasInterruptsOnly(cause) ? Fx.fromEffect(Effect.interrupt) : Fx.failCause(cause)));
51
+ });
52
+ }
package/package.json ADDED
@@ -0,0 +1,99 @@
1
+ {
2
+ "name": "@typed/svelte",
3
+ "version": "1.0.0-beta.7",
4
+ "description": "Bidirectional Svelte integration for Typed templates.",
5
+ "homepage": "https://github.com/TylorS/typed-smol/tree/main/packages/svelte#readme",
6
+ "bugs": "https://github.com/TylorS/typed-smol/issues",
7
+ "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/TylorS/typed-smol.git",
11
+ "directory": "packages/svelte"
12
+ },
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "type": "module",
17
+ "sideEffects": false,
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js"
22
+ },
23
+ "./view": {
24
+ "types": "./dist/view.d.ts",
25
+ "import": "./dist/view.js"
26
+ },
27
+ "./Source": {
28
+ "types": "./dist/Source.d.ts",
29
+ "import": "./dist/Source.js"
30
+ },
31
+ "./Store": {
32
+ "types": "./dist/Store.d.ts",
33
+ "import": "./dist/Store.js"
34
+ },
35
+ "./Attachment": {
36
+ "types": "./dist/Attachment.d.ts",
37
+ "import": "./dist/Attachment.js"
38
+ },
39
+ "./Typed.svelte": {
40
+ "types": "./dist/TypedComponent.d.ts",
41
+ "browser": "./dist/Typed.client.js",
42
+ "default": "./dist/Typed.server.js"
43
+ },
44
+ "./Runtime": {
45
+ "types": "./dist/Runtime.d.ts",
46
+ "import": "./dist/Runtime.js"
47
+ },
48
+ "./Reactive": {
49
+ "types": "./dist/Reactive.d.ts",
50
+ "import": "./dist/Reactive.js"
51
+ },
52
+ "./AsyncData": {
53
+ "types": "./dist/AsyncData.d.ts",
54
+ "import": "./dist/AsyncData.js"
55
+ },
56
+ "./Router": {
57
+ "types": "./dist/Router.d.ts",
58
+ "import": "./dist/Router.js"
59
+ },
60
+ "./Typed": {
61
+ "types": "./dist/Typed.d.ts",
62
+ "import": "./dist/Typed.js"
63
+ }
64
+ },
65
+ "publishConfig": {
66
+ "access": "public"
67
+ },
68
+ "dependencies": {
69
+ "@typed/async-data": "1.0.0-beta.7",
70
+ "@typed/fx": "2.0.0-beta.7",
71
+ "@typed/navigation": "1.0.0-beta.7",
72
+ "@typed/router": "1.0.0-beta.7",
73
+ "@typed/template": "1.0.0-beta.7",
74
+ "effect": "4.0.0-rc.112"
75
+ },
76
+ "devDependencies": {
77
+ "@sveltejs/vite-plugin-svelte": "7.3.0",
78
+ "@typescript/native": "npm:typescript@7.0.2",
79
+ "@vitest/browser-playwright": "5.0.0",
80
+ "playwright": "^1.62.1",
81
+ "svelte": "5.57.0",
82
+ "svelte-check": "4.7.6",
83
+ "typescript": "npm:@typescript/typescript6@6.0.2",
84
+ "vite": "8.2.2",
85
+ "vitest": "5.0.0"
86
+ },
87
+ "peerDependencies": {
88
+ "svelte": "^5.57.0"
89
+ },
90
+ "scripts": {
91
+ "build": "rm -rf dist tsconfig.tsbuildinfo && tsc && pnpm run build:components",
92
+ "test": "pnpm run build && pnpm run test:node && pnpm run test:browser && pnpm run test:types",
93
+ "test:node": "vitest run --config vitest.config.ts",
94
+ "test:browser": "vitest run --config vitest.browser.config.ts",
95
+ "test:types": "tsc -p tsconfig.type-tests.json && pnpm run check:svelte",
96
+ "check:svelte": "rm -rf .svelte-check && svelte-check --tsgo --tsconfig tsconfig.tests.json --fail-on-warnings",
97
+ "build:components": "pnpm run check:svelte && node build.mjs"
98
+ }
99
+ }