@opsydyn/astro-foldkit 0.5.0 → 0.7.2
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/CHANGELOG.md +44 -2
- package/README.md +332 -29
- package/dist/build-id.d.mts +7 -0
- package/dist/build-id.mjs +8 -0
- package/dist/client.d.mts +24 -9
- package/dist/client.mjs +41 -16
- package/dist/define-app.d.mts +2 -2
- package/dist/define-page.d.mts +6 -0
- package/dist/define-page.mjs +10 -0
- package/dist/index.d.mts +7 -2
- package/dist/index.mjs +5 -2
- package/dist/server-public.d.mts +14 -0
- package/dist/server-public.mjs +16 -0
- package/dist/server-render.d.mts +8 -0
- package/dist/server-render.mjs +15 -0
- package/dist/server.d.mts +21 -3
- package/dist/server.mjs +35 -3
- package/dist/types-DDk3MMb7.d.mts +62 -0
- package/package.json +19 -4
- package/dist/types-BOU7iNnu.d.mts +0 -30
package/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,53 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## [0.
|
|
3
|
+
## [0.7.2](https://github.com/opsydyn/fold-kit-experiments/compare/astro-foldkit-v0.7.1...astro-foldkit-v0.7.2) (2026-10-05)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* support FoldKit 0.166.0 ([248636e](https://github.com/opsydyn/fold-kit-experiments/commit/248636efea03a2048432260da6261bb657a282dc))
|
|
9
|
+
|
|
10
|
+
## [0.7.1](https://github.com/opsydyn/fold-kit-experiments/compare/astro-foldkit-v0.7.0...astro-foldkit-v0.7.1) (2026-10-04)
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
- clear oxlint warnings ([4bd5016](https://github.com/opsydyn/fold-kit-experiments/commit/4bd5016f71dde9621bb5bbd6b587792f9585e6ea))
|
|
15
|
+
|
|
16
|
+
## [0.7.0](https://github.com/opsydyn/fold-kit-experiments/compare/astro-foldkit-v0.6.0...astro-foldkit-v0.7.0) (2026-09-20)
|
|
17
|
+
|
|
18
|
+
### Features
|
|
4
19
|
|
|
20
|
+
- **web:** add stateflow observatory ([b50446e](https://github.com/opsydyn/fold-kit-experiments/commit/b50446e11f2fad81d1b5799974dd1ab10b705f1f))
|
|
21
|
+
|
|
22
|
+
### Bug Fixes
|
|
23
|
+
|
|
24
|
+
- align Vite plugin with Effect rc.116 ([33682f8](https://github.com/opsydyn/fold-kit-experiments/commit/33682f8fda999ee82d963d5d6687aee56f08c413))
|
|
25
|
+
- satisfy Astro smoke lint contract ([f67f71e](https://github.com/opsydyn/fold-kit-experiments/commit/f67f71e4f7b2ce480ccce841c1dcd4ef3c81cdf7))
|
|
26
|
+
- **web:** complete stateflow SSR and replay interactions ([d71ad2a](https://github.com/opsydyn/fold-kit-experiments/commit/d71ad2aeaf5ad0f1a8ff4e86c77ba99d5da3368f))
|
|
27
|
+
|
|
28
|
+
## [0.6.0](https://github.com/opsydyn/fold-kit-experiments/compare/astro-foldkit-v0.5.0...astro-foldkit-v0.6.0) (2026-08-20)
|
|
29
|
+
|
|
30
|
+
### Features
|
|
31
|
+
|
|
32
|
+
- **astro-foldkit:** add server render handoff ([9773a4d](https://github.com/opsydyn/fold-kit-experiments/commit/9773a4d1883c53fa60957368a0125d3b57b7cd24))
|
|
33
|
+
- **astro-foldkit:** document opt-in server rendering ([53e9d00](https://github.com/opsydyn/fold-kit-experiments/commit/53e9d004c75c10245d0aa88fc4c412b96c7f2f4c))
|
|
34
|
+
- **astro-foldkit:** expose server document resolver ([969dc2f](https://github.com/opsydyn/fold-kit-experiments/commit/969dc2f7e4a679df8b04d60c57783d6b8fb84bd1))
|
|
35
|
+
- **astro-foldkit:** formalize define-page contract ([62863c5](https://github.com/opsydyn/fold-kit-experiments/commit/62863c58fa1462d2ecb04bd52cf3d5e0bb444601))
|
|
36
|
+
- **astro-foldkit:** hydrate page owners on client ([9f8f76b](https://github.com/opsydyn/fold-kit-experiments/commit/9f8f76bef77ea734006c1faa90defdfdd115d09d))
|
|
37
|
+
- support FoldKit 0.136 ([50f4134](https://github.com/opsydyn/fold-kit-experiments/commit/50f4134d7596926fed373408642816736907934f))
|
|
38
|
+
|
|
39
|
+
### Bug Fixes
|
|
40
|
+
|
|
41
|
+
- **astro-foldkit:** align server document tests ([f71c2c2](https://github.com/opsydyn/fold-kit-experiments/commit/f71c2c2ccea94f148e81126b00174375566fa5bb))
|
|
42
|
+
- **astro-foldkit:** keep define-page markers inert ([0fb4e54](https://github.com/opsydyn/fold-kit-experiments/commit/0fb4e54dbd3a0b53f21de57f27f3948e13fcf80b))
|
|
43
|
+
- **astro-foldkit:** pass stamped root to page hydration ([b3b3ba6](https://github.com/opsydyn/fold-kit-experiments/commit/b3b3ba65c4bb25bb9c2738f82d1148e5e6407679))
|
|
44
|
+
- **astro-foldkit:** reject empty server build id ([320bc39](https://github.com/opsydyn/fold-kit-experiments/commit/320bc39a9ca8d610fe60480c0c399a71fc029b51))
|
|
45
|
+
|
|
46
|
+
## [0.5.0](https://github.com/opsydyn/fold-kit-experiments/compare/astro-foldkit-v0.4.0...astro-foldkit-v0.5.0) (2026-07-18)
|
|
5
47
|
|
|
6
48
|
### Features
|
|
7
49
|
|
|
8
|
-
|
|
50
|
+
- **astro-foldkit:** add lazy app entry API ([9786bdd](https://github.com/opsydyn/fold-kit-experiments/commit/9786bdd226cfd2200b6e64d5b198a53a7aad6d13))
|
|
9
51
|
|
|
10
52
|
## [0.4.0](https://github.com/opsydyn/fold-kit-experiments/compare/astro-foldkit-v0.3.0...astro-foldkit-v0.4.0) (2026-07-18)
|
|
11
53
|
|
package/README.md
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
# @opsydyn/astro-foldkit
|
|
2
2
|
|
|
3
|
-
Astro integration and renderer for [FoldKit](https://foldkit.dev)
|
|
3
|
+
Astro integration and renderer for [FoldKit](https://foldkit.dev), with
|
|
4
|
+
client-only islands and an opt-in server-rendered page path.
|
|
4
5
|
|
|
5
6
|
FoldKit is an Elm Architecture runtime built on [Effect](https://effect.website). This package registers FoldKit as an Astro renderer so you can drop any FoldKit app into a `.astro` page as a component and hydrate it with `client:load`.
|
|
6
7
|
|
|
8
|
+
There are two deliberately separate entry paths:
|
|
9
|
+
|
|
10
|
+
- `lazyApp` / `defineApp` keeps the existing client-only island contract. Astro receives a deterministic mount shell and FoldKit starts in the browser.
|
|
11
|
+
- `definePage` opts one FoldKit application into SSG or request SSR. The server emits FoldKit HTML and public Flags, and `client:load` hydrates that exact DOM.
|
|
12
|
+
|
|
7
13
|
## Installation
|
|
8
14
|
|
|
9
15
|
```sh
|
|
@@ -14,9 +20,11 @@ npm install astro foldkit
|
|
|
14
20
|
|
|
15
21
|
## FoldKit compatibility
|
|
16
22
|
|
|
17
|
-
`@opsydyn/astro-foldkit`
|
|
18
|
-
|
|
19
|
-
|
|
23
|
+
`@opsydyn/astro-foldkit` is tested with FoldKit `0.165.x`, stable Effect
|
|
24
|
+
`4.0.0`, and the matching `@foldkit/vite-plugin` `0.26.x` line.
|
|
25
|
+
Applications can define interruptible work with
|
|
26
|
+
`Command.define(name, { interrupt: true, ... })` inside their own update loop;
|
|
27
|
+
this integration continues to own Astro rendering, hydration, and lifecycle
|
|
20
28
|
event delivery.
|
|
21
29
|
|
|
22
30
|
## Setup
|
|
@@ -28,10 +36,22 @@ import { defineConfig } from 'astro/config';
|
|
|
28
36
|
import foldkit from '@opsydyn/astro-foldkit';
|
|
29
37
|
|
|
30
38
|
export default defineConfig({
|
|
31
|
-
integrations: [
|
|
39
|
+
integrations: [
|
|
40
|
+
foldkit({
|
|
41
|
+
server: {
|
|
42
|
+
buildId: process.env.FOLDKIT_BUILD_ID ?? 'development',
|
|
43
|
+
},
|
|
44
|
+
}),
|
|
45
|
+
],
|
|
32
46
|
});
|
|
33
47
|
```
|
|
34
48
|
|
|
49
|
+
The build ID is an explicit server/client handoff identity. Use a stable
|
|
50
|
+
deployment-specific value in production and the same value in every process
|
|
51
|
+
that serves the build. The integration defaults to `development` for local
|
|
52
|
+
use, rejects a blank value, and fails a `definePage` render closed rather than
|
|
53
|
+
hydrating a mismatched document when no usable identity is available.
|
|
54
|
+
|
|
35
55
|
## Defining an app
|
|
36
56
|
|
|
37
57
|
Use `lazyApp` to register a FoldKit app for lazy loading. The literal loader keeps each Astro island as an explicit code-splitting boundary; it returns your `main.ts` module, which must export a value that satisfies `AppConfig`. `defineApp` remains available as a backwards-compatible alias.
|
|
@@ -45,12 +65,18 @@ export default lazyApp(() => import('./main'));
|
|
|
45
65
|
|
|
46
66
|
```ts
|
|
47
67
|
// src/apps/counter/main.ts
|
|
68
|
+
import type { Document, HtmlBuilder } from 'foldkit/html';
|
|
69
|
+
|
|
70
|
+
type Message = 'Inc' | 'Dec';
|
|
71
|
+
|
|
48
72
|
export const Model = null;
|
|
49
|
-
export const init = () =>
|
|
50
|
-
export const update = (model: number, message:
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
73
|
+
export const init = () => ({ model: 0 });
|
|
74
|
+
export const update = (model: number, message: Message) => ({
|
|
75
|
+
model: message === 'Inc' ? model + 1 : model - 1,
|
|
76
|
+
});
|
|
77
|
+
export const view = (model: number, h: HtmlBuilder<Message>): Document => ({
|
|
78
|
+
title: `Counter: ${model}`,
|
|
79
|
+
body: h.button([h.OnClick('Inc')], [String(model)]),
|
|
54
80
|
});
|
|
55
81
|
```
|
|
56
82
|
|
|
@@ -63,10 +89,161 @@ import Counter from '../apps/counter/app'
|
|
|
63
89
|
<Counter client:load />
|
|
64
90
|
```
|
|
65
91
|
|
|
66
|
-
|
|
92
|
+
For `lazyApp` / `defineApp`, the server renderer emits a deterministic
|
|
93
|
+
`<div data-foldkit-island="true"></div>` mount shell. It does not load or
|
|
94
|
+
execute the FoldKit application during SSR; the application is loaded and
|
|
95
|
+
embedded only by the client renderer. Astro still owns the outer island
|
|
96
|
+
serialisation and client directive behavior.
|
|
67
97
|
|
|
68
98
|
The demo app's [`/request-diagnostics`](../../apps/web/src/pages/request-diagnostics.astro) page shows the integration boundary with a practical machine-driven chart workflow. The page uses `@opsydyn/astro-foldkit` for hydration, `@opsydyn/foldkit-viz` for chart primitives, and `foldkit/experimental/machine` in the application update layer.
|
|
69
99
|
|
|
100
|
+
## Server-rendered pages (opt-in)
|
|
101
|
+
|
|
102
|
+
Use `definePage` when one FoldKit application owns the document content for an
|
|
103
|
+
Astro route. It is intentionally separate from `lazyApp`: existing apps and
|
|
104
|
+
charts remain client-only islands unless they are explicitly migrated.
|
|
105
|
+
|
|
106
|
+
The page loader has the same literal lazy-module shape as `lazyApp`, but its
|
|
107
|
+
Flags factory is synchronous and receives request facts from Astro:
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
// src/apps/greeting/page.ts
|
|
111
|
+
import { definePage } from '@opsydyn/astro-foldkit/define-page';
|
|
112
|
+
import { Match, Schema } from 'effect';
|
|
113
|
+
|
|
114
|
+
import { Flags, type Locale, type Name } from './model';
|
|
115
|
+
|
|
116
|
+
type Props = { readonly name: Name };
|
|
117
|
+
|
|
118
|
+
const localeFromUrl = (url: URL): Locale =>
|
|
119
|
+
Match.value(url.searchParams.get('locale')).pipe(
|
|
120
|
+
Match.when('ar', () => 'ar' as const),
|
|
121
|
+
Match.when('en', () => 'en' as const),
|
|
122
|
+
Match.orElse(() => 'en' as const),
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
export default definePage<Props, Flags>(() => import('./main'), {
|
|
126
|
+
flags: ({ props, url }) =>
|
|
127
|
+
Schema.decodeSync(Flags)({
|
|
128
|
+
name: props.name,
|
|
129
|
+
locale: localeFromUrl(url),
|
|
130
|
+
}),
|
|
131
|
+
});
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
The loaded `main` module exports the page configuration, including the runtime
|
|
135
|
+
`Flags` Schema/value used by FoldKit to validate the serialized handoff:
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
// src/apps/greeting/main.ts
|
|
139
|
+
import { Message } from './message';
|
|
140
|
+
import { Flags, init, Model } from './model';
|
|
141
|
+
import { update } from './update';
|
|
142
|
+
import { view } from './view';
|
|
143
|
+
|
|
144
|
+
export { Flags, init, Message, Model, update, view };
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
`Flags` must be public JSON-serializable data required to create the first
|
|
148
|
+
Model. The factory may derive it from `request`, `url`, `params`, and validated
|
|
149
|
+
component `props`, but it must not return secrets, credentials, request bodies,
|
|
150
|
+
or runtime objects. It must not run Commands, Subscriptions, remote loads, or
|
|
151
|
+
browser-only resources. Server rendering is a deterministic render handoff,
|
|
152
|
+
not a server data-loading abstraction.
|
|
153
|
+
|
|
154
|
+
### Request SSR
|
|
155
|
+
|
|
156
|
+
Resolve the same page document in the Astro frontmatter so its FoldKit metadata
|
|
157
|
+
can reach the outer layout. Keep the resolver import server-only:
|
|
158
|
+
|
|
159
|
+
```astro
|
|
160
|
+
---
|
|
161
|
+
export const prerender = false;
|
|
162
|
+
|
|
163
|
+
import { Schema } from 'effect';
|
|
164
|
+
import { resolvePageDocument } from '@opsydyn/astro-foldkit/server';
|
|
165
|
+
|
|
166
|
+
import GreetingPage from '../apps/greeting/page';
|
|
167
|
+
import { Name } from '../apps/greeting/model';
|
|
168
|
+
import Layout from '../layouts/Layout.astro';
|
|
169
|
+
|
|
170
|
+
const name = Schema.decodeSync(Name)(Astro.url.searchParams.get('name') ?? 'astronaut');
|
|
171
|
+
const document = await resolvePageDocument(GreetingPage, {
|
|
172
|
+
request: Astro.request,
|
|
173
|
+
url: Astro.url,
|
|
174
|
+
params: Astro.params,
|
|
175
|
+
props: { name },
|
|
176
|
+
});
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
<Layout
|
|
180
|
+
title={document.title}
|
|
181
|
+
lang={document.lang}
|
|
182
|
+
dir={document.dir}
|
|
183
|
+
canonical={document.canonical}
|
|
184
|
+
ogUrl={document.ogUrl}
|
|
185
|
+
>
|
|
186
|
+
<GreetingPage client:load name={name} />
|
|
187
|
+
</Layout>
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
The layout owns the outer `<html>` structure and applies `title`, `lang`,
|
|
191
|
+
`dir`, `canonical`, and `ogUrl` from the resolved FoldKit `Document`. The
|
|
192
|
+
`client:load` directive is still required for an interactive page: the server
|
|
193
|
+
HTML contains one stamped FoldKit root and the browser hydrates that exact root
|
|
194
|
+
with the serialized Flags payload.
|
|
195
|
+
|
|
196
|
+
### Canonical metadata
|
|
197
|
+
|
|
198
|
+
`definePage` does not infer a canonical URL from `Astro.url`, route parameters,
|
|
199
|
+
or the browser location. The page view must return `Document.canonical` when the
|
|
200
|
+
application has a canonical identity. Query parameters and alternate
|
|
201
|
+
representations remain application-owned. When FoldKit supplies the 0.165
|
|
202
|
+
canonical-to-`ogUrl` fallback, the resolver passes it through unchanged.
|
|
203
|
+
|
|
204
|
+
### SSG
|
|
205
|
+
|
|
206
|
+
The same page owner can be prerendered when its props and Flags are universal:
|
|
207
|
+
|
|
208
|
+
```astro
|
|
209
|
+
---
|
|
210
|
+
export const prerender = true;
|
|
211
|
+
|
|
212
|
+
import { Schema } from 'effect';
|
|
213
|
+
import { resolvePageDocument } from '@opsydyn/astro-foldkit/server';
|
|
214
|
+
|
|
215
|
+
import GreetingPage from '../apps/greeting/page';
|
|
216
|
+
import { Name } from '../apps/greeting/model';
|
|
217
|
+
import Layout from '../layouts/Layout.astro';
|
|
218
|
+
|
|
219
|
+
const name = Schema.decodeSync(Name)('static astronaut');
|
|
220
|
+
const document = await resolvePageDocument(GreetingPage, {
|
|
221
|
+
request: Astro.request,
|
|
222
|
+
url: Astro.url,
|
|
223
|
+
params: Astro.params,
|
|
224
|
+
props: { name },
|
|
225
|
+
});
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
<Layout
|
|
229
|
+
title={document.title}
|
|
230
|
+
lang={document.lang}
|
|
231
|
+
dir={document.dir}
|
|
232
|
+
canonical={document.canonical}
|
|
233
|
+
ogUrl={document.ogUrl}
|
|
234
|
+
>
|
|
235
|
+
<GreetingPage client:load name={name} />
|
|
236
|
+
</Layout>
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
An SSG error fails the build. A request-SSR error reaches Astro's error
|
|
240
|
+
response. The integration does not replace failed page rendering with the
|
|
241
|
+
client-only shell. A document may have only one `definePage` owner; use
|
|
242
|
+
`lazyApp` / `defineApp` for additional charts or embedded applications.
|
|
243
|
+
|
|
244
|
+
`noMeta` remains an island-only option for `defineApp`. It does not change the
|
|
245
|
+
page-owner metadata contract.
|
|
246
|
+
|
|
70
247
|
## Passing props
|
|
71
248
|
|
|
72
249
|
`lazyApp` accepts a type parameter for the props your FoldKit app expects. This makes the component callable with typed attributes in `.astro` files.
|
|
@@ -90,9 +267,9 @@ export type Name = typeof Name.Type;
|
|
|
90
267
|
|
|
91
268
|
const Props = Schema.Struct({ name: Name });
|
|
92
269
|
|
|
93
|
-
export const init = (props: unknown): readonly
|
|
270
|
+
export const init = (props: unknown): { readonly model: Model } => {
|
|
94
271
|
const { name } = Schema.decodeUnknownSync(Props)(props);
|
|
95
|
-
return
|
|
272
|
+
return { model: name };
|
|
96
273
|
};
|
|
97
274
|
```
|
|
98
275
|
|
|
@@ -123,10 +300,17 @@ Prevents the FoldKit program from overwriting `document.title`. Use this wheneve
|
|
|
123
300
|
<DashboardChart client:load noMeta data={chartData} />
|
|
124
301
|
```
|
|
125
302
|
|
|
126
|
-
Both `noMeta` and `noMeta={true}` are accepted. The
|
|
303
|
+
Both `noMeta` and `noMeta={true}` are accepted. The wrapper pins only the
|
|
304
|
+
Document `title`; FoldKit still applies `lang` and `dir` from the app's current
|
|
305
|
+
Document.
|
|
127
306
|
|
|
128
307
|
## Architecture
|
|
129
308
|
|
|
309
|
+
`definePage` owns one server-rendered FoldKit application for a document;
|
|
310
|
+
`lazyApp` / `defineApp` owns an independent client island. The integration does
|
|
311
|
+
not infer page ownership from ordinary app markers, and adding `definePage`
|
|
312
|
+
does not migrate existing chart routes.
|
|
313
|
+
|
|
130
314
|
### Imperative shell, functional core
|
|
131
315
|
|
|
132
316
|
The Astro page is the **imperative shell**: it performs side effects (HTTP fetches, query-param reads, URL parsing) and validates raw values into branded types via `Schema.decodeSync`. The shell hands only clean, typed values into the component.
|
|
@@ -166,19 +350,25 @@ The double-decode is intentional: `Schema.decodeSync` at the Astro boundary ensu
|
|
|
166
350
|
|
|
167
351
|
The module returned by your loader must export:
|
|
168
352
|
|
|
169
|
-
| Export | Type
|
|
170
|
-
| :------- |
|
|
171
|
-
| `Model` | `unknown`
|
|
172
|
-
| `init` | `(props: unknown) =>
|
|
173
|
-
| `update` | `(model, message) =>
|
|
174
|
-
| `view` | `(model) => Document`
|
|
353
|
+
| Export | Type | Description |
|
|
354
|
+
| :------- | :------------------------------------------------------------------------ | :-------------------------------------------- |
|
|
355
|
+
| `Model` | `unknown` | Initial model type marker |
|
|
356
|
+
| `init` | `(props: unknown) => { model: Model; commands?: ReadonlyArray<Command> }` | Initial state from props and startup commands |
|
|
357
|
+
| `update` | `(model, message) => { model: Model; commands?: ReadonlyArray<Command> }` | Pure state transition |
|
|
358
|
+
| `view` | `(model, h: HtmlBuilder<Message>) => Document` | Render with the current render-frame builder |
|
|
359
|
+
|
|
360
|
+
For `definePage`, `init` receives the validated `Flags` value rather than raw
|
|
361
|
+
Astro props, and the module must additionally export the runtime `Flags`
|
|
362
|
+
Schema/value. `defineApp` keeps the existing props-based `init` contract.
|
|
175
363
|
|
|
176
364
|
## Exports
|
|
177
365
|
|
|
178
|
-
| Entry point
|
|
179
|
-
|
|
|
180
|
-
| `@opsydyn/astro-foldkit`
|
|
181
|
-
| `@opsydyn/astro-foldkit/define-app`
|
|
366
|
+
| Entry point | Description |
|
|
367
|
+
| :----------------------------------- | :-------------------------------------------------------- |
|
|
368
|
+
| `@opsydyn/astro-foldkit` | Default Astro integration (`foldkit()`) |
|
|
369
|
+
| `@opsydyn/astro-foldkit/define-app` | `lazyApp` helper (`defineApp` alias) and `AppConfig` type |
|
|
370
|
+
| `@opsydyn/astro-foldkit/define-page` | `definePage`, `PageConfig`, and page Flags context types |
|
|
371
|
+
| `@opsydyn/astro-foldkit/server` | Server-only `resolvePageDocument` metadata resolver |
|
|
182
372
|
|
|
183
373
|
The root entry point also exports the `NavigationConfig`, `NavigationEvent`, and `NavigationPhase` types.
|
|
184
374
|
|
|
@@ -242,7 +432,7 @@ type NavigationEvent = {
|
|
|
242
432
|
|
|
243
433
|
The bridge sends `coldLoad` immediately for the first mount of an island identity. A retained island receives `stayed` on `astro:before-swap` when its matching `uid` exists in the incoming document, but does not receive `entered` from the following global `astro:page-load`. A same-identity remount emits `entered` on mount; an active island can also emit `entered` for a later page load when it was not retained. Every mounted island emits `exited` once on `astro:unmount`. Events contain normalized pathnames; route parsing and route-specific message decisions belong in the app mapper. If the configured inbound port is missing, the integration warns once and leaves the FoldKit runtime mounted without forwarding events.
|
|
244
434
|
|
|
245
|
-
The integration owns only lifecycle observation and port delivery. The app owns parsing `path` into its route type, mapping the event into a past-tense Message, and deciding whether an `entered` event should run a load or revalidation command. Keep that policy in `update` or a FoldKit `Transition`, so SSR props, navigation facts, and side effects remain separate.
|
|
435
|
+
The integration owns only lifecycle observation and port delivery. The app owns parsing `path` into its route type, mapping the event into a past-tense Message, and deciding whether an `entered` event should run a load or revalidation command. Keep that policy in `update` or a FoldKit `Transition`, so SSR props, navigation facts, and side effects remain separate. When an app uses exited to interrupt work, the interrupt key, state, and outcome policy stay in its update loop; the integration does not cancel or replace commands.
|
|
246
436
|
|
|
247
437
|
Pass the ports map to `makeApplication` alongside your `init`, `update`, and `view`:
|
|
248
438
|
|
|
@@ -293,10 +483,123 @@ element.addEventListener(
|
|
|
293
483
|
|
|
294
484
|
## Peer dependencies
|
|
295
485
|
|
|
296
|
-
| Package | Version
|
|
297
|
-
| :-------- |
|
|
298
|
-
| `astro` | `≥ 5.0`
|
|
299
|
-
| `foldkit` | `≥ 0.
|
|
486
|
+
| Package | Version |
|
|
487
|
+
| :-------- | :-------------------- |
|
|
488
|
+
| `astro` | `≥ 5.0` |
|
|
489
|
+
| `foldkit` | `≥ 0.165.0 < 0.167.0` |
|
|
490
|
+
|
|
491
|
+
## Stateflow Observatory example
|
|
492
|
+
|
|
493
|
+
The demo route `/stateflow` uses `StateflowPage`, an app-owned `definePage` entry,
|
|
494
|
+
to server-render the graph and current state before hydrating with `client:load`
|
|
495
|
+
inside the existing Astro layout. Astro supplies the island and lifecycle facts;
|
|
496
|
+
the app owns the Machine, typed inbound replay Port, outbound transition telemetry Port,
|
|
497
|
+
replay policy, and trace inspector. The graph consumes plain layout records.
|
|
498
|
+
|
|
499
|
+
This slice adds no Astro integration API and moves no async work into the
|
|
500
|
+
integration. Commands and subscriptions remain app-owned, including telemetry
|
|
501
|
+
emission, validation of inbound replay events, and the reduced-motion
|
|
502
|
+
`Subscription.fromMediaQuery` subscription. That subscription is the app's
|
|
503
|
+
example of FoldKit PR [#1424](https://github.com/foldkit/foldkit/pull/1424): it
|
|
504
|
+
records the browser's initial media-query match and subsequent changes, then
|
|
505
|
+
lets the Model decide whether visual motion is allowed.
|
|
506
|
+
|
|
507
|
+
## Remote visual loads
|
|
508
|
+
|
|
509
|
+
For future remote filter, brush, or zoom loads, construct the refresh step with
|
|
510
|
+
an explicit selection snapshot and request ID. `LoadFilteredData` is an
|
|
511
|
+
app-owned interruptible Command whose declared args include `selection` and
|
|
512
|
+
`requestId`; its `execute` uses those args and returns the ID with its result
|
|
513
|
+
Message. Commands do not read the later Model implicitly.
|
|
514
|
+
|
|
515
|
+
In this example, `Model.data` is `AsyncData<Data, string>`. `Selection`, `Data`,
|
|
516
|
+
`Model`, and `Message` are application types. The app also stores the latest
|
|
517
|
+
`selection`, a monotonic `nextRequestId`, `routeActive`, and a discriminated
|
|
518
|
+
`request` union: `Idle | Running { requestId } | Cancelling { requestId }`.
|
|
519
|
+
|
|
520
|
+
```ts
|
|
521
|
+
import { Option } from 'effect';
|
|
522
|
+
import { getData, Idle, revalidateOrLoad, succeed } from 'foldkit/asyncData';
|
|
523
|
+
import { refresh } from 'foldkit/update';
|
|
524
|
+
import type { Return } from 'foldkit/update';
|
|
525
|
+
|
|
526
|
+
import { LoadFilteredData } from './command';
|
|
527
|
+
import type { Message } from './message';
|
|
528
|
+
import type { Data, Model, Selection } from './model';
|
|
529
|
+
|
|
530
|
+
const loadOnFilter = (selection: Selection, requestId: number) =>
|
|
531
|
+
refresh<Model, Message, Data, string>({
|
|
532
|
+
read: (model) => Option.some(model.data),
|
|
533
|
+
revalidate: revalidateOrLoad,
|
|
534
|
+
write: (model, data) => ({ ...model, data }),
|
|
535
|
+
load: LoadFilteredData({ selection, requestId }),
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
// Call only when request is Idle and data is not Loading or Refreshing.
|
|
539
|
+
const startLatest = (model: Model): Return<Model, Message> => {
|
|
540
|
+
const requestId = model.nextRequestId;
|
|
541
|
+
const next: Model = {
|
|
542
|
+
...model,
|
|
543
|
+
nextRequestId: requestId + 1,
|
|
544
|
+
request: { _tag: 'Running', requestId },
|
|
545
|
+
};
|
|
546
|
+
return loadOnFilter(next.selection, requestId)(next);
|
|
547
|
+
};
|
|
548
|
+
|
|
549
|
+
// The outcome handler first checks Cancelling and the cancelled request ID.
|
|
550
|
+
const afterInterruption = (model: Model): Return<Model, Message> => {
|
|
551
|
+
const next: Model = {
|
|
552
|
+
...model,
|
|
553
|
+
request: { _tag: 'Idle' },
|
|
554
|
+
data: Option.match(getData(model.data), {
|
|
555
|
+
onNone: () => Idle(),
|
|
556
|
+
onSome: (data) => succeed(data),
|
|
557
|
+
}),
|
|
558
|
+
};
|
|
559
|
+
if (!next.routeActive) return { model: next };
|
|
560
|
+
return startLatest(next);
|
|
561
|
+
};
|
|
562
|
+
```
|
|
563
|
+
|
|
564
|
+
Use this explicit **latest-selection wins** policy in the app's update loop:
|
|
565
|
+
|
|
566
|
+
1. Record every new filter, brush, or zoom selection in `Model.selection`. If
|
|
567
|
+
the route is active and `request` is `Idle`, call `startLatest` with that
|
|
568
|
+
updated Model. While the route is inactive, only store the selection.
|
|
569
|
+
2. If a request is `Running`, change it to `Cancelling` with the same request
|
|
570
|
+
ID and return only its keyed interruption Command. Capture that ID in the
|
|
571
|
+
interruption outcome Message. Do not start a replacement in the same batch.
|
|
572
|
+
3. While `Cancelling`, keep replacing `Model.selection` with the latest input;
|
|
573
|
+
emit no further load or interruption Commands. Ignore normal result Messages
|
|
574
|
+
for this cancelled request, including a result racing with interruption.
|
|
575
|
+
4. For a matching interruption outcome (`Interrupted` or `NotFound`), call
|
|
576
|
+
`afterInterruption` using the current Model. An interrupted Command will not
|
|
577
|
+
send its original result Message. The helper therefore explicitly clears
|
|
578
|
+
pending AsyncData: `Loading` becomes `Idle`, and `Refreshing(data)` becomes
|
|
579
|
+
`Success(data)`. It then starts the latest selection with a fresh ID, moving
|
|
580
|
+
back to `Loading` or `Refreshing`. Calling `refresh` on the old pending state
|
|
581
|
+
would produce no Command because `revalidateOrLoad` returns `None` there.
|
|
582
|
+
5. Accept a normal result only when its ID matches the `Running` request.
|
|
583
|
+
Apply `settle(model.data, result)` from `foldkit/asyncData` and set `request`
|
|
584
|
+
to `Idle` in the same update. Ignore stale IDs and duplicate outcomes. Cached
|
|
585
|
+
data retained during replacement still belongs to the previous selection;
|
|
586
|
+
present it as such until the matching replacement result arrives.
|
|
587
|
+
6. On route exit, mark the route inactive and interrupt any `Running` request,
|
|
588
|
+
or wait for the existing `Cancelling` outcome. The same outcome handler
|
|
589
|
+
clears pending AsyncData but starts no replacement while inactive. Route
|
|
590
|
+
entry can call `startLatest` from `Idle`; if still `Cancelling`, wait for its
|
|
591
|
+
outcome before loading the latest selection.
|
|
592
|
+
|
|
593
|
+
The app owns command keys and correlation, interruption/cancellation policy,
|
|
594
|
+
AsyncData, and the Model. `refresh` supplies the revalidation step, not that
|
|
595
|
+
replacement policy. The app derives the records supplied to `foldkit-viz`,
|
|
596
|
+
whose synchronous functions compute geometry; chart primitives cannot fetch
|
|
597
|
+
data or subscribe to events or Ports.
|
|
598
|
+
|
|
599
|
+
Use typed Ports only for host input/output: map validated inbound values to app
|
|
600
|
+
Messages and emit outbound values through app-owned Commands. Keep internal
|
|
601
|
+
state in the Model and internal event flow in Messages and update. Astro mounts
|
|
602
|
+
the island and supplies lifecycle facts; it does not own remote visual loads.
|
|
300
603
|
|
|
301
604
|
## License
|
|
302
605
|
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region src/build-id.ts
|
|
2
|
+
function readFoldkitBuildId(env = import.meta.env) {
|
|
3
|
+
const buildId = env?.FOLDKIT_BUILD_ID;
|
|
4
|
+
if (buildId === void 0 || buildId === "") throw new Error("FoldKit server rendering requires import.meta.env.FOLDKIT_BUILD_ID. Configure foldkit({ server: { buildId } }).");
|
|
5
|
+
return buildId;
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
8
|
+
export { readFoldkitBuildId };
|
package/dist/client.d.mts
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
|
-
import { n as
|
|
1
|
+
import { n as NavigationEvent } from "./navigation-Cy2lnE4G.mjs";
|
|
2
|
+
import { a as FoldkitApp, n as AppConfigContract } from "./types-DDk3MMb7.mjs";
|
|
2
3
|
|
|
3
4
|
//#region src/client.d.ts
|
|
5
|
+
interface RuntimeConfigInput {}
|
|
6
|
+
interface RuntimeProgram {}
|
|
7
|
+
interface RuntimeHydrationOptions {
|
|
8
|
+
readonly buildId: string;
|
|
9
|
+
}
|
|
10
|
+
interface ClientSlots {}
|
|
4
11
|
type EventTargetLike = {
|
|
5
12
|
readonly addEventListener: (type: string, listener: EventListener) => void;
|
|
6
13
|
readonly removeEventListener: (type: string, listener: EventListener) => void;
|
|
7
14
|
};
|
|
8
15
|
type NavigationDocument = EventTargetLike & {
|
|
9
16
|
readonly title: string;
|
|
10
|
-
readonly querySelector: (selector: string) =>
|
|
17
|
+
readonly querySelector: (selector: string) => object | null;
|
|
18
|
+
};
|
|
19
|
+
type RuntimePortHandle<Value> = {
|
|
20
|
+
readonly send: (value: Value) => void;
|
|
11
21
|
};
|
|
12
22
|
type EmbedHandle = {
|
|
13
|
-
readonly ports?: Record<string,
|
|
14
|
-
readonly send: (value: unknown) => unknown;
|
|
15
|
-
}>;
|
|
23
|
+
readonly ports?: Readonly<Record<string, RuntimePortHandle<NavigationEvent>>>;
|
|
16
24
|
readonly dispose: () => void;
|
|
17
25
|
};
|
|
18
26
|
type ClientEnvironment = {
|
|
@@ -24,13 +32,20 @@ type ClientEnvironment = {
|
|
|
24
32
|
};
|
|
25
33
|
};
|
|
26
34
|
type ClientRuntime = {
|
|
27
|
-
readonly makeApplication: (config:
|
|
28
|
-
readonly embed: (program:
|
|
35
|
+
readonly makeApplication: (config: RuntimeConfigInput) => RuntimeProgram;
|
|
36
|
+
readonly embed: (program: RuntimeProgram) => EmbedHandle;
|
|
37
|
+
readonly hydrate?: (program: RuntimeProgram, options: RuntimeHydrationOptions) => void;
|
|
29
38
|
};
|
|
30
|
-
|
|
39
|
+
interface ClientPage {
|
|
40
|
+
(props?: never): void;
|
|
41
|
+
readonly __foldkitPage: true;
|
|
42
|
+
readonly load: () => Promise<RuntimeConfigInput>;
|
|
43
|
+
}
|
|
44
|
+
type ClientComponent<Props extends object, Config extends AppConfigContract<Props>> = FoldkitApp<Props, Config> | ClientPage;
|
|
45
|
+
declare function createClientRenderer(runtime?: ClientRuntime, environment?: Partial<ClientEnvironment>): (element: HTMLElement) => <Props extends object, Config extends AppConfigContract<Props>>(component: ClientComponent<Props, Config>, props: Props, _slots: ClientSlots, _meta: {
|
|
31
46
|
client: string;
|
|
32
47
|
}) => Promise<void>;
|
|
33
|
-
declare const _default: (element: HTMLElement) => <Props extends
|
|
48
|
+
declare const _default: (element: HTMLElement) => <Props extends object, Config extends AppConfigContract<Props>>(component: ClientComponent<Props, Config>, props: Props, _slots: ClientSlots, _meta: {
|
|
34
49
|
client: string;
|
|
35
50
|
}) => Promise<void>;
|
|
36
51
|
//#endregion
|
package/dist/client.mjs
CHANGED
|
@@ -1,15 +1,26 @@
|
|
|
1
|
+
import { readFoldkitBuildId } from "./build-id.mjs";
|
|
1
2
|
import { Runtime } from "foldkit";
|
|
2
3
|
//#region src/client-helpers.ts
|
|
4
|
+
const FOLDKIT_ROOT_SELECTOR = "[data-foldkit-app]";
|
|
5
|
+
const findSingleFoldkitRoot = (container) => {
|
|
6
|
+
const roots = Array.from(container.querySelectorAll(FOLDKIT_ROOT_SELECTOR));
|
|
7
|
+
if (roots.length !== 1) throw new Error(`Expected exactly one stamped FoldKit root inside the Astro island, found ${roots.length}.`);
|
|
8
|
+
return roots[0];
|
|
9
|
+
};
|
|
3
10
|
/** Returns true when the `noMeta` prop should suppress document metadata writes. */
|
|
4
|
-
const shouldSkipMetadata = (props) =>
|
|
11
|
+
const shouldSkipMetadata = (props) => {
|
|
12
|
+
if (!("noMeta" in props)) return false;
|
|
13
|
+
const value = props.noMeta;
|
|
14
|
+
return value === true || value === "";
|
|
15
|
+
};
|
|
5
16
|
/**
|
|
6
17
|
* Wraps a foldkit view function so the Document it returns always carries
|
|
7
18
|
* `initialTitle` as its title, preventing the runtime from overwriting
|
|
8
19
|
* `document.title` when the app is embedded as an island on a page that
|
|
9
20
|
* owns its own title.
|
|
10
21
|
*/
|
|
11
|
-
const
|
|
12
|
-
...view(model),
|
|
22
|
+
const withNoMetaView = (view, initialTitle) => (model, h) => ({
|
|
23
|
+
...view(model, h),
|
|
13
24
|
title: initialTitle
|
|
14
25
|
});
|
|
15
26
|
//#endregion
|
|
@@ -43,12 +54,11 @@ const newDocumentFrom = (event) => {
|
|
|
43
54
|
return beforeSwap.newDocument ?? beforeSwap.detail?.newDocument;
|
|
44
55
|
};
|
|
45
56
|
const destinationHrefFrom = (event, fallback) => {
|
|
46
|
-
|
|
47
|
-
return typeof href === "string" ? href : fallback;
|
|
57
|
+
return event.detail?.to?.href ?? fallback;
|
|
48
58
|
};
|
|
49
59
|
const containsIsland = (document, identity) => {
|
|
50
|
-
if (
|
|
51
|
-
return
|
|
60
|
+
if (document === void 0) return false;
|
|
61
|
+
return document.querySelector(`astro-island[uid="${identity}"]`) !== null;
|
|
52
62
|
};
|
|
53
63
|
const attachNavigationBridge = (element, navigation, send, environment) => {
|
|
54
64
|
let active = true;
|
|
@@ -99,20 +109,34 @@ const attachNavigationBridge = (element, navigation, send, environment) => {
|
|
|
99
109
|
};
|
|
100
110
|
const defaultRuntime = {
|
|
101
111
|
makeApplication: (config) => Runtime.makeApplication(config),
|
|
102
|
-
embed: (program) => Runtime.embed(program)
|
|
112
|
+
embed: (program) => Runtime.embed(program),
|
|
113
|
+
hydrate: (program, options) => Runtime.hydrate(program, options)
|
|
103
114
|
};
|
|
115
|
+
const isPageOwner = (component) => typeof component === "function" && "__foldkitPage" in component && component.__foldkitPage === true;
|
|
104
116
|
function createClientRenderer(runtime = defaultRuntime, environment = {}) {
|
|
105
117
|
return (element) => async (component, props, _slots, _meta) => {
|
|
106
|
-
const config = await component.load();
|
|
107
118
|
const clientEnvironment = {
|
|
108
119
|
document: environment.document ?? globalThis.document,
|
|
109
120
|
window: environment.window ?? globalThis.window
|
|
110
121
|
};
|
|
111
122
|
element.id ||= element.getAttribute("uid") ?? crypto.randomUUID();
|
|
112
|
-
|
|
113
|
-
|
|
123
|
+
if (isPageOwner(component)) {
|
|
124
|
+
const config = await component.load();
|
|
125
|
+
const root = findSingleFoldkitRoot(element);
|
|
126
|
+
const application = runtime.makeApplication({
|
|
127
|
+
...config,
|
|
128
|
+
container: root
|
|
129
|
+
});
|
|
130
|
+
if (runtime.hydrate === void 0) throw new Error("FoldKit Runtime.hydrate is not available for page hydration.");
|
|
131
|
+
runtime.hydrate(application, { buildId: readFoldkitBuildId() });
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const config = await component.load();
|
|
135
|
+
const runtimeConfig = config;
|
|
136
|
+
const baseView = runtimeConfig.view;
|
|
137
|
+
const view = shouldSkipMetadata(props) ? withNoMetaView(baseView, clientEnvironment.document.title) : baseView;
|
|
114
138
|
const program = runtime.makeApplication({
|
|
115
|
-
...
|
|
139
|
+
...runtimeConfig,
|
|
116
140
|
init: () => config.init(props),
|
|
117
141
|
view,
|
|
118
142
|
container: element,
|
|
@@ -127,10 +151,11 @@ function createClientRenderer(runtime = defaultRuntime, environment = {}) {
|
|
|
127
151
|
else console.warn(`FoldKit navigation port "${config.navigation.port}" is not available`);
|
|
128
152
|
}
|
|
129
153
|
element.addEventListener("astro:unmount", () => {
|
|
130
|
-
if (disposed)
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
154
|
+
if (!disposed) {
|
|
155
|
+
disposed = true;
|
|
156
|
+
detachNavigation();
|
|
157
|
+
handle.dispose();
|
|
158
|
+
}
|
|
134
159
|
}, { once: true });
|
|
135
160
|
};
|
|
136
161
|
}
|
package/dist/define-app.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as FoldkitApp, i as EmptyProps, n as AppConfigContract, t as AppConfig } from "./types-DDk3MMb7.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/define-app.d.ts
|
|
4
|
-
declare function defineApp<Props extends
|
|
4
|
+
declare function defineApp<Props extends object = EmptyProps, Config extends AppConfigContract<Props> = AppConfigContract<Props>>(load: () => Promise<Config>): FoldkitApp<Props, Config>;
|
|
5
5
|
/** Preferred name for Astro's intentional lazy island entry boundary. */
|
|
6
6
|
declare const lazyApp: typeof defineApp;
|
|
7
7
|
//#endregion
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { c as PageConfigContract, d as PageFlagsSchema, f as PageParams, i as EmptyProps, l as PageContext, o as FoldkitPage, r as DefinePageOptions, s as PageConfig, u as PageFlagsContext } from "./types-DDk3MMb7.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/define-page.d.ts
|
|
4
|
+
declare function definePage<Props extends object = EmptyProps, Flags extends object = EmptyProps, Config extends PageConfigContract<Flags> = PageConfigContract<Flags>>(load: () => Promise<Config>, options: DefinePageOptions<Props, Flags>): FoldkitPage<Props, Flags, Config>;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { type DefinePageOptions, type FoldkitPage, type PageConfig, type PageConfigContract, type PageContext, type PageFlagsContext, type PageFlagsSchema, type PageParams, definePage };
|
package/dist/index.d.mts
CHANGED
|
@@ -2,6 +2,11 @@ import { n as NavigationEvent, r as NavigationPhase, t as NavigationConfig } fro
|
|
|
2
2
|
import { AstroIntegration } from "astro";
|
|
3
3
|
|
|
4
4
|
//#region src/index.d.ts
|
|
5
|
-
|
|
5
|
+
type FoldkitIntegrationOptions = Readonly<{
|
|
6
|
+
server?: Readonly<{
|
|
7
|
+
buildId: string;
|
|
8
|
+
}>;
|
|
9
|
+
}>;
|
|
10
|
+
declare function foldkit(options?: FoldkitIntegrationOptions): AstroIntegration;
|
|
6
11
|
//#endregion
|
|
7
|
-
export { type NavigationConfig, type NavigationEvent, type NavigationPhase, foldkit as default };
|
|
12
|
+
export { FoldkitIntegrationOptions, type NavigationConfig, type NavigationEvent, type NavigationPhase, foldkit as default };
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { fileURLToPath } from "node:url";
|
|
2
2
|
import { foldkit as foldkit$1 } from "@foldkit/vite-plugin";
|
|
3
3
|
//#region src/index.ts
|
|
4
|
-
function foldkit() {
|
|
4
|
+
function foldkit(options = {}) {
|
|
5
|
+
const configuredBuildId = options.server?.buildId;
|
|
6
|
+
if (configuredBuildId !== void 0 && configuredBuildId.trim() === "") throw new Error("foldkit({ server: { buildId } }) requires a non-empty server.buildId.");
|
|
7
|
+
const buildId = configuredBuildId ?? "development";
|
|
5
8
|
return {
|
|
6
9
|
name: "astro-foldkit",
|
|
7
10
|
hooks: { "astro:config:setup": ({ addRenderer, updateConfig }) => {
|
|
@@ -10,7 +13,7 @@ function foldkit() {
|
|
|
10
13
|
clientEntrypoint: fileURLToPath(new URL("./client.mjs", import.meta.url)),
|
|
11
14
|
serverEntrypoint: fileURLToPath(new URL("./server.mjs", import.meta.url))
|
|
12
15
|
});
|
|
13
|
-
updateConfig({ vite: { plugins: [foldkit$1()] } });
|
|
16
|
+
updateConfig({ vite: { plugins: [foldkit$1({ buildId })] } });
|
|
14
17
|
} }
|
|
15
18
|
};
|
|
16
19
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { l as PageContext, o as FoldkitPage } from "./types-DDk3MMb7.mjs";
|
|
2
|
+
import { RenderedApplication } from "foldkit/experimental/server";
|
|
3
|
+
|
|
4
|
+
//#region src/server-document.d.ts
|
|
5
|
+
type ResolvedPageDocument = {
|
|
6
|
+
readonly title: string;
|
|
7
|
+
readonly lang?: string;
|
|
8
|
+
readonly dir?: 'ltr' | 'rtl' | 'auto';
|
|
9
|
+
readonly canonical?: string;
|
|
10
|
+
readonly ogUrl?: string;
|
|
11
|
+
};
|
|
12
|
+
declare function resolvePageDocument<Props extends object = object, Flags extends object = object>(page: FoldkitPage<Props, Flags>, context: PageContext<Props>): Promise<ResolvedPageDocument>;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { type ResolvedPageDocument, resolvePageDocument };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { readFoldkitBuildId } from "./build-id.mjs";
|
|
2
|
+
import { renderFoldkitServerApplication } from "./server-render.mjs";
|
|
3
|
+
//#region src/server-document.ts
|
|
4
|
+
const setOptional = (document, key, value) => value === void 0 ? document : {
|
|
5
|
+
...document,
|
|
6
|
+
[key]: value
|
|
7
|
+
};
|
|
8
|
+
const mapRenderedApplicationDocument = (rendered) => {
|
|
9
|
+
return setOptional(setOptional(setOptional(setOptional({ title: rendered.title }, "lang", rendered.lang), "dir", rendered.dir), "canonical", rendered.canonical), "ogUrl", rendered.ogUrl);
|
|
10
|
+
};
|
|
11
|
+
async function resolvePageDocument(page, context) {
|
|
12
|
+
const flags = page.flags(context);
|
|
13
|
+
return mapRenderedApplicationDocument(await renderFoldkitServerApplication(await page.load(), flags, readFoldkitBuildId()));
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { resolvePageDocument };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { c as PageConfigContract } from "./types-DDk3MMb7.mjs";
|
|
2
|
+
import { RenderedApplication } from "foldkit/experimental/server";
|
|
3
|
+
|
|
4
|
+
//#region src/server-render.d.ts
|
|
5
|
+
type ServerConfig<Flags extends object> = Pick<PageConfigContract<Flags>, 'Flags' | 'init' | 'view'>;
|
|
6
|
+
declare function renderFoldkitServerApplication<Flags extends object>(config: ServerConfig<Flags>, flags: Flags, buildId: string): Promise<RenderedApplication>;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { renderFoldkitServerApplication };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { renderToString } from "foldkit/experimental/server";
|
|
3
|
+
//#region src/server-render.ts
|
|
4
|
+
async function renderFoldkitServerApplication(config, flags, buildId) {
|
|
5
|
+
return await Effect.runPromise(renderToString({
|
|
6
|
+
Flags: config.Flags,
|
|
7
|
+
init: config.init,
|
|
8
|
+
view: config.view
|
|
9
|
+
}, {
|
|
10
|
+
flags,
|
|
11
|
+
buildId
|
|
12
|
+
}));
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { renderFoldkitServerApplication };
|
package/dist/server.d.mts
CHANGED
|
@@ -1,10 +1,28 @@
|
|
|
1
|
+
import { f as PageParams } from "./types-DDk3MMb7.mjs";
|
|
1
2
|
import { NamedSSRLoadedRendererValue } from "astro";
|
|
2
3
|
|
|
3
4
|
//#region src/server.d.ts
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
interface AstroComponentInput {}
|
|
6
|
+
interface AstroProps {}
|
|
7
|
+
interface AstroSlots {}
|
|
8
|
+
type AstroRendererResult = Readonly<{
|
|
9
|
+
createAstro: (props: AstroProps, slots: AstroSlots) => AstroLike<AstroProps>;
|
|
10
|
+
params: PageParams;
|
|
11
|
+
request: Request;
|
|
12
|
+
}>;
|
|
13
|
+
type RendererThis = Readonly<{
|
|
14
|
+
result?: AstroRendererResult;
|
|
15
|
+
}>;
|
|
16
|
+
type AstroLike<Props extends AstroProps> = Readonly<{
|
|
17
|
+
request?: Request;
|
|
18
|
+
url?: URL;
|
|
19
|
+
params?: PageParams;
|
|
20
|
+
props?: Props;
|
|
21
|
+
}>;
|
|
22
|
+
declare function check<Component>(component: Component): Promise<boolean>;
|
|
23
|
+
declare function renderToStaticMarkup(this: RendererThis | void, component: AstroComponentInput, props: AstroProps, slots: AstroSlots): Promise<{
|
|
6
24
|
html: string;
|
|
7
25
|
}>;
|
|
8
26
|
declare const renderer: NamedSSRLoadedRendererValue;
|
|
9
27
|
//#endregion
|
|
10
|
-
export { check, renderer as default, renderToStaticMarkup };
|
|
28
|
+
export { AstroComponentInput, AstroProps, AstroSlots, check, renderer as default, renderToStaticMarkup };
|
package/dist/server.mjs
CHANGED
|
@@ -1,8 +1,40 @@
|
|
|
1
|
+
import { readFoldkitBuildId } from "./build-id.mjs";
|
|
2
|
+
import { renderFoldkitServerApplication } from "./server-render.mjs";
|
|
1
3
|
//#region src/server.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
+
const claimedPageResults = /* @__PURE__ */ new WeakSet();
|
|
5
|
+
const isObjectOrFunction = (value) => value != null && (typeof value === "object" || typeof value === "function");
|
|
6
|
+
const isFoldkitApp = (value) => isObjectOrFunction(value) && "__foldkit" in value && value.__foldkit === true;
|
|
7
|
+
const isFoldkitPage = (value) => isObjectOrFunction(value) && "__foldkitPage" in value && value.__foldkitPage === true;
|
|
8
|
+
const claimPageResult = (result) => {
|
|
9
|
+
if (claimedPageResults.has(result)) throw new Error("Astro FoldKit server rendering supports exactly one FoldKit page owner per result.");
|
|
10
|
+
claimedPageResults.add(result);
|
|
11
|
+
};
|
|
12
|
+
const requireResult = (result) => {
|
|
13
|
+
if (result === void 0) throw new Error("Astro FoldKit server rendering requires the Astro renderer result.");
|
|
14
|
+
return result;
|
|
15
|
+
};
|
|
16
|
+
const pageContext = (result, props, slots) => {
|
|
17
|
+
const astro = result.createAstro(props, slots);
|
|
18
|
+
const request = astro.request ?? result.request;
|
|
19
|
+
return {
|
|
20
|
+
request,
|
|
21
|
+
url: astro.url ?? new URL(request.url),
|
|
22
|
+
params: astro.params ?? result.params,
|
|
23
|
+
props: astro.props ?? props
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
const renderPage = async (result, component, props, slots) => {
|
|
27
|
+
const currentResult = requireResult(result);
|
|
28
|
+
claimPageResult(currentResult);
|
|
29
|
+
const context = pageContext(currentResult, props, slots);
|
|
30
|
+
const flags = component.flags(context);
|
|
31
|
+
return { html: (await renderFoldkitServerApplication(await component.load(), flags, readFoldkitBuildId())).html };
|
|
32
|
+
};
|
|
33
|
+
async function check(component) {
|
|
34
|
+
return isFoldkitApp(component) || isFoldkitPage(component);
|
|
4
35
|
}
|
|
5
|
-
async function renderToStaticMarkup(
|
|
36
|
+
async function renderToStaticMarkup(component, props, slots) {
|
|
37
|
+
if (isFoldkitPage(component)) return renderPage(this?.result, component, props, slots);
|
|
6
38
|
return { html: "<div data-foldkit-island=\"true\"></div>" };
|
|
7
39
|
}
|
|
8
40
|
const renderer = {
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { n as NavigationEvent, t as NavigationConfig } from "./navigation-Cy2lnE4G.mjs";
|
|
2
|
+
import { Runtime } from "foldkit";
|
|
3
|
+
import { Schema } from "effect";
|
|
4
|
+
import { Document } from "foldkit/html";
|
|
5
|
+
import { Ports } from "foldkit/port";
|
|
6
|
+
|
|
7
|
+
//#region src/types.d.ts
|
|
8
|
+
type TaggedMessage = {
|
|
9
|
+
readonly _tag: string;
|
|
10
|
+
};
|
|
11
|
+
interface EmptyProps {
|
|
12
|
+
readonly noMeta?: boolean | '';
|
|
13
|
+
}
|
|
14
|
+
type AppReturn<Model = unknown> = Readonly<{
|
|
15
|
+
readonly model: Model;
|
|
16
|
+
readonly commands?: ReadonlyArray<unknown>;
|
|
17
|
+
}>;
|
|
18
|
+
type AppConfigContract<Props extends object = EmptyProps> = {
|
|
19
|
+
readonly Model: unknown;
|
|
20
|
+
readonly init: (props: Props) => AppReturn;
|
|
21
|
+
readonly update: (model: never, message: never) => AppReturn;
|
|
22
|
+
readonly view: (model: never, h: never) => Document;
|
|
23
|
+
readonly navigation?: NavigationConfig<NavigationEvent>;
|
|
24
|
+
readonly ports?: Ports;
|
|
25
|
+
};
|
|
26
|
+
type AppConfig<Props extends object = EmptyProps, Model = unknown, Message extends TaggedMessage = TaggedMessage> = {
|
|
27
|
+
readonly Model: unknown;
|
|
28
|
+
readonly init: (props: Props) => AppReturn<Model>;
|
|
29
|
+
readonly update: Runtime.ApplicationConfig<Model, Message>['update'];
|
|
30
|
+
readonly view: Runtime.ApplicationConfig<Model, Message>['view'];
|
|
31
|
+
};
|
|
32
|
+
type FoldkitApp<Props extends object = EmptyProps, Config extends AppConfigContract<Props> = AppConfigContract<Props>> = {
|
|
33
|
+
(props?: Props): void;
|
|
34
|
+
readonly __foldkit: true;
|
|
35
|
+
readonly load: () => Promise<Config>;
|
|
36
|
+
};
|
|
37
|
+
type PageParams = Readonly<Record<string, string | undefined>>;
|
|
38
|
+
type PageFlagsContext<Props extends object = EmptyProps> = {
|
|
39
|
+
readonly request: Request;
|
|
40
|
+
readonly url: URL;
|
|
41
|
+
readonly params: PageParams;
|
|
42
|
+
readonly props: Props;
|
|
43
|
+
};
|
|
44
|
+
type PageContext<Props extends object = EmptyProps> = PageFlagsContext<Props>;
|
|
45
|
+
type PageFlagsSchema<Flags extends object> = Schema.Codec<Flags, any, never, never>;
|
|
46
|
+
type PageConfig<Flags extends object = EmptyProps, Model = unknown, Message extends TaggedMessage = TaggedMessage> = AppConfig<Flags, Model, Message> & {
|
|
47
|
+
readonly Flags: PageFlagsSchema<Flags>;
|
|
48
|
+
};
|
|
49
|
+
type PageConfigContract<Flags extends object = EmptyProps> = AppConfigContract<Flags> & {
|
|
50
|
+
readonly Flags: PageFlagsSchema<Flags>;
|
|
51
|
+
};
|
|
52
|
+
type DefinePageOptions<Props extends object = EmptyProps, Flags extends object = EmptyProps> = {
|
|
53
|
+
readonly flags: (context: PageFlagsContext<Props>) => Flags;
|
|
54
|
+
};
|
|
55
|
+
type FoldkitPage<Props extends object = EmptyProps, Flags extends object = EmptyProps, Config extends PageConfigContract<Flags> = PageConfigContract<Flags>> = {
|
|
56
|
+
(props?: Props): void;
|
|
57
|
+
readonly __foldkitPage: true;
|
|
58
|
+
readonly load: () => Promise<Config>;
|
|
59
|
+
readonly flags: (context: PageFlagsContext<Props>) => Flags;
|
|
60
|
+
};
|
|
61
|
+
//#endregion
|
|
62
|
+
export { FoldkitApp as a, PageConfigContract as c, PageFlagsSchema as d, PageParams as f, EmptyProps as i, PageContext as l, AppConfigContract as n, FoldkitPage as o, DefinePageOptions as r, PageConfig as s, AppConfig as t, PageFlagsContext as u };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opsydyn/astro-foldkit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"description": "Astro integration and renderer for FoldKit.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astro",
|
|
@@ -32,6 +32,12 @@
|
|
|
32
32
|
"*": {
|
|
33
33
|
"define-app": [
|
|
34
34
|
"./dist/define-app.d.mts"
|
|
35
|
+
],
|
|
36
|
+
"define-page": [
|
|
37
|
+
"./dist/define-page.d.mts"
|
|
38
|
+
],
|
|
39
|
+
"server": [
|
|
40
|
+
"./dist/server-public.d.mts"
|
|
35
41
|
]
|
|
36
42
|
}
|
|
37
43
|
},
|
|
@@ -43,6 +49,14 @@
|
|
|
43
49
|
"./define-app": {
|
|
44
50
|
"types": "./dist/define-app.d.mts",
|
|
45
51
|
"import": "./dist/define-app.mjs"
|
|
52
|
+
},
|
|
53
|
+
"./define-page": {
|
|
54
|
+
"types": "./dist/define-page.d.mts",
|
|
55
|
+
"import": "./dist/define-page.mjs"
|
|
56
|
+
},
|
|
57
|
+
"./server": {
|
|
58
|
+
"types": "./dist/server-public.d.mts",
|
|
59
|
+
"import": "./dist/server-public.mjs"
|
|
46
60
|
}
|
|
47
61
|
},
|
|
48
62
|
"publishConfig": {
|
|
@@ -58,20 +72,21 @@
|
|
|
58
72
|
"check:fix": "oxfmt . && NODE_OPTIONS=\"--experimental-strip-types\" oxlint --fix ."
|
|
59
73
|
},
|
|
60
74
|
"dependencies": {
|
|
61
|
-
"@foldkit/vite-plugin": "^0.
|
|
75
|
+
"@foldkit/vite-plugin": "^0.26.1",
|
|
76
|
+
"effect": "4.0.0"
|
|
62
77
|
},
|
|
63
78
|
"devDependencies": {
|
|
64
79
|
"@types/node": "^22.0.0",
|
|
65
80
|
"astro": "7.1.1",
|
|
66
81
|
"bun-types": "^1.3.14",
|
|
67
82
|
"fast-check": "^4.8.0",
|
|
68
|
-
"foldkit": "
|
|
83
|
+
"foldkit": "0.166.0",
|
|
69
84
|
"tsdown": "^0.21.8",
|
|
70
85
|
"typescript": "^6.0.3"
|
|
71
86
|
},
|
|
72
87
|
"peerDependencies": {
|
|
73
88
|
"astro": ">=5.0.0",
|
|
74
|
-
"foldkit": ">=0.
|
|
89
|
+
"foldkit": ">=0.165.0 <0.167.0"
|
|
75
90
|
},
|
|
76
91
|
"engines": {
|
|
77
92
|
"node": ">=22.0.0"
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { t as NavigationConfig } from "./navigation-Cy2lnE4G.mjs";
|
|
2
|
-
import { Runtime } from "foldkit";
|
|
3
|
-
import { Document } from "foldkit/html";
|
|
4
|
-
|
|
5
|
-
//#region src/types.d.ts
|
|
6
|
-
type TaggedMessage = {
|
|
7
|
-
readonly _tag: string;
|
|
8
|
-
};
|
|
9
|
-
type CommandBatch = ReadonlyArray<unknown>;
|
|
10
|
-
type AppConfigShape<Props extends Record<string, unknown>> = {
|
|
11
|
-
readonly Model: unknown;
|
|
12
|
-
readonly init: (props: Props) => readonly [unknown, CommandBatch];
|
|
13
|
-
readonly update: (model: never, message: never) => readonly [unknown, CommandBatch];
|
|
14
|
-
readonly view: (model: never) => Document;
|
|
15
|
-
readonly navigation?: NavigationConfig<unknown>;
|
|
16
|
-
readonly ports?: Record<string, unknown>;
|
|
17
|
-
};
|
|
18
|
-
type AppConfig<Props extends Record<string, unknown> = Record<string, unknown>, Model = unknown, Message extends TaggedMessage = TaggedMessage> = {
|
|
19
|
-
readonly Model: unknown;
|
|
20
|
-
readonly init: (props: Props) => readonly [Model, CommandBatch];
|
|
21
|
-
readonly update: Runtime.ApplicationConfig<Model, Message>['update'];
|
|
22
|
-
readonly view: (model: Model) => Document;
|
|
23
|
-
};
|
|
24
|
-
type FoldkitApp<Props extends Record<string, unknown> = Record<string, unknown>, Config extends AppConfigShape<Props> = AppConfigShape<Props>> = {
|
|
25
|
-
(props?: Props): void;
|
|
26
|
-
readonly __foldkit: true;
|
|
27
|
-
readonly load: () => Promise<Config>;
|
|
28
|
-
};
|
|
29
|
-
//#endregion
|
|
30
|
-
export { AppConfigShape as n, FoldkitApp as r, AppConfig as t };
|