@opsydyn/astro-foldkit 0.6.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 CHANGED
@@ -1,24 +1,47 @@
1
1
  # Changelog
2
2
 
3
- ## [0.6.0](https://github.com/opsydyn/fold-kit-experiments/compare/astro-foldkit-v0.5.0...astro-foldkit-v0.6.0) (2026-08-20)
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
4
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)
5
17
 
6
18
  ### Features
7
19
 
8
- * **astro-foldkit:** add server render handoff ([9773a4d](https://github.com/opsydyn/fold-kit-experiments/commit/9773a4d1883c53fa60957368a0125d3b57b7cd24))
9
- * **astro-foldkit:** document opt-in server rendering ([53e9d00](https://github.com/opsydyn/fold-kit-experiments/commit/53e9d004c75c10245d0aa88fc4c412b96c7f2f4c))
10
- * **astro-foldkit:** expose server document resolver ([969dc2f](https://github.com/opsydyn/fold-kit-experiments/commit/969dc2f7e4a679df8b04d60c57783d6b8fb84bd1))
11
- * **astro-foldkit:** formalize define-page contract ([62863c5](https://github.com/opsydyn/fold-kit-experiments/commit/62863c58fa1462d2ecb04bd52cf3d5e0bb444601))
12
- * **astro-foldkit:** hydrate page owners on client ([9f8f76b](https://github.com/opsydyn/fold-kit-experiments/commit/9f8f76bef77ea734006c1faa90defdfdd115d09d))
13
- * support FoldKit 0.136 ([50f4134](https://github.com/opsydyn/fold-kit-experiments/commit/50f4134d7596926fed373408642816736907934f))
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
14
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))
15
38
 
16
39
  ### Bug Fixes
17
40
 
18
- * **astro-foldkit:** align server document tests ([f71c2c2](https://github.com/opsydyn/fold-kit-experiments/commit/f71c2c2ccea94f148e81126b00174375566fa5bb))
19
- * **astro-foldkit:** keep define-page markers inert ([0fb4e54](https://github.com/opsydyn/fold-kit-experiments/commit/0fb4e54dbd3a0b53f21de57f27f3948e13fcf80b))
20
- * **astro-foldkit:** pass stamped root to page hydration ([b3b3ba6](https://github.com/opsydyn/fold-kit-experiments/commit/b3b3ba65c4bb25bb9c2738f82d1148e5e6407679))
21
- * **astro-foldkit:** reject empty server build id ([320bc39](https://github.com/opsydyn/fold-kit-experiments/commit/320bc39a9ca8d610fe60480c0c399a71fc029b51))
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))
22
45
 
23
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)
24
47
 
package/README.md CHANGED
@@ -20,11 +20,12 @@ npm install astro foldkit
20
20
 
21
21
  ## FoldKit compatibility
22
22
 
23
- `@opsydyn/astro-foldkit` is tested with FoldKit `0.148.x` and the matching
24
- `@foldkit/vite-plugin` `0.16.x` line. Applications can define interruptible
25
- work with `Command.define(name, { interrupt: true, ... })` inside their own
26
- update loop; this integration continues to own Astro rendering, hydration,
27
- and lifecycle event delivery.
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
28
+ event delivery.
28
29
 
29
30
  ## Setup
30
31
 
@@ -69,9 +70,10 @@ import type { Document, HtmlBuilder } from 'foldkit/html';
69
70
  type Message = 'Inc' | 'Dec';
70
71
 
71
72
  export const Model = null;
72
- export const init = () => [0, []] as const;
73
- export const update = (model: number, message: Message) =>
74
- [message === 'Inc' ? model + 1 : model - 1, []] as const;
73
+ export const init = () => ({ model: 0 });
74
+ export const update = (model: number, message: Message) => ({
75
+ model: message === 'Inc' ? model + 1 : model - 1,
76
+ });
75
77
  export const view = (model: number, h: HtmlBuilder<Message>): Document => ({
76
78
  title: `Counter: ${model}`,
77
79
  body: h.button([h.OnClick('Inc')], [String(model)]),
@@ -191,6 +193,14 @@ The layout owns the outer `<html>` structure and applies `title`, `lang`,
191
193
  HTML contains one stamped FoldKit root and the browser hydrates that exact root
192
194
  with the serialized Flags payload.
193
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
+
194
204
  ### SSG
195
205
 
196
206
  The same page owner can be prerendered when its props and Flags are universal:
@@ -257,9 +267,9 @@ export type Name = typeof Name.Type;
257
267
 
258
268
  const Props = Schema.Struct({ name: Name });
259
269
 
260
- export const init = (props: unknown): readonly [Model, readonly []] => {
270
+ export const init = (props: unknown): { readonly model: Model } => {
261
271
  const { name } = Schema.decodeUnknownSync(Props)(props);
262
- return [name, []];
272
+ return { model: name };
263
273
  };
264
274
  ```
265
275
 
@@ -340,12 +350,12 @@ The double-decode is intentional: `Schema.decodeSync` at the Astro boundary ensu
340
350
 
341
351
  The module returned by your loader must export:
342
352
 
343
- | Export | Type | Description |
344
- | :------- | :------------------------------------------------------------- | :-------------------------------------------- |
345
- | `Model` | `unknown` | Initial model type marker |
346
- | `init` | `(props: unknown) => readonly [Model, ReadonlyArray<Command>]` | Initial state from props and startup commands |
347
- | `update` | `(model, message) => readonly [Model, ReadonlyArray<Command>]` | Pure state transition |
348
- | `view` | `(model, h: HtmlBuilder<Message>) => Document` | Render with the current render-frame builder |
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 |
349
359
 
350
360
  For `definePage`, `init` receives the validated `Flags` value rather than raw
351
361
  Astro props, and the module must additionally export the runtime `Flags`
@@ -476,7 +486,120 @@ element.addEventListener(
476
486
  | Package | Version |
477
487
  | :-------- | :-------------------- |
478
488
  | `astro` | `≥ 5.0` |
479
- | `foldkit` | `≥ 0.148.0 < 0.149.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.
480
603
 
481
604
  ## License
482
605
 
package/dist/client.d.mts CHANGED
@@ -1,18 +1,26 @@
1
- import { a as FoldkitPage, i as FoldkitApp, n as AppConfigShape, s as PageConfigShape } from "./types-4PDoP5Mh.mjs";
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) => unknown;
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,18 +32,20 @@ type ClientEnvironment = {
24
32
  };
25
33
  };
26
34
  type ClientRuntime = {
27
- readonly makeApplication: (config: unknown) => unknown;
28
- readonly embed: (program: unknown) => EmbedHandle;
29
- readonly hydrate?: (program: unknown, options: {
30
- readonly buildId: string;
31
- }) => unknown;
35
+ readonly makeApplication: (config: RuntimeConfigInput) => RuntimeProgram;
36
+ readonly embed: (program: RuntimeProgram) => EmbedHandle;
37
+ readonly hydrate?: (program: RuntimeProgram, options: RuntimeHydrationOptions) => void;
32
38
  };
33
- type ClientPage = FoldkitPage<Record<string, unknown>, Record<string, unknown>, PageConfigShape<Record<string, unknown>>>;
34
- type ClientComponent<Props extends Record<string, unknown>, Config extends AppConfigShape<Props>> = FoldkitApp<Props, Config> | ClientPage;
35
- declare function createClientRenderer(runtime?: ClientRuntime, environment?: Partial<ClientEnvironment>): (element: HTMLElement) => <Props extends Record<string, unknown>, Config extends AppConfigShape<Props>>(component: ClientComponent<Props, Config>, props: Props, _slots: Record<string, unknown>, _meta: {
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: {
36
46
  client: string;
37
47
  }) => Promise<void>;
38
- declare const _default: (element: HTMLElement) => <Props extends Record<string, unknown>, Config extends AppConfigShape<Props>>(component: ClientComponent<Props, Config>, props: Props, _slots: Record<string, unknown>, _meta: {
48
+ declare const _default: (element: HTMLElement) => <Props extends object, Config extends AppConfigContract<Props>>(component: ClientComponent<Props, Config>, props: Props, _slots: ClientSlots, _meta: {
39
49
  client: string;
40
50
  }) => Promise<void>;
41
51
  //#endregion
package/dist/client.mjs CHANGED
@@ -8,14 +8,18 @@ const findSingleFoldkitRoot = (container) => {
8
8
  return roots[0];
9
9
  };
10
10
  /** Returns true when the `noMeta` prop should suppress document metadata writes. */
11
- const shouldSkipMetadata = (props) => props.noMeta === true || props.noMeta === "";
11
+ const shouldSkipMetadata = (props) => {
12
+ if (!("noMeta" in props)) return false;
13
+ const value = props.noMeta;
14
+ return value === true || value === "";
15
+ };
12
16
  /**
13
17
  * Wraps a foldkit view function so the Document it returns always carries
14
18
  * `initialTitle` as its title, preventing the runtime from overwriting
15
19
  * `document.title` when the app is embedded as an island on a page that
16
20
  * owns its own title.
17
21
  */
18
- const makeNoMetaView = (view, initialTitle) => (model, h) => ({
22
+ const withNoMetaView = (view, initialTitle) => (model, h) => ({
19
23
  ...view(model, h),
20
24
  title: initialTitle
21
25
  });
@@ -50,12 +54,11 @@ const newDocumentFrom = (event) => {
50
54
  return beforeSwap.newDocument ?? beforeSwap.detail?.newDocument;
51
55
  };
52
56
  const destinationHrefFrom = (event, fallback) => {
53
- const href = event.detail?.to?.href;
54
- return typeof href === "string" ? href : fallback;
57
+ return event.detail?.to?.href ?? fallback;
55
58
  };
56
59
  const containsIsland = (document, identity) => {
57
- if (!document || typeof document.querySelector !== "function") return false;
58
- return Boolean(document.querySelector(`astro-island[uid="${identity}"]`));
60
+ if (document === void 0) return false;
61
+ return document.querySelector(`astro-island[uid="${identity}"]`) !== null;
59
62
  };
60
63
  const attachNavigationBridge = (element, navigation, send, environment) => {
61
64
  let active = true;
@@ -112,14 +115,13 @@ const defaultRuntime = {
112
115
  const isPageOwner = (component) => typeof component === "function" && "__foldkitPage" in component && component.__foldkitPage === true;
113
116
  function createClientRenderer(runtime = defaultRuntime, environment = {}) {
114
117
  return (element) => async (component, props, _slots, _meta) => {
115
- const config = await component.load();
116
- const runtimeConfig = config;
117
118
  const clientEnvironment = {
118
119
  document: environment.document ?? globalThis.document,
119
120
  window: environment.window ?? globalThis.window
120
121
  };
121
122
  element.id ||= element.getAttribute("uid") ?? crypto.randomUUID();
122
123
  if (isPageOwner(component)) {
124
+ const config = await component.load();
123
125
  const root = findSingleFoldkitRoot(element);
124
126
  const application = runtime.makeApplication({
125
127
  ...config,
@@ -129,8 +131,10 @@ function createClientRenderer(runtime = defaultRuntime, environment = {}) {
129
131
  runtime.hydrate(application, { buildId: readFoldkitBuildId() });
130
132
  return;
131
133
  }
134
+ const config = await component.load();
135
+ const runtimeConfig = config;
132
136
  const baseView = runtimeConfig.view;
133
- const view = shouldSkipMetadata(props) ? makeNoMetaView(baseView, clientEnvironment.document.title) : baseView;
137
+ const view = shouldSkipMetadata(props) ? withNoMetaView(baseView, clientEnvironment.document.title) : baseView;
134
138
  const program = runtime.makeApplication({
135
139
  ...runtimeConfig,
136
140
  init: () => config.init(props),
@@ -147,10 +151,11 @@ function createClientRenderer(runtime = defaultRuntime, environment = {}) {
147
151
  else console.warn(`FoldKit navigation port "${config.navigation.port}" is not available`);
148
152
  }
149
153
  element.addEventListener("astro:unmount", () => {
150
- if (disposed) return;
151
- disposed = true;
152
- detachNavigation();
153
- handle.dispose();
154
+ if (!disposed) {
155
+ disposed = true;
156
+ detachNavigation();
157
+ handle.dispose();
158
+ }
154
159
  }, { once: true });
155
160
  };
156
161
  }
@@ -1,7 +1,7 @@
1
- import { i as FoldkitApp, n as AppConfigShape, t as AppConfig } from "./types-4PDoP5Mh.mjs";
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 Record<string, unknown> = Record<string, unknown>, Config extends AppConfigShape<Props> = AppConfigShape<Props>>(load: () => Promise<Config>): FoldkitApp<Props, Config>;
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
@@ -1,6 +1,6 @@
1
- import { a as FoldkitPage, c as PageContext, d as PageParams, l as PageFlagsContext, o as PageConfig, r as DefinePageOptions, s as PageConfigShape, u as PageFlagsSchema } from "./types-4PDoP5Mh.mjs";
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
2
 
3
3
  //#region src/define-page.d.ts
4
- declare function definePage<Props extends Record<string, unknown> = Record<string, unknown>, Flags extends Record<string, unknown> = Record<string, unknown>, Config extends PageConfigShape<Flags> = PageConfigShape<Flags>>(load: () => Promise<Config>, options: DefinePageOptions<Props, Flags>): FoldkitPage<Props, Flags, Config>;
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
5
  //#endregion
6
- export { type DefinePageOptions, type FoldkitPage, type PageConfig, type PageConfigShape, type PageContext, type PageFlagsContext, type PageFlagsSchema, type PageParams, definePage };
6
+ export { type DefinePageOptions, type FoldkitPage, type PageConfig, type PageConfigContract, type PageContext, type PageFlagsContext, type PageFlagsSchema, type PageParams, definePage };
@@ -1,4 +1,4 @@
1
- import { a as FoldkitPage, c as PageContext } from "./types-4PDoP5Mh.mjs";
1
+ import { l as PageContext, o as FoldkitPage } from "./types-DDk3MMb7.mjs";
2
2
  import { RenderedApplication } from "foldkit/experimental/server";
3
3
 
4
4
  //#region src/server-document.d.ts
@@ -9,6 +9,6 @@ type ResolvedPageDocument = {
9
9
  readonly canonical?: string;
10
10
  readonly ogUrl?: string;
11
11
  };
12
- declare function resolvePageDocument<Props extends Record<string, unknown> = Record<string, unknown>, Flags extends Record<string, unknown> = Record<string, unknown>>(page: FoldkitPage<Props, Flags>, context: PageContext<Props>): Promise<ResolvedPageDocument>;
12
+ declare function resolvePageDocument<Props extends object = object, Flags extends object = object>(page: FoldkitPage<Props, Flags>, context: PageContext<Props>): Promise<ResolvedPageDocument>;
13
13
  //#endregion
14
14
  export { type ResolvedPageDocument, resolvePageDocument };
@@ -1,8 +1,8 @@
1
- import { s as PageConfigShape } from "./types-4PDoP5Mh.mjs";
1
+ import { c as PageConfigContract } from "./types-DDk3MMb7.mjs";
2
2
  import { RenderedApplication } from "foldkit/experimental/server";
3
3
 
4
4
  //#region src/server-render.d.ts
5
- type ServerConfig<Flags extends Record<string, unknown>> = Pick<PageConfigShape<Flags>, 'Flags' | 'init' | 'view'>;
6
- declare function renderFoldkitServerApplication<Flags extends Record<string, unknown>>(config: ServerConfig<Flags>, flags: Flags, buildId: string): Promise<RenderedApplication>;
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
7
  //#endregion
8
8
  export { renderFoldkitServerApplication };
package/dist/server.d.mts CHANGED
@@ -1,19 +1,28 @@
1
- import { d as PageParams } from "./types-4PDoP5Mh.mjs";
1
+ import { f as PageParams } from "./types-DDk3MMb7.mjs";
2
2
  import { NamedSSRLoadedRendererValue } from "astro";
3
3
 
4
4
  //#region src/server.d.ts
5
+ interface AstroComponentInput {}
6
+ interface AstroProps {}
7
+ interface AstroSlots {}
5
8
  type AstroRendererResult = Readonly<{
6
- createAstro: (props: Record<string, unknown>, slots: Record<string, string>) => unknown;
9
+ createAstro: (props: AstroProps, slots: AstroSlots) => AstroLike<AstroProps>;
7
10
  params: PageParams;
8
11
  request: Request;
9
12
  }>;
10
13
  type RendererThis = Readonly<{
11
14
  result?: AstroRendererResult;
12
15
  }>;
13
- declare function check(Component: unknown): Promise<boolean>;
14
- declare function renderToStaticMarkup(this: RendererThis | void, component: unknown, props: Record<string, unknown>, slots: Record<string, string>): Promise<{
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<{
15
24
  html: string;
16
25
  }>;
17
26
  declare const renderer: NamedSSRLoadedRendererValue;
18
27
  //#endregion
19
- export { check, renderer as default, renderToStaticMarkup };
28
+ export { AstroComponentInput, AstroProps, AstroSlots, check, renderer as default, renderToStaticMarkup };
package/dist/server.mjs CHANGED
@@ -30,8 +30,8 @@ const renderPage = async (result, component, props, slots) => {
30
30
  const flags = component.flags(context);
31
31
  return { html: (await renderFoldkitServerApplication(await component.load(), flags, readFoldkitBuildId())).html };
32
32
  };
33
- async function check(Component) {
34
- return isFoldkitApp(Component) || isFoldkitPage(Component);
33
+ async function check(component) {
34
+ return isFoldkitApp(component) || isFoldkitPage(component);
35
35
  }
36
36
  async function renderToStaticMarkup(component, props, slots) {
37
37
  if (isFoldkitPage(component)) return renderPage(this?.result, component, props, slots);
@@ -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.6.0",
3
+ "version": "0.7.2",
4
4
  "description": "Astro integration and renderer for FoldKit.",
5
5
  "keywords": [
6
6
  "astro",
@@ -72,21 +72,21 @@
72
72
  "check:fix": "oxfmt . && NODE_OPTIONS=\"--experimental-strip-types\" oxlint --fix ."
73
73
  },
74
74
  "dependencies": {
75
- "@foldkit/vite-plugin": "^0.16.0",
76
- "effect": "4.0.0-rc.109"
75
+ "@foldkit/vite-plugin": "^0.26.1",
76
+ "effect": "4.0.0"
77
77
  },
78
78
  "devDependencies": {
79
79
  "@types/node": "^22.0.0",
80
80
  "astro": "7.1.1",
81
81
  "bun-types": "^1.3.14",
82
82
  "fast-check": "^4.8.0",
83
- "foldkit": "^0.148.0",
83
+ "foldkit": "0.166.0",
84
84
  "tsdown": "^0.21.8",
85
85
  "typescript": "^6.0.3"
86
86
  },
87
87
  "peerDependencies": {
88
88
  "astro": ">=5.0.0",
89
- "foldkit": ">=0.148.0 <0.149.0"
89
+ "foldkit": ">=0.165.0 <0.167.0"
90
90
  },
91
91
  "engines": {
92
92
  "node": ">=22.0.0"
@@ -1,55 +0,0 @@
1
- import { t as NavigationConfig } from "./navigation-Cy2lnE4G.mjs";
2
- import { Runtime } from "foldkit";
3
- import { Schema } from "effect";
4
- import { Document } from "foldkit/html";
5
-
6
- //#region src/types.d.ts
7
- type TaggedMessage = {
8
- readonly _tag: string;
9
- };
10
- type CommandBatch = ReadonlyArray<unknown>;
11
- type AppConfigShape<Props extends Record<string, unknown>> = {
12
- readonly Model: unknown;
13
- readonly init: (props: Props) => readonly [unknown, CommandBatch];
14
- readonly update: (model: never, message: never) => readonly [unknown, CommandBatch];
15
- readonly view: (model: never, h: never) => Document;
16
- readonly navigation?: NavigationConfig<unknown>;
17
- readonly ports?: Record<string, unknown>;
18
- };
19
- type AppConfig<Props extends Record<string, unknown> = Record<string, unknown>, Model = unknown, Message extends TaggedMessage = TaggedMessage> = {
20
- readonly Model: unknown;
21
- readonly init: (props: Props) => readonly [Model, CommandBatch];
22
- readonly update: Runtime.ApplicationConfig<Model, Message>['update'];
23
- readonly view: Runtime.ApplicationConfig<Model, Message>['view'];
24
- };
25
- type FoldkitApp<Props extends Record<string, unknown> = Record<string, unknown>, Config extends AppConfigShape<Props> = AppConfigShape<Props>> = {
26
- (props?: Props): void;
27
- readonly __foldkit: true;
28
- readonly load: () => Promise<Config>;
29
- };
30
- type PageParams = Readonly<Record<string, string | undefined>>;
31
- type PageFlagsContext<Props extends Record<string, unknown> = Record<string, unknown>> = {
32
- readonly request: Request;
33
- readonly url: URL;
34
- readonly params: PageParams;
35
- readonly props: Props;
36
- };
37
- type PageContext<Props extends Record<string, unknown> = Record<string, unknown>> = PageFlagsContext<Props>;
38
- type PageFlagsSchema<Flags extends Record<string, unknown>> = Schema.Codec<Flags, any, never, never>;
39
- type PageConfig<Flags extends Record<string, unknown> = Record<string, unknown>, Model = unknown, Message extends TaggedMessage = TaggedMessage> = AppConfig<Flags, Model, Message> & {
40
- readonly Flags: PageFlagsSchema<Flags>;
41
- };
42
- type PageConfigShape<Flags extends Record<string, unknown>> = AppConfigShape<Flags> & {
43
- readonly Flags: PageFlagsSchema<Flags>;
44
- };
45
- type DefinePageOptions<Props extends Record<string, unknown> = Record<string, unknown>, Flags extends Record<string, unknown> = Record<string, unknown>> = {
46
- readonly flags: (context: PageFlagsContext<Props>) => Flags;
47
- };
48
- type FoldkitPage<Props extends Record<string, unknown> = Record<string, unknown>, Flags extends Record<string, unknown> = Record<string, unknown>, Config extends PageConfigShape<Flags> = PageConfigShape<Flags>> = {
49
- (props?: Props): void;
50
- readonly __foldkitPage: true;
51
- readonly load: () => Promise<Config>;
52
- readonly flags: (context: PageFlagsContext<Props>) => Flags;
53
- };
54
- //#endregion
55
- export { FoldkitPage as a, PageContext as c, PageParams as d, FoldkitApp as i, PageFlagsContext as l, AppConfigShape as n, PageConfig as o, DefinePageOptions as r, PageConfigShape as s, AppConfig as t, PageFlagsSchema as u };