@opsydyn/astro-foldkit 0.13.0 → 1.0.0-next.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 +6 -0
- package/README.md +26 -820
- package/dist/component.d.mts +6 -0
- package/dist/component.mjs +5 -0
- package/dist/index.d.mts +3 -20
- package/dist/index.mjs +3 -188
- package/package.json +17 -32
- package/dist/build-id.d.mts +0 -7
- package/dist/build-id.mjs +0 -8
- package/dist/client.d.mts +0 -52
- package/dist/client.mjs +0 -217
- package/dist/define-app.d.mts +0 -8
- package/dist/define-app.mjs +0 -12
- package/dist/define-page.d.mts +0 -6
- package/dist/define-page.mjs +0 -10
- package/dist/directive-interaction.d.mts +0 -90
- package/dist/directive-interaction.mjs +0 -197
- package/dist/navigation-Cy2lnE4G.d.mts +0 -13
- package/dist/server-public.d.mts +0 -14
- package/dist/server-public.mjs +0 -16
- package/dist/server-render.d.mts +0 -21
- package/dist/server-render.mjs +0 -32
- package/dist/server.d.mts +0 -37
- package/dist/server.mjs +0 -92
- package/dist/types-Dws9AyDS.d.mts +0 -80
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
//#region src/directive-interaction.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* `client:interaction`: hydrate a pre-rendered FoldKit island on the reader's
|
|
4
|
-
* first sign of intent rather than at load or on sight, and replay what they
|
|
5
|
-
* did before it booted.
|
|
6
|
-
*
|
|
7
|
-
* FoldKit's `embed` renders fresh: it replaces the pre-rendered markup instead
|
|
8
|
-
* of adopting it. A click that triggers the download would otherwise be lost,
|
|
9
|
-
* and anything typed or focused before the swap would vanish with the old DOM.
|
|
10
|
-
* So the directive records clicks, edited form values and focus inside the
|
|
11
|
-
* island while the application loads, and replays them onto the matching
|
|
12
|
-
* elements of the first client render. The match is by position: server and
|
|
13
|
-
* client run the same pure `init` and `view` over the same props, so the two
|
|
14
|
-
* trees have the same shape.
|
|
15
|
-
*
|
|
16
|
-
* Astro bundles this module on its own into an inline script, so it imports
|
|
17
|
-
* nothing.
|
|
18
|
-
*/
|
|
19
|
-
/** Options for `client:interaction`. */
|
|
20
|
-
type InteractionOptions = Readonly<{
|
|
21
|
-
/**
|
|
22
|
-
* Also hydrate when a mouse pointer moves over the island. Hover usually
|
|
23
|
-
* comes well before a click, so the application is often ready by then, at
|
|
24
|
-
* the cost of loading for readers who only pass over it.
|
|
25
|
-
*/
|
|
26
|
-
hover?: boolean;
|
|
27
|
-
}>;
|
|
28
|
-
type TreeNode = {
|
|
29
|
-
readonly tagName: string;
|
|
30
|
-
readonly parentElement: TreeNode | null;
|
|
31
|
-
readonly children: ArrayLike<TreeNode>;
|
|
32
|
-
};
|
|
33
|
-
/** Where an element sits under a root: the child index at each level. */
|
|
34
|
-
type Position = Readonly<{
|
|
35
|
-
path: ReadonlyArray<number>;
|
|
36
|
-
tagName: string;
|
|
37
|
-
}>;
|
|
38
|
-
declare const positionOf: (root: TreeNode, target: TreeNode) => Position | undefined;
|
|
39
|
-
/** The element at `position` under `root`, if it is still the same kind of element. */
|
|
40
|
-
declare const resolvePosition: (root: TreeNode, position: Position) => TreeNode | undefined;
|
|
41
|
-
/** One thing the reader did before the application booted. */
|
|
42
|
-
type Step = Readonly<{
|
|
43
|
-
kind: 'click';
|
|
44
|
-
position: Position;
|
|
45
|
-
}> | Readonly<{
|
|
46
|
-
kind: 'value';
|
|
47
|
-
position: Position;
|
|
48
|
-
value: string;
|
|
49
|
-
}>;
|
|
50
|
-
/** What the reader did inside the island before the application booted, in order. */
|
|
51
|
-
type Recording = Readonly<{
|
|
52
|
-
steps: ReadonlyArray<Step>;
|
|
53
|
-
focus: Readonly<{
|
|
54
|
-
position: Position;
|
|
55
|
-
selection?: readonly [number, number] | undefined;
|
|
56
|
-
}> | undefined;
|
|
57
|
-
}>;
|
|
58
|
-
/**
|
|
59
|
-
* Adds a step, folding a run of edits to one field into its latest value: the
|
|
60
|
-
* application needs where the reader got to, not every keystroke.
|
|
61
|
-
*/
|
|
62
|
-
declare const appendStep: (steps: ReadonlyArray<Step>, step: Step) => ReadonlyArray<Step>;
|
|
63
|
-
/**
|
|
64
|
-
* Replays a recording onto the freshly rendered application under `root`, in
|
|
65
|
-
* the order the reader acted, then restores focus. A value reaches the
|
|
66
|
-
* application as `input` and `change` events, as typing would.
|
|
67
|
-
*
|
|
68
|
-
* Steps whose element no longer matches, or is disabled, are skipped: a
|
|
69
|
-
* control the application has not enabled must not receive input the reader
|
|
70
|
-
* could not have given it. The pre-rendered markup never reacted to the
|
|
71
|
-
* reader, so a field the application would have changed between two edits
|
|
72
|
-
* holds the reader's text as typed into the static field.
|
|
73
|
-
*/
|
|
74
|
-
declare const replay: (root: TreeNode, recording: Recording) => void;
|
|
75
|
-
/**
|
|
76
|
-
* The application root that replaced `oldRoot`. FoldKit renders its root in
|
|
77
|
-
* place of the mount element; should it ever render inside the mount instead,
|
|
78
|
-
* the mount is still in its slot and the root is its first child.
|
|
79
|
-
*/
|
|
80
|
-
declare const currentRoot: <Node extends TreeNode>(slot: Readonly<{
|
|
81
|
-
parent: Node;
|
|
82
|
-
index: number;
|
|
83
|
-
mount: Node;
|
|
84
|
-
}>) => Node | undefined;
|
|
85
|
-
type DirectiveLoad = () => Promise<() => Promise<void>>;
|
|
86
|
-
declare const interactionDirective: (load: DirectiveLoad, options: {
|
|
87
|
-
readonly value: unknown;
|
|
88
|
-
}, el: HTMLElement) => void;
|
|
89
|
-
//#endregion
|
|
90
|
-
export { InteractionOptions, Position, Recording, Step, TreeNode, appendStep, currentRoot, interactionDirective as default, positionOf, replay, resolvePosition };
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
//#region src/directive-interaction.ts
|
|
2
|
-
const positionOf = (root, target) => {
|
|
3
|
-
const path = [];
|
|
4
|
-
let node = target;
|
|
5
|
-
while (node !== root) {
|
|
6
|
-
const parent = node.parentElement;
|
|
7
|
-
if (parent === null) return void 0;
|
|
8
|
-
path.unshift(Array.prototype.indexOf.call(parent.children, node));
|
|
9
|
-
node = parent;
|
|
10
|
-
}
|
|
11
|
-
return {
|
|
12
|
-
path,
|
|
13
|
-
tagName: target.tagName
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
/** The element at `position` under `root`, if it is still the same kind of element. */
|
|
17
|
-
const resolvePosition = (root, position) => {
|
|
18
|
-
let node = root;
|
|
19
|
-
for (const index of position.path) {
|
|
20
|
-
node = node.children[index];
|
|
21
|
-
if (node === void 0) return void 0;
|
|
22
|
-
}
|
|
23
|
-
return node.tagName === position.tagName ? node : void 0;
|
|
24
|
-
};
|
|
25
|
-
const samePosition = (a, b) => a.tagName === b.tagName && a.path.length === b.path.length && a.path.every((index, level) => index === b.path[level]);
|
|
26
|
-
/**
|
|
27
|
-
* Adds a step, folding a run of edits to one field into its latest value: the
|
|
28
|
-
* application needs where the reader got to, not every keystroke.
|
|
29
|
-
*/
|
|
30
|
-
const appendStep = (steps, step) => {
|
|
31
|
-
const last = steps.at(-1);
|
|
32
|
-
return step.kind === "value" && last?.kind === "value" && samePosition(last.position, step.position) ? [...steps.slice(0, -1), step] : [...steps, step];
|
|
33
|
-
};
|
|
34
|
-
const dispatch = (target, type) => {
|
|
35
|
-
target.dispatchEvent(new Event(type, { bubbles: true }));
|
|
36
|
-
};
|
|
37
|
-
const replayStep = (root, step) => {
|
|
38
|
-
const target = resolvePosition(root, step.position);
|
|
39
|
-
if (target === void 0 || target.disabled === true) return;
|
|
40
|
-
if (step.kind === "click") return target.click();
|
|
41
|
-
if (target.value === step.value) return;
|
|
42
|
-
target.value = step.value;
|
|
43
|
-
dispatch(target, "input");
|
|
44
|
-
dispatch(target, "change");
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* Replays a recording onto the freshly rendered application under `root`, in
|
|
48
|
-
* the order the reader acted, then restores focus. A value reaches the
|
|
49
|
-
* application as `input` and `change` events, as typing would.
|
|
50
|
-
*
|
|
51
|
-
* Steps whose element no longer matches, or is disabled, are skipped: a
|
|
52
|
-
* control the application has not enabled must not receive input the reader
|
|
53
|
-
* could not have given it. The pre-rendered markup never reacted to the
|
|
54
|
-
* reader, so a field the application would have changed between two edits
|
|
55
|
-
* holds the reader's text as typed into the static field.
|
|
56
|
-
*/
|
|
57
|
-
const replay = (root, recording) => {
|
|
58
|
-
for (const step of recording.steps) replayStep(root, step);
|
|
59
|
-
if (recording.focus === void 0) return;
|
|
60
|
-
const target = resolvePosition(root, recording.focus.position);
|
|
61
|
-
if (target === void 0 || target.disabled === true) return;
|
|
62
|
-
target.focus({ preventScroll: true });
|
|
63
|
-
const selection = recording.focus.selection;
|
|
64
|
-
if (selection !== void 0) target.setSelectionRange?.(selection[0], selection[1]);
|
|
65
|
-
};
|
|
66
|
-
const triggers = [
|
|
67
|
-
"pointerdown",
|
|
68
|
-
"focusin",
|
|
69
|
-
"keydown"
|
|
70
|
-
];
|
|
71
|
-
const recorded = [
|
|
72
|
-
"click",
|
|
73
|
-
"focusin",
|
|
74
|
-
"focusout",
|
|
75
|
-
"input",
|
|
76
|
-
"change",
|
|
77
|
-
"submit"
|
|
78
|
-
];
|
|
79
|
-
/** Fields whose state a click changes, so replaying the click carries it. */
|
|
80
|
-
const checkable = new Set(["checkbox", "radio"]);
|
|
81
|
-
/** The control a click on `target` will be forwarded to, when it is inside a label for another element. */
|
|
82
|
-
const labelledControl = (target) => {
|
|
83
|
-
const control = target.closest("label")?.control ?? null;
|
|
84
|
-
return control === null || control === target || control.contains(target) ? null : control;
|
|
85
|
-
};
|
|
86
|
-
/** The caret or selection of a text field, if it has one. */
|
|
87
|
-
const selectionOf = (element) => {
|
|
88
|
-
if (!(element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement)) return void 0;
|
|
89
|
-
const { selectionStart, selectionEnd } = element;
|
|
90
|
-
return selectionStart === null || selectionEnd === null ? void 0 : [selectionStart, selectionEnd];
|
|
91
|
-
};
|
|
92
|
-
/**
|
|
93
|
-
* The application root that replaced `oldRoot`. FoldKit renders its root in
|
|
94
|
-
* place of the mount element; should it ever render inside the mount instead,
|
|
95
|
-
* the mount is still in its slot and the root is its first child.
|
|
96
|
-
*/
|
|
97
|
-
const currentRoot = (slot) => {
|
|
98
|
-
const occupant = slot.parent.children[slot.index];
|
|
99
|
-
return occupant === slot.mount ? slot.mount.children[0] : occupant;
|
|
100
|
-
};
|
|
101
|
-
/** Resolves once `oldRoot` has left the document, which is when the client render replaced it. */
|
|
102
|
-
const replacement = (el, oldRoot) => new Promise((resolve) => {
|
|
103
|
-
if (!oldRoot.isConnected) return resolve();
|
|
104
|
-
const observer = new MutationObserver(() => {
|
|
105
|
-
if (oldRoot.isConnected) return;
|
|
106
|
-
observer.disconnect();
|
|
107
|
-
resolve();
|
|
108
|
-
});
|
|
109
|
-
observer.observe(el, {
|
|
110
|
-
childList: true,
|
|
111
|
-
subtree: true
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
const interactionDirective = (load, options, el) => {
|
|
115
|
-
const { value } = options;
|
|
116
|
-
const hover = value instanceof Object && "hover" in value && value.hover === true;
|
|
117
|
-
const mount = el.querySelector("[data-foldkit-island]");
|
|
118
|
-
const oldRoot = mount?.firstElementChild ?? null;
|
|
119
|
-
const parent = mount?.parentElement ?? null;
|
|
120
|
-
if (mount === null || oldRoot === null || parent === null) {
|
|
121
|
-
load().then((hydrate) => hydrate());
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
const slot = {
|
|
125
|
-
parent,
|
|
126
|
-
index: Array.prototype.indexOf.call(parent.children, mount),
|
|
127
|
-
mount
|
|
128
|
-
};
|
|
129
|
-
let steps = [];
|
|
130
|
-
let focused;
|
|
131
|
-
let started = false;
|
|
132
|
-
const record = (event) => {
|
|
133
|
-
const target = event.target;
|
|
134
|
-
if (!(target instanceof Element)) return;
|
|
135
|
-
const position = positionOf(oldRoot, target);
|
|
136
|
-
if (position === void 0) return;
|
|
137
|
-
switch (event.type) {
|
|
138
|
-
case "click":
|
|
139
|
-
if (target.closest("a[href]") !== null) return;
|
|
140
|
-
if (labelledControl(target) !== null) return;
|
|
141
|
-
steps = appendStep(steps, {
|
|
142
|
-
kind: "click",
|
|
143
|
-
position
|
|
144
|
-
});
|
|
145
|
-
return;
|
|
146
|
-
case "focusin":
|
|
147
|
-
focused = {
|
|
148
|
-
element: target,
|
|
149
|
-
position
|
|
150
|
-
};
|
|
151
|
-
return;
|
|
152
|
-
case "focusout":
|
|
153
|
-
setTimeout(() => {
|
|
154
|
-
if (focused?.element === target && target.isConnected) focused = void 0;
|
|
155
|
-
});
|
|
156
|
-
return;
|
|
157
|
-
case "submit":
|
|
158
|
-
event.preventDefault();
|
|
159
|
-
return;
|
|
160
|
-
default: if (target instanceof HTMLInputElement && !checkable.has(target.type) || target instanceof HTMLTextAreaElement || target instanceof HTMLSelectElement) steps = appendStep(steps, {
|
|
161
|
-
kind: "value",
|
|
162
|
-
position,
|
|
163
|
-
value: target.value
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
const stopRecording = () => {
|
|
168
|
-
for (const type of recorded) el.removeEventListener(type, record, true);
|
|
169
|
-
};
|
|
170
|
-
const replayRecording = () => {
|
|
171
|
-
const recording = {
|
|
172
|
-
steps,
|
|
173
|
-
focus: focused === void 0 || focused.element.isConnected ? void 0 : {
|
|
174
|
-
position: focused.position,
|
|
175
|
-
selection: selectionOf(focused.element)
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
const root = currentRoot(slot);
|
|
179
|
-
if (root !== void 0) replay(root, recording);
|
|
180
|
-
};
|
|
181
|
-
const hydrateAndReplay = () => {
|
|
182
|
-
const swapped = replacement(el, oldRoot);
|
|
183
|
-
return load().then((hydrate) => hydrate()).then(() => swapped).finally(stopRecording).then(replayRecording);
|
|
184
|
-
};
|
|
185
|
-
const start = (event) => {
|
|
186
|
-
if (event.type === "pointerover" && event.pointerType !== "mouse") return;
|
|
187
|
-
if (started) return;
|
|
188
|
-
started = true;
|
|
189
|
-
for (const type of [...triggers, "pointerover"]) el.removeEventListener(type, start, true);
|
|
190
|
-
hydrateAndReplay();
|
|
191
|
-
};
|
|
192
|
-
for (const type of recorded) el.addEventListener(type, record, true);
|
|
193
|
-
for (const type of triggers) el.addEventListener(type, start, true);
|
|
194
|
-
if (hover) el.addEventListener("pointerover", start, true);
|
|
195
|
-
};
|
|
196
|
-
//#endregion
|
|
197
|
-
export { appendStep, currentRoot, interactionDirective as default, positionOf, replay, resolvePosition };
|
|
@@ -1,13 +0,0 @@
|
|
|
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-public.d.mts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { s as FoldkitPage, u as PageContext } from "./types-Dws9AyDS.mjs";
|
|
2
|
-
import { RenderedApplication } from "foldkit/experimental/server";
|
|
3
|
-
|
|
4
|
-
//#region src/server-document.d.ts
|
|
5
|
-
type ResolvedPageDocument = {
|
|
6
|
-
readonly title: string;
|
|
7
|
-
readonly lang?: string;
|
|
8
|
-
readonly dir?: 'ltr' | 'rtl' | 'auto';
|
|
9
|
-
readonly canonical?: string;
|
|
10
|
-
readonly ogUrl?: string;
|
|
11
|
-
};
|
|
12
|
-
declare function resolvePageDocument<Props extends object = object, Flags extends object = object>(page: FoldkitPage<Props, Flags>, context: PageContext<Props>): Promise<ResolvedPageDocument>;
|
|
13
|
-
//#endregion
|
|
14
|
-
export { type ResolvedPageDocument, resolvePageDocument };
|
package/dist/server-public.mjs
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { readFoldkitBuildId } from "./build-id.mjs";
|
|
2
|
-
import { renderFoldkitServerApplication } from "./server-render.mjs";
|
|
3
|
-
//#region src/server-document.ts
|
|
4
|
-
const setOptional = (document, key, value) => value === void 0 ? document : {
|
|
5
|
-
...document,
|
|
6
|
-
[key]: value
|
|
7
|
-
};
|
|
8
|
-
const mapRenderedApplicationDocument = (rendered) => {
|
|
9
|
-
return setOptional(setOptional(setOptional(setOptional({ title: rendered.title }, "lang", rendered.lang), "dir", rendered.dir), "canonical", rendered.canonical), "ogUrl", rendered.ogUrl);
|
|
10
|
-
};
|
|
11
|
-
async function resolvePageDocument(page, context) {
|
|
12
|
-
const flags = page.flags(context);
|
|
13
|
-
return mapRenderedApplicationDocument(await renderFoldkitServerApplication(await page.load(), flags, readFoldkitBuildId()));
|
|
14
|
-
}
|
|
15
|
-
//#endregion
|
|
16
|
-
export { resolvePageDocument };
|
package/dist/server-render.d.mts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { l as PageConfigContract, n as AppConfigContract } from "./types-Dws9AyDS.mjs";
|
|
2
|
-
import { RenderedApplication } from "foldkit/experimental/server";
|
|
3
|
-
|
|
4
|
-
//#region src/server-render.d.ts
|
|
5
|
-
type ServerConfig<Flags extends object> = Pick<PageConfigContract<Flags>, 'Flags' | 'init' | 'view'>;
|
|
6
|
-
declare function renderFoldkitServerApplication<Flags extends object>(config: ServerConfig<Flags>, flags: Flags, buildId?: string): Promise<RenderedApplication>;
|
|
7
|
-
type IslandConfig<Props extends object> = Pick<AppConfigContract<Props>, 'init' | 'view'>;
|
|
8
|
-
/**
|
|
9
|
-
* Renders an island's first paint as static markup.
|
|
10
|
-
*
|
|
11
|
-
* The island declares no Flags, and needs none: `renderToString` accepts a
|
|
12
|
-
* config whose `init` takes no argument, so the props Astro already serialises
|
|
13
|
-
* for the client are closed over here. `isHydratable: false` is what keeps
|
|
14
|
-
* this safe beside other islands — the render carries no root stamp, so it
|
|
15
|
-
* cannot collide with another island's, and `Runtime.hydrate`'s one-root rule
|
|
16
|
-
* never applies because nothing hydrates this markup. The client's existing
|
|
17
|
-
* `embed` replaces it on boot.
|
|
18
|
-
*/
|
|
19
|
-
declare function renderFoldkitIslandMarkup<Props extends object>(config: IslandConfig<Props>, props: Props): Promise<RenderedApplication>;
|
|
20
|
-
//#endregion
|
|
21
|
-
export { renderFoldkitIslandMarkup, renderFoldkitServerApplication };
|
package/dist/server-render.mjs
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { Effect } from "effect";
|
|
2
|
-
import { renderToString } from "foldkit/experimental/server";
|
|
3
|
-
//#region src/server-render.ts
|
|
4
|
-
async function renderFoldkitServerApplication(config, flags, buildId) {
|
|
5
|
-
return await Effect.runPromise(renderToString({
|
|
6
|
-
Flags: config.Flags,
|
|
7
|
-
init: config.init,
|
|
8
|
-
view: config.view
|
|
9
|
-
}, {
|
|
10
|
-
flags,
|
|
11
|
-
buildId
|
|
12
|
-
}));
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Renders an island's first paint as static markup.
|
|
16
|
-
*
|
|
17
|
-
* The island declares no Flags, and needs none: `renderToString` accepts a
|
|
18
|
-
* config whose `init` takes no argument, so the props Astro already serialises
|
|
19
|
-
* for the client are closed over here. `isHydratable: false` is what keeps
|
|
20
|
-
* this safe beside other islands — the render carries no root stamp, so it
|
|
21
|
-
* cannot collide with another island's, and `Runtime.hydrate`'s one-root rule
|
|
22
|
-
* never applies because nothing hydrates this markup. The client's existing
|
|
23
|
-
* `embed` replaces it on boot.
|
|
24
|
-
*/
|
|
25
|
-
async function renderFoldkitIslandMarkup(config, props) {
|
|
26
|
-
return await Effect.runPromise(renderToString({
|
|
27
|
-
init: () => config.init(props),
|
|
28
|
-
view: config.view
|
|
29
|
-
}, { isHydratable: false }));
|
|
30
|
-
}
|
|
31
|
-
//#endregion
|
|
32
|
-
export { renderFoldkitIslandMarkup, renderFoldkitServerApplication };
|
package/dist/server.d.mts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { p as PageParams } from "./types-Dws9AyDS.mjs";
|
|
2
|
-
import { NamedSSRLoadedRendererValue } from "astro";
|
|
3
|
-
|
|
4
|
-
//#region src/server.d.ts
|
|
5
|
-
interface AstroComponentInput {}
|
|
6
|
-
interface AstroProps {}
|
|
7
|
-
interface AstroSlots {}
|
|
8
|
-
type AstroRendererResult = Readonly<{
|
|
9
|
-
createAstro: (props: AstroProps, slots: AstroSlots) => AstroLike<AstroProps>;
|
|
10
|
-
params: PageParams;
|
|
11
|
-
request: Request;
|
|
12
|
-
}>;
|
|
13
|
-
type RendererThis = Readonly<{
|
|
14
|
-
result?: AstroRendererResult;
|
|
15
|
-
}>;
|
|
16
|
-
type AstroLike<Props extends AstroProps> = Readonly<{
|
|
17
|
-
request?: Request;
|
|
18
|
-
url?: URL;
|
|
19
|
-
params?: PageParams;
|
|
20
|
-
props?: Props;
|
|
21
|
-
}>;
|
|
22
|
-
/**
|
|
23
|
-
* What Astro passes a renderer about the component it is rendering: its name,
|
|
24
|
-
* and the client directive it carries, if any. A `client:only` component never
|
|
25
|
-
* reaches the renderer, so it never appears here.
|
|
26
|
-
*/
|
|
27
|
-
type AstroRenderMetadata = Readonly<{
|
|
28
|
-
displayName?: string;
|
|
29
|
-
hydrate?: string;
|
|
30
|
-
}>;
|
|
31
|
-
declare function check<Component>(component: Component): Promise<boolean>;
|
|
32
|
-
declare function renderToStaticMarkup(this: RendererThis | void, component: AstroComponentInput, props: AstroProps, slots: AstroSlots, metadata?: AstroRenderMetadata): Promise<{
|
|
33
|
-
html: string;
|
|
34
|
-
}>;
|
|
35
|
-
declare const renderer: NamedSSRLoadedRendererValue;
|
|
36
|
-
//#endregion
|
|
37
|
-
export { AstroComponentInput, AstroProps, AstroRenderMetadata, AstroSlots, check, renderer as default, renderToStaticMarkup };
|
package/dist/server.mjs
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { readFoldkitBuildId } from "./build-id.mjs";
|
|
2
|
-
import { renderFoldkitIslandMarkup, renderFoldkitServerApplication } from "./server-render.mjs";
|
|
3
|
-
//#region src/server.ts
|
|
4
|
-
const claimedPageResults = /* @__PURE__ */ new WeakSet();
|
|
5
|
-
const isObjectOrFunction = (value) => value != null && (typeof value === "object" || typeof value === "function");
|
|
6
|
-
const isFoldkitApp = (value) => isObjectOrFunction(value) && "__foldkit" in value && value.__foldkit === true;
|
|
7
|
-
const isFoldkitPage = (value) => isObjectOrFunction(value) && "__foldkitPage" in value && value.__foldkitPage === true;
|
|
8
|
-
const claimPageResult = (result) => {
|
|
9
|
-
if (claimedPageResults.has(result)) throw new Error("Astro FoldKit server rendering supports exactly one FoldKit page owner per result.");
|
|
10
|
-
claimedPageResults.add(result);
|
|
11
|
-
};
|
|
12
|
-
const requireResult = (result) => {
|
|
13
|
-
if (result === void 0) throw new Error("Astro FoldKit server rendering requires the Astro renderer result.");
|
|
14
|
-
return result;
|
|
15
|
-
};
|
|
16
|
-
const pageContext = (result, props, slots) => {
|
|
17
|
-
const astro = result.createAstro(props, slots);
|
|
18
|
-
const request = astro.request ?? result.request;
|
|
19
|
-
return {
|
|
20
|
-
request,
|
|
21
|
-
url: astro.url ?? new URL(request.url),
|
|
22
|
-
params: astro.params ?? result.params,
|
|
23
|
-
props: astro.props ?? props
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
const renderPage = async (result, component, props, slots) => {
|
|
27
|
-
const currentResult = requireResult(result);
|
|
28
|
-
claimPageResult(currentResult);
|
|
29
|
-
const context = pageContext(currentResult, props, slots);
|
|
30
|
-
const flags = component.flags(context);
|
|
31
|
-
return { html: (await renderFoldkitServerApplication(await component.load(), flags, readFoldkitBuildId())).html };
|
|
32
|
-
};
|
|
33
|
-
/** The mount the client's `findIslandMount` resolves, empty or filled. */
|
|
34
|
-
const islandMount = (markup) => `<div data-foldkit-island="true">${markup}</div>`;
|
|
35
|
-
const isPrerenderedApp = (value) => isFoldkitApp(value) && value.prerender === true;
|
|
36
|
-
/**
|
|
37
|
-
* Renders an opted-in island inside the mount the client already resolves.
|
|
38
|
-
*
|
|
39
|
-
* The markup goes inside the mount rather than beside it, because
|
|
40
|
-
* `findIslandMount` resolves that element as the runtime's container and the
|
|
41
|
-
* runtime replaces its contents on boot. Server and client run the same pure
|
|
42
|
-
* `init` and `view` over the same props, so the replacement is the same markup
|
|
43
|
-
* and the swap is invisible.
|
|
44
|
-
*/
|
|
45
|
-
const renderIsland = async (component, props) => {
|
|
46
|
-
return { html: islandMount((await renderFoldkitIslandMarkup(await component.load(), props)).html) };
|
|
47
|
-
};
|
|
48
|
-
const warnedIslands = /* @__PURE__ */ new Set();
|
|
49
|
-
const warnOnce = (key, message) => {
|
|
50
|
-
if (warnedIslands.has(key)) return;
|
|
51
|
-
warnedIslands.add(key);
|
|
52
|
-
console.warn(message);
|
|
53
|
-
};
|
|
54
|
-
/**
|
|
55
|
-
* Names the ways an island that is not pre-rendered silently misbehaves. Two
|
|
56
|
-
* leave it as the empty mount shell forever.
|
|
57
|
-
*
|
|
58
|
-
* With no client directive, nothing ever replaces the shell, so the island
|
|
59
|
-
* renders nothing and ships nothing. With `client:visible`, Astro observes the
|
|
60
|
-
* island's children because `astro-island` is `display: contents`; the empty
|
|
61
|
-
* mount measures 0x0, a zero-area target never intersects, and the island never
|
|
62
|
-
* hydrates. Other directives fire whatever the island's size.
|
|
63
|
-
*
|
|
64
|
-
* `client:interaction` on a shell does not fail, but it cannot do its job: it
|
|
65
|
-
* waits for input on markup the shell does not have, so it hydrates at once.
|
|
66
|
-
*
|
|
67
|
-
* Both warn rather than fail: the shell is still valid output, and a warning
|
|
68
|
-
* should never be what breaks a build.
|
|
69
|
-
*/
|
|
70
|
-
const diagnoseShellIsland = (metadata) => {
|
|
71
|
-
const name = metadata?.displayName ?? "A FoldKit island";
|
|
72
|
-
if (metadata?.hydrate === void 0) warnOnce(`${name}:no-directive`, `[astro-foldkit] ${name} has no client directive and is not pre-rendered, so it renders an empty mount and ships no JavaScript: it will never display anything. Pass { prerender: true } to lazyApp to render it as static HTML, or add a client directive.`);
|
|
73
|
-
else if (metadata.hydrate === "interaction") warnOnce(`${name}:interaction`, `[astro-foldkit] ${name} uses client:interaction but is not pre-rendered. It waits for the reader to interact with the island's markup, and an empty FoldKit mount has none, so it hydrates at once, as client:load would. Pass { prerender: true } to lazyApp, or use client:load or client:idle.`);
|
|
74
|
-
else if (metadata.hydrate === "visible") warnOnce(`${name}:visible`, `[astro-foldkit] ${name} uses client:visible but is not pre-rendered. Astro observes an island's children, and an empty FoldKit mount measures 0x0, so it never intersects and the island never hydrates. Pass { prerender: true } to lazyApp, or use client:load or client:idle.`);
|
|
75
|
-
};
|
|
76
|
-
async function check(component) {
|
|
77
|
-
return isFoldkitApp(component) || isFoldkitPage(component);
|
|
78
|
-
}
|
|
79
|
-
async function renderToStaticMarkup(component, props, slots, metadata) {
|
|
80
|
-
if (isFoldkitPage(component)) return renderPage(this?.result, component, props, slots);
|
|
81
|
-
if (isPrerenderedApp(component)) return renderIsland(component, props);
|
|
82
|
-
diagnoseShellIsland(metadata);
|
|
83
|
-
return { html: islandMount("") };
|
|
84
|
-
}
|
|
85
|
-
const renderer = {
|
|
86
|
-
name: "astro-foldkit",
|
|
87
|
-
check,
|
|
88
|
-
renderToStaticMarkup,
|
|
89
|
-
supportsAstroStaticSlot: true
|
|
90
|
-
};
|
|
91
|
-
//#endregion
|
|
92
|
-
export { check, renderer as default, renderToStaticMarkup };
|
|
@@ -1,80 +0,0 @@
|
|
|
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 DefineAppOptions = {
|
|
33
|
-
/**
|
|
34
|
-
* Render this island's markup on the server for first paint.
|
|
35
|
-
*
|
|
36
|
-
* The markup is static: nothing hydrates it, and the client replaces it when
|
|
37
|
-
* the island boots, exactly as it replaces the empty mount today. It carries
|
|
38
|
-
* no hydration stamp and no Flags payload, so any number of pre-rendered
|
|
39
|
-
* islands may share a document — unlike a `definePage` owner, of which a
|
|
40
|
-
* document may hold one.
|
|
41
|
-
*
|
|
42
|
-
* `init` and `view` therefore run on the server. An island whose `init`
|
|
43
|
-
* touches a browser-only resource must leave this off; opting in and failing
|
|
44
|
-
* fails the render rather than quietly serving the empty mount, because an
|
|
45
|
-
* author who asked for markup should be told they did not get it.
|
|
46
|
-
*/
|
|
47
|
-
readonly prerender?: boolean;
|
|
48
|
-
};
|
|
49
|
-
type FoldkitApp<Props extends object = EmptyProps, Config extends AppConfigContract<Props> = AppConfigContract<Props>> = {
|
|
50
|
-
(props?: Props): void;
|
|
51
|
-
readonly __foldkit: true;
|
|
52
|
-
readonly load: () => Promise<Config>;
|
|
53
|
-
readonly prerender?: boolean;
|
|
54
|
-
};
|
|
55
|
-
type PageParams = Readonly<Record<string, string | undefined>>;
|
|
56
|
-
type PageFlagsContext<Props extends object = EmptyProps> = {
|
|
57
|
-
readonly request: Request;
|
|
58
|
-
readonly url: URL;
|
|
59
|
-
readonly params: PageParams;
|
|
60
|
-
readonly props: Props;
|
|
61
|
-
};
|
|
62
|
-
type PageContext<Props extends object = EmptyProps> = PageFlagsContext<Props>;
|
|
63
|
-
type PageFlagsSchema<Flags extends object> = Schema.Codec<Flags, any, never, never>;
|
|
64
|
-
type PageConfig<Flags extends object = EmptyProps, Model = unknown, Message extends TaggedMessage = TaggedMessage> = AppConfig<Flags, Model, Message> & {
|
|
65
|
-
readonly Flags: PageFlagsSchema<Flags>;
|
|
66
|
-
};
|
|
67
|
-
type PageConfigContract<Flags extends object = EmptyProps> = AppConfigContract<Flags> & {
|
|
68
|
-
readonly Flags: PageFlagsSchema<Flags>;
|
|
69
|
-
};
|
|
70
|
-
type DefinePageOptions<Props extends object = EmptyProps, Flags extends object = EmptyProps> = {
|
|
71
|
-
readonly flags: (context: PageFlagsContext<Props>) => Flags;
|
|
72
|
-
};
|
|
73
|
-
type FoldkitPage<Props extends object = EmptyProps, Flags extends object = EmptyProps, Config extends PageConfigContract<Flags> = PageConfigContract<Flags>> = {
|
|
74
|
-
(props?: Props): void;
|
|
75
|
-
readonly __foldkitPage: true;
|
|
76
|
-
readonly load: () => Promise<Config>;
|
|
77
|
-
readonly flags: (context: PageFlagsContext<Props>) => Flags;
|
|
78
|
-
};
|
|
79
|
-
//#endregion
|
|
80
|
-
export { EmptyProps as a, PageConfig as c, PageFlagsContext as d, PageFlagsSchema as f, DefinePageOptions as i, PageConfigContract as l, AppConfigContract as n, FoldkitApp as o, PageParams as p, DefineAppOptions as r, FoldkitPage as s, AppConfig as t, PageContext as u };
|