@opsydyn/astro-foldkit 0.2.1 → 0.3.0

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 CHANGED
@@ -1,28 +1,45 @@
1
1
  # Changelog
2
2
 
3
- ## [0.2.1](https://github.com/opsydyn/fold-kit-experiments/compare/astro-foldkit-v0.2.0...astro-foldkit-v0.2.1) (2026-06-12)
3
+ ## [0.3.0](https://github.com/opsydyn/fold-kit-experiments/compare/astro-foldkit-v0.2.1...astro-foldkit-v0.3.0) (2026-07-15)
4
+
5
+
6
+ ### Features
7
+
8
+ * **astro-foldkit:** add navigation event contract ([5d4678d](https://github.com/opsydyn/fold-kit-experiments/commit/5d4678d94eac9e5e9f6d6f15e9d4074f1e99df3d))
9
+ * **astro-foldkit:** define stable ssr shell ([e325b89](https://github.com/opsydyn/fold-kit-experiments/commit/e325b89f63515194abf37a85f568dddef4d97855))
10
+ * **astro-foldkit:** forward navigation through inbound ports ([da6ade5](https://github.com/opsydyn/fold-kit-experiments/commit/da6ade569a312b886a5732f1a401a47b065f4f20))
11
+ * **astro-foldkit:** type application contract ([9fbc36d](https://github.com/opsydyn/fold-kit-experiments/commit/9fbc36de9fde1e17b2d29d791d620bc9eddf573a))
4
12
 
5
13
 
6
14
  ### Bug Fixes
7
15
 
8
- * correct repository url for npm provenance ([723fc7f](https://github.com/opsydyn/fold-kit-experiments/commit/723fc7f932ab6bbfd077b2a49df4904624ff89d2))
16
+ * address astro navigation review findings ([ec6faad](https://github.com/opsydyn/fold-kit-experiments/commit/ec6faad38c05d9a1b5d5fe32a710215864fe8fb6))
17
+ * align packages with foldkit 0.128.1 ([ebadeaa](https://github.com/opsydyn/fold-kit-experiments/commit/ebadeaaf29e854660aa2d5c9eba04c017269d075))
18
+ * **astro-foldkit:** make island disposal one-shot ([694e17a](https://github.com/opsydyn/fold-kit-experiments/commit/694e17a32453c6f98561f6f2cb767d3c4c59ab8a))
19
+ * **astro-foldkit:** preserve schema overlay compatibility ([4f4be0b](https://github.com/opsydyn/fold-kit-experiments/commit/4f4be0b5da7bebb7c40acb535727acd8f448a903))
20
+ * **astro-foldkit:** scope navigation to island lifecycle ([e8627d8](https://github.com/opsydyn/fold-kit-experiments/commit/e8627d82cb7a76e4887b7e40121e2d6cf3906347))
21
+ * resolve final astro navigation review findings ([baefd61](https://github.com/opsydyn/fold-kit-experiments/commit/baefd615231832ffca5dc10d18f4919e7672d3f9))
9
22
 
10
- ## [0.2.0](https://github.com/opsydyn/fold-kit-experiments/compare/astro-foldkit-v0.1.0...astro-foldkit-v0.2.0) (2026-06-12)
23
+ ## [0.2.1](https://github.com/opsydyn/fold-kit-experiments/compare/astro-foldkit-v0.2.0...astro-foldkit-v0.2.1) (2026-06-12)
11
24
 
25
+ ### Bug Fixes
12
26
 
13
- ### Features
27
+ - correct repository url for npm provenance ([723fc7f](https://github.com/opsydyn/fold-kit-experiments/commit/723fc7f932ab6bbfd077b2a49df4904624ff89d2))
14
28
 
15
- * :arrow_up: bump foldkit to 0.108.0 and migrate runtime API ([7441538](https://github.com/opsydyn/fold-kit-experiments/commit/744153844de11b096e2434e7e678d1149238d1b0))
16
- * :rotating_light: add Effect language service and linteffect rules ([c2fad21](https://github.com/opsydyn/fold-kit-experiments/commit/c2fad2198616a0df333bb41e8fe0aaa9af9c433c))
17
- * :sparkles: add prop to remove foldkit meta data optionally ([2ae7989](https://github.com/opsydyn/fold-kit-experiments/commit/2ae798977b7e78706bf329bef394f6e1604e2f73))
18
- * :sparkles: add props to fold kit ([de04151](https://github.com/opsydyn/fold-kit-experiments/commit/de04151cd0bbe54c1fc4e36af34836fb5c39d4c3))
19
- * :sparkles: charts updates ([cd052d9](https://github.com/opsydyn/fold-kit-experiments/commit/cd052d9e0bccd7994ec2f4283fb3e2ccff9bc030))
20
- * :sparkles: foldkit upgrade ([cafc368](https://github.com/opsydyn/fold-kit-experiments/commit/cafc36852352e66c7446e06701eaa87103279ff0))
21
- * :sparkles: mono repo refactor ([18079de](https://github.com/opsydyn/fold-kit-experiments/commit/18079de599b3848a50b89bfe897ad47f50f43919))
22
- * :sparkles: prepare package for npm ([3d5850b](https://github.com/opsydyn/fold-kit-experiments/commit/3d5850bf536b2d10ae1483bd108a2eda89de321a))
23
- * :sparkles: tests for package ([086808d](https://github.com/opsydyn/fold-kit-experiments/commit/086808daafdc5331609fcf34fa1734d7d2d5b28f))
29
+ ## [0.2.0](https://github.com/opsydyn/fold-kit-experiments/compare/astro-foldkit-v0.1.0...astro-foldkit-v0.2.0) (2026-06-12)
30
+
31
+ ### Features
24
32
 
33
+ - :arrow_up: bump foldkit to 0.108.0 and migrate runtime API ([7441538](https://github.com/opsydyn/fold-kit-experiments/commit/744153844de11b096e2434e7e678d1149238d1b0))
34
+ - :rotating_light: add Effect language service and linteffect rules ([c2fad21](https://github.com/opsydyn/fold-kit-experiments/commit/c2fad2198616a0df333bb41e8fe0aaa9af9c433c))
35
+ - :sparkles: add prop to remove foldkit meta data optionally ([2ae7989](https://github.com/opsydyn/fold-kit-experiments/commit/2ae798977b7e78706bf329bef394f6e1604e2f73))
36
+ - :sparkles: add props to fold kit ([de04151](https://github.com/opsydyn/fold-kit-experiments/commit/de04151cd0bbe54c1fc4e36af34836fb5c39d4c3))
37
+ - :sparkles: charts updates ([cd052d9](https://github.com/opsydyn/fold-kit-experiments/commit/cd052d9e0bccd7994ec2f4283fb3e2ccff9bc030))
38
+ - :sparkles: foldkit upgrade ([cafc368](https://github.com/opsydyn/fold-kit-experiments/commit/cafc36852352e66c7446e06701eaa87103279ff0))
39
+ - :sparkles: mono repo refactor ([18079de](https://github.com/opsydyn/fold-kit-experiments/commit/18079de599b3848a50b89bfe897ad47f50f43919))
40
+ - :sparkles: prepare package for npm ([3d5850b](https://github.com/opsydyn/fold-kit-experiments/commit/3d5850bf536b2d10ae1483bd108a2eda89de321a))
41
+ - :sparkles: tests for package ([086808d](https://github.com/opsydyn/fold-kit-experiments/commit/086808daafdc5331609fcf34fa1734d7d2d5b28f))
25
42
 
26
43
  ### Bug Fixes
27
44
 
28
- * :white_check_mark: resolve all biome lint errors ([b09399d](https://github.com/opsydyn/fold-kit-experiments/commit/b09399dc0c9e68a2cca0fc53c0a1b59c2b517c90))
45
+ - :white_check_mark: resolve all biome lint errors ([b09399d](https://github.com/opsydyn/fold-kit-experiments/commit/b09399dc0c9e68a2cca0fc53c0a1b59c2b517c90))
package/README.md CHANGED
@@ -17,12 +17,12 @@ npm install astro foldkit
17
17
  Add the integration to `astro.config.ts`:
18
18
 
19
19
  ```ts
20
- import { defineConfig } from 'astro/config'
21
- import foldkit from '@opsydyn/astro-foldkit'
20
+ import { defineConfig } from 'astro/config';
21
+ import foldkit from '@opsydyn/astro-foldkit';
22
22
 
23
23
  export default defineConfig({
24
24
  integrations: [foldkit()],
25
- })
25
+ });
26
26
  ```
27
27
 
28
28
  ## Defining an app
@@ -31,18 +31,20 @@ Use `defineApp` to register a FoldKit app for lazy loading. The loader returns y
31
31
 
32
32
  ```ts
33
33
  // src/apps/counter/app.ts
34
- import { defineApp } from '@opsydyn/astro-foldkit/define-app'
34
+ import { defineApp } from '@opsydyn/astro-foldkit/define-app';
35
35
 
36
- export default defineApp(() => import('./main'))
36
+ export default defineApp(() => import('./main'));
37
37
  ```
38
38
 
39
39
  ```ts
40
40
  // src/apps/counter/main.ts
41
- export const Model = null
42
- export const init = () => [0, []] as const
41
+ export const Model = null;
42
+ export const init = () => [0, []] as const;
43
43
  export const update = (model: number, message: 'Inc' | 'Dec') =>
44
- [message === 'Inc' ? model + 1 : model - 1, []] as const
45
- export const view = (model: number) => ({ /* foldkit view tree */ })
44
+ [message === 'Inc' ? model + 1 : model - 1, []] as const;
45
+ export const view = (model: number) => ({
46
+ /* foldkit view tree */
47
+ });
46
48
  ```
47
49
 
48
50
  Use the app in an Astro page:
@@ -54,33 +56,37 @@ import Counter from '../apps/counter/app'
54
56
  <Counter client:load />
55
57
  ```
56
58
 
59
+ The server renderer emits a deterministic `<div data-foldkit-island="true">` mount shell. It does not load or execute the FoldKit application during SSR; the application is loaded and embedded only by the client renderer. Astro still owns the outer island serialisation and client directive behavior.
60
+
61
+ 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.
62
+
57
63
  ## Passing props
58
64
 
59
65
  `defineApp` accepts a type parameter for the props your FoldKit app expects. This makes the component callable with typed attributes in `.astro` files.
60
66
 
61
67
  ```ts
62
68
  // src/apps/greeting/app.ts
63
- import { defineApp } from '@opsydyn/astro-foldkit/define-app'
64
- import type { Name } from './model'
69
+ import { defineApp } from '@opsydyn/astro-foldkit/define-app';
70
+ import type { Name } from './model';
65
71
 
66
- export default defineApp<{ name: Name }>(() => import('./main'))
72
+ export default defineApp<{ name: Name }>(() => import('./main'));
67
73
  ```
68
74
 
69
75
  Props are forwarded from Astro's `<astro-island>` serialisation into your `init` function. Declare `init` to accept `props: unknown` and validate at the boundary with Effect Schema:
70
76
 
71
77
  ```ts
72
78
  // src/apps/greeting/model.ts
73
- import { Schema } from 'effect'
79
+ import { Schema } from 'effect';
74
80
 
75
- export const Name = Schema.String.pipe(Schema.brand('Name'))
76
- export type Name = typeof Name.Type
81
+ export const Name = Schema.String.pipe(Schema.brand('Name'));
82
+ export type Name = typeof Name.Type;
77
83
 
78
- const Props = Schema.Struct({ name: Name })
84
+ const Props = Schema.Struct({ name: Name });
79
85
 
80
86
  export const init = (props: unknown): readonly [Model, readonly []] => {
81
- const { name } = Schema.decodeUnknownSync(Props)(props)
82
- return [name, []]
83
- }
87
+ const { name } = Schema.decodeUnknownSync(Props)(props);
88
+ return [name, []];
89
+ };
84
90
  ```
85
91
 
86
92
  Pass the branded value from the Astro page:
@@ -167,6 +173,8 @@ The module returned by your loader must export:
167
173
  | `@opsydyn/astro-foldkit` | Default Astro integration (`foldkit()`) |
168
174
  | `@opsydyn/astro-foldkit/define-app` | `defineApp` helper and `AppConfig` type |
169
175
 
176
+ The root entry point also exports the `NavigationConfig`, `NavigationEvent`, and `NavigationPhase` types.
177
+
170
178
  ## Embedding
171
179
 
172
180
  `Runtime.embed` gives you a typed handle to the running program so you can clean it up on unmount and push live data in without remounting. This integration uses `embed` internally — the `astro:unmount` event calls `handle.dispose()` to tear down subscriptions and animation-frame loops when Astro navigates away.
@@ -177,8 +185,8 @@ Ports are typed channels declared in your app's `main.ts`. Pass a `Schema` for e
177
185
 
178
186
  ```ts
179
187
  // src/apps/dashboard/main.ts
180
- import { Port } from 'foldkit'
181
- import { Schema } from 'effect'
188
+ import { Port } from 'foldkit';
189
+ import { Schema } from 'effect';
182
190
 
183
191
  export const ports = {
184
192
  inbound: {
@@ -187,13 +195,52 @@ export const ports = {
187
195
  outbound: {
188
196
  selection: Port.outbound(Schema.NullOr(Schema.String)),
189
197
  },
190
- }
198
+ };
191
199
  ```
192
200
 
201
+ ### Navigation events
202
+
203
+ To receive Astro View Transition lifecycle events, declare an inbound port and a mapper in the app configuration. Astro props remain the input to `init`; navigation events are runtime messages delivered through the configured port.
204
+
205
+ ```ts
206
+ // src/apps/dashboard/main.ts
207
+ import { Schema } from 'effect';
208
+ import { Port } from 'foldkit';
209
+ import type { NavigationEvent } from '@opsydyn/astro-foldkit';
210
+
211
+ export const ports = {
212
+ inbound: {
213
+ navigation: Port.inbound(Schema.Unknown),
214
+ },
215
+ };
216
+
217
+ export const navigation = {
218
+ port: 'navigation',
219
+ map: (event: NavigationEvent) => ({
220
+ _tag: 'Navigated' as const,
221
+ ...event,
222
+ }),
223
+ };
224
+ ```
225
+
226
+ The mapper receives this value shape:
227
+
228
+ ```ts
229
+ type NavigationEvent = {
230
+ readonly phase: 'coldLoad' | 'entered' | 'exited' | 'stayed';
231
+ readonly path: string;
232
+ readonly previousPath: string | null;
233
+ };
234
+ ```
235
+
236
+ 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.
237
+
238
+ 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.
239
+
193
240
  Pass the ports map to `makeApplication` alongside your `init`, `update`, and `view`:
194
241
 
195
242
  ```ts
196
- import { Runtime } from 'foldkit'
243
+ import { Runtime } from 'foldkit';
197
244
 
198
245
  const program = Runtime.makeApplication({
199
246
  Model,
@@ -203,7 +250,7 @@ const program = Runtime.makeApplication({
203
250
  container,
204
251
  devTools: false,
205
252
  ports,
206
- })
253
+ });
207
254
  ```
208
255
 
209
256
  ### Live prop updates
@@ -211,10 +258,10 @@ const program = Runtime.makeApplication({
211
258
  Once embedded, push new data through an inbound port instead of remounting the component. This is particularly useful in Astro View Transition flows where the page shell re-runs but the island should preserve its running state:
212
259
 
213
260
  ```ts
214
- const handle = Runtime.embed(program)
261
+ const handle = Runtime.embed(program);
215
262
 
216
263
  // Called when Astro soft-navigates back to this page with new data
217
- handle.ports.data.send(nextDataPoints)
264
+ handle.ports.data.send(nextDataPoints);
218
265
  ```
219
266
 
220
267
  ### Outbound subscriptions
@@ -224,21 +271,25 @@ Subscribe to outbound ports to react to events inside the program from the host
224
271
  ```ts
225
272
  const unsubscribe = handle.ports.selection.subscribe((id) => {
226
273
  // sync selection state to the URL or another island
227
- history.replaceState({}, '', `?selected=${id ?? ''}`)
228
- })
229
-
230
- element.addEventListener('astro:unmount', () => {
231
- unsubscribe()
232
- handle.dispose()
233
- }, { once: true })
274
+ history.replaceState({}, '', `?selected=${id ?? ''}`);
275
+ });
276
+
277
+ element.addEventListener(
278
+ 'astro:unmount',
279
+ () => {
280
+ unsubscribe();
281
+ handle.dispose();
282
+ },
283
+ { once: true },
284
+ );
234
285
  ```
235
286
 
236
287
  ## Peer dependencies
237
288
 
238
- | Package | Version |
239
- | :-------- | :--------- |
240
- | `astro` | `≥ 5.0` |
241
- | `foldkit` | `≥ 0.108` |
289
+ | Package | Version |
290
+ | :-------- | :-------- |
291
+ | `astro` | `≥ 5.0` |
292
+ | `foldkit` | `≥ 0.126` |
242
293
 
243
294
  ## License
244
295
 
package/dist/client.d.mts CHANGED
@@ -1,8 +1,37 @@
1
- import { n as FoldkitApp } from "./types-CuEHzdpH.mjs";
1
+ import { n as AppConfigShape, r as FoldkitApp } from "./types-BOU7iNnu.mjs";
2
2
 
3
3
  //#region src/client.d.ts
4
- declare const _default: (element: HTMLElement) => (component: FoldkitApp, props: Record<string, unknown>, _slots: Record<string, unknown>, _meta: {
4
+ type EventTargetLike = {
5
+ readonly addEventListener: (type: string, listener: EventListener) => void;
6
+ readonly removeEventListener: (type: string, listener: EventListener) => void;
7
+ };
8
+ type NavigationDocument = EventTargetLike & {
9
+ readonly title: string;
10
+ readonly querySelector: (selector: string) => unknown;
11
+ };
12
+ type EmbedHandle = {
13
+ readonly ports?: Record<string, {
14
+ readonly send: (value: unknown) => unknown;
15
+ }>;
16
+ readonly dispose: () => void;
17
+ };
18
+ type ClientEnvironment = {
19
+ readonly document: NavigationDocument;
20
+ readonly window: {
21
+ readonly location: {
22
+ readonly href: string;
23
+ };
24
+ };
25
+ };
26
+ type ClientRuntime = {
27
+ readonly makeApplication: (config: unknown) => unknown;
28
+ readonly embed: (program: unknown) => EmbedHandle;
29
+ };
30
+ declare function createClientRenderer(runtime?: ClientRuntime, environment?: Partial<ClientEnvironment>): (element: HTMLElement) => <Props extends Record<string, unknown>, Config extends AppConfigShape<Props>>(component: FoldkitApp<Props, Config>, props: Props, _slots: Record<string, unknown>, _meta: {
31
+ client: string;
32
+ }) => Promise<void>;
33
+ declare const _default: (element: HTMLElement) => <Props extends Record<string, unknown>, Config extends AppConfigShape<Props>>(component: FoldkitApp<Props, Config>, props: Props, _slots: Record<string, unknown>, _meta: {
5
34
  client: string;
6
35
  }) => Promise<void>;
7
36
  //#endregion
8
- export { _default as default };
37
+ export { ClientRuntime, createClientRenderer, _default as default };
package/dist/client.mjs CHANGED
@@ -13,20 +13,127 @@ const makeNoMetaView = (view, initialTitle) => (model) => ({
13
13
  title: initialTitle
14
14
  });
15
15
  //#endregion
16
+ //#region src/navigation.ts
17
+ const normalizeNavigationEvent = (phase, currentUrl, previousUrl) => ({
18
+ phase,
19
+ path: new URL(currentUrl, "https://astro-foldkit.invalid").pathname,
20
+ previousPath: previousUrl === null ? null : new URL(previousUrl, "https://astro-foldkit.invalid").pathname
21
+ });
22
+ //#endregion
16
23
  //#region src/client.ts
17
- var client_default = (element) => async (component, props, _slots, _meta) => {
18
- const config = await component.load();
19
- element.id ||= element.getAttribute("uid") ?? crypto.randomUUID();
20
- const baseView = config.view;
21
- const view = shouldSkipMetadata(props) ? makeNoMetaView(baseView, document.title) : baseView;
22
- const program = Runtime.makeApplication({
23
- ...config,
24
- init: () => config.init(props),
25
- view,
26
- container: element
24
+ const listenOnce = (target, type, listener) => {
25
+ let active = true;
26
+ const wrapped = (event) => {
27
+ if (!active) return;
28
+ active = false;
29
+ target.removeEventListener(type, wrapped);
30
+ listener(event);
31
+ };
32
+ target.addEventListener(type, wrapped);
33
+ return () => {
34
+ if (!active) return;
35
+ active = false;
36
+ target.removeEventListener(type, wrapped);
37
+ };
38
+ };
39
+ const seenIslandIdentities = /* @__PURE__ */ new Set();
40
+ const islandIdentity = (element) => element.getAttribute("uid") ?? element.id;
41
+ const newDocumentFrom = (event) => {
42
+ const beforeSwap = event;
43
+ return beforeSwap.newDocument ?? beforeSwap.detail?.newDocument;
44
+ };
45
+ const destinationHrefFrom = (event, fallback) => {
46
+ const href = event.detail?.to?.href;
47
+ return typeof href === "string" ? href : fallback;
48
+ };
49
+ const containsIsland = (document, identity) => {
50
+ if (!document || typeof document.querySelector !== "function") return false;
51
+ return Boolean(document.querySelector(`astro-island[uid="${identity}"]`));
52
+ };
53
+ const attachNavigationBridge = (element, navigation, send, environment) => {
54
+ let active = true;
55
+ let previousUrl = null;
56
+ let initialPageLoad = true;
57
+ let retainedThroughSwap = false;
58
+ const identity = islandIdentity(element);
59
+ const initialPhase = seenIslandIdentities.has(identity) ? "entered" : "coldLoad";
60
+ seenIslandIdentities.add(identity);
61
+ const forward = (phase, href = environment.window.location.href) => {
62
+ if (!active) return;
63
+ const event = normalizeNavigationEvent(phase, href, previousUrl);
64
+ previousUrl = href;
65
+ send(navigation.map(event));
66
+ };
67
+ forward(initialPhase);
68
+ const removePageLoad = () => environment.document.removeEventListener("astro:page-load", onPageLoad);
69
+ const removeBeforeSwap = () => environment.document.removeEventListener("astro:before-swap", onBeforeSwap);
70
+ const onPageLoad = () => {
71
+ if (initialPageLoad) {
72
+ initialPageLoad = false;
73
+ return;
74
+ }
75
+ if (retainedThroughSwap) {
76
+ retainedThroughSwap = false;
77
+ return;
78
+ }
79
+ forward("entered");
80
+ };
81
+ const onBeforeSwap = (event) => {
82
+ retainedThroughSwap = containsIsland(newDocumentFrom(event), identity);
83
+ if (retainedThroughSwap) forward("stayed", destinationHrefFrom(event, environment.window.location.href));
84
+ };
85
+ environment.document.addEventListener("astro:page-load", onPageLoad);
86
+ environment.document.addEventListener("astro:before-swap", onBeforeSwap);
87
+ const removeUnmount = listenOnce(element, "astro:unmount", () => {
88
+ forward("exited");
89
+ active = false;
90
+ removePageLoad();
91
+ removeBeforeSwap();
27
92
  });
28
- const handle = Runtime.embed(program);
29
- element.addEventListener("astro:unmount", () => handle.dispose(), { once: true });
93
+ return () => {
94
+ active = false;
95
+ removePageLoad();
96
+ removeBeforeSwap();
97
+ removeUnmount();
98
+ };
99
+ };
100
+ const defaultRuntime = {
101
+ makeApplication: (config) => Runtime.makeApplication(config),
102
+ embed: (program) => Runtime.embed(program)
30
103
  };
104
+ function createClientRenderer(runtime = defaultRuntime, environment = {}) {
105
+ return (element) => async (component, props, _slots, _meta) => {
106
+ const config = await component.load();
107
+ const clientEnvironment = {
108
+ document: environment.document ?? globalThis.document,
109
+ window: environment.window ?? globalThis.window
110
+ };
111
+ element.id ||= element.getAttribute("uid") ?? crypto.randomUUID();
112
+ const baseView = config.view;
113
+ const view = shouldSkipMetadata(props) ? makeNoMetaView(baseView, clientEnvironment.document.title) : baseView;
114
+ const program = runtime.makeApplication({
115
+ ...config,
116
+ init: () => config.init(props),
117
+ view,
118
+ container: element,
119
+ preserveScroll: true
120
+ });
121
+ const handle = runtime.embed(program);
122
+ let disposed = false;
123
+ let detachNavigation = () => {};
124
+ if (config.navigation) {
125
+ const port = handle.ports?.[config.navigation.port];
126
+ if (port) detachNavigation = attachNavigationBridge(element, config.navigation, (value) => port.send(value), clientEnvironment);
127
+ else console.warn(`FoldKit navigation port "${config.navigation.port}" is not available`);
128
+ }
129
+ element.addEventListener("astro:unmount", () => {
130
+ if (disposed) return;
131
+ disposed = true;
132
+ detachNavigation();
133
+ handle.dispose();
134
+ }, { once: true });
135
+ };
136
+ }
137
+ var client_default = createClientRenderer();
31
138
  //#endregion
32
- export { client_default as default };
139
+ export { createClientRenderer, client_default as default };
@@ -1,6 +1,6 @@
1
- import { n as FoldkitApp, t as AppConfig } from "./types-CuEHzdpH.mjs";
1
+ import { n as AppConfigShape, r as FoldkitApp, t as AppConfig } from "./types-BOU7iNnu.mjs";
2
2
 
3
3
  //#region src/define-app.d.ts
4
- declare function defineApp<Props extends Record<string, unknown> = Record<string, unknown>>(load: () => Promise<AppConfig>): FoldkitApp<Props>;
4
+ declare function defineApp<Props extends Record<string, unknown> = Record<string, unknown>, Config extends AppConfigShape<Props> = AppConfigShape<Props>>(load: () => Promise<Config>): FoldkitApp<Props, Config>;
5
5
  //#endregion
6
6
  export { type AppConfig, type FoldkitApp, defineApp };
package/dist/index.d.mts CHANGED
@@ -1,6 +1,7 @@
1
+ import { n as NavigationEvent, r as NavigationPhase, t as NavigationConfig } from "./navigation-Cy2lnE4G.mjs";
1
2
  import { AstroIntegration } from "astro";
2
3
 
3
4
  //#region src/index.d.ts
4
5
  declare function foldkit(): AstroIntegration;
5
6
  //#endregion
6
- export { foldkit as default };
7
+ export { type NavigationConfig, type NavigationEvent, type NavigationPhase, foldkit as default };
@@ -0,0 +1,13 @@
1
+ //#region src/navigation.d.ts
2
+ type NavigationPhase = 'coldLoad' | 'entered' | 'exited' | 'stayed';
3
+ type NavigationEvent = {
4
+ readonly phase: NavigationPhase;
5
+ readonly path: string;
6
+ readonly previousPath: string | null;
7
+ };
8
+ type NavigationConfig<Value> = {
9
+ readonly port: string;
10
+ readonly map: (event: NavigationEvent) => Value;
11
+ };
12
+ //#endregion
13
+ export { NavigationEvent as n, NavigationPhase as r, NavigationConfig as t };
package/dist/server.d.mts CHANGED
@@ -2,6 +2,9 @@ import { NamedSSRLoadedRendererValue } from "astro";
2
2
 
3
3
  //#region src/server.d.ts
4
4
  declare function check(Component: unknown): Promise<boolean>;
5
+ declare function renderToStaticMarkup(_component: unknown, _props: Record<string, unknown>, _slots: Record<string, string>): Promise<{
6
+ html: string;
7
+ }>;
5
8
  declare const renderer: NamedSSRLoadedRendererValue;
6
9
  //#endregion
7
- export { check, renderer as default };
10
+ export { check, renderer as default, renderToStaticMarkup };
package/dist/server.mjs CHANGED
@@ -2,8 +2,8 @@
2
2
  async function check(Component) {
3
3
  return Component != null && (typeof Component === "object" || typeof Component === "function") && "__foldkit" in Component && Component.__foldkit === true;
4
4
  }
5
- async function renderToStaticMarkup() {
6
- return { html: "" };
5
+ async function renderToStaticMarkup(_component, _props, _slots) {
6
+ return { html: "<div data-foldkit-island=\"true\"></div>" };
7
7
  }
8
8
  const renderer = {
9
9
  name: "astro-foldkit",
@@ -12,4 +12,4 @@ const renderer = {
12
12
  supportsAstroStaticSlot: true
13
13
  };
14
14
  //#endregion
15
- export { check, renderer as default };
15
+ export { check, renderer as default, renderToStaticMarkup };
@@ -0,0 +1,30 @@
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 };
package/package.json CHANGED
@@ -1,14 +1,40 @@
1
1
  {
2
2
  "name": "@opsydyn/astro-foldkit",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Astro integration and renderer for FoldKit.",
5
- "publishConfig": {
6
- "access": "public"
5
+ "keywords": [
6
+ "astro",
7
+ "astro-integration",
8
+ "effect",
9
+ "elm-architecture",
10
+ "foldkit"
11
+ ],
12
+ "bugs": {
13
+ "url": "https://github.com/opsydyn/fold-kit-experiments/issues"
7
14
  },
8
- "sideEffects": false,
15
+ "license": "MIT",
16
+ "author": "Alan P Currie",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/opsydyn/fold-kit-experiments.git",
20
+ "directory": "packages/astro-foldkit"
21
+ },
22
+ "files": [
23
+ "CHANGELOG.md",
24
+ "dist",
25
+ "README.md"
26
+ ],
9
27
  "type": "module",
28
+ "sideEffects": false,
10
29
  "main": "./dist/index.mjs",
11
30
  "types": "./dist/index.d.mts",
31
+ "typesVersions": {
32
+ "*": {
33
+ "define-app": [
34
+ "./dist/define-app.d.mts"
35
+ ]
36
+ }
37
+ },
12
38
  "exports": {
13
39
  ".": {
14
40
  "types": "./dist/index.d.mts",
@@ -19,61 +45,35 @@
19
45
  "import": "./dist/define-app.mjs"
20
46
  }
21
47
  },
22
- "typesVersions": {
23
- "*": {
24
- "define-app": [
25
- "./dist/define-app.d.mts"
26
- ]
27
- }
48
+ "publishConfig": {
49
+ "access": "public"
28
50
  },
29
- "files": [
30
- "CHANGELOG.md",
31
- "dist",
32
- "README.md"
33
- ],
34
51
  "scripts": {
35
52
  "build": "tsdown",
36
53
  "typecheck": "tsc --noEmit",
37
54
  "test": "bun test",
38
55
  "test:unit": "bun test test/unit",
39
56
  "test:integration": "bun test test/integration",
40
- "check": "biome check .",
41
- "check:fix": "biome check --write ."
42
- },
43
- "keywords": [
44
- "astro",
45
- "astro-integration",
46
- "foldkit",
47
- "elm-architecture",
48
- "effect"
49
- ],
50
- "author": "Alan P Currie",
51
- "license": "MIT",
52
- "repository": {
53
- "type": "git",
54
- "url": "git+https://github.com/opsydyn/fold-kit-experiments.git",
55
- "directory": "packages/astro-foldkit"
56
- },
57
- "bugs": {
58
- "url": "https://github.com/opsydyn/fold-kit-experiments/issues"
59
- },
60
- "engines": {
61
- "node": ">=22.0.0"
62
- },
63
- "peerDependencies": {
64
- "astro": ">=5.0.0",
65
- "foldkit": ">=0.108.0"
57
+ "check": "NODE_OPTIONS=\"--experimental-strip-types\" oxlint . && oxfmt --check .",
58
+ "check:fix": "oxfmt . && NODE_OPTIONS=\"--experimental-strip-types\" oxlint --fix ."
66
59
  },
67
60
  "dependencies": {
68
- "@foldkit/vite-plugin": "^0.5.1"
61
+ "@foldkit/vite-plugin": "^0.10.1"
69
62
  },
70
63
  "devDependencies": {
71
64
  "@types/node": "^22.0.0",
72
- "astro": "^7.0.0-alpha.1",
65
+ "astro": "^7.0.6",
73
66
  "bun-types": "^1.3.14",
74
67
  "fast-check": "^4.8.0",
75
- "foldkit": "^0.108.0",
68
+ "foldkit": "^0.128.1",
76
69
  "tsdown": "^0.21.8",
77
70
  "typescript": "^6.0.3"
71
+ },
72
+ "peerDependencies": {
73
+ "astro": ">=5.0.0",
74
+ "foldkit": ">=0.128.1"
75
+ },
76
+ "engines": {
77
+ "node": ">=22.0.0"
78
78
  }
79
79
  }
@@ -1,14 +0,0 @@
1
- //#region src/types.d.ts
2
- type AppConfig = {
3
- readonly Model: unknown;
4
- readonly init: (...args: ReadonlyArray<unknown>) => readonly [unknown, ReadonlyArray<unknown>];
5
- readonly update: (model: any, message: any) => readonly [any, ReadonlyArray<any>];
6
- readonly view: (model: any) => unknown;
7
- };
8
- type FoldkitApp<Props extends Record<string, unknown> = Record<string, unknown>> = {
9
- (props?: Props): void;
10
- readonly __foldkit: true;
11
- readonly load: () => Promise<AppConfig>;
12
- };
13
- //#endregion
14
- export { FoldkitApp as n, AppConfig as t };