foldkit-ssr 0.8.2 → 0.10.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.
Files changed (54) hide show
  1. package/README.md +496 -83
  2. package/dist/client-XnpTQZHw.d.ts +85 -0
  3. package/dist/client-XnpTQZHw.d.ts.map +1 -0
  4. package/dist/client.d.ts +5 -0
  5. package/dist/client.js +343 -0
  6. package/dist/client.js.map +1 -0
  7. package/dist/context.d.ts +2 -0
  8. package/dist/context.js +33 -0
  9. package/dist/context.js.map +1 -0
  10. package/dist/diagnostics.d.ts +2 -0
  11. package/dist/diagnostics.js +59 -0
  12. package/dist/diagnostics.js.map +1 -0
  13. package/dist/{index.d.mts → index.d.ts} +96 -25
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/{index.mjs → index.js} +247 -108
  16. package/dist/index.js.map +1 -0
  17. package/dist/keep.d.ts +34 -0
  18. package/dist/keep.d.ts.map +1 -0
  19. package/dist/keep.js +80 -0
  20. package/dist/keep.js.map +1 -0
  21. package/dist/listen-DaUPRKVR.d.ts +71 -0
  22. package/dist/listen-DaUPRKVR.d.ts.map +1 -0
  23. package/dist/listen.d.ts +2 -0
  24. package/dist/listen.js +187 -0
  25. package/dist/listen.js.map +1 -0
  26. package/dist/requestContext-D9nsbGSJ.d.ts +21 -0
  27. package/dist/requestContext-D9nsbGSJ.d.ts.map +1 -0
  28. package/dist/requestContext.d.ts +2 -0
  29. package/dist/requestContext.js +48 -0
  30. package/dist/requestContext.js.map +1 -0
  31. package/dist/resumable-BPN_qQHU.d.ts +107 -0
  32. package/dist/resumable-BPN_qQHU.d.ts.map +1 -0
  33. package/dist/resumable.d.ts +2 -0
  34. package/dist/resumable.js +401 -0
  35. package/dist/resumable.js.map +1 -0
  36. package/dist/{client-DkwAniQQ.d.mts → shared-DbupL3vO.d.ts} +233 -194
  37. package/dist/shared-DbupL3vO.d.ts.map +1 -0
  38. package/dist/shared.d.ts +2 -0
  39. package/dist/shared.js +347 -0
  40. package/dist/shared.js.map +1 -0
  41. package/dist/{vite.d.mts → vite.d.ts} +3 -5
  42. package/dist/vite.d.ts.map +1 -0
  43. package/dist/{vite.mjs → vite.js} +3 -4
  44. package/dist/vite.js.map +1 -0
  45. package/package.json +18 -18
  46. package/dist/client-DVG9_3rL.mjs +0 -1113
  47. package/dist/client-DVG9_3rL.mjs.map +0 -1
  48. package/dist/client-DkwAniQQ.d.mts.map +0 -1
  49. package/dist/client.d.mts +0 -2
  50. package/dist/client.mjs +0 -1
  51. package/dist/index.d.mts.map +0 -1
  52. package/dist/index.mjs.map +0 -1
  53. package/dist/vite.d.mts.map +0 -1
  54. package/dist/vite.mjs.map +0 -1
@@ -0,0 +1,401 @@
1
+ import { current } from "./context.js";
2
+ import { Schema, SchemaAST } from "effect";
3
+ // src/resumable.ts
4
+ /**
5
+ * The resumable builder: the application's `h`, whose event attributes say, in
6
+ * the server's markup, which Message each element causes.
7
+ *
8
+ * A Foldkit handler is a Message value (`h.OnClick(Message.Liked({ id }))`), so
9
+ * for most events that is already data. The events that carry a value
10
+ * (`OnInput`, `OnChange`, `OnKeyDown`, `OnKeyUp`) take a closure only to put
11
+ * the value into a Message field; this builder also takes the Message's own
12
+ * constructor there, a Message with a hole, and fills the hole the same way.
13
+ *
14
+ * During the server's renders each binding gets an ordinal, recorded in render
15
+ * order, and its element a `data-foldkit-plus-on-<event>` attribute naming it.
16
+ * In the browser the builder marks nothing: it is the application's `h`, with
17
+ * the hole forms turned into the closures Foldkit expects.
18
+ */
19
+ /** The attribute prefix of an element's binding marker. */
20
+ const BINDING_ATTRIBUTE = "data-foldkit-plus-on-";
21
+ /**
22
+ * The DOM event each of Foldkit's event attributes listens to, read from
23
+ * Foldkit's own attribute table (0.163). `OnCustomEvent` names its event in
24
+ * its payload, and `OnMount` and `OnUnmount` listen to none.
25
+ */
26
+ const EVENT_OF = {
27
+ OnClick: "click",
28
+ OnDoubleClick: "dblclick",
29
+ OnMouseDown: "mousedown",
30
+ OnMouseUp: "mouseup",
31
+ OnMouseEnter: "mouseenter",
32
+ OnMouseLeave: "mouseleave",
33
+ OnMouseOver: "mouseover",
34
+ OnMouseOut: "mouseout",
35
+ OnMouseMove: "mousemove",
36
+ OnPointerMove: "pointermove",
37
+ OnPointerLeave: "pointerleave",
38
+ OnPointerDown: "pointerdown",
39
+ OnPointerUp: "pointerup",
40
+ OnKeyDown: "keydown",
41
+ OnKeyDownPreventDefault: "keydown",
42
+ OnKeyDownSelf: "keydown",
43
+ OnKeyDownSelfPreventDefault: "keydown",
44
+ OnKeyDownFocus: "keydown",
45
+ OnKeyUp: "keyup",
46
+ OnKeyUpPreventDefault: "keyup",
47
+ OnKeyPress: "keypress",
48
+ OnFocus: "focus",
49
+ OnBlur: "blur",
50
+ OnFocusEnter: "focusin",
51
+ OnFocusLeave: "focusout",
52
+ OnInput: "input",
53
+ OnChange: "change",
54
+ OnBeforeInput: "beforeinput",
55
+ OnBeforeInputPreventDefault: "beforeinput",
56
+ OnFileChange: "change",
57
+ OnSubmit: "submit",
58
+ OnReset: "reset",
59
+ OnScroll: "scroll",
60
+ OnWheel: "wheel",
61
+ OnCopy: "copy",
62
+ OnCut: "cut",
63
+ OnPaste: "paste",
64
+ OnPastePreventDefault: "paste",
65
+ OnCopyText: "copy",
66
+ OnCutText: "cut",
67
+ OnCancel: "cancel",
68
+ OnCancelPreventDefault: "cancel",
69
+ OnToggle: "toggle",
70
+ OnContextMenu: "contextmenu",
71
+ OnDragStart: "dragstart",
72
+ OnDrag: "drag",
73
+ OnDragEnd: "dragend",
74
+ OnDragEnter: "dragenter",
75
+ OnDragLeave: "dragleave",
76
+ OnDragOver: "dragover",
77
+ OnDrop: "drop",
78
+ OnDropFiles: "drop",
79
+ OnTouchStart: "touchstart",
80
+ OnTouchEnd: "touchend",
81
+ OnTouchMove: "touchmove",
82
+ OnTouchCancel: "touchcancel",
83
+ OnAnimationStart: "animationstart",
84
+ OnAnimationEnd: "animationend",
85
+ OnAnimationIteration: "animationiteration",
86
+ OnTransitionEnd: "transitionend",
87
+ OnLoad: "load",
88
+ OnError: "error",
89
+ OnPlay: "play",
90
+ OnPause: "pause",
91
+ OnEnded: "ended",
92
+ OnTimeUpdate: "timeupdate",
93
+ OnVolumeChange: "volumechange",
94
+ OnSelect: "select"
95
+ };
96
+ /**
97
+ * The attributes whose binding the page can describe: a Message value, or one
98
+ * of the hole forms this builder records. Any other handler still runs on the
99
+ * live page, so its event is marked `*`: the page does something there it
100
+ * cannot name, and a dispatcher that ran only the named bindings would do less.
101
+ */
102
+ const MARKABLE = /* @__PURE__ */ new Set([
103
+ "OnClick",
104
+ "OnDoubleClick",
105
+ "OnMouseDown",
106
+ "OnMouseUp",
107
+ "OnMouseEnter",
108
+ "OnMouseLeave",
109
+ "OnMouseOver",
110
+ "OnMouseOut",
111
+ "OnMouseMove",
112
+ "OnFocus",
113
+ "OnBlur",
114
+ "OnSubmit",
115
+ "OnReset",
116
+ "OnInput",
117
+ "OnChange",
118
+ "OnKeyDown",
119
+ "OnKeyUp"
120
+ ]);
121
+ /** The token in a marker for a handler the page cannot describe. */
122
+ const UNNAMED_HANDLER = "*";
123
+ /** The posted field that carries a form's encoded Message, for the server fallback. */
124
+ const FALLBACK_FIELD = "foldkit-plus-message";
125
+ /** The posted field that says how many placement wrappers the form's fields sit under. */
126
+ const FALLBACK_DEPTH_FIELD = "foldkit-plus-depth";
127
+ /**
128
+ * The attribute on a field whose typing before boot is kept (`KeepTyped`),
129
+ * naming the binding whose Message replays it.
130
+ */
131
+ const KEEP_ATTRIBUTE = "data-foldkit-plus-keep";
132
+ /** The value of a `KeepTyped` marker no resumable element took, while the server renders. */
133
+ const UNPLACED_KEEP = "?";
134
+ /**
135
+ * The `input` types whose value is not something typed, so `KeepTyped` has
136
+ * nothing to keep on them.
137
+ */
138
+ const UNTYPED_INPUTS = /* @__PURE__ */ new Set([
139
+ "checkbox",
140
+ "radio",
141
+ "file",
142
+ "hidden",
143
+ "button",
144
+ "submit",
145
+ "reset",
146
+ "image"
147
+ ]);
148
+ /** The attribute on a placement's root naming its slot, while the server renders. */
149
+ const SLOT_ATTRIBUTE = "data-foldkit-plus-slot";
150
+ const isMember = (value) => typeof value === "function" && typeof value.fields === "object";
151
+ const tagOf = (member) => {
152
+ const tag = member.fields._tag;
153
+ return Schema.isSchema(tag) && SchemaAST.isLiteral(tag.ast) && typeof tag.ast.literal === "string" ? tag.ast.literal : "the member";
154
+ };
155
+ /**
156
+ * The fields a member leaves for the event to fill, given what is fixed. Only
157
+ * `fixed`'s own keys fix a field: `in` finds `constructor` on every object.
158
+ */
159
+ const holeOf = (member, fixed) => Object.keys(member.fields).filter((field) => field !== "_tag" && !Object.hasOwn(fixed, field));
160
+ const NO_MODIFIERS = {
161
+ shiftKey: false,
162
+ ctrlKey: false,
163
+ altKey: false,
164
+ metaKey: false
165
+ };
166
+ /** Each hole-form attribute, with its Message filled by a placeholder and the fields the event fills. */
167
+ const holes = /* @__PURE__ */ new WeakMap();
168
+ const isAttribute = (item) => "_tag" in item;
169
+ const builders = /* @__PURE__ */ new WeakMap();
170
+ /** Each attribute `KeepTyped` made: a request to the element it is given, never written as it is. */
171
+ const keeps = /* @__PURE__ */ new WeakSet();
172
+ /** A hole form's placeholder Message, or `undefined` when its field's checks refuse one. */
173
+ const placeholder = (make) => {
174
+ try {
175
+ return make();
176
+ } catch {
177
+ return;
178
+ }
179
+ };
180
+ /**
181
+ * The resumable builder for a view's `h`. Use it in place of `h`; it has the
182
+ * same elements and attributes, and the hole forms of the four value events.
183
+ */
184
+ const builder = (h) => {
185
+ const cached = builders.get(h);
186
+ if (cached !== void 0) return cached;
187
+ const source = h;
188
+ const attribute = source.Attribute;
189
+ /** The attributes with a marker for each binding, while the server renders. */
190
+ const mark = (tag, given) => {
191
+ const kept = given.some((item) => keeps.has(item));
192
+ const attributes = kept ? given.filter((item) => !keeps.has(item)) : given;
193
+ const now = current();
194
+ if (now?.mode !== "collect" && now?.mode !== "replay") return attributes;
195
+ const id = attributes.find((item) => isAttribute(item) && item._tag === "Id");
196
+ const element = id === void 0 ? tag : `${tag}#${id.value}`;
197
+ const tokens = /* @__PURE__ */ new Map();
198
+ const typed = /* @__PURE__ */ new Map();
199
+ for (const item of attributes) {
200
+ if (!isAttribute(item)) continue;
201
+ const event = item._tag === "OnCustomEvent" ? item.name : EVENT_OF[item._tag];
202
+ if (event === void 0) continue;
203
+ if (now.mode === "collect" && now.region !== void 0) now.inStatic.push({
204
+ region: now.region,
205
+ element,
206
+ event
207
+ });
208
+ const recorded = holes.get(item);
209
+ const nested = now.depth === 0 ? {} : { depth: now.depth };
210
+ const binding = !MARKABLE.has(item._tag) ? void 0 : "message" in item ? {
211
+ attribute: item._tag,
212
+ event,
213
+ element,
214
+ message: now.wrap(item.message),
215
+ ..."options" in item && item.options !== void 0 ? { options: item.options } : {}
216
+ } : recorded === void 0 ? void 0 : {
217
+ attribute: item._tag,
218
+ event,
219
+ element,
220
+ message: now.wrap(recorded.template),
221
+ hole: recorded.hole,
222
+ ...nested
223
+ };
224
+ const list = tokens.get(event) ?? [];
225
+ tokens.set(event, list);
226
+ if (binding === void 0) {
227
+ if (now.mode === "collect" && !list.includes("*")) now.unnamed.push({
228
+ element,
229
+ event
230
+ });
231
+ list.push("*");
232
+ } else {
233
+ if (binding.hole !== void 0 && !typed.has(binding.attribute)) typed.set(binding.attribute, now.bindings.length);
234
+ list.push(String(now.bindings.length));
235
+ now.bindings.push(binding);
236
+ }
237
+ }
238
+ const markers = [...tokens].map(([event, list]) => attribute(`${BINDING_ATTRIBUTE}${event}`, list.join(" ")));
239
+ if (kept) {
240
+ const ordinal = typed.get("OnInput") ?? typed.get("OnChange");
241
+ const type = attributes.find((item) => isAttribute(item) && item._tag === "Type")?.value;
242
+ if (!(tag === "textarea" || tag === "select" || tag === "input" && (type === void 0 || !UNTYPED_INPUTS.has(type.toLowerCase())))) {
243
+ if (now.mode === "collect") now.unkeepable.push(`KeepTyped on ${type === void 0 ? element : `${element} of type ${type}`}, which holds no typed value: keep an input that takes text, a textarea or a select`);
244
+ } else if (ordinal === void 0) {
245
+ if (now.mode === "collect") now.unkeepable.push(`KeepTyped on ${element}, which has no OnInput or OnChange given a Message member, so nothing names the Message its typing replays as`);
246
+ } else markers.push(attribute(KEEP_ATTRIBUTE, String(ordinal)));
247
+ }
248
+ return markers.length === 0 ? attributes : [...attributes, ...markers];
249
+ };
250
+ /**
251
+ * A form whose `OnSubmit` names a Message, while the server renders for a
252
+ * plan with a fallback, also posts that Message: `method="post"` to its own
253
+ * URL, and a hidden input carrying the Message encoded. Posted fields named
254
+ * as the Message's own fields override them, so a typed title reaches
255
+ * `update` as it would through the page. A form given its own `Method` is
256
+ * the view's, left as drawn: a search is a GET of the address the URL
257
+ * mirror reads, and posts no Message.
258
+ */
259
+ const fallback = (tag, attributes, children) => {
260
+ const now = current();
261
+ if (tag !== "form" || now?.mode === void 0 || now.mode === "resume" || now.fallback === void 0) return {
262
+ attributes,
263
+ children
264
+ };
265
+ const submit = attributes.find((item) => isAttribute(item) && item._tag === "OnSubmit");
266
+ const method = attributes.some((item) => isAttribute(item) && item._tag === "Method");
267
+ if (submit === void 0 || method || !Array.isArray(children)) return {
268
+ attributes,
269
+ children
270
+ };
271
+ const encoded = now.fallback(now.wrap(submit.message));
272
+ if (encoded === void 0) return {
273
+ attributes,
274
+ children
275
+ };
276
+ const make = (name) => source[name];
277
+ const input = source.input;
278
+ const hidden = (name, value) => input([
279
+ make("Type")("hidden"),
280
+ make("Name")(name),
281
+ make("Value")(value)
282
+ ]);
283
+ return {
284
+ attributes: [...attributes, make("Method")("post")],
285
+ children: [
286
+ ...children,
287
+ hidden(FALLBACK_FIELD, encoded),
288
+ ...now.depth === 0 ? [] : [hidden(FALLBACK_DEPTH_FIELD, String(now.depth))]
289
+ ]
290
+ };
291
+ };
292
+ const textHole = (name) => (given, fixed = {}) => {
293
+ const make = source[name];
294
+ if (!isMember(given)) return make(given);
295
+ const hole = holeOf(given, fixed);
296
+ if (hole.length !== 1) throw new Error(`Resume.builder: ${name}(${tagOf(given)}) leaves ${hole.length === 0 ? "no field" : hole.join(", ")} for the event to fill; it must leave one string field`);
297
+ const [field] = hole;
298
+ const made = make((value) => given({
299
+ ...fixed,
300
+ [field]: value
301
+ }));
302
+ const template = placeholder(() => given({
303
+ ...fixed,
304
+ [field]: ""
305
+ }));
306
+ if (template !== void 0) holes.set(made, {
307
+ template,
308
+ hole
309
+ });
310
+ return made;
311
+ };
312
+ const keyHole = (name) => (given, fixed = {}) => {
313
+ const make = source[name];
314
+ if (!isMember(given)) return make(given);
315
+ const hole = holeOf(given, fixed);
316
+ if (hole.length !== 2 || !hole.includes("key") || !hole.includes("modifiers")) throw new Error(`Resume.builder: ${name}(${tagOf(given)}) leaves ${hole.join(", ") || "no field"} for the event to fill; it must leave exactly key and modifiers`);
317
+ const made = make((key, modifiers) => given({
318
+ ...fixed,
319
+ key,
320
+ modifiers
321
+ }));
322
+ const template = placeholder(() => given({
323
+ ...fixed,
324
+ key: "",
325
+ modifiers: NO_MODIFIERS
326
+ }));
327
+ if (template !== void 0) holes.set(made, {
328
+ template,
329
+ hole
330
+ });
331
+ return made;
332
+ };
333
+ /**
334
+ * `h.submodel` with the child's root stamped with its slot, while the
335
+ * server renders: a boundary a tool can find, which the browser takes off
336
+ * as the page boots, with the markers.
337
+ */
338
+ const submodel = (config) => {
339
+ const original = source.submodel;
340
+ const now = current();
341
+ if (now?.mode !== "collect" && now?.mode !== "replay") return original(config);
342
+ const view = config.view;
343
+ const stamped = (...args) => {
344
+ const outer = {
345
+ wrap: now.wrap,
346
+ depth: now.depth
347
+ };
348
+ now.wrap = (message) => outer.wrap(config.toParentMessage(message));
349
+ now.depth = outer.depth + 1;
350
+ let out;
351
+ try {
352
+ out = view(...args);
353
+ } finally {
354
+ now.wrap = outer.wrap;
355
+ now.depth = outer.depth;
356
+ }
357
+ if (out !== null && typeof out === "object" && out.data !== void 0) out.data.attrs = {
358
+ ...out.data.attrs,
359
+ [SLOT_ATTRIBUTE]: config.slotId
360
+ };
361
+ return out;
362
+ };
363
+ return original({
364
+ ...config,
365
+ view: Object.assign(stamped, view)
366
+ });
367
+ };
368
+ const wrapped = {};
369
+ for (const [name, value] of Object.entries(source)) if (name === "submodel") wrapped[name] = submodel;
370
+ else if (name === "OnInput" || name === "OnChange") wrapped[name] = textHole(name);
371
+ else if (name === "OnKeyDown" || name === "OnKeyUp") wrapped[name] = keyHole(name);
372
+ else if (name === "keyed") {
373
+ const keyed = value;
374
+ wrapped[name] = (tag) => (key, attributes = [], ...rest) => {
375
+ const posted = fallback(tag, attributes, rest[0]);
376
+ return keyed(tag)(key, mark(tag, posted.attributes), posted.children, ...rest.slice(1));
377
+ };
378
+ } else if (/^[a-z]/.test(name) && typeof value === "function") {
379
+ const element = value;
380
+ wrapped[name] = (attributes, ...rest) => {
381
+ const posted = fallback(name, attributes, rest[0]);
382
+ return element(mark(name, posted.attributes), posted.children, ...rest.slice(1));
383
+ };
384
+ } else wrapped[name] = value;
385
+ wrapped.KeepTyped = () => {
386
+ const made = attribute(KEEP_ATTRIBUTE, current()?.mode === "collect" ? "?" : "");
387
+ keeps.add(made);
388
+ return made;
389
+ };
390
+ builders.set(h, wrapped);
391
+ return wrapped;
392
+ };
393
+ /**
394
+ * A view or renderer written against the resumable builder, as one that takes
395
+ * the builder it is given: `Surface.rootView(Page, params, Resume.view(render))`,
396
+ * `SurfaceView.define`, or an application's own view.
397
+ */
398
+ const view = (render) => (model, h) => render(model, builder(h));
399
+ export { BINDING_ATTRIBUTE, EVENT_OF, FALLBACK_DEPTH_FIELD, FALLBACK_FIELD, KEEP_ATTRIBUTE, SLOT_ATTRIBUTE, UNNAMED_HANDLER, UNPLACED_KEEP, builder, view };
400
+
401
+ //# sourceMappingURL=resumable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resumable.js","names":[],"sources":["../src/resumable.ts"],"sourcesContent":["/**\n * The resumable builder: the application's `h`, whose event attributes say, in\n * the server's markup, which Message each element causes.\n *\n * A Foldkit handler is a Message value (`h.OnClick(Message.Liked({ id }))`), so\n * for most events that is already data. The events that carry a value\n * (`OnInput`, `OnChange`, `OnKeyDown`, `OnKeyUp`) take a closure only to put\n * the value into a Message field; this builder also takes the Message's own\n * constructor there, a Message with a hole, and fills the hole the same way.\n *\n * During the server's renders each binding gets an ordinal, recorded in render\n * order, and its element a `data-foldkit-plus-on-<event>` attribute naming it.\n * In the browser the builder marks nothing: it is the application's `h`, with\n * the hole forms turned into the closures Foldkit expects.\n */\nimport { Schema, SchemaAST } from 'effect'\nimport type { Attribute, ChildAttribute, HtmlBuilder, KeyboardModifiers } from 'foldkit/html'\nimport { current, type Binding } from './context.js'\n\n/** The attribute prefix of an element's binding marker. */\nexport const BINDING_ATTRIBUTE = 'data-foldkit-plus-on-'\n\n/**\n * The DOM event each of Foldkit's event attributes listens to, read from\n * Foldkit's own attribute table (0.163). `OnCustomEvent` names its event in\n * its payload, and `OnMount` and `OnUnmount` listen to none.\n */\nexport const EVENT_OF: Readonly<Record<string, string>> = {\n OnClick: 'click',\n OnDoubleClick: 'dblclick',\n OnMouseDown: 'mousedown',\n OnMouseUp: 'mouseup',\n OnMouseEnter: 'mouseenter',\n OnMouseLeave: 'mouseleave',\n OnMouseOver: 'mouseover',\n OnMouseOut: 'mouseout',\n OnMouseMove: 'mousemove',\n OnPointerMove: 'pointermove',\n OnPointerLeave: 'pointerleave',\n OnPointerDown: 'pointerdown',\n OnPointerUp: 'pointerup',\n OnKeyDown: 'keydown',\n OnKeyDownPreventDefault: 'keydown',\n OnKeyDownSelf: 'keydown',\n OnKeyDownSelfPreventDefault: 'keydown',\n OnKeyDownFocus: 'keydown',\n OnKeyUp: 'keyup',\n OnKeyUpPreventDefault: 'keyup',\n OnKeyPress: 'keypress',\n OnFocus: 'focus',\n OnBlur: 'blur',\n OnFocusEnter: 'focusin',\n OnFocusLeave: 'focusout',\n OnInput: 'input',\n OnChange: 'change',\n OnBeforeInput: 'beforeinput',\n OnBeforeInputPreventDefault: 'beforeinput',\n OnFileChange: 'change',\n OnSubmit: 'submit',\n OnReset: 'reset',\n OnScroll: 'scroll',\n OnWheel: 'wheel',\n OnCopy: 'copy',\n OnCut: 'cut',\n OnPaste: 'paste',\n OnPastePreventDefault: 'paste',\n OnCopyText: 'copy',\n OnCutText: 'cut',\n OnCancel: 'cancel',\n OnCancelPreventDefault: 'cancel',\n OnToggle: 'toggle',\n OnContextMenu: 'contextmenu',\n OnDragStart: 'dragstart',\n OnDrag: 'drag',\n OnDragEnd: 'dragend',\n OnDragEnter: 'dragenter',\n OnDragLeave: 'dragleave',\n OnDragOver: 'dragover',\n OnDrop: 'drop',\n OnDropFiles: 'drop',\n OnTouchStart: 'touchstart',\n OnTouchEnd: 'touchend',\n OnTouchMove: 'touchmove',\n OnTouchCancel: 'touchcancel',\n OnAnimationStart: 'animationstart',\n OnAnimationEnd: 'animationend',\n OnAnimationIteration: 'animationiteration',\n OnTransitionEnd: 'transitionend',\n OnLoad: 'load',\n OnError: 'error',\n OnPlay: 'play',\n OnPause: 'pause',\n OnEnded: 'ended',\n OnTimeUpdate: 'timeupdate',\n OnVolumeChange: 'volumechange',\n OnSelect: 'select',\n}\n\n/**\n * The attributes whose binding the page can describe: a Message value, or one\n * of the hole forms this builder records. Any other handler still runs on the\n * live page, so its event is marked `*`: the page does something there it\n * cannot name, and a dispatcher that ran only the named bindings would do less.\n */\nconst MARKABLE: ReadonlySet<string> = new Set([\n 'OnClick',\n 'OnDoubleClick',\n 'OnMouseDown',\n 'OnMouseUp',\n 'OnMouseEnter',\n 'OnMouseLeave',\n 'OnMouseOver',\n 'OnMouseOut',\n 'OnMouseMove',\n 'OnFocus',\n 'OnBlur',\n 'OnSubmit',\n 'OnReset',\n 'OnInput',\n 'OnChange',\n 'OnKeyDown',\n 'OnKeyUp',\n])\n\n/** The token in a marker for a handler the page cannot describe. */\nexport const UNNAMED_HANDLER = '*'\n\n/** The posted field that carries a form's encoded Message, for the server fallback. */\nexport const FALLBACK_FIELD = 'foldkit-plus-message'\n\n/** The posted field that says how many placement wrappers the form's fields sit under. */\nexport const FALLBACK_DEPTH_FIELD = 'foldkit-plus-depth'\n\n/**\n * The attribute on a field whose typing before boot is kept (`KeepTyped`),\n * naming the binding whose Message replays it.\n */\nexport const KEEP_ATTRIBUTE = 'data-foldkit-plus-keep'\n\n/** The value of a `KeepTyped` marker no resumable element took, while the server renders. */\nexport const UNPLACED_KEEP = '?'\n\n/**\n * The `input` types whose value is not something typed, so `KeepTyped` has\n * nothing to keep on them.\n */\nconst UNTYPED_INPUTS: ReadonlySet<string> = new Set([\n 'checkbox',\n 'radio',\n 'file',\n 'hidden',\n 'button',\n 'submit',\n 'reset',\n 'image',\n])\n\n/** The attribute on a placement's root naming its slot, while the server renders. */\nexport const SLOT_ATTRIBUTE = 'data-foldkit-plus-slot'\n\ndeclare const invalid: unique symbol\n\n/** A compile-time failure that names its cause. */\nexport interface Invalid<Message extends string> {\n readonly [invalid]: Message\n}\n\ntype IsUnion<T, U = T> = T extends unknown ? ([U] extends [T] ? false : true) : never\n\n/** A Message constructor from `defineMessageUnion`: a tagged Schema that can be called. */\ntype AnyMemberSchema = Schema.Top & { readonly fields: Schema.Struct.Fields }\n\n/** The Message a member makes. */\ntype Made<M> = M extends { readonly Type: infer T } ? T : never\n\n/** The fields a member's event may be given fixed: all but `_tag`. */\ntype Fixable<M> = Partial<Omit<Made<M>, '_tag'>>\n\n/** The fields of a member the event fills: those neither `_tag` nor fixed. */\ntype Rest<M, Fixed> = Omit<Made<M>, '_tag' | keyof Fixed>\n\ntype ProducesMessage<M, Message> = [Made<M>] extends [Message]\n ? unknown\n : Invalid<\"the member is not one of this view's Messages\">\n\ntype TextHoleCheck<M, Fixed> = [keyof Rest<M, Fixed>] extends [never]\n ? Invalid<'the member has no field left for the event to fill'>\n : true extends IsUnion<keyof Rest<M, Fixed>>\n ? Invalid<'the member leaves more than one field for the event to fill: fix the others'>\n : Rest<M, Fixed>[keyof Rest<M, Fixed>] extends string\n ? string extends Rest<M, Fixed>[keyof Rest<M, Fixed>]\n ? unknown\n : Invalid<'the field the event fills must be a string'>\n : Invalid<'the field the event fills must be a string'>\n\ntype KeyHoleCheck<M, Fixed> = [keyof Rest<M, Fixed>] extends ['key' | 'modifiers']\n ? ['key' | 'modifiers'] extends [keyof Rest<M, Fixed>]\n ? unknown\n : Invalid<'the member must leave exactly key and modifiers for the event to fill'>\n : Invalid<'the member must leave exactly key and modifiers for the event to fill'>\n\n/**\n * Foldkit's attribute of one tag, as its own builder returns it, so an\n * element that refuses some attributes (a `textarea`, `InnerHTML`) takes it.\n */\ntype Tagged<Message, Tag extends string> = Extract<Attribute<Message>, { readonly _tag: Tag }>\n\n/** `OnInput` and `OnChange`: a closure, or a member whose one string field the event fills. */\nexport interface TextHole<Message, Tag extends string> {\n (toMessage: (value: string) => Message): Tagged<Message, Tag>\n <M extends AnyMemberSchema, const Fixed extends Fixable<M> = {}>(\n member: M & ProducesMessage<M, Message> & TextHoleCheck<M, Fixed>,\n fixed?: Fixed,\n ): Tagged<Message, Tag>\n}\n\n/** `OnKeyDown` and `OnKeyUp`: a closure, or a member whose `key` and `modifiers` the event fills. */\nexport interface KeyHole<Message, Tag extends string> {\n (toMessage: (key: string, modifiers: KeyboardModifiers) => Message): Tagged<Message, Tag>\n <M extends AnyMemberSchema, const Fixed extends Fixable<M> = {}>(\n member: M & ProducesMessage<M, Message> & KeyHoleCheck<M, Fixed>,\n fixed?: Fixed,\n ): Tagged<Message, Tag>\n}\n\n/**\n * A builder a view is given: Foldkit's `HtmlBuilder`, or a Surface renderer's,\n * which leaves out Foldkit's phantom key. Its Message is what `OnClick` takes.\n */\nexport type AnyBuilder = {\n readonly OnClick: (message: never, ...rest: ReadonlyArray<never>) => unknown\n}\n\n/** The Message a builder's handlers make. */\nexport type MessageOf<Builder> = Builder extends {\n readonly OnClick: (message: infer Message, ...rest: ReadonlyArray<never>) => unknown\n}\n ? Message\n : never\n\n/**\n * The resumable builder for a view whose Messages are `Message`: its elements\n * and attributes, and the hole forms of the four value events. One shape\n * whether it wraps a view's `HtmlBuilder` or a Surface renderer's builder, so a\n * helper typed with it takes either. It keeps Foldkit's phantom Message key,\n * so a placement's view accepts it as the parent's builder.\n */\nexport type ResumableBuilder<Message> = Omit<\n HtmlBuilder<Message>,\n 'OnInput' | 'OnChange' | 'OnKeyDown' | 'OnKeyUp'\n> & {\n readonly OnInput: TextHole<Message, 'OnInput'>\n readonly OnChange: TextHole<Message, 'OnChange'>\n readonly OnKeyDown: KeyHole<Message, 'OnKeyDown'>\n readonly OnKeyUp: KeyHole<Message, 'OnKeyUp'>\n /**\n * Keeps what is typed into this field before the runtime starts: the\n * browser replays it as the field's `OnInput` Message (else its\n * `OnChange`), given in the hole form, and keeps the caret. The field must\n * be an `input` that takes text, a `textarea` or a `select`.\n */\n readonly KeepTyped: () => Tagged<Message, 'Attribute'>\n}\n\ntype AnyMember = ((value: Record<string, unknown>) => unknown) & {\n readonly fields: Readonly<Record<string, unknown>>\n}\n\nconst isMember = (value: unknown): value is AnyMember =>\n typeof value === 'function' && typeof (value as { fields?: unknown }).fields === 'object'\n\nconst tagOf = (member: AnyMember): string => {\n const tag = member.fields._tag\n return Schema.isSchema(tag) && SchemaAST.isLiteral(tag.ast) && typeof tag.ast.literal === 'string'\n ? tag.ast.literal\n : 'the member'\n}\n\n/**\n * The fields a member leaves for the event to fill, given what is fixed. Only\n * `fixed`'s own keys fix a field: `in` finds `constructor` on every object.\n */\nconst holeOf = (member: AnyMember, fixed: object): ReadonlyArray<string> =>\n Object.keys(member.fields).filter(field => field !== '_tag' && !Object.hasOwn(fixed, field))\n\nconst NO_MODIFIERS: KeyboardModifiers = {\n shiftKey: false,\n ctrlKey: false,\n altKey: false,\n metaKey: false,\n}\n\n/** Each hole-form attribute, with its Message filled by a placeholder and the fields the event fills. */\nconst holes = new WeakMap<\n object,\n { readonly template: unknown; readonly hole: ReadonlyArray<string> }\n>()\n\n/** What an element is given: Foldkit's attributes, and a Submodel's wrapped ones, which carry no tag. */\ntype Item = Attribute<unknown> | ChildAttribute\n\nconst isAttribute = (item: Item): item is Attribute<unknown> => '_tag' in item\n\nconst builders = new WeakMap<object, unknown>()\n\n/** Each attribute `KeepTyped` made: a request to the element it is given, never written as it is. */\nconst keeps = new WeakSet<object>()\n\n/** A hole form's placeholder Message, or `undefined` when its field's checks refuse one. */\nconst placeholder = (make: () => unknown): unknown => {\n try {\n return make()\n } catch {\n return undefined\n }\n}\n\n/**\n * The resumable builder for a view's `h`. Use it in place of `h`; it has the\n * same elements and attributes, and the hole forms of the four value events.\n */\nexport const builder = <Builder extends AnyBuilder>(\n h: Builder,\n): ResumableBuilder<MessageOf<Builder>> => {\n const cached = builders.get(h)\n if (cached !== undefined) return cached as ResumableBuilder<MessageOf<Builder>>\n const source = h as unknown as Record<string, unknown>\n const attribute = source.Attribute as (name: string, value: string) => unknown\n\n /** The attributes with a marker for each binding, while the server renders. */\n const mark = (tag: string, given: ReadonlyArray<Item>): ReadonlyArray<unknown> => {\n const kept = given.some(item => keeps.has(item))\n const attributes = kept ? given.filter(item => !keeps.has(item)) : given\n const now = current()\n if (now?.mode !== 'collect' && now?.mode !== 'replay') return attributes\n const id = attributes.find(\n (item): item is Extract<Attribute<unknown>, { readonly _tag: 'Id' }> =>\n isAttribute(item) && item._tag === 'Id',\n )\n const element = id === undefined ? tag : `${tag}#${id.value}`\n // Foldkit chains every handler of an event, in the order the attributes\n // come, so a marker lists every binding of its event in that order.\n const tokens = new Map<string, Array<string>>()\n // The ordinal of the element's hole-form `OnInput` and `OnChange`, which `KeepTyped` replays.\n const typed = new Map<string, number>()\n for (const item of attributes) {\n if (!isAttribute(item)) continue\n const event = item._tag === 'OnCustomEvent' ? item.name : EVENT_OF[item._tag]\n if (event === undefined) continue\n // Recorded for the refusal; the render does not survive it.\n if (now.mode === 'collect' && now.region !== undefined) {\n now.inStatic.push({ region: now.region, element, event })\n }\n const recorded = holes.get(item)\n const nested = now.depth === 0 ? {} : { depth: now.depth }\n const binding: Binding | undefined = !MARKABLE.has(item._tag)\n ? undefined\n : 'message' in item\n ? {\n attribute: item._tag,\n event,\n element,\n message: now.wrap(item.message),\n ...('options' in item && item.options !== undefined ? { options: item.options } : {}),\n }\n : recorded === undefined\n ? undefined\n : {\n attribute: item._tag,\n event,\n element,\n message: now.wrap(recorded.template),\n hole: recorded.hole,\n ...nested,\n }\n const list = tokens.get(event) ?? []\n tokens.set(event, list)\n if (binding === undefined) {\n // One entry per element and event, however many handlers it chains.\n if (now.mode === 'collect' && !list.includes(UNNAMED_HANDLER)) {\n now.unnamed.push({ element, event })\n }\n list.push(UNNAMED_HANDLER)\n } else {\n if (binding.hole !== undefined && !typed.has(binding.attribute)) {\n typed.set(binding.attribute, now.bindings.length)\n }\n list.push(String(now.bindings.length))\n now.bindings.push(binding)\n }\n }\n const markers = [...tokens].map(([event, list]) =>\n attribute(`${BINDING_ATTRIBUTE}${event}`, list.join(' ')),\n )\n if (kept) {\n const ordinal = typed.get('OnInput') ?? typed.get('OnChange')\n const type = attributes.find(\n (item): item is Extract<Attribute<unknown>, { readonly _tag: 'Type' }> =>\n isAttribute(item) && item._tag === 'Type',\n )?.value\n const field =\n tag === 'textarea' ||\n tag === 'select' ||\n (tag === 'input' && (type === undefined || !UNTYPED_INPUTS.has(type.toLowerCase())))\n if (!field) {\n if (now.mode === 'collect') {\n now.unkeepable.push(\n `KeepTyped on ${type === undefined ? element : `${element} of type ${type}`}, which holds no typed value: keep an input that takes text, a textarea or a select`,\n )\n }\n } else if (ordinal === undefined) {\n if (now.mode === 'collect') {\n now.unkeepable.push(\n `KeepTyped on ${element}, which has no OnInput or OnChange given a Message member, so nothing names the Message its typing replays as`,\n )\n }\n } else markers.push(attribute(KEEP_ATTRIBUTE, String(ordinal)))\n }\n return markers.length === 0 ? attributes : [...attributes, ...markers]\n }\n\n /**\n * A form whose `OnSubmit` names a Message, while the server renders for a\n * plan with a fallback, also posts that Message: `method=\"post\"` to its own\n * URL, and a hidden input carrying the Message encoded. Posted fields named\n * as the Message's own fields override them, so a typed title reaches\n * `update` as it would through the page. A form given its own `Method` is\n * the view's, left as drawn: a search is a GET of the address the URL\n * mirror reads, and posts no Message.\n */\n const fallback = (\n tag: string,\n attributes: ReadonlyArray<Item>,\n children: unknown,\n ): { readonly attributes: ReadonlyArray<Item>; readonly children: unknown } => {\n const now = current()\n if (\n tag !== 'form' ||\n now?.mode === undefined ||\n now.mode === 'resume' ||\n now.fallback === undefined\n ) {\n return { attributes, children }\n }\n const submit = attributes.find(\n (item): item is Extract<Attribute<unknown>, { readonly _tag: 'OnSubmit' }> =>\n isAttribute(item) && item._tag === 'OnSubmit',\n )\n const method = attributes.some(item => isAttribute(item) && item._tag === 'Method')\n if (submit === undefined || method || !Array.isArray(children)) return { attributes, children }\n const encoded = now.fallback(now.wrap(submit.message))\n if (encoded === undefined) return { attributes, children }\n const make = (name: string) => source[name] as (value: string) => Attribute<unknown>\n const input = source.input as (attributes: ReadonlyArray<unknown>) => unknown\n const hidden = (name: string, value: string) =>\n input([make('Type')('hidden'), make('Name')(name), make('Value')(value)])\n return {\n attributes: [...attributes, make('Method')('post')],\n children: [\n ...children,\n hidden(FALLBACK_FIELD, encoded),\n ...(now.depth === 0 ? [] : [hidden(FALLBACK_DEPTH_FIELD, String(now.depth))]),\n ],\n }\n }\n\n const textHole =\n (name: string) =>\n (given: unknown, fixed: Record<string, unknown> = {}): unknown => {\n const make = source[name] as (toMessage: (value: string) => unknown) => object\n if (!isMember(given)) return make(given as (value: string) => unknown)\n const hole = holeOf(given, fixed)\n if (hole.length !== 1) {\n throw new Error(\n `Resume.builder: ${name}(${tagOf(given)}) leaves ${hole.length === 0 ? 'no field' : hole.join(', ')} for the event to fill; it must leave one string field`,\n )\n }\n const [field] = hole as [string]\n const made = make(value => given({ ...fixed, [field]: value }))\n const template = placeholder(() => given({ ...fixed, [field]: '' }))\n // A field whose checks refuse the empty placeholder cannot be written\n // into the page as data; left unrecorded, the handler is marked as one\n // the page cannot name, and the live page answers it.\n if (template !== undefined) holes.set(made, { template, hole })\n return made\n }\n\n const keyHole =\n (name: string) =>\n (given: unknown, fixed: Record<string, unknown> = {}): unknown => {\n const make = source[name] as (\n toMessage: (key: string, modifiers: KeyboardModifiers) => unknown,\n ) => object\n if (!isMember(given)) {\n return make(given as (key: string, modifiers: KeyboardModifiers) => unknown)\n }\n const hole = holeOf(given, fixed)\n if (hole.length !== 2 || !hole.includes('key') || !hole.includes('modifiers')) {\n throw new Error(\n `Resume.builder: ${name}(${tagOf(given)}) leaves ${hole.join(', ') || 'no field'} for the event to fill; it must leave exactly key and modifiers`,\n )\n }\n const made = make((key, modifiers) => given({ ...fixed, key, modifiers }))\n const template = placeholder(() => given({ ...fixed, key: '', modifiers: NO_MODIFIERS }))\n if (template !== undefined) holes.set(made, { template, hole })\n return made\n }\n\n /**\n * `h.submodel` with the child's root stamped with its slot, while the\n * server renders: a boundary a tool can find, which the browser takes off\n * as the page boots, with the markers.\n */\n const submodel = (config: {\n readonly slotId: string\n readonly view: unknown\n readonly toParentMessage: (message: unknown) => unknown\n }): unknown => {\n const original = source.submodel as (config: unknown) => unknown\n const now = current()\n if (now?.mode !== 'collect' && now?.mode !== 'replay') return original(config)\n const view = config.view as (...args: ReadonlyArray<unknown>) => unknown\n const stamped = (...args: ReadonlyArray<unknown>) => {\n // A binding inside dispatches the parent's Message, as Foldkit's own\n // handlers do, so it is recorded lifted through this placement.\n const outer = { wrap: now.wrap, depth: now.depth }\n now.wrap = message => outer.wrap(config.toParentMessage(message))\n now.depth = outer.depth + 1\n let out: { data?: { attrs?: Record<string, unknown> } } | null\n try {\n out = view(...args) as typeof out\n } finally {\n now.wrap = outer.wrap\n now.depth = outer.depth\n }\n if (out !== null && typeof out === 'object' && out.data !== undefined) {\n out.data.attrs = { ...out.data.attrs, [SLOT_ATTRIBUTE]: config.slotId }\n }\n return out\n }\n // The view carries Foldkit's Submodel brand as an own property; keep it.\n return original({ ...config, view: Object.assign(stamped, view) })\n }\n\n const wrapped: Record<string, unknown> = {}\n for (const [name, value] of Object.entries(source)) {\n if (name === 'submodel') wrapped[name] = submodel\n else if (name === 'OnInput' || name === 'OnChange') wrapped[name] = textHole(name)\n else if (name === 'OnKeyDown' || name === 'OnKeyUp') wrapped[name] = keyHole(name)\n else if (name === 'keyed') {\n const keyed = value as (tag: string) => (key: PropertyKey, ...rest: Array<unknown>) => unknown\n wrapped[name] =\n (tag: string) =>\n (key: PropertyKey, attributes: ReadonlyArray<Item> = [], ...rest: Array<unknown>) => {\n const posted = fallback(tag, attributes, rest[0])\n return keyed(tag)(key, mark(tag, posted.attributes), posted.children, ...rest.slice(1))\n }\n } else if (/^[a-z]/.test(name) && typeof value === 'function') {\n const element = value as (\n attributes: ReadonlyArray<unknown>,\n ...rest: Array<unknown>\n ) => unknown\n wrapped[name] = (attributes: ReadonlyArray<Item>, ...rest: Array<unknown>) => {\n const posted = fallback(name, attributes, rest[0])\n return element(mark(name, posted.attributes), posted.children, ...rest.slice(1))\n }\n } else wrapped[name] = value\n }\n wrapped.KeepTyped = () => {\n // Written so during the server's first render: an element this builder\n // builds takes it out, so one left in the markup is on an element `h`\n // built, which nothing marks, and is refused there, naming the element.\n const made = attribute(KEEP_ATTRIBUTE, current()?.mode === 'collect' ? UNPLACED_KEEP : '')\n keeps.add(made as object)\n return made\n }\n builders.set(h, wrapped)\n return wrapped as unknown as ResumableBuilder<MessageOf<Builder>>\n}\n\n/**\n * A view or renderer written against the resumable builder, as one that takes\n * the builder it is given: `Surface.rootView(Page, params, Resume.view(render))`,\n * `SurfaceView.define`, or an application's own view.\n */\nexport const view =\n <Model, Builder extends AnyBuilder, Out>(\n render: (model: Model, rh: ResumableBuilder<MessageOf<Builder>>) => Out,\n ) =>\n (model: Model, h: Builder): Out =>\n render(model, builder(h))\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAoBA,MAAa,oBAAoB;;;;;;AAOjC,MAAa,WAA6C;CACxD,SAAS;CACT,eAAe;CACf,aAAa;CACb,WAAW;C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