foldkit-ssr 0.8.2 → 0.9.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/README.md +203 -69
- package/dist/client-F16QT0sc.d.ts +75 -0
- package/dist/client-F16QT0sc.d.ts.map +1 -0
- package/dist/client.d.ts +5 -0
- package/dist/client.js +271 -0
- package/dist/client.js.map +1 -0
- package/dist/context.d.ts +2 -0
- package/dist/context.js +21 -0
- package/dist/context.js.map +1 -0
- package/dist/diagnostics.d.ts +2 -0
- package/dist/diagnostics.js +59 -0
- package/dist/diagnostics.js.map +1 -0
- package/dist/{index.d.mts → index.d.ts} +18 -7
- package/dist/index.d.ts.map +1 -0
- package/dist/{index.mjs → index.js} +79 -60
- package/dist/index.js.map +1 -0
- package/dist/listen-zNd0IIAT.d.ts +69 -0
- package/dist/listen-zNd0IIAT.d.ts.map +1 -0
- package/dist/listen.d.ts +2 -0
- package/dist/listen.js +179 -0
- package/dist/listen.js.map +1 -0
- package/dist/requestContext-D9nsbGSJ.d.ts +21 -0
- package/dist/requestContext-D9nsbGSJ.d.ts.map +1 -0
- package/dist/requestContext.d.ts +2 -0
- package/dist/requestContext.js +48 -0
- package/dist/requestContext.js.map +1 -0
- package/dist/resumable-BWItJsxF.d.ts +86 -0
- package/dist/resumable-BWItJsxF.d.ts.map +1 -0
- package/dist/resumable.d.ts +2 -0
- package/dist/resumable.js +358 -0
- package/dist/resumable.js.map +1 -0
- package/dist/{client-DkwAniQQ.d.mts → shared-v1u-OEQI.d.ts} +218 -194
- package/dist/shared-v1u-OEQI.d.ts.map +1 -0
- package/dist/shared.d.ts +2 -0
- package/dist/shared.js +324 -0
- package/dist/shared.js.map +1 -0
- package/dist/{vite.d.mts → vite.d.ts} +3 -5
- package/dist/vite.d.ts.map +1 -0
- package/dist/{vite.mjs → vite.js} +3 -4
- package/dist/vite.js.map +1 -0
- package/package.json +17 -17
- package/dist/client-DVG9_3rL.mjs +0 -1113
- package/dist/client-DVG9_3rL.mjs.map +0 -1
- package/dist/client-DkwAniQQ.d.mts.map +0 -1
- package/dist/client.d.mts +0 -2
- package/dist/client.mjs +0 -1
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/vite.d.mts.map +0 -1
- package/dist/vite.mjs.map +0 -1
package/dist/listen.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { BINDING_ATTRIBUTE, EVENT_OF } from "./resumable.js";
|
|
2
|
+
import { Predicate, Result, Schema } from "effect";
|
|
3
|
+
// src/listen.ts
|
|
4
|
+
/**
|
|
5
|
+
* Delegated dispatch: the page answers an event from its markers, before the
|
|
6
|
+
* application has booted.
|
|
7
|
+
*
|
|
8
|
+
* One capture-phase listener per event type sits at the root, so events that
|
|
9
|
+
* do not bubble (`focus`, `blur`) are caught, and it runs before anything
|
|
10
|
+
* Foldkit attaches later. On an event it walks from the target to the root
|
|
11
|
+
* and, for every marker of that event on the way, collects each binding's
|
|
12
|
+
* Message in order, the way Foldkit's own handler would dispatch it: a hole is
|
|
13
|
+
* filled from the event, `OnClick`'s options are honoured, `OnSubmit`
|
|
14
|
+
* prevents the default. A marker token the page could not name (`*`) means
|
|
15
|
+
* the live page does something here the page cannot describe, so the walk
|
|
16
|
+
* ends and the answer names that element.
|
|
17
|
+
*/
|
|
18
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
19
|
+
/**
|
|
20
|
+
* The page's list of bindings, read as untrusted input: each entry checked,
|
|
21
|
+
* and only its known keys kept, or the reason the list is refused. Checked by
|
|
22
|
+
* hand rather than through a Schema, which at a thousand rows took most of a
|
|
23
|
+
* frame for a shape this plain; the Message inside each entry is still decoded
|
|
24
|
+
* through the application's Schema by `decodeBindings`.
|
|
25
|
+
*/
|
|
26
|
+
const readBindings = (value) => {
|
|
27
|
+
if (!Array.isArray(value)) return Result.fail("the list is not an array");
|
|
28
|
+
const out = [];
|
|
29
|
+
for (const [index, entry] of value.entries()) {
|
|
30
|
+
if (!isRecord(entry)) return Result.fail(`entry ${index} is not an object`);
|
|
31
|
+
if (typeof entry.attribute !== "string") return Result.fail(`entry ${index} has no attribute`);
|
|
32
|
+
if (!Object.hasOwn(entry, "message")) return Result.fail(`entry ${index} has no message`);
|
|
33
|
+
const { hole, depth } = entry;
|
|
34
|
+
if (hole !== void 0 && !(Array.isArray(hole) && hole.every((field) => typeof field === "string"))) return Result.fail(`entry ${index} has a hole that is not a list of fields`);
|
|
35
|
+
if (depth !== void 0 && !(Number.isInteger(depth) && depth >= 0)) return Result.fail(`entry ${index} has a depth that is not a count`);
|
|
36
|
+
out.push({
|
|
37
|
+
attribute: entry.attribute,
|
|
38
|
+
message: entry.message,
|
|
39
|
+
...hole === void 0 ? {} : { hole },
|
|
40
|
+
...depth === void 0 ? {} : { depth },
|
|
41
|
+
...Object.hasOwn(entry, "options") ? { options: entry.options } : {}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return Result.succeed(out);
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* The page's bindings, decoded through the application's Message Schema, and
|
|
48
|
+
* every marker in `root` checked against them. A page whose markers name a
|
|
49
|
+
* binding it does not carry, or whose entry is not one of the application's
|
|
50
|
+
* Messages, is refused whole, with the reason.
|
|
51
|
+
*/
|
|
52
|
+
const decodeBindings = (Message, encoded, root, allowed) => {
|
|
53
|
+
if (encoded.length > 0 && Message === void 0) return Result.fail("the page has bindings and the plan has no Message Schema to decode them with");
|
|
54
|
+
const decode = Message === void 0 ? void 0 : Schema.decodeUnknownResult(Message);
|
|
55
|
+
const bindings = [];
|
|
56
|
+
for (const [index, entry] of encoded.entries()) {
|
|
57
|
+
const event = EVENT_OF[entry.attribute];
|
|
58
|
+
if (event === void 0) return Result.fail(`binding ${index} is for "${entry.attribute}", which is no event attribute`);
|
|
59
|
+
const message = decode(entry.message);
|
|
60
|
+
if (Result.isFailure(message)) return Result.fail(`binding ${index} does not decode as a Message: ${message.failure.message}`);
|
|
61
|
+
const tag = Predicate.hasProperty(message.success, "_tag") ? message.success._tag : void 0;
|
|
62
|
+
if (typeof tag !== "string" || !allowed.has(tag)) return Result.fail(`binding ${index} dispatches ${typeof tag === "string" ? tag : "an untagged Message"}, which no active Surface lists in its messages`);
|
|
63
|
+
bindings.push({
|
|
64
|
+
attribute: entry.attribute,
|
|
65
|
+
event,
|
|
66
|
+
message: message.success,
|
|
67
|
+
...entry.hole === void 0 ? {} : { hole: entry.hole },
|
|
68
|
+
...entry.depth === void 0 ? {} : { depth: entry.depth },
|
|
69
|
+
...entry.options === void 0 ? {} : { options: entry.options }
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
for (const element of Array.from(root.querySelectorAll("*"))) for (const attribute of element.getAttributeNames()) {
|
|
73
|
+
if (!attribute.startsWith("data-foldkit-plus-on-")) continue;
|
|
74
|
+
for (const token of (element.getAttribute(attribute) ?? "").split(" ")) {
|
|
75
|
+
if (token === "*") continue;
|
|
76
|
+
const ordinal = Number(token);
|
|
77
|
+
if (!Number.isInteger(ordinal) || bindings[ordinal] === void 0) return Result.fail(`the marker ${attribute}="${token}" names no binding the page carries`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return Result.succeed(bindings);
|
|
81
|
+
};
|
|
82
|
+
/** A string property of the target, if it has one. */
|
|
83
|
+
const stringProperty = (target, name) => {
|
|
84
|
+
if (target === null || !(name in target)) return void 0;
|
|
85
|
+
const value = Reflect.get(target, name);
|
|
86
|
+
return typeof value === "string" ? value : void 0;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Foldkit's reading of an input's value (`inputEventValue`): any target's
|
|
90
|
+
* string `value`, a custom element's included, else its `innerText`, else its
|
|
91
|
+
* `textContent`.
|
|
92
|
+
*/
|
|
93
|
+
const inputValue = (target) => stringProperty(target, "value") ?? stringProperty(target, "innerText") ?? stringProperty(target, "textContent") ?? "";
|
|
94
|
+
const modifiersOf = (event) => ({
|
|
95
|
+
shiftKey: event.shiftKey,
|
|
96
|
+
ctrlKey: event.ctrlKey,
|
|
97
|
+
altKey: event.altKey,
|
|
98
|
+
metaKey: event.metaKey
|
|
99
|
+
});
|
|
100
|
+
/** The Message a binding dispatches for this event: its own, with the hole filled. */
|
|
101
|
+
const messageFor = (binding, event) => {
|
|
102
|
+
if (binding.hole === void 0) return binding.message;
|
|
103
|
+
const fill = (template) => {
|
|
104
|
+
if (binding.event === "input" || binding.event === "change") {
|
|
105
|
+
const [field] = binding.hole ?? [];
|
|
106
|
+
return {
|
|
107
|
+
...template,
|
|
108
|
+
[field ?? "value"]: inputValue(event.target)
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
if (event instanceof KeyboardEvent) return {
|
|
112
|
+
...template,
|
|
113
|
+
key: event.key,
|
|
114
|
+
modifiers: modifiersOf(event)
|
|
115
|
+
};
|
|
116
|
+
return template;
|
|
117
|
+
};
|
|
118
|
+
const inside = (template, depth) => depth === 0 ? fill(template) : {
|
|
119
|
+
...template,
|
|
120
|
+
message: inside(template.message, depth - 1)
|
|
121
|
+
};
|
|
122
|
+
return inside(binding.message, binding.depth ?? 0);
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Listens at `root` for every event the bindings name, and answers each from
|
|
126
|
+
* the markers. Returns what removes the listeners.
|
|
127
|
+
*/
|
|
128
|
+
const listen = (root, options) => {
|
|
129
|
+
const events = new Set(options.bindings.map((binding) => binding.event));
|
|
130
|
+
if (options.events !== void 0) for (const event of options.events) events.add(event);
|
|
131
|
+
else for (const element of [root, ...Array.from(root.querySelectorAll("*"))]) for (const { name } of Array.from(element.attributes)) if (name.startsWith("data-foldkit-plus-on-")) events.add(name.slice(BINDING_ATTRIBUTE.length));
|
|
132
|
+
const handler = (event) => {
|
|
133
|
+
const type = event.type;
|
|
134
|
+
const attribute = `${BINDING_ATTRIBUTE}${type}`;
|
|
135
|
+
const messages = [];
|
|
136
|
+
const path = event.bubbles ? event.composedPath() : [event.target];
|
|
137
|
+
for (const node of path) {
|
|
138
|
+
if (!(node instanceof Element)) continue;
|
|
139
|
+
const tokens = node.getAttribute(attribute);
|
|
140
|
+
let stopped = false;
|
|
141
|
+
if (tokens !== null) for (const token of tokens.split(" ")) {
|
|
142
|
+
if (token === "*") {
|
|
143
|
+
options.onAnswer({
|
|
144
|
+
event,
|
|
145
|
+
messages,
|
|
146
|
+
unnamed: node
|
|
147
|
+
});
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const binding = options.bindings[Number(token)];
|
|
151
|
+
if (binding === void 0) continue;
|
|
152
|
+
if (binding.attribute === "OnSubmit") event.preventDefault();
|
|
153
|
+
if (binding.attribute === "OnClick") {
|
|
154
|
+
const click = binding.options ?? {};
|
|
155
|
+
if (click.defaultAction === "Prevent") event.preventDefault();
|
|
156
|
+
if (click.propagation === "Stop") event.stopPropagation();
|
|
157
|
+
if (click.focusSelector !== void 0) {
|
|
158
|
+
const focusTarget = document.querySelector(click.focusSelector);
|
|
159
|
+
if (focusTarget instanceof HTMLElement) focusTarget.focus();
|
|
160
|
+
}
|
|
161
|
+
if (click.propagation === "Stop") stopped = true;
|
|
162
|
+
}
|
|
163
|
+
messages.push(messageFor(binding, event));
|
|
164
|
+
}
|
|
165
|
+
if (stopped || node === root) break;
|
|
166
|
+
}
|
|
167
|
+
options.onAnswer({
|
|
168
|
+
event,
|
|
169
|
+
messages
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
for (const type of events) root.addEventListener(type, handler, true);
|
|
173
|
+
return () => {
|
|
174
|
+
for (const type of events) root.removeEventListener(type, handler, true);
|
|
175
|
+
};
|
|
176
|
+
};
|
|
177
|
+
export { decodeBindings, listen, readBindings };
|
|
178
|
+
|
|
179
|
+
//# sourceMappingURL=listen.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listen.js","names":[],"sources":["../src/listen.ts"],"sourcesContent":["/**\n * Delegated dispatch: the page answers an event from its markers, before the\n * application has booted.\n *\n * One capture-phase listener per event type sits at the root, so events that\n * do not bubble (`focus`, `blur`) are caught, and it runs before anything\n * Foldkit attaches later. On an event it walks from the target to the root\n * and, for every marker of that event on the way, collects each binding's\n * Message in order, the way Foldkit's own handler would dispatch it: a hole is\n * filled from the event, `OnClick`'s options are honoured, `OnSubmit`\n * prevents the default. A marker token the page could not name (`*`) means\n * the live page does something here the page cannot describe, so the walk\n * ends and the answer names that element.\n */\nimport { Predicate, Result, Schema } from 'effect'\nimport type { KeyboardModifiers } from 'foldkit/html'\nimport { BINDING_ATTRIBUTE, EVENT_OF, UNNAMED_HANDLER } from './resumable.js'\n\n/**\n * A binding as the envelope carries it: Foldkit's attribute (`OnSubmit`,\n * `OnBlur`), whose tag says what its handler does beside dispatching; the\n * Message, encoded through the application's Message Schema (for a hole, with\n * the hole filled by a placeholder); the fields the event fills, `depth`\n * placement wrappers down; and the attribute's options. Its ordinal is its\n * index.\n */\nexport interface EncodedBinding {\n readonly attribute: string\n readonly message: unknown\n readonly hole?: ReadonlyArray<string>\n readonly depth?: number\n readonly options?: unknown\n}\n\nconst isRecord = (value: unknown): value is Readonly<Record<string, unknown>> =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n\n/**\n * The page's list of bindings, read as untrusted input: each entry checked,\n * and only its known keys kept, or the reason the list is refused. Checked by\n * hand rather than through a Schema, which at a thousand rows took most of a\n * frame for a shape this plain; the Message inside each entry is still decoded\n * through the application's Schema by `decodeBindings`.\n */\nexport const readBindings = (\n value: unknown,\n): Result.Result<ReadonlyArray<EncodedBinding>, string> => {\n if (!Array.isArray(value)) return Result.fail('the list is not an array')\n const out: Array<EncodedBinding> = []\n for (const [index, entry] of value.entries()) {\n if (!isRecord(entry)) return Result.fail(`entry ${index} is not an object`)\n if (typeof entry.attribute !== 'string') {\n return Result.fail(`entry ${index} has no attribute`)\n }\n if (!Object.hasOwn(entry, 'message')) return Result.fail(`entry ${index} has no message`)\n const { hole, depth } = entry\n if (\n hole !== undefined &&\n !(Array.isArray(hole) && hole.every(field => typeof field === 'string'))\n ) {\n return Result.fail(`entry ${index} has a hole that is not a list of fields`)\n }\n if (depth !== undefined && !(Number.isInteger(depth) && (depth as number) >= 0)) {\n return Result.fail(`entry ${index} has a depth that is not a count`)\n }\n out.push({\n attribute: entry.attribute,\n message: entry.message,\n ...(hole === undefined ? {} : { hole: hole as ReadonlyArray<string> }),\n ...(depth === undefined ? {} : { depth: depth as number }),\n ...(Object.hasOwn(entry, 'options') ? { options: entry.options } : {}),\n })\n }\n return Result.succeed(out)\n}\n\n/** A binding decoded from the page: its Message is one of the application's. */\nexport interface DecodedBinding {\n readonly attribute: string\n readonly event: string\n readonly message: unknown\n readonly hole?: ReadonlyArray<string> | undefined\n readonly depth?: number | undefined\n readonly options?: unknown\n}\n\n/**\n * The page's bindings, decoded through the application's Message Schema, and\n * every marker in `root` checked against them. A page whose markers name a\n * binding it does not carry, or whose entry is not one of the application's\n * Messages, is refused whole, with the reason.\n */\nexport const decodeBindings = (\n Message: Schema.Top | undefined,\n encoded: ReadonlyArray<EncodedBinding>,\n root: ParentNode,\n allowed: ReadonlySet<string>,\n): Result.Result<ReadonlyArray<DecodedBinding>, string> => {\n if (encoded.length > 0 && Message === undefined) {\n return Result.fail(\n 'the page has bindings and the plan has no Message Schema to decode them with',\n )\n }\n const decode =\n Message === undefined\n ? undefined\n : Schema.decodeUnknownResult(Message as Schema.Codec<unknown, unknown>)\n const bindings: Array<DecodedBinding> = []\n for (const [index, entry] of encoded.entries()) {\n const event = EVENT_OF[entry.attribute]\n if (event === undefined) {\n return Result.fail(\n `binding ${index} is for \"${entry.attribute}\", which is no event attribute`,\n )\n }\n const message = decode!(entry.message)\n if (Result.isFailure(message)) {\n return Result.fail(\n `binding ${index} does not decode as a Message: ${message.failure.message}`,\n )\n }\n const tag = Predicate.hasProperty(message.success, '_tag') ? message.success._tag : undefined\n if (typeof tag !== 'string' || !allowed.has(tag)) {\n return Result.fail(\n `binding ${index} dispatches ${typeof tag === 'string' ? tag : 'an untagged Message'}, which no active Surface lists in its messages`,\n )\n }\n bindings.push({\n attribute: entry.attribute,\n event,\n message: message.success,\n ...(entry.hole === undefined ? {} : { hole: entry.hole }),\n ...(entry.depth === undefined ? {} : { depth: entry.depth }),\n ...(entry.options === undefined ? {} : { options: entry.options }),\n })\n }\n for (const element of Array.from(root.querySelectorAll('*'))) {\n for (const attribute of element.getAttributeNames()) {\n if (!attribute.startsWith(BINDING_ATTRIBUTE)) continue\n for (const token of (element.getAttribute(attribute) ?? '').split(' ')) {\n if (token === UNNAMED_HANDLER) continue\n const ordinal = Number(token)\n if (!Number.isInteger(ordinal) || bindings[ordinal] === undefined) {\n return Result.fail(`the marker ${attribute}=\"${token}\" names no binding the page carries`)\n }\n }\n }\n }\n return Result.succeed(bindings)\n}\n\n/** A string property of the target, if it has one. */\nconst stringProperty = (target: EventTarget | null, name: string): string | undefined => {\n if (target === null || !(name in target)) return undefined\n const value: unknown = Reflect.get(target, name)\n return typeof value === 'string' ? value : undefined\n}\n\n/**\n * Foldkit's reading of an input's value (`inputEventValue`): any target's\n * string `value`, a custom element's included, else its `innerText`, else its\n * `textContent`.\n */\nconst inputValue = (target: EventTarget | null): string =>\n stringProperty(target, 'value') ??\n stringProperty(target, 'innerText') ??\n stringProperty(target, 'textContent') ??\n ''\n\nconst modifiersOf = (event: KeyboardEvent): KeyboardModifiers => ({\n shiftKey: event.shiftKey,\n ctrlKey: event.ctrlKey,\n altKey: event.altKey,\n metaKey: event.metaKey,\n})\n\n/** The Message a binding dispatches for this event: its own, with the hole filled. */\nconst messageFor = (binding: DecodedBinding, event: Event): unknown => {\n if (binding.hole === undefined) return binding.message\n const fill = (template: Readonly<Record<string, unknown>>): unknown => {\n if (binding.event === 'input' || binding.event === 'change') {\n const [field] = binding.hole ?? []\n return { ...template, [field ?? 'value']: inputValue(event.target) }\n }\n if (event instanceof KeyboardEvent) {\n return { ...template, key: event.key, modifiers: modifiersOf(event) }\n }\n return template\n }\n // The hole's fields sit inside each placement wrapper's `message`.\n const inside = (template: Readonly<Record<string, unknown>>, depth: number): unknown =>\n depth === 0\n ? fill(template)\n : {\n ...template,\n message: inside(template.message as Readonly<Record<string, unknown>>, depth - 1),\n }\n return inside(binding.message as Readonly<Record<string, unknown>>, binding.depth ?? 0)\n}\n\n/** What `OnClick` declares beside its Message. */\ninterface ClickOptions {\n readonly defaultAction?: 'Allow' | 'Prevent'\n readonly propagation?: 'Bubble' | 'Stop'\n readonly focusSelector?: string\n}\n\n/**\n * What the markers make of one event: the Messages its bindings dispatch, in\n * the order the live page would, and, when the walk met a handler the page\n * could not name, that element. An answer with `unnamed` is incomplete: the\n * live page would do more than its Messages say.\n */\nexport interface Answer {\n readonly event: Event\n readonly messages: ReadonlyArray<unknown>\n readonly unnamed?: Element | undefined\n}\n\nexport interface ListenOptions {\n readonly bindings: ReadonlyArray<DecodedBinding>\n readonly onAnswer: (answer: Answer) => void\n /**\n * Every event the page's markers name, as the envelope lists them. Given,\n * `listen` needs no pass over the page to find the events a marker names\n * with `*` alone; without it, it reads every element's attributes, which on\n * a large page is most of its cost.\n */\n readonly events?: Iterable<string> | undefined\n}\n\n/**\n * Listens at `root` for every event the bindings name, and answers each from\n * the markers. Returns what removes the listeners.\n */\nexport const listen = (root: Element, options: ListenOptions): (() => void) => {\n // The bindings name most events; a marker whose handlers the page could not\n // name is `*` alone, so the markers themselves say the rest.\n const events = new Set(options.bindings.map(binding => binding.event))\n if (options.events !== undefined) {\n for (const event of options.events) events.add(event)\n } else {\n for (const element of [root, ...Array.from(root.querySelectorAll('*'))]) {\n for (const { name } of Array.from(element.attributes)) {\n if (name.startsWith(BINDING_ATTRIBUTE)) events.add(name.slice(BINDING_ATTRIBUTE.length))\n }\n }\n }\n const handler = (event: Event) => {\n const type = event.type\n const attribute = `${BINDING_ATTRIBUTE}${type}`\n const messages: Array<unknown> = []\n // An event that does not bubble (`focus`, `blur`, `mouseenter`) reaches only\n // its target's own handlers on the live page, so only those answer it here.\n const path = event.bubbles ? event.composedPath() : [event.target]\n for (const node of path) {\n if (!(node instanceof Element)) continue\n const tokens = node.getAttribute(attribute)\n // Foldkit chains an element's handlers in one listener, so a Stop among\n // them keeps the event from other elements, not from its siblings.\n let stopped = false\n if (tokens !== null) {\n for (const token of tokens.split(' ')) {\n if (token === UNNAMED_HANDLER) {\n options.onAnswer({ event, messages, unnamed: node })\n return\n }\n const binding = options.bindings[Number(token)]\n if (binding === undefined) continue\n if (binding.attribute === 'OnSubmit') event.preventDefault()\n if (binding.attribute === 'OnClick') {\n const click = (binding.options ?? {}) as ClickOptions\n if (click.defaultAction === 'Prevent') event.preventDefault()\n if (click.propagation === 'Stop') event.stopPropagation()\n if (click.focusSelector !== undefined) {\n const focusTarget = document.querySelector(click.focusSelector)\n if (focusTarget instanceof HTMLElement) focusTarget.focus()\n }\n if (click.propagation === 'Stop') stopped = true\n }\n messages.push(messageFor(binding, event))\n }\n }\n if (stopped || node === root) break\n }\n options.onAnswer({ event, messages })\n }\n for (const type of events) root.addEventListener(type, handler, true)\n return () => {\n for (const type of events) root.removeEventListener(type, handler, true)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAkCA,MAAM,YAAY,UAChB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;;;;;;;;AASrE,MAAa,gBACX,UACyD;CACzD,IAAI,CAAC,MAAM,QAAQ,KAAK,GAAG,OAAO,OAAO,KAAK,0BAA0B;CACxE,MAAM,MAA6B,CAAC;CACpC,KAAK,MAAM,CAAC,OAAO,UAAU,MAAM,QAAQ,GAAG;EAC5C,IAAI,CAAC,SAAS,KAAK,GAAG,OAAO,OAAO,KAAK,SAAS,MAAM,kBAAkB;EAC1E,IAAI,OAAO,MAAM,cAAc,UAC7B,OAAO,OAAO,KAAK,SAAS,MAAM,kBAAkB;EAEtD,IAAI,CAAC,OAAO,OAAO,OAAO,SAAS,GAAG,OAAO,OAAO,KAAK,SAAS,MAAM,gBAAgB;EACxF,MAAM,EAAE,MAAM,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ChC,MAAM,SAAS,KAAK,aAAa,SAAS;GAG1C,IAAI,UAAU;GACd,IAAI,WAAW,MACb,KAAK,MAAM,SAAS,OAAO,MAAM,GAAG,GAAG;IACrC,IAAI,UAAA,KAA2B;KAC7B,QAAQ,SAAS;MAAE;MAAO;MAAU,SAAS;KAAK,CAAC;KACnD;IACF;IACA,MAAM,UAAU,QAAQ,SAAS,OAAO,KAAK;IAC7C,IAAI,YAAY,KAAA,GAAW;IAC3B,IAAI,QAAQ,cAAc,YAAY,MAAM,eAAe;IAC3D,IAAI,QAAQ,cAAc,WAAW;KACnC,MAAM,QAAS,QAAQ,WAAW,CAAC;KACnC,IAAI,MAAM,kBAAkB,WAAW,MAAM,eAAe;KAC5D,IAAI,MAAM,gBAAgB,QAAQ,MAAM,gBAAgB;KACxD,IAAI,MAAM,kBAAkB,KAAA,GAAW;MACrC,MAAM,cAAc,SAAS,cAAc,MAAM,aAAa;MAC9D,IAAI,uBAAuB,aAAa,YAAY,MAAM;KAC5D;KACA,IAAI,MAAM,gBAAgB,QAAQ,UAAU;IAC9C;IACA,SAAS,KAAK,WAAW,SAAS,KAAK,CAAC;GAC1C;GAEF,IAAI,WAAW,SAAS,MAAM;EAChC;EACA,QAAQ,SAAS;GAAE;GAAO;EAAS,CAAC;CACtC;CACA,KAAK,MAAM,QAAQ,QAAQ,KAAK,iBAAiB,MAAM,SAAS,IAAI;CACpE,aAAa;EACX,KAAK,MAAM,QAAQ,QAAQ,KAAK,oBAAoB,MAAM,SAAS,IAAI;CACzE;AACF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Option } from "effect";
|
|
2
|
+
/** A value of type `C` the host attaches to a request, for its `renderPage` to read. */
|
|
3
|
+
interface RequestContext<C> {
|
|
4
|
+
readonly name: string;
|
|
5
|
+
/** Keeps `value` for `request` and returns the request. A second value under this name throws. */
|
|
6
|
+
readonly attach: (request: Request, value: C) => Request;
|
|
7
|
+
/**
|
|
8
|
+
* The value the host attached to `request`; none when it attached nothing,
|
|
9
|
+
* as Vite's dev server, which builds its own `Request`, or a host that
|
|
10
|
+
* passed on a copy (`new Request(request)`).
|
|
11
|
+
*/
|
|
12
|
+
readonly of: (request: Request) => Option.Option<C>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A request context named `name`. The host and the page each import it from
|
|
16
|
+
* one module, so both agree on `C`; two bundles of that module find each
|
|
17
|
+
* other's values by the name.
|
|
18
|
+
*/
|
|
19
|
+
declare const requestContext: <C>(name: string) => RequestContext<C>;
|
|
20
|
+
export { requestContext as n, RequestContext as t };
|
|
21
|
+
//# sourceMappingURL=requestContext-D9nsbGSJ.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requestContext-D9nsbGSJ.d.ts","names":[],"sources":["../src/requestContext.ts"],"mappings":";;UA+BiB,eAAe;WACrB;;WAEA,SAAS,SAAS,SAAS,OAAO,MAAM;;;;;;WAMxC,KAAK,SAAS,YAAY,OAAO,OAAO;;;;;;;cAQtC,iBAAkB,GAAC,iBAAiB,eAAe"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Option } from "effect";
|
|
2
|
+
// src/requestContext.ts
|
|
3
|
+
/**
|
|
4
|
+
* A value the host hands `renderPage` with the request. Foldkit's
|
|
5
|
+
* `handleRequest` calls `renderPage(request)` and nothing more, so what the
|
|
6
|
+
* host holds (a Worker's bindings, a reader built from them) rides the
|
|
7
|
+
* request itself: kept in a `WeakMap` keyed by it, which holds nothing past
|
|
8
|
+
* the request's life and never shares one request's value with another.
|
|
9
|
+
*
|
|
10
|
+
* The Worker and the page bundle Vite built are separate module graphs, each
|
|
11
|
+
* with its own copy of this module, so the map lives on `globalThis` under a
|
|
12
|
+
* registered symbol, and a context is known by its name.
|
|
13
|
+
*/
|
|
14
|
+
const KEY = Symbol.for("foldkit-ssr/request-context");
|
|
15
|
+
const valuesOf = () => {
|
|
16
|
+
const global = globalThis;
|
|
17
|
+
const held = global[KEY];
|
|
18
|
+
if (held === void 0) {
|
|
19
|
+
const made = /* @__PURE__ */ new WeakMap();
|
|
20
|
+
global[KEY] = made;
|
|
21
|
+
return made;
|
|
22
|
+
}
|
|
23
|
+
if (!(held instanceof WeakMap)) throw new Error(`foldkit-ssr: globalThis holds something else under ${String(KEY)}`);
|
|
24
|
+
return held;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* A request context named `name`. The host and the page each import it from
|
|
28
|
+
* one module, so both agree on `C`; two bundles of that module find each
|
|
29
|
+
* other's values by the name.
|
|
30
|
+
*/
|
|
31
|
+
const requestContext = (name) => ({
|
|
32
|
+
name,
|
|
33
|
+
attach: (request, value) => {
|
|
34
|
+
const values = valuesOf();
|
|
35
|
+
const held = values.get(request) ?? /* @__PURE__ */ new Map();
|
|
36
|
+
if (held.has(name)) throw new Error(`foldkit-ssr: the request already carries a "${name}" context`);
|
|
37
|
+
held.set(name, value);
|
|
38
|
+
values.set(request, held);
|
|
39
|
+
return request;
|
|
40
|
+
},
|
|
41
|
+
of: (request) => {
|
|
42
|
+
const held = valuesOf().get(request);
|
|
43
|
+
return held !== void 0 && held.has(name) ? Option.some(held.get(name)) : Option.none();
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
export { requestContext };
|
|
47
|
+
|
|
48
|
+
//# sourceMappingURL=requestContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requestContext.js","names":[],"sources":["../src/requestContext.ts"],"sourcesContent":["/**\n * A value the host hands `renderPage` with the request. Foldkit's\n * `handleRequest` calls `renderPage(request)` and nothing more, so what the\n * host holds (a Worker's bindings, a reader built from them) rides the\n * request itself: kept in a `WeakMap` keyed by it, which holds nothing past\n * the request's life and never shares one request's value with another.\n *\n * The Worker and the page bundle Vite built are separate module graphs, each\n * with its own copy of this module, so the map lives on `globalThis` under a\n * registered symbol, and a context is known by its name.\n */\nimport { Option } from 'effect'\n\nconst KEY = Symbol.for('foldkit-ssr/request-context')\n\ntype Values = WeakMap<Request, Map<string, unknown>>\n\nconst valuesOf = (): Values => {\n const global = globalThis as { [KEY]?: unknown }\n const held = global[KEY]\n if (held === undefined) {\n const made: Values = new WeakMap()\n global[KEY] = made\n return made\n }\n if (!(held instanceof WeakMap))\n throw new Error(`foldkit-ssr: globalThis holds something else under ${String(KEY)}`)\n return held as Values\n}\n\n/** A value of type `C` the host attaches to a request, for its `renderPage` to read. */\nexport interface RequestContext<C> {\n readonly name: string\n /** Keeps `value` for `request` and returns the request. A second value under this name throws. */\n readonly attach: (request: Request, value: C) => Request\n /**\n * The value the host attached to `request`; none when it attached nothing,\n * as Vite's dev server, which builds its own `Request`, or a host that\n * passed on a copy (`new Request(request)`).\n */\n readonly of: (request: Request) => Option.Option<C>\n}\n\n/**\n * A request context named `name`. The host and the page each import it from\n * one module, so both agree on `C`; two bundles of that module find each\n * other's values by the name.\n */\nexport const requestContext = <C>(name: string): RequestContext<C> => ({\n name,\n attach: (request, value) => {\n const values = valuesOf()\n const held = values.get(request) ?? new Map<string, unknown>()\n if (held.has(name))\n throw new Error(`foldkit-ssr: the request already carries a \"${name}\" context`)\n held.set(name, value)\n values.set(request, held)\n return request\n },\n of: request => {\n const held = valuesOf().get(request)\n return held !== undefined && held.has(name) ? Option.some(held.get(name) as C) : Option.none()\n },\n})\n"],"mappings":";;;;;;;;;;;;;AAaA,MAAM,MAAM,OAAO,IAAI,6BAA6B;AAIpD,MAAM,iBAAyB;CAC7B,MAAM,SAAS;CACf,MAAM,OAAO,OAAO;CACpB,IAAI,SAAS,KAAA,GAAW;EACtB,MAAM,uBAAe,IAAI,QAAQ;EACjC,OAAO,OAAO;EACd,OAAO;CACT;CACA,IAAI,EAAE,gBAAgB,UACpB,MAAM,IAAI,MAAM,sDAAsD,OAAO,GAAG,GAAG;CACrF,OAAO;AACT;;;;;;AAoBA,MAAa,kBAAqB,UAAqC;CACrE;CACA,SAAS,SAAS,UAAU;EAC1B,MAAM,SAAS,SAAS;EACxB,MAAM,OAAO,OAAO,IAAI,OAAO,qBAAK,IAAI,IAAqB;EAC7D,IAAI,KAAK,IAAI,IAAI,GACf,MAAM,IAAI,MAAM,+CAA+C,KAAK,UAAU;EAChF,KAAK,IAAI,MAAM,KAAK;EACpB,OAAO,IAAI,SAAS,IAAI;EACxB,OAAO;CACT;CACA,KAAI,YAAW;EACb,MAAM,OAAO,SAAS,CAAC,CAAC,IAAI,OAAO;EACnC,OAAO,SAAS,KAAA,KAAa,KAAK,IAAI,IAAI,IAAI,OAAO,KAAK,KAAK,IAAI,IAAI,CAAM,IAAI,OAAO,KAAK;CAC/F;AACF"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { Attribute, HtmlBuilder, KeyboardModifiers } from "foldkit/html";
|
|
3
|
+
/** The attribute prefix of an element's binding marker. */
|
|
4
|
+
declare const BINDING_ATTRIBUTE = "data-foldkit-plus-on-";
|
|
5
|
+
/**
|
|
6
|
+
* The DOM event each of Foldkit's event attributes listens to, read from
|
|
7
|
+
* Foldkit's own attribute table (0.163). `OnCustomEvent` names its event in
|
|
8
|
+
* its payload, and `OnMount` and `OnUnmount` listen to none.
|
|
9
|
+
*/
|
|
10
|
+
declare const EVENT_OF: Readonly<Record<string, string>>;
|
|
11
|
+
/** The token in a marker for a handler the page cannot describe. */
|
|
12
|
+
declare const UNNAMED_HANDLER = "*";
|
|
13
|
+
/** The posted field that carries a form's encoded Message, for the server fallback. */
|
|
14
|
+
declare const FALLBACK_FIELD = "foldkit-plus-message";
|
|
15
|
+
/** The posted field that says how many placement wrappers the form's fields sit under. */
|
|
16
|
+
declare const FALLBACK_DEPTH_FIELD = "foldkit-plus-depth";
|
|
17
|
+
/** The attribute on a placement's root naming its slot, while the server renders. */
|
|
18
|
+
declare const SLOT_ATTRIBUTE = "data-foldkit-plus-slot";
|
|
19
|
+
declare const invalid: unique symbol;
|
|
20
|
+
/** A compile-time failure that names its cause. */
|
|
21
|
+
interface Invalid<Message extends string> {
|
|
22
|
+
readonly [invalid]: Message;
|
|
23
|
+
}
|
|
24
|
+
type IsUnion<T, U = T> = T extends unknown ? ([U] extends [T] ? false : true) : never;
|
|
25
|
+
/** A Message constructor from `defineMessageUnion`: a tagged Schema that can be called. */
|
|
26
|
+
type AnyMemberSchema = Schema.Top & {
|
|
27
|
+
readonly fields: Schema.Struct.Fields;
|
|
28
|
+
};
|
|
29
|
+
/** The Message a member makes. */
|
|
30
|
+
type Made<M> = M extends {
|
|
31
|
+
readonly Type: infer T;
|
|
32
|
+
} ? T : never;
|
|
33
|
+
/** The fields a member's event may be given fixed: all but `_tag`. */
|
|
34
|
+
type Fixable<M> = Partial<Omit<Made<M>, '_tag'>>;
|
|
35
|
+
/** The fields of a member the event fills: those neither `_tag` nor fixed. */
|
|
36
|
+
type Rest<M, Fixed> = Omit<Made<M>, '_tag' | keyof Fixed>;
|
|
37
|
+
type ProducesMessage<M, Message> = [Made<M>] extends [Message] ? unknown : Invalid<"the member is not one of this view's Messages">;
|
|
38
|
+
type TextHoleCheck<M, Fixed> = [keyof Rest<M, Fixed>] extends [never] ? Invalid<'the member has no field left for the event to fill'> : true extends IsUnion<keyof Rest<M, Fixed>> ? Invalid<'the member leaves more than one field for the event to fill: fix the others'> : Rest<M, Fixed>[keyof Rest<M, Fixed>] extends string ? string extends Rest<M, Fixed>[keyof Rest<M, Fixed>] ? unknown : Invalid<'the field the event fills must be a string'> : Invalid<'the field the event fills must be a string'>;
|
|
39
|
+
type KeyHoleCheck<M, Fixed> = [keyof Rest<M, Fixed>] extends ['key' | 'modifiers'] ? ['key' | 'modifiers'] extends [keyof Rest<M, Fixed>] ? unknown : Invalid<'the member must leave exactly key and modifiers for the event to fill'> : Invalid<'the member must leave exactly key and modifiers for the event to fill'>;
|
|
40
|
+
/** `OnInput` and `OnChange`: a closure, or a member whose one string field the event fills. */
|
|
41
|
+
interface TextHole<Message> {
|
|
42
|
+
(toMessage: (value: string) => Message): Attribute<Message>;
|
|
43
|
+
<M extends AnyMemberSchema, const Fixed extends Fixable<M> = {}>(member: M & ProducesMessage<M, Message> & TextHoleCheck<M, Fixed>, fixed?: Fixed): Attribute<Message>;
|
|
44
|
+
}
|
|
45
|
+
/** `OnKeyDown` and `OnKeyUp`: a closure, or a member whose `key` and `modifiers` the event fills. */
|
|
46
|
+
interface KeyHole<Message> {
|
|
47
|
+
(toMessage: (key: string, modifiers: KeyboardModifiers) => Message): Attribute<Message>;
|
|
48
|
+
<M extends AnyMemberSchema, const Fixed extends Fixable<M> = {}>(member: M & ProducesMessage<M, Message> & KeyHoleCheck<M, Fixed>, fixed?: Fixed): Attribute<Message>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* A builder a view is given: Foldkit's `HtmlBuilder`, or a Surface renderer's,
|
|
52
|
+
* which leaves out Foldkit's phantom key. Its Message is what `OnClick` takes.
|
|
53
|
+
*/
|
|
54
|
+
type AnyBuilder = {
|
|
55
|
+
readonly OnClick: (message: never, ...rest: ReadonlyArray<never>) => unknown;
|
|
56
|
+
};
|
|
57
|
+
/** The Message a builder's handlers make. */
|
|
58
|
+
type MessageOf<Builder> = Builder extends {
|
|
59
|
+
readonly OnClick: (message: infer Message, ...rest: ReadonlyArray<never>) => unknown;
|
|
60
|
+
} ? Message : never;
|
|
61
|
+
/**
|
|
62
|
+
* The resumable builder for a view whose Messages are `Message`: its elements
|
|
63
|
+
* and attributes, and the hole forms of the four value events. One shape
|
|
64
|
+
* whether it wraps a view's `HtmlBuilder` or a Surface renderer's builder, so a
|
|
65
|
+
* helper typed with it takes either. It keeps Foldkit's phantom Message key,
|
|
66
|
+
* so a placement's view accepts it as the parent's builder.
|
|
67
|
+
*/
|
|
68
|
+
type ResumableBuilder<Message> = Omit<HtmlBuilder<Message>, 'OnInput' | 'OnChange' | 'OnKeyDown' | 'OnKeyUp'> & {
|
|
69
|
+
readonly OnInput: TextHole<Message>;
|
|
70
|
+
readonly OnChange: TextHole<Message>;
|
|
71
|
+
readonly OnKeyDown: KeyHole<Message>;
|
|
72
|
+
readonly OnKeyUp: KeyHole<Message>;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* The resumable builder for a view's `h`. Use it in place of `h`; it has the
|
|
76
|
+
* same elements and attributes, and the hole forms of the four value events.
|
|
77
|
+
*/
|
|
78
|
+
declare const builder: <Builder extends AnyBuilder>(h: Builder) => ResumableBuilder<MessageOf<Builder>>;
|
|
79
|
+
/**
|
|
80
|
+
* A view or renderer written against the resumable builder, as one that takes
|
|
81
|
+
* the builder it is given: `Surface.rootView(Page, params, Resume.view(render))`,
|
|
82
|
+
* `SurfaceView.define`, or an application's own view.
|
|
83
|
+
*/
|
|
84
|
+
declare const view: <Model, Builder extends AnyBuilder, Out>(render: (model: Model, rh: ResumableBuilder<MessageOf<Builder>>) => Out) => (model: Model, h: Builder) => Out;
|
|
85
|
+
export { FALLBACK_FIELD as a, MessageOf as c, TextHole as d, UNNAMED_HANDLER as f, FALLBACK_DEPTH_FIELD as i, ResumableBuilder as l, view as m, BINDING_ATTRIBUTE as n, Invalid as o, builder as p, EVENT_OF as r, KeyHole as s, AnyBuilder as t, SLOT_ATTRIBUTE as u };
|
|
86
|
+
//# sourceMappingURL=resumable-BWItJsxF.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resumable-BWItJsxF.d.ts","names":[],"sources":["../src/resumable.ts"],"mappings":";;;cAoBa;;;;;;cAOA,UAAU,SAAS;;cAkGnB;;cAGA;;cAGA;;cAGA;cAEC;;UAGG,QAAQ;YACb,UAAU;;KAGjB,QAAQ,GAAG,IAAI,KAAK,sBAAsB,YAAY;;KAGtD,kBAAkB,OAAO;WAAiB,QAAQ,OAAO,OAAO;;;KAGhE,KAAK,KAAK;WAAqB,YAAY;IAAM;;KAGjD,QAAQ,KAAK,QAAQ,KAAK,KAAK;;KAG/B,KAAK,GAAG,SAAS,KAAK,KAAK,mBAAmB;KAE9C,gBAAgB,GAAG,YAAY,KAAK,aAAa,qBAElD;KAEC,cAAc,GAAG,gBAAgB,KAAK,GAAG,0BAC1C,6EACa,cAAc,KAAK,GAAG,UACjC,yFACA,KAAK,GAAG,aAAa,KAAK,GAAG,wCACZ,KAAK,GAAG,aAAa,KAAK,GAAG,oBAE1C,wDACF;KAEH,aAAa,GAAG,gBAAgB,KAAK,GAAG,6EACJ,KAAK,GAAG,oBAE3C,mFACF;;UAGa,SAAS;GACvB,YAAY,kBAAkB,UAAU,UAAU;GAClD,UAAU,uBAAuB,cAAc,QAAQ,SACtD,QAAQ,IAAI,gBAAgB,GAAG,WAAW,cAAc,GAAG,QAC3D,QAAQ,QACP,UAAU;;;UAIE,QAAQ;GACtB,YAAY,aAAa,WAAW,sBAAsB,UAAU,UAAU;GAC9E,UAAU,uBAAuB,cAAc,QAAQ,SACtD,QAAQ,IAAI,gBAAgB,GAAG,WAAW,aAAa,GAAG,QAC1D,QAAQ,QACP,UAAU;;;;;;KAOH;WACD,UAAU,mBAAmB,MAAM;;;KAIlC,UAAU,WAAW;WACtB,UAAU,eAAe,YAAY,MAAM;IAElD;;;;;;;;KAUQ,iBAAiB,WAAW,KACtC,YAAY;WAGH,SAAS,SAAS;WAClB,UAAU,SAAS;WACnB,WAAW,QAAQ;WACnB,SAAS,QAAQ;;;;;;cAyDf,UAAW,gBAAgB,YAAU,GAC7C,YACF,iBAAiB,UAAU;;;;;;cA6NjB,OACV,OAAO,gBAAgB,YAAY,KAAG,SAC5B,OAAO,OAAO,IAAI,iBAAiB,UAAU,cAAc,SAAG,OAEjE,OAAK,GAAK,YAAU"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as FALLBACK_FIELD, c as MessageOf, d as TextHole, f as UNNAMED_HANDLER, i as FALLBACK_DEPTH_FIELD, l as ResumableBuilder, m as view, n as BINDING_ATTRIBUTE, o as Invalid, p as builder, r as EVENT_OF, s as KeyHole, t as AnyBuilder, u as SLOT_ATTRIBUTE } from "./resumable-BWItJsxF.js";
|
|
2
|
+
export { AnyBuilder, BINDING_ATTRIBUTE, EVENT_OF, FALLBACK_DEPTH_FIELD, FALLBACK_FIELD, Invalid, KeyHole, MessageOf, ResumableBuilder, SLOT_ATTRIBUTE, TextHole, UNNAMED_HANDLER, builder, view };
|