@typed/svelte 1.0.0-beta.10
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/LICENSE +21 -0
- package/README.md +140 -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 +54 -0
- package/dist/Reactive.d.ts.map +1 -0
- package/dist/Reactive.js +180 -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 +44 -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 +12 -0
- package/dist/view.d.ts.map +1 -0
- package/dist/view.js +59 -0
- package/package.json +100 -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 @@
|
|
|
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,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,12 @@
|
|
|
1
|
+
import type { RandomValues } from "@typed/id/RandomValues";
|
|
2
|
+
import * as Scope from "effect/Scope";
|
|
3
|
+
import * as Fx from "@typed/fx/Fx";
|
|
4
|
+
import { type RenderEvent } from "@typed/template/RenderEvent";
|
|
5
|
+
import { type RenderTemplate } from "@typed/template/RenderTemplate";
|
|
6
|
+
import type { Component } from "svelte";
|
|
7
|
+
import { type Source } from "./Source.js";
|
|
8
|
+
import type { ViewOptions } from "./ViewOptions.js";
|
|
9
|
+
export type { ViewOptions } from "./ViewOptions.js";
|
|
10
|
+
/** A native Typed template that mounts or serializes a Svelte component. */
|
|
11
|
+
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 | RandomValues>;
|
|
12
|
+
//# sourceMappingURL=view.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../src/view.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAO3D,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAIL,KAAK,WAAW,EACjB,MAAM,6BAA6B,CAAC;AAGrC,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,GAAE,WAAgB,GACxB,EAAE,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,KAAK,GAAG,cAAc,GAAG,YAAY,CAAC,CAqExE"}
|
package/dist/view.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
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 { rootIdentity } from "@typed/template/RootIdentity";
|
|
11
|
+
import { HydrateContext } from "@typed/template/HydrateContext";
|
|
12
|
+
import { html } from "@typed/template/RenderTemplate";
|
|
13
|
+
import { toFx } from "./Source.js";
|
|
14
|
+
/** A native Typed template that mounts or serializes a Svelte component. */
|
|
15
|
+
export function view(component, props, options = {}) {
|
|
16
|
+
return Fx.gen(function* () {
|
|
17
|
+
const identity = yield* rootIdentity(options.id);
|
|
18
|
+
const source = toFx(props);
|
|
19
|
+
const scope = yield* Scope.fork(yield* Effect.scope);
|
|
20
|
+
const ready = yield* Deferred.make();
|
|
21
|
+
let published = false;
|
|
22
|
+
let target;
|
|
23
|
+
const ref = (element) => {
|
|
24
|
+
target = element;
|
|
25
|
+
};
|
|
26
|
+
const content = Fx.gen(function* () {
|
|
27
|
+
const settings = { ...options, id: yield* identity.id };
|
|
28
|
+
if (target === undefined) {
|
|
29
|
+
const { render } = yield* Effect.promise(() => import("./internal/Html.js"));
|
|
30
|
+
return Fx.fromEffect(render(component, source, settings)).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, settings, ready, hydrate))), Effect.onExit((exit) => Deferred.done(ready, exit)));
|
|
41
|
+
return Fx.fromEffect(mount).pipe(Fx.prepend(DomRenderEvent([])));
|
|
42
|
+
});
|
|
43
|
+
return html `<div
|
|
44
|
+
...${{ ref: identity.ref }}
|
|
45
|
+
id=${identity.id}
|
|
46
|
+
style="display: contents"
|
|
47
|
+
ref=${ref}
|
|
48
|
+
>
|
|
49
|
+
${content}
|
|
50
|
+
</div>`.pipe(Fx.provideService(Scope.Scope, scope), Fx.concatMap((event) => isDomRenderEvent(event)
|
|
51
|
+
? Fx.fromEffect(Deferred.await(ready)).pipe(Fx.map(() => {
|
|
52
|
+
published = true;
|
|
53
|
+
return event;
|
|
54
|
+
}))
|
|
55
|
+
: Fx.succeed(event)), Fx.onExit((exit) => published && (Exit.isSuccess(exit) || Cause.hasInterruptsOnly(exit.cause))
|
|
56
|
+
? Effect.void
|
|
57
|
+
: Scope.close(scope, exit)), Fx.catchCause((cause) => Cause.hasInterruptsOnly(cause) ? Fx.fromEffect(Effect.interrupt) : Fx.failCause(cause)));
|
|
58
|
+
});
|
|
59
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@typed/svelte",
|
|
3
|
+
"version": "1.0.0-beta.10",
|
|
4
|
+
"description": "Bidirectional Svelte integration for Typed templates.",
|
|
5
|
+
"homepage": "https://github.com/TylorS/typed/tree/development/packages/svelte#readme",
|
|
6
|
+
"bugs": "https://github.com/TylorS/typed/issues",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/TylorS/typed.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.10",
|
|
70
|
+
"@typed/fx": "2.0.0-beta.10",
|
|
71
|
+
"@typed/id": "1.0.0-beta.10",
|
|
72
|
+
"@typed/navigation": "1.0.0-beta.10",
|
|
73
|
+
"@typed/router": "1.0.0-beta.10",
|
|
74
|
+
"@typed/template": "1.0.0-beta.10",
|
|
75
|
+
"effect": "4.0.0-rc.112"
|
|
76
|
+
},
|
|
77
|
+
"devDependencies": {
|
|
78
|
+
"@sveltejs/vite-plugin-svelte": "7.3.0",
|
|
79
|
+
"@typescript/native": "npm:typescript@7.0.2",
|
|
80
|
+
"@vitest/browser-playwright": "5.0.0",
|
|
81
|
+
"playwright": "^1.63.0",
|
|
82
|
+
"svelte": "5.57.0",
|
|
83
|
+
"svelte-check": "4.7.6",
|
|
84
|
+
"typescript": "npm:@typescript/typescript6@6.0.2",
|
|
85
|
+
"vite": "8.2.2",
|
|
86
|
+
"vitest": "5.0.0"
|
|
87
|
+
},
|
|
88
|
+
"peerDependencies": {
|
|
89
|
+
"svelte": "^5.57.0"
|
|
90
|
+
},
|
|
91
|
+
"scripts": {
|
|
92
|
+
"build": "rm -rf dist tsconfig.tsbuildinfo && tsc && pnpm run build:components",
|
|
93
|
+
"test": "pnpm run build && pnpm run test:node && pnpm run test:browser && pnpm run test:types",
|
|
94
|
+
"test:node": "vitest run --config vitest.config.ts",
|
|
95
|
+
"test:browser": "vitest run --config vitest.browser.config.ts",
|
|
96
|
+
"test:types": "tsc -p tsconfig.type-tests.json && pnpm run check:svelte",
|
|
97
|
+
"check:svelte": "rm -rf .svelte-check && svelte-check --tsgo --tsconfig tsconfig.tests.json --fail-on-warnings",
|
|
98
|
+
"build:components": "pnpm run check:svelte && node build.mjs"
|
|
99
|
+
}
|
|
100
|
+
}
|