@atolljs/islands 0.1.12 → 0.1.13

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/dist/app.d.ts ADDED
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Component-reference app handles — `islandApp(name, app)` stamps an app
3
+ * (React component or `{ imperative }` def) with its registry name so the
4
+ * shell can mount by reference: `<Island app={ChartsApp} props={…}/>` gets
5
+ * prop inference from the component's own signature while the wire still
6
+ * carries a string instance key.
7
+ *
8
+ * Why a stamp instead of `Component.name`: bundlers mangle function names
9
+ * in production builds, so `ChartsApp` → 'charts' can't be derived reliably.
10
+ * The stamp is a plain data property — stable through minification.
11
+ */
12
+ import type { IslandContract } from './contract.js';
13
+ /**
14
+ * Stamp an app with its registry name. The stamped value IS the app — use
15
+ * it directly as the `apps` map value in `definePolyWorker` and as the
16
+ * `app` prop of `<Island/>`.
17
+ *
18
+ * ```ts
19
+ * // worker/apps.tsx
20
+ * export const ChartsApp = islandApp('charts', function ChartsApp(props: ChartsProps) { ... });
21
+ * export const mapApp = islandApp('map', { imperative: buildMap });
22
+ * // worker entry: apps: { charts: ChartsApp, map: mapApp }
23
+ * // shell: <Island app={ChartsApp} props={{ width: 520 }} />
24
+ * ```
25
+ */
26
+ export declare const islandApp: <A>(name: string, app: A) => A & {
27
+ readonly islandAppName: string;
28
+ };
29
+ /**
30
+ * Resolve a mountable app reference to its wire name:
31
+ * string → itself; stamped app → its `islandAppName`; otherwise falls back
32
+ * to displayName/function name (dev-mode convenience — minification may
33
+ * strip it, which is what the stamp exists for). `undefined` when nothing
34
+ * derivable remains.
35
+ */
36
+ export declare const islandAppNameOf: (app: unknown) => string | undefined;
37
+ /**
38
+ * The props an app reference infers: a React component's own props, an
39
+ * imperative def's props parameter, `Record<string, unknown>` for plain
40
+ * string names (the un-typed mount path). Interfaces without index
41
+ * signatures still infer here — serialization happens at mount.
42
+ */
43
+ export type IslandAppProps<A> = A extends IslandContract<infer P, infer _E> ? P : A extends {
44
+ imperative: (doc: never, props: infer P) => void;
45
+ } ? P : A extends (props: infer P) => unknown ? P : Record<string, unknown>;
46
+ /**
47
+ * The structural shape of a mountable app — `never` params so ANY component,
48
+ * imperative def, or framework-adapter output (`{ mount }` — what
49
+ * `reactIslandApp`/`vueIslandApp`/`reactIsland` produce) is assignable.
50
+ * Kept worker-free: importing the real `IslandApp` union from
51
+ * `worker/defineWorkers` would drag worker code into shell bundles.
52
+ */
53
+ export type IslandAppLike = ((props: never) => unknown) | {
54
+ imperative: (doc: never, props: never) => void;
55
+ } | {
56
+ mount: (ctx: never) => unknown;
57
+ } | IslandContract;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Callback-prop marshalling — props cross postMessage as plain data, so a
3
+ * function prop can't travel as-is. `callbackProp(fn)` marks a shell-side
4
+ * function; mount/updateProps marshal markers into `{ __cb: id }` handles
5
+ * (registered in the island's callback table); the worker deserializes
6
+ * them into callables that push an `emit` op back on a reserved name, and
7
+ * the driver dispatches those emits to the table instead of `onEvent`.
8
+ *
9
+ * Fire-and-forget by design: the worker can't await a shell function — the
10
+ * call returns `undefined` in-worker. A callback invoked from a dispatched
11
+ * event lands on the shell in the same postMessage round trip; invoked from
12
+ * a timer/continuation it still routes correctly (instance captured at mount).
13
+ */
14
+ /** Reserved emit-op name — payload `{ id, args }`, consumed by the driver. */
15
+ export declare const CALLBACK_EVENT = "__island_cb__";
16
+ /**
17
+ * Mark a shell function so it can travel as a prop: `mountIsland({ props:
18
+ * { onSave: callbackProp(fn) } })`. In the worker the prop arrives as a
19
+ * callable — invoking it fires `fn(...args)` on the shell asynchronously.
20
+ * The callable returns `undefined` (fire-and-forget — no await channel).
21
+ */
22
+ export declare function callbackProp<Args extends unknown[]>(fn: (...args: Args) => void): (...args: Args) => void;
23
+ /** True for a `callbackProp(fn)` marker — devtools previews show it as '[fn]'. */
24
+ export declare const isCallbackMarker: (v: unknown) => boolean;
25
+ /**
26
+ * Shell side: walk props replacing `callbackProp` markers with `{ __cb: id }`
27
+ * wire handles — `register` assigns each function a table id. Runs before
28
+ * the structured-clone preflight (markers hold a function — uncloneable).
29
+ */
30
+ export declare function marshalCallbackProps(value: unknown, register: (fn: (...args: unknown[]) => void) => number): unknown;
31
+ /**
32
+ * Worker side: walk received props replacing `{ __cb: id }` handles with
33
+ * callables — `make` wraps an id into the emit-backed caller.
34
+ */
35
+ export declare function unmarshalCallbackProps(value: unknown, make: (id: number) => (...args: unknown[]) => void): unknown;