@opsydyn/astro-foldkit 0.2.1 → 0.4.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,52 @@
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.4.0](https://github.com/opsydyn/fold-kit-experiments/compare/astro-foldkit-v0.3.0...astro-foldkit-v0.4.0) (2026-07-18)
4
4
 
5
5
 
6
- ### Bug Fixes
6
+ ### Features
7
7
 
8
- * correct repository url for npm provenance ([723fc7f](https://github.com/opsydyn/fold-kit-experiments/commit/723fc7f932ab6bbfd077b2a49df4904624ff89d2))
8
+ * **astro-foldkit:** support foldkit 0.129 ([345b18c](https://github.com/opsydyn/fold-kit-experiments/commit/345b18c325706ae2aebbe7c1c3a5bded2248e343))
9
9
 
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)
10
+ ## [0.3.0](https://github.com/opsydyn/fold-kit-experiments/compare/astro-foldkit-v0.2.1...astro-foldkit-v0.3.0) (2026-07-15)
11
11
 
12
12
 
13
13
  ### Features
14
14
 
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))
15
+ * **astro-foldkit:** add navigation event contract ([5d4678d](https://github.com/opsydyn/fold-kit-experiments/commit/5d4678d94eac9e5e9f6d6f15e9d4074f1e99df3d))
16
+ * **astro-foldkit:** define stable ssr shell ([e325b89](https://github.com/opsydyn/fold-kit-experiments/commit/e325b89f63515194abf37a85f568dddef4d97855))
17
+ * **astro-foldkit:** forward navigation through inbound ports ([da6ade5](https://github.com/opsydyn/fold-kit-experiments/commit/da6ade569a312b886a5732f1a401a47b065f4f20))
18
+ * **astro-foldkit:** type application contract ([9fbc36d](https://github.com/opsydyn/fold-kit-experiments/commit/9fbc36de9fde1e17b2d29d791d620bc9eddf573a))
19
+
20
+
21
+ ### Bug Fixes
22
+
23
+ * address astro navigation review findings ([ec6faad](https://github.com/opsydyn/fold-kit-experiments/commit/ec6faad38c05d9a1b5d5fe32a710215864fe8fb6))
24
+ * align packages with foldkit 0.128.1 ([ebadeaa](https://github.com/opsydyn/fold-kit-experiments/commit/ebadeaaf29e854660aa2d5c9eba04c017269d075))
25
+ * **astro-foldkit:** make island disposal one-shot ([694e17a](https://github.com/opsydyn/fold-kit-experiments/commit/694e17a32453c6f98561f6f2cb767d3c4c59ab8a))
26
+ * **astro-foldkit:** preserve schema overlay compatibility ([4f4be0b](https://github.com/opsydyn/fold-kit-experiments/commit/4f4be0b5da7bebb7c40acb535727acd8f448a903))
27
+ * **astro-foldkit:** scope navigation to island lifecycle ([e8627d8](https://github.com/opsydyn/fold-kit-experiments/commit/e8627d82cb7a76e4887b7e40121e2d6cf3906347))
28
+ * resolve final astro navigation review findings ([baefd61](https://github.com/opsydyn/fold-kit-experiments/commit/baefd615231832ffca5dc10d18f4919e7672d3f9))
29
+
30
+ ## [0.2.1](https://github.com/opsydyn/fold-kit-experiments/compare/astro-foldkit-v0.2.0...astro-foldkit-v0.2.1) (2026-06-12)
31
+
32
+ ### Bug Fixes
33
+
34
+ - correct repository url for npm provenance ([723fc7f](https://github.com/opsydyn/fold-kit-experiments/commit/723fc7f932ab6bbfd077b2a49df4904624ff89d2))
35
+
36
+ ## [0.2.0](https://github.com/opsydyn/fold-kit-experiments/compare/astro-foldkit-v0.1.0...astro-foldkit-v0.2.0) (2026-06-12)
37
+
38
+ ### Features
24
39
 
40
+ - :arrow_up: bump foldkit to 0.108.0 and migrate runtime API ([7441538](https://github.com/opsydyn/fold-kit-experiments/commit/744153844de11b096e2434e7e678d1149238d1b0))
41
+ - :rotating_light: add Effect language service and linteffect rules ([c2fad21](https://github.com/opsydyn/fold-kit-experiments/commit/c2fad2198616a0df333bb41e8fe0aaa9af9c433c))
42
+ - :sparkles: add prop to remove foldkit meta data optionally ([2ae7989](https://github.com/opsydyn/fold-kit-experiments/commit/2ae798977b7e78706bf329bef394f6e1604e2f73))
43
+ - :sparkles: add props to fold kit ([de04151](https://github.com/opsydyn/fold-kit-experiments/commit/de04151cd0bbe54c1fc4e36af34836fb5c39d4c3))
44
+ - :sparkles: charts updates ([cd052d9](https://github.com/opsydyn/fold-kit-experiments/commit/cd052d9e0bccd7994ec2f4283fb3e2ccff9bc030))
45
+ - :sparkles: foldkit upgrade ([cafc368](https://github.com/opsydyn/fold-kit-experiments/commit/cafc36852352e66c7446e06701eaa87103279ff0))
46
+ - :sparkles: mono repo refactor ([18079de](https://github.com/opsydyn/fold-kit-experiments/commit/18079de599b3848a50b89bfe897ad47f50f43919))
47
+ - :sparkles: prepare package for npm ([3d5850b](https://github.com/opsydyn/fold-kit-experiments/commit/3d5850bf536b2d10ae1483bd108a2eda89de321a))
48
+ - :sparkles: tests for package ([086808d](https://github.com/opsydyn/fold-kit-experiments/commit/086808daafdc5331609fcf34fa1734d7d2d5b28f))
25
49
 
26
50
  ### Bug Fixes
27
51
 
28
- * :white_check_mark: resolve all biome lint errors ([b09399d](https://github.com/opsydyn/fold-kit-experiments/commit/b09399dc0c9e68a2cca0fc53c0a1b59c2b517c90))
52
+ - :white_check_mark: resolve all biome lint errors ([b09399d](https://github.com/opsydyn/fold-kit-experiments/commit/b09399dc0c9e68a2cca0fc53c0a1b59c2b517c90))
package/README.md CHANGED
@@ -12,17 +12,24 @@ npm install @opsydyn/astro-foldkit
12
12
  npm install astro foldkit
13
13
  ```
14
14
 
15
+ ## FoldKit compatibility
16
+
17
+ `@opsydyn/astro-foldkit` requires FoldKit `0.129.0` or later. Applications can
18
+ use `Command.Interruptible` for request cancellation inside their own update
19
+ loop; this integration continues to own only Astro hydration and lifecycle
20
+ event delivery.
21
+
15
22
  ## Setup
16
23
 
17
24
  Add the integration to `astro.config.ts`:
18
25
 
19
26
  ```ts
20
- import { defineConfig } from 'astro/config'
21
- import foldkit from '@opsydyn/astro-foldkit'
27
+ import { defineConfig } from 'astro/config';
28
+ import foldkit from '@opsydyn/astro-foldkit';
22
29
 
23
30
  export default defineConfig({
24
31
  integrations: [foldkit()],
25
- })
32
+ });
26
33
  ```
27
34
 
28
35
  ## Defining an app
@@ -31,18 +38,20 @@ Use `defineApp` to register a FoldKit app for lazy loading. The loader returns y
31
38
 
32
39
  ```ts
33
40
  // src/apps/counter/app.ts
34
- import { defineApp } from '@opsydyn/astro-foldkit/define-app'
41
+ import { defineApp } from '@opsydyn/astro-foldkit/define-app';
35
42
 
36
- export default defineApp(() => import('./main'))
43
+ export default defineApp(() => import('./main'));
37
44
  ```
38
45
 
39
46
  ```ts
40
47
  // src/apps/counter/main.ts
41
- export const Model = null
42
- export const init = () => [0, []] as const
48
+ export const Model = null;
49
+ export const init = () => [0, []] as const;
43
50
  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 */ })
51
+ [message === 'Inc' ? model + 1 : model - 1, []] as const;
52
+ export const view = (model: number) => ({
53
+ /* foldkit view tree */
54
+ });
46
55
  ```
47
56
 
48
57
  Use the app in an Astro page:
@@ -54,33 +63,37 @@ import Counter from '../apps/counter/app'
54
63
  <Counter client:load />
55
64
  ```
56
65
 
66
+ 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.
67
+
68
+ 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
+
57
70
  ## Passing props
58
71
 
59
72
  `defineApp` accepts a type parameter for the props your FoldKit app expects. This makes the component callable with typed attributes in `.astro` files.
60
73
 
61
74
  ```ts
62
75
  // src/apps/greeting/app.ts
63
- import { defineApp } from '@opsydyn/astro-foldkit/define-app'
64
- import type { Name } from './model'
76
+ import { defineApp } from '@opsydyn/astro-foldkit/define-app';
77
+ import type { Name } from './model';
65
78
 
66
- export default defineApp<{ name: Name }>(() => import('./main'))
79
+ export default defineApp<{ name: Name }>(() => import('./main'));
67
80
  ```
68
81
 
69
82
  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
83
 
71
84
  ```ts
72
85
  // src/apps/greeting/model.ts
73
- import { Schema } from 'effect'
86
+ import { Schema } from 'effect';
74
87
 
75
- export const Name = Schema.String.pipe(Schema.brand('Name'))
76
- export type Name = typeof Name.Type
88
+ export const Name = Schema.String.pipe(Schema.brand('Name'));
89
+ export type Name = typeof Name.Type;
77
90
 
78
- const Props = Schema.Struct({ name: Name })
91
+ const Props = Schema.Struct({ name: Name });
79
92
 
80
93
  export const init = (props: unknown): readonly [Model, readonly []] => {
81
- const { name } = Schema.decodeUnknownSync(Props)(props)
82
- return [name, []]
83
- }
94
+ const { name } = Schema.decodeUnknownSync(Props)(props);
95
+ return [name, []];
96
+ };
84
97
  ```
85
98
 
86
99
  Pass the branded value from the Astro page:
@@ -167,6 +180,8 @@ The module returned by your loader must export:
167
180
  | `@opsydyn/astro-foldkit` | Default Astro integration (`foldkit()`) |
168
181
  | `@opsydyn/astro-foldkit/define-app` | `defineApp` helper and `AppConfig` type |
169
182
 
183
+ The root entry point also exports the `NavigationConfig`, `NavigationEvent`, and `NavigationPhase` types.
184
+
170
185
  ## Embedding
171
186
 
172
187
  `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 +192,8 @@ Ports are typed channels declared in your app's `main.ts`. Pass a `Schema` for e
177
192
 
178
193
  ```ts
179
194
  // src/apps/dashboard/main.ts
180
- import { Port } from 'foldkit'
181
- import { Schema } from 'effect'
195
+ import { Port } from 'foldkit';
196
+ import { Schema } from 'effect';
182
197
 
183
198
  export const ports = {
184
199
  inbound: {
@@ -187,13 +202,52 @@ export const ports = {
187
202
  outbound: {
188
203
  selection: Port.outbound(Schema.NullOr(Schema.String)),
189
204
  },
190
- }
205
+ };
191
206
  ```
192
207
 
208
+ ### Navigation events
209
+
210
+ 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.
211
+
212
+ ```ts
213
+ // src/apps/dashboard/main.ts
214
+ import { Schema } from 'effect';
215
+ import { Port } from 'foldkit';
216
+ import type { NavigationEvent } from '@opsydyn/astro-foldkit';
217
+
218
+ export const ports = {
219
+ inbound: {
220
+ navigation: Port.inbound(Schema.Unknown),
221
+ },
222
+ };
223
+
224
+ export const navigation = {
225
+ port: 'navigation',
226
+ map: (event: NavigationEvent) => ({
227
+ _tag: 'Navigated' as const,
228
+ ...event,
229
+ }),
230
+ };
231
+ ```
232
+
233
+ The mapper receives this value shape:
234
+
235
+ ```ts
236
+ type NavigationEvent = {
237
+ readonly phase: 'coldLoad' | 'entered' | 'exited' | 'stayed';
238
+ readonly path: string;
239
+ readonly previousPath: string | null;
240
+ };
241
+ ```
242
+
243
+ 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
+
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.
246
+
193
247
  Pass the ports map to `makeApplication` alongside your `init`, `update`, and `view`:
194
248
 
195
249
  ```ts
196
- import { Runtime } from 'foldkit'
250
+ import { Runtime } from 'foldkit';
197
251
 
198
252
  const program = Runtime.makeApplication({
199
253
  Model,
@@ -203,7 +257,7 @@ const program = Runtime.makeApplication({
203
257
  container,
204
258
  devTools: false,
205
259
  ports,
206
- })
260
+ });
207
261
  ```
208
262
 
209
263
  ### Live prop updates
@@ -211,10 +265,10 @@ const program = Runtime.makeApplication({
211
265
  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
266
 
213
267
  ```ts
214
- const handle = Runtime.embed(program)
268
+ const handle = Runtime.embed(program);
215
269
 
216
270
  // Called when Astro soft-navigates back to this page with new data
217
- handle.ports.data.send(nextDataPoints)
271
+ handle.ports.data.send(nextDataPoints);
218
272
  ```
219
273
 
220
274
  ### Outbound subscriptions
@@ -224,21 +278,25 @@ Subscribe to outbound ports to react to events inside the program from the host
224
278
  ```ts
225
279
  const unsubscribe = handle.ports.selection.subscribe((id) => {
226
280
  // 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 })
281
+ history.replaceState({}, '', `?selected=${id ?? ''}`);
282
+ });
283
+
284
+ element.addEventListener(
285
+ 'astro:unmount',
286
+ () => {
287
+ unsubscribe();
288
+ handle.dispose();
289
+ },
290
+ { once: true },
291
+ );
234
292
  ```
235
293
 
236
294
  ## Peer dependencies
237
295
 
238
- | Package | Version |
239
- | :-------- | :--------- |
240
- | `astro` | `≥ 5.0` |
241
- | `foldkit` | `≥ 0.108` |
296
+ | Package | Version |
297
+ | :-------- | :-------- |
298
+ | `astro` | `≥ 5.0` |
299
+ | `foldkit` | `≥ 0.126` |
242
300
 
243
301
  ## License
244
302
 
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.4.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.129.0",
76
69
  "tsdown": "^0.21.8",
77
70
  "typescript": "^6.0.3"
71
+ },
72
+ "peerDependencies": {
73
+ "astro": ">=5.0.0",
74
+ "foldkit": ">=0.129.0"
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 };