foldkit-ssr 0.10.0 → 0.12.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 +693 -61
- package/dist/{client-XnpTQZHw.d.ts → client-BEHlUHBv.d.ts} +10 -7
- package/dist/client-BEHlUHBv.d.ts.map +1 -0
- package/dist/client.d.ts +6 -5
- package/dist/client.js +66 -18
- package/dist/client.js.map +1 -1
- package/dist/context.d.ts +1 -1
- package/dist/context.js.map +1 -1
- package/dist/diagnostics.d.ts +2 -2
- package/dist/diagnostics.js +14 -1
- package/dist/diagnostics.js.map +1 -1
- package/dist/handoff.d.ts +23 -0
- package/dist/handoff.d.ts.map +1 -0
- package/dist/handoff.js +15 -0
- package/dist/handoff.js.map +1 -0
- package/dist/index.d.ts +108 -26
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +386 -51
- package/dist/index.js.map +1 -1
- package/dist/keep.d.ts +5 -1
- package/dist/keep.d.ts.map +1 -1
- package/dist/keep.js +55 -11
- package/dist/keep.js.map +1 -1
- package/dist/{listen-DaUPRKVR.d.ts → listen-7HzKBhqU.d.ts} +11 -2
- package/dist/{listen-DaUPRKVR.d.ts.map → listen-7HzKBhqU.d.ts.map} +1 -1
- package/dist/listen.d.ts +2 -2
- package/dist/listen.js +17 -7
- package/dist/listen.js.map +1 -1
- package/dist/loader.d.ts +13 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +156 -0
- package/dist/loader.js.map +1 -0
- package/dist/marks-CX15BwOw.d.ts +39 -0
- package/dist/marks-CX15BwOw.d.ts.map +1 -0
- package/dist/marks.d.ts +2 -0
- package/dist/marks.js +41 -0
- package/dist/marks.js.map +1 -0
- package/dist/pageCache-DO0pOgnc.d.ts +80 -0
- package/dist/pageCache-DO0pOgnc.d.ts.map +1 -0
- package/dist/pageCache.d.ts +2 -0
- package/dist/pageCache.js +112 -0
- package/dist/pageCache.js.map +1 -0
- package/dist/{requestContext-D9nsbGSJ.d.ts → requestContext-DmwmQeci.d.ts} +12 -2
- package/dist/requestContext-DmwmQeci.d.ts.map +1 -0
- package/dist/requestContext.d.ts +2 -2
- package/dist/requestContext.js +30 -13
- package/dist/requestContext.js.map +1 -1
- package/dist/{resumable-BPN_qQHU.d.ts → resumable-BV9_OKxr.d.ts} +7 -10
- package/dist/resumable-BV9_OKxr.d.ts.map +1 -0
- package/dist/resumable.d.ts +2 -1
- package/dist/resumable.js +16 -19
- package/dist/resumable.js.map +1 -1
- package/dist/runtimeChunk.d.ts +13 -0
- package/dist/runtimeChunk.d.ts.map +1 -0
- package/dist/runtimeChunk.js +36 -0
- package/dist/runtimeChunk.js.map +1 -0
- package/dist/runtimeUrl.d.ts +10 -0
- package/dist/runtimeUrl.d.ts.map +1 -0
- package/dist/runtimeUrl.js +13 -0
- package/dist/runtimeUrl.js.map +1 -0
- package/dist/{shared-DbupL3vO.d.ts → shared-mQ8CXr-r.d.ts} +69 -22
- package/dist/shared-mQ8CXr-r.d.ts.map +1 -0
- package/dist/shared.d.ts +3 -2
- package/dist/shared.js +40 -18
- package/dist/shared.js.map +1 -1
- package/dist/vite.d.ts +3 -2
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +2 -1
- package/dist/vite.js.map +1 -1
- package/package.json +11 -6
- package/dist/client-XnpTQZHw.d.ts.map +0 -1
- package/dist/requestContext-D9nsbGSJ.d.ts.map +0 -1
- package/dist/resumable-BPN_qQHU.d.ts.map +0 -1
- package/dist/shared-DbupL3vO.d.ts.map +0 -1
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { Effect, Option, Schema } from "effect";
|
|
2
|
+
import { RenderedApplication } from "foldkit/experimental/server";
|
|
3
|
+
/** What a render read of its request's headers: names, or every one. */
|
|
4
|
+
interface HeadersRead {
|
|
5
|
+
readonly names: Set<string>;
|
|
6
|
+
all: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* `request` as the render sees it, every header it reads recorded in `read`.
|
|
10
|
+
* A lookup by name records that name; enumerating the headers records all.
|
|
11
|
+
* Everything else is the request's own, so its getters keep their receiver.
|
|
12
|
+
* A request context read of it (`SSR.requestContext`) is the host's request's,
|
|
13
|
+
* and records all: what a host attaches may say who is asking.
|
|
14
|
+
*/
|
|
15
|
+
declare const tracked: (request: Request, read: HeadersRead) => Request;
|
|
16
|
+
/** Whether a page drawn from `read` serves `request`: it carries none of the headers read. */
|
|
17
|
+
declare const fits: (request: Request, vary: ReadonlyArray<string>) => boolean;
|
|
18
|
+
/** A kept page: what the host draws, its status and headers, and the headers it must lack. */
|
|
19
|
+
declare const KeptPage: Schema.Struct<{
|
|
20
|
+
readonly application: Schema.Struct<{
|
|
21
|
+
readonly html: Schema.String;
|
|
22
|
+
readonly title: Schema.String;
|
|
23
|
+
readonly lang: Schema.optionalKey<Schema.String>;
|
|
24
|
+
readonly dir: Schema.optionalKey<Schema.Literals<readonly ["ltr", "rtl", "auto"]>>;
|
|
25
|
+
readonly canonical: Schema.optionalKey<Schema.String>;
|
|
26
|
+
readonly ogUrl: Schema.optionalKey<Schema.String>;
|
|
27
|
+
}>;
|
|
28
|
+
readonly status: Schema.optionalKey<Schema.Number>;
|
|
29
|
+
readonly headers: Schema.$Array<Schema.Tuple<readonly [Schema.String, Schema.String]>>;
|
|
30
|
+
readonly vary: Schema.$Array<Schema.String>;
|
|
31
|
+
}>;
|
|
32
|
+
type KeptPage = typeof KeptPage.Type;
|
|
33
|
+
declare const decodeKept: (input: unknown, options?: import("effect/SchemaAST").ParseOptions) => Option.Option<{
|
|
34
|
+
readonly application: {
|
|
35
|
+
readonly html: string;
|
|
36
|
+
readonly title: string;
|
|
37
|
+
readonly lang?: string;
|
|
38
|
+
readonly dir?: "auto" | "ltr" | "rtl";
|
|
39
|
+
readonly canonical?: string;
|
|
40
|
+
readonly ogUrl?: string;
|
|
41
|
+
};
|
|
42
|
+
readonly status?: number;
|
|
43
|
+
readonly headers: readonly (readonly [string, string])[];
|
|
44
|
+
readonly vary: readonly string[];
|
|
45
|
+
}>;
|
|
46
|
+
/** Whether two renders drew the same page: what the host draws, and its status. */
|
|
47
|
+
declare const samePage: (a: {
|
|
48
|
+
readonly application: RenderedApplication;
|
|
49
|
+
readonly status?: number | undefined;
|
|
50
|
+
}, b: {
|
|
51
|
+
readonly application: RenderedApplication;
|
|
52
|
+
readonly status?: number | undefined;
|
|
53
|
+
}, now: number) => boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Where a page is kept: by its build and its full URL, under the request's
|
|
56
|
+
* origin, since the Workers Cache API keys by URL. A deploy's pages never
|
|
57
|
+
* meet another build's.
|
|
58
|
+
*/
|
|
59
|
+
declare const pageKey: (buildId: string, url: string) => Effect.Effect<string>;
|
|
60
|
+
/** The value a `Rendered` result's `headers` gives, none when absent. */
|
|
61
|
+
declare const headerOf: (headers: HeadersInit | undefined, name: string) => Option.Option<string>;
|
|
62
|
+
/** The pages `SSR.entry` serves from its cache, by the object it serves. */
|
|
63
|
+
declare const keptApplications: WeakSet<Readonly<{
|
|
64
|
+
html: string;
|
|
65
|
+
title: string;
|
|
66
|
+
lang?: string;
|
|
67
|
+
dir?: 'ltr' | 'rtl' | 'auto';
|
|
68
|
+
canonical?: string;
|
|
69
|
+
ogUrl?: string;
|
|
70
|
+
}>>;
|
|
71
|
+
/**
|
|
72
|
+
* `render`, remembering the document it drew for each kept page (one
|
|
73
|
+
* `SSR.entry` serves from its `cache`), by the page and the assets: the
|
|
74
|
+
* host draws a page into its document on every request, which parses the
|
|
75
|
+
* page again (`injectIntoTemplate`), so a kept page would cost that much
|
|
76
|
+
* every time it is served. Any other page is drawn as `render` draws it.
|
|
77
|
+
*/
|
|
78
|
+
declare const keptDocuments: <Assets>(render: (application: RenderedApplication, assets: Assets) => string) => (application: RenderedApplication, assets: Assets) => string;
|
|
79
|
+
export { headerOf as a, pageKey as c, fits as i, samePage as l, KeptPage as n, keptApplications as o, decodeKept as r, keptDocuments as s, HeadersRead as t, tracked as u };
|
|
80
|
+
//# sourceMappingURL=pageCache-DO0pOgnc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pageCache-DO0pOgnc.d.ts","names":[],"sources":["../src/pageCache.ts"],"mappings":";;;UAYiB;WACN,OAAO;EAChB;;;;;;;;;cAUW,UAAO,SAAa,SAAO,MAAQ,gBAAc;;cAkCjD,OAAI,SAAa,SAAO,MAAQ;;cAIhC,UAAQ,OAAA;;;;;;;;;;;;;KAaT,kBAAkB,SAAS;cAE1B,aAAU,gBAAA,qCAAA,iBAAA,OAAA;;;;;;;;;;;;;;cAcV,WAAQ;WACL,aAAa;WAA8B;GAA6B;WACxE,aAAa;WAA8B;GAA6B;;;;;;cAc3E,UAAO,iBAAmB,gBAAgB,OAAO;;cAMjD,WAAQ,SAAa,yBAAuB,iBAAiB,OAAO;;cAIpE,kBAAgB,QAAA;;;;;;;;;;;;;;;cAYhB,gBAAiB,QAAM,SACzB,aAAa,qBAAqB,QAAQ,uBAAiB,aAG/C,qBAAmB,QAAU"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as headerOf, c as pageKey, i as fits, l as samePage, n as KeptPage, o as keptApplications, r as decodeKept, s as keptDocuments, t as HeadersRead, u as tracked } from "./pageCache-DO0pOgnc.js";
|
|
2
|
+
export { HeadersRead, KeptPage, decodeKept, fits, headerOf, keptApplications, keptDocuments, pageKey, samePage, tracked };
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { watchedOf } from "./requestContext.js";
|
|
2
|
+
import { Effect, Option, Schema } from "effect";
|
|
3
|
+
// src/pageCache.ts
|
|
4
|
+
/**
|
|
5
|
+
* What `SSR.entry` needs to keep a rendered page (#428): a request that
|
|
6
|
+
* records which of its headers the render read, and a page as a store keeps
|
|
7
|
+
* it. A page is kept only when every header the render read was absent, so
|
|
8
|
+
* it was drawn from the URL alone and serves every request that also lacks
|
|
9
|
+
* them; the names it read are its `Vary`.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* `request` as the render sees it, every header it reads recorded in `read`.
|
|
13
|
+
* A lookup by name records that name; enumerating the headers records all.
|
|
14
|
+
* Everything else is the request's own, so its getters keep their receiver.
|
|
15
|
+
* A request context read of it (`SSR.requestContext`) is the host's request's,
|
|
16
|
+
* and records all: what a host attaches may say who is asking.
|
|
17
|
+
*/
|
|
18
|
+
const tracked = (request, read) => {
|
|
19
|
+
const headers = new Proxy(request.headers, { get: (target, property) => {
|
|
20
|
+
const value = Reflect.get(target, property, target);
|
|
21
|
+
if (typeof value !== "function") return value;
|
|
22
|
+
if (property === "get" || property === "has") return (name) => {
|
|
23
|
+
read.names.add(name.toLowerCase());
|
|
24
|
+
return value.call(target, name);
|
|
25
|
+
};
|
|
26
|
+
read.all = true;
|
|
27
|
+
return value.bind(target);
|
|
28
|
+
} });
|
|
29
|
+
const watched = new Proxy(request, { get: (target, property) => {
|
|
30
|
+
if (property === "headers") return headers;
|
|
31
|
+
if (property === "clone") read.all = true;
|
|
32
|
+
const value = Reflect.get(target, property, target);
|
|
33
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
34
|
+
} });
|
|
35
|
+
watchedOf().set(watched, {
|
|
36
|
+
original: request,
|
|
37
|
+
readContext: () => {
|
|
38
|
+
read.all = true;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return watched;
|
|
42
|
+
};
|
|
43
|
+
/** Whether a page drawn from `read` serves `request`: it carries none of the headers read. */
|
|
44
|
+
const fits = (request, vary) => vary.every((name) => !request.headers.has(name));
|
|
45
|
+
/** A kept page: what the host draws, its status and headers, and the headers it must lack. */
|
|
46
|
+
const KeptPage = Schema.Struct({
|
|
47
|
+
application: Schema.Struct({
|
|
48
|
+
html: Schema.String,
|
|
49
|
+
title: Schema.String,
|
|
50
|
+
lang: Schema.optionalKey(Schema.String),
|
|
51
|
+
dir: Schema.optionalKey(Schema.Literals([
|
|
52
|
+
"ltr",
|
|
53
|
+
"rtl",
|
|
54
|
+
"auto"
|
|
55
|
+
])),
|
|
56
|
+
canonical: Schema.optionalKey(Schema.String),
|
|
57
|
+
ogUrl: Schema.optionalKey(Schema.String)
|
|
58
|
+
}),
|
|
59
|
+
status: Schema.optionalKey(Schema.Number),
|
|
60
|
+
headers: Schema.Array(Schema.Tuple([Schema.String, Schema.String])),
|
|
61
|
+
vary: Schema.Array(Schema.String)
|
|
62
|
+
});
|
|
63
|
+
const decodeKept = Schema.decodeUnknownOption(Schema.fromJsonString(KeptPage));
|
|
64
|
+
const DAY_MS = 864e5;
|
|
65
|
+
/**
|
|
66
|
+
* A page with each time stamped on it as `T`: a run of 13 digits within a
|
|
67
|
+
* day of `now`, as milliseconds since the epoch read now are (a read's
|
|
68
|
+
* `updatedAt` in the resumed Model). A page drawn a moment later is stamped
|
|
69
|
+
* later, and is still the same page.
|
|
70
|
+
*/
|
|
71
|
+
const unstamped = (text, now) => text.replace(/\b\d{13}\b/g, (digits) => Math.abs(Number(digits) - now) < DAY_MS ? "T" : digits);
|
|
72
|
+
/** Whether two renders drew the same page: what the host draws, and its status. */
|
|
73
|
+
const samePage = (a, b, now) => unstamped(JSON.stringify([a.application, a.status ?? 200]), now) === unstamped(JSON.stringify([b.application, b.status ?? 200]), now);
|
|
74
|
+
const hex = (bytes) => [...new Uint8Array(bytes)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
75
|
+
/**
|
|
76
|
+
* Where a page is kept: by its build and its full URL, under the request's
|
|
77
|
+
* origin, since the Workers Cache API keys by URL. A deploy's pages never
|
|
78
|
+
* meet another build's.
|
|
79
|
+
*/
|
|
80
|
+
const pageKey = (buildId, url) => Effect.promise(() => crypto.subtle.digest("SHA-256", new TextEncoder().encode(`${buildId}\n${url}`))).pipe(Effect.map((digest) => `${new URL(url).origin}/__foldkit/cache/page/${hex(digest)}`));
|
|
81
|
+
/** The value a `Rendered` result's `headers` gives, none when absent. */
|
|
82
|
+
const headerOf = (headers, name) => Option.fromNullishOr(headers === void 0 ? null : new Headers(headers).get(name));
|
|
83
|
+
/** The pages `SSR.entry` serves from its cache, by the object it serves. */
|
|
84
|
+
const keptApplications = /* @__PURE__ */ new WeakSet();
|
|
85
|
+
/** The most documents `keptDocuments` holds: each is a whole page's markup. */
|
|
86
|
+
const KEPT_DOCUMENTS = 32;
|
|
87
|
+
/**
|
|
88
|
+
* `render`, remembering the document it drew for each kept page (one
|
|
89
|
+
* `SSR.entry` serves from its `cache`), by the page and the assets: the
|
|
90
|
+
* host draws a page into its document on every request, which parses the
|
|
91
|
+
* page again (`injectIntoTemplate`), so a kept page would cost that much
|
|
92
|
+
* every time it is served. Any other page is drawn as `render` draws it.
|
|
93
|
+
*/
|
|
94
|
+
const keptDocuments = (render) => {
|
|
95
|
+
const drawn = /* @__PURE__ */ new Map();
|
|
96
|
+
return (application, assets) => {
|
|
97
|
+
if (!keptApplications.has(application)) return render(application, assets);
|
|
98
|
+
const key = JSON.stringify([application, assets]);
|
|
99
|
+
const held = drawn.get(key);
|
|
100
|
+
if (held !== void 0) return held;
|
|
101
|
+
const document = render(application, assets);
|
|
102
|
+
drawn.set(key, document);
|
|
103
|
+
for (const oldest of drawn.keys()) {
|
|
104
|
+
if (drawn.size <= KEPT_DOCUMENTS) break;
|
|
105
|
+
drawn.delete(oldest);
|
|
106
|
+
}
|
|
107
|
+
return document;
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
export { KeptPage, decodeKept, fits, headerOf, keptApplications, keptDocuments, pageKey, samePage, tracked };
|
|
111
|
+
|
|
112
|
+
//# sourceMappingURL=pageCache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pageCache.js","names":[],"sources":["../src/pageCache.ts"],"sourcesContent":["/**\n * What `SSR.entry` needs to keep a rendered page (#428): a request that\n * records which of its headers the render read, and a page as a store keeps\n * it. A page is kept only when every header the render read was absent, so\n * it was drawn from the URL alone and serves every request that also lacks\n * them; the names it read are its `Vary`.\n */\nimport { Effect, Option, Schema } from 'effect'\nimport type { RenderedApplication } from 'foldkit/experimental/server'\nimport { watchedOf } from './requestContext.js'\n\n/** What a render read of its request's headers: names, or every one. */\nexport interface HeadersRead {\n readonly names: Set<string>\n all: boolean\n}\n\n/**\n * `request` as the render sees it, every header it reads recorded in `read`.\n * A lookup by name records that name; enumerating the headers records all.\n * Everything else is the request's own, so its getters keep their receiver.\n * A request context read of it (`SSR.requestContext`) is the host's request's,\n * and records all: what a host attaches may say who is asking.\n */\nexport const tracked = (request: Request, read: HeadersRead): Request => {\n const headers = new Proxy(request.headers, {\n get: (target, property) => {\n const value: unknown = Reflect.get(target, property, target)\n if (typeof value !== 'function') return value\n if (property === 'get' || property === 'has') {\n return (name: string) => {\n read.names.add(name.toLowerCase())\n return value.call(target, name)\n }\n }\n read.all = true\n return value.bind(target)\n },\n })\n const watched = new Proxy(request, {\n get: (target, property) => {\n if (property === 'headers') return headers\n // `clone` would hand out a request this one cannot see into.\n if (property === 'clone') read.all = true\n const value: unknown = Reflect.get(target, property, target)\n return typeof value === 'function' ? value.bind(target) : value\n },\n })\n watchedOf().set(watched, {\n original: request,\n readContext: () => {\n read.all = true\n },\n })\n return watched\n}\n\n/** Whether a page drawn from `read` serves `request`: it carries none of the headers read. */\nexport const fits = (request: Request, vary: ReadonlyArray<string>): boolean =>\n vary.every(name => !request.headers.has(name))\n\n/** A kept page: what the host draws, its status and headers, and the headers it must lack. */\nexport const KeptPage = Schema.Struct({\n application: Schema.Struct({\n html: Schema.String,\n title: Schema.String,\n lang: Schema.optionalKey(Schema.String),\n dir: Schema.optionalKey(Schema.Literals(['ltr', 'rtl', 'auto'])),\n canonical: Schema.optionalKey(Schema.String),\n ogUrl: Schema.optionalKey(Schema.String),\n }),\n status: Schema.optionalKey(Schema.Number),\n headers: Schema.Array(Schema.Tuple([Schema.String, Schema.String])),\n vary: Schema.Array(Schema.String),\n})\nexport type KeptPage = typeof KeptPage.Type\n\nexport const decodeKept = Schema.decodeUnknownOption(Schema.fromJsonString(KeptPage))\n\nconst DAY_MS = 86_400_000\n\n/**\n * A page with each time stamped on it as `T`: a run of 13 digits within a\n * day of `now`, as milliseconds since the epoch read now are (a read's\n * `updatedAt` in the resumed Model). A page drawn a moment later is stamped\n * later, and is still the same page.\n */\nconst unstamped = (text: string, now: number): string =>\n text.replace(/\\b\\d{13}\\b/g, digits => (Math.abs(Number(digits) - now) < DAY_MS ? 'T' : digits))\n\n/** Whether two renders drew the same page: what the host draws, and its status. */\nexport const samePage = (\n a: { readonly application: RenderedApplication; readonly status?: number | undefined },\n b: { readonly application: RenderedApplication; readonly status?: number | undefined },\n now: number,\n): boolean =>\n unstamped(JSON.stringify([a.application, a.status ?? 200]), now) ===\n unstamped(JSON.stringify([b.application, b.status ?? 200]), now)\n\nconst hex = (bytes: ArrayBuffer): string =>\n [...new Uint8Array(bytes)].map(byte => byte.toString(16).padStart(2, '0')).join('')\n\n/**\n * Where a page is kept: by its build and its full URL, under the request's\n * origin, since the Workers Cache API keys by URL. A deploy's pages never\n * meet another build's.\n */\nexport const pageKey = (buildId: string, url: string): Effect.Effect<string> =>\n Effect.promise(() =>\n crypto.subtle.digest('SHA-256', new TextEncoder().encode(`${buildId}\\n${url}`)),\n ).pipe(Effect.map(digest => `${new URL(url).origin}/__foldkit/cache/page/${hex(digest)}`))\n\n/** The value a `Rendered` result's `headers` gives, none when absent. */\nexport const headerOf = (headers: HeadersInit | undefined, name: string): Option.Option<string> =>\n Option.fromNullishOr(headers === undefined ? null : new Headers(headers).get(name))\n\n/** The pages `SSR.entry` serves from its cache, by the object it serves. */\nexport const keptApplications = new WeakSet<RenderedApplication>()\n\n/** The most documents `keptDocuments` holds: each is a whole page's markup. */\nconst KEPT_DOCUMENTS = 32\n\n/**\n * `render`, remembering the document it drew for each kept page (one\n * `SSR.entry` serves from its `cache`), by the page and the assets: the\n * host draws a page into its document on every request, which parses the\n * page again (`injectIntoTemplate`), so a kept page would cost that much\n * every time it is served. Any other page is drawn as `render` draws it.\n */\nexport const keptDocuments = <Assets>(\n render: (application: RenderedApplication, assets: Assets) => string,\n) => {\n const drawn = new Map<string, string>()\n return (application: RenderedApplication, assets: Assets): string => {\n if (!keptApplications.has(application)) return render(application, assets)\n const key = JSON.stringify([application, assets])\n const held = drawn.get(key)\n if (held !== undefined) return held\n const document = render(application, assets)\n drawn.set(key, document)\n for (const oldest of drawn.keys()) {\n if (drawn.size <= KEPT_DOCUMENTS) break\n drawn.delete(oldest)\n }\n return document\n }\n}\n"],"mappings":"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"}
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import { Option } from "effect";
|
|
2
|
+
/**
|
|
3
|
+
* The request a render that may be kept reads in place of the host's, to the
|
|
4
|
+
* host's, with what to record when the render reads a context of it. On
|
|
5
|
+
* `globalThis`, as the values are, since the Worker's copy of this module
|
|
6
|
+
* may be asked about a request the page bundle's `SSR.entry` made.
|
|
7
|
+
*/
|
|
8
|
+
declare const watchedOf: () => WeakMap<Request, {
|
|
9
|
+
readonly original: Request;
|
|
10
|
+
readonly readContext: () => void;
|
|
11
|
+
}>;
|
|
2
12
|
/** A value of type `C` the host attaches to a request, for its `renderPage` to read. */
|
|
3
13
|
interface RequestContext<C> {
|
|
4
14
|
readonly name: string;
|
|
@@ -17,5 +27,5 @@ interface RequestContext<C> {
|
|
|
17
27
|
* other's values by the name.
|
|
18
28
|
*/
|
|
19
29
|
declare const requestContext: <C>(name: string) => RequestContext<C>;
|
|
20
|
-
export { requestContext as n, RequestContext as t };
|
|
21
|
-
//# sourceMappingURL=requestContext-
|
|
30
|
+
export { requestContext as n, watchedOf as r, RequestContext as t };
|
|
31
|
+
//# sourceMappingURL=requestContext-DmwmQeci.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requestContext-DmwmQeci.d.ts","names":[],"sources":["../src/requestContext.ts"],"mappings":";;;;;;;cAyCa,iBAAS,QAAA;WACD,UAAA;WACG;;;UAIP,eAAe;WACrB;;WAEA,SAAS,SAAS,SAAS,OAAO,MAAM;;;;;;WAMxC,KAAK,SAAS,YAAY,OAAO,OAAO;;;;;;;cAQtC,iBAAkB,GAAC,iBAAiB,eAAe"}
|
package/dist/requestContext.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as requestContext, t as RequestContext } from "./requestContext-
|
|
2
|
-
export { RequestContext, requestContext };
|
|
1
|
+
import { n as requestContext, r as watchedOf, t as RequestContext } from "./requestContext-DmwmQeci.js";
|
|
2
|
+
export { RequestContext, requestContext, watchedOf };
|
package/dist/requestContext.js
CHANGED
|
@@ -11,18 +11,32 @@ import { Option } from "effect";
|
|
|
11
11
|
* with its own copy of this module, so the map lives on `globalThis` under a
|
|
12
12
|
* registered symbol, and a context is known by its name.
|
|
13
13
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
14
|
+
/**
|
|
15
|
+
* The map on `globalThis` under `name`'s registered symbol, made the first
|
|
16
|
+
* time it is asked for: every bundle's copy of this module finds the same one.
|
|
17
|
+
*/
|
|
18
|
+
const globalMap = (name) => {
|
|
19
|
+
const key = Symbol.for(name);
|
|
20
|
+
return () => {
|
|
21
|
+
const global = globalThis;
|
|
22
|
+
const held = global[key];
|
|
23
|
+
if (held === void 0) {
|
|
24
|
+
const made = /* @__PURE__ */ new WeakMap();
|
|
25
|
+
global[key] = made;
|
|
26
|
+
return made;
|
|
27
|
+
}
|
|
28
|
+
if (!(held instanceof WeakMap)) throw new Error(`foldkit-ssr: globalThis holds something else under ${String(key)}`);
|
|
29
|
+
return held;
|
|
30
|
+
};
|
|
25
31
|
};
|
|
32
|
+
const valuesOf = globalMap("foldkit-ssr/request-context");
|
|
33
|
+
/**
|
|
34
|
+
* The request a render that may be kept reads in place of the host's, to the
|
|
35
|
+
* host's, with what to record when the render reads a context of it. On
|
|
36
|
+
* `globalThis`, as the values are, since the Worker's copy of this module
|
|
37
|
+
* may be asked about a request the page bundle's `SSR.entry` made.
|
|
38
|
+
*/
|
|
39
|
+
const watchedOf = globalMap("foldkit-ssr/watched-requests");
|
|
26
40
|
/**
|
|
27
41
|
* A request context named `name`. The host and the page each import it from
|
|
28
42
|
* one module, so both agree on `C`; two bundles of that module find each
|
|
@@ -38,11 +52,14 @@ const requestContext = (name) => ({
|
|
|
38
52
|
values.set(request, held);
|
|
39
53
|
return request;
|
|
40
54
|
},
|
|
41
|
-
of: (
|
|
55
|
+
of: (given) => {
|
|
56
|
+
const watched = watchedOf().get(given);
|
|
57
|
+
watched?.readContext();
|
|
58
|
+
const request = watched?.original ?? given;
|
|
42
59
|
const held = valuesOf().get(request);
|
|
43
60
|
return held !== void 0 && held.has(name) ? Option.some(held.get(name)) : Option.none();
|
|
44
61
|
}
|
|
45
62
|
});
|
|
46
|
-
export { requestContext };
|
|
63
|
+
export { requestContext, watchedOf };
|
|
47
64
|
|
|
48
65
|
//# sourceMappingURL=requestContext.js.map
|
|
@@ -1 +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\
|
|
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\n/**\n * The map on `globalThis` under `name`'s registered symbol, made the first\n * time it is asked for: every bundle's copy of this module finds the same one.\n */\nconst globalMap = <V>(name: string) => {\n const key = Symbol.for(name)\n return (): WeakMap<Request, V> => {\n const global = globalThis as { [key]?: unknown }\n const held = global[key]\n if (held === undefined) {\n const made = new WeakMap<Request, V>()\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 WeakMap<Request, V>\n }\n}\n\nconst valuesOf = globalMap<Map<string, unknown>>('foldkit-ssr/request-context')\n\n/**\n * The request a render that may be kept reads in place of the host's, to the\n * host's, with what to record when the render reads a context of it. On\n * `globalThis`, as the values are, since the Worker's copy of this module\n * may be asked about a request the page bundle's `SSR.entry` made.\n */\nexport const watchedOf = globalMap<{\n readonly original: Request\n readonly readContext: () => void\n}>('foldkit-ssr/watched-requests')\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: given => {\n const watched = watchedOf().get(given)\n // A context may say who is asking, which a kept page must not depend on.\n watched?.readContext()\n const request = watched?.original ?? given\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":";;;;;;;;;;;;;;;;;AAiBA,MAAM,aAAgB,SAAiB;CACrC,MAAM,MAAM,OAAO,IAAI,IAAI;CAC3B,aAAkC;EAChC,MAAM,SAAS;EACf,MAAM,OAAO,OAAO;EACpB,IAAI,SAAS,KAAA,GAAW;GACtB,MAAM,uBAAO,IAAI,QAAoB;GACrC,OAAO,OAAO;GACd,OAAO;EACT;EACA,IAAI,EAAE,gBAAgB,UACpB,MAAM,IAAI,MAAM,sDAAsD,OAAO,GAAG,GAAG;EACrF,OAAO;CACT;AACF;AAEA,MAAM,WAAW,UAAgC,6BAA6B;;;;;;;AAQ9E,MAAa,YAAY,UAGtB,8BAA8B;;;;;;AAoBjC,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,UAAS;EACX,MAAM,UAAU,UAAU,CAAC,CAAC,IAAI,KAAK;EAErC,SAAS,YAAY;EACrB,MAAM,UAAU,SAAS,YAAY;EACrC,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"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
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
3
|
/**
|
|
6
4
|
* The DOM event each of Foldkit's event attributes listens to, read from
|
|
7
5
|
* Foldkit's own attribute table (0.163). `OnCustomEvent` names its event in
|
|
@@ -14,11 +12,6 @@ declare const UNNAMED_HANDLER = "*";
|
|
|
14
12
|
declare const FALLBACK_FIELD = "foldkit-plus-message";
|
|
15
13
|
/** The posted field that says how many placement wrappers the form's fields sit under. */
|
|
16
14
|
declare const FALLBACK_DEPTH_FIELD = "foldkit-plus-depth";
|
|
17
|
-
/**
|
|
18
|
-
* The attribute on a field whose typing before boot is kept (`KeepTyped`),
|
|
19
|
-
* naming the binding whose Message replays it.
|
|
20
|
-
*/
|
|
21
|
-
declare const KEEP_ATTRIBUTE = "data-foldkit-plus-keep";
|
|
22
15
|
/** The value of a `KeepTyped` marker no resumable element took, while the server renders. */
|
|
23
16
|
declare const UNPLACED_KEEP = "?";
|
|
24
17
|
/** The attribute on a placement's root naming its slot, while the server renders. */
|
|
@@ -88,7 +81,11 @@ type ResumableBuilder<Message> = Omit<HtmlBuilder<Message>, 'OnInput' | 'OnChang
|
|
|
88
81
|
* Keeps what is typed into this field before the runtime starts: the
|
|
89
82
|
* browser replays it as the field's `OnInput` Message (else its
|
|
90
83
|
* `OnChange`), given in the hole form, and keeps the caret. The field must
|
|
91
|
-
* be an `input` that takes text, a `textarea` or a `select
|
|
84
|
+
* be an `input` that takes text, a `textarea` or a `select`; or a
|
|
85
|
+
* checkbox or radio, whose ticking replays its `OnChange` (else `OnInput`,
|
|
86
|
+
* else `OnClick`) Message, in either form. On a plan whose `start` is not
|
|
87
|
+
* `'now'`, a field with such a binding and no `KeepTyped` is refused
|
|
88
|
+
* (`UnkeptField`).
|
|
92
89
|
*/
|
|
93
90
|
readonly KeepTyped: () => Tagged<Message, 'Attribute'>;
|
|
94
91
|
};
|
|
@@ -103,5 +100,5 @@ declare const builder: <Builder extends AnyBuilder>(h: Builder) => ResumableBuil
|
|
|
103
100
|
* `SurfaceView.define`, or an application's own view.
|
|
104
101
|
*/
|
|
105
102
|
declare const view: <Model, Builder extends AnyBuilder, Out>(render: (model: Model, rh: ResumableBuilder<MessageOf<Builder>>) => Out) => (model: Model, h: Builder) => Out;
|
|
106
|
-
export {
|
|
107
|
-
//# sourceMappingURL=resumable-
|
|
103
|
+
export { Invalid as a, ResumableBuilder as c, UNNAMED_HANDLER as d, UNPLACED_KEEP as f, FALLBACK_FIELD as i, SLOT_ATTRIBUTE as l, view as m, EVENT_OF as n, KeyHole as o, builder as p, FALLBACK_DEPTH_FIELD as r, MessageOf as s, AnyBuilder as t, TextHole as u };
|
|
104
|
+
//# sourceMappingURL=resumable-BV9_OKxr.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resumable-BV9_OKxr.d.ts","names":[],"sources":["../src/resumable.ts"],"mappings":";;;;;;;cA2Ba,UAAU,SAAS;;cAkGnB;;cAGA;;cAGA;;cAGA;;cAgBA;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;;;;;KAMC,OAAO,SAAS,sBAAsB,QAAQ,UAAU;WAAqB,MAAM;;;UAGvE,SAAS,SAAS;GAChC,YAAY,kBAAkB,UAAU,OAAO,SAAS;GACxD,UAAU,uBAAuB,cAAc,QAAQ,SACtD,QAAQ,IAAI,gBAAgB,GAAG,WAAW,cAAc,GAAG,QAC3D,QAAQ,QACP,OAAO,SAAS;;;UAIJ,QAAQ,SAAS;GAC/B,YAAY,aAAa,WAAW,sBAAsB,UAAU,OAAO,SAAS;GACpF,UAAU,uBAAuB,cAAc,QAAQ,SACtD,QAAQ,IAAI,gBAAgB,GAAG,WAAW,aAAa,GAAG,QAC1D,QAAQ,QACP,OAAO,SAAS;;;;;;KAOT;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;;;;;;;;;;;WAWjB,iBAAiB,OAAO;;;;;;cAkEtB,UAAW,gBAAgB,YAAU,GAC7C,YACF,iBAAiB,UAAU;;;;;;cAqRjB,OACV,OAAO,gBAAgB,YAAY,KAAG,SAC5B,OAAO,OAAO,IAAI,iBAAiB,UAAU,cAAc,SAAG,OAEjE,OAAK,GAAK,YAAU"}
|
package/dist/resumable.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { r as KEEP_ATTRIBUTE, t as BINDING_ATTRIBUTE } from "./marks-CX15BwOw.js";
|
|
2
|
+
import { a as Invalid, c as ResumableBuilder, d as UNNAMED_HANDLER, f as UNPLACED_KEEP, i as FALLBACK_FIELD, l as SLOT_ATTRIBUTE, m as view, n as EVENT_OF, o as KeyHole, p as builder, r as FALLBACK_DEPTH_FIELD, s as MessageOf, t as AnyBuilder, u as TextHole } from "./resumable-BV9_OKxr.js";
|
|
2
3
|
export { AnyBuilder, BINDING_ATTRIBUTE, EVENT_OF, FALLBACK_DEPTH_FIELD, FALLBACK_FIELD, Invalid, KEEP_ATTRIBUTE, KeyHole, MessageOf, ResumableBuilder, SLOT_ATTRIBUTE, TextHole, UNNAMED_HANDLER, UNPLACED_KEEP, builder, view };
|
package/dist/resumable.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { current } from "./context.js";
|
|
2
|
-
import {
|
|
2
|
+
import { BINDING_ATTRIBUTE, KEEP_ATTRIBUTE } from "./marks.js";
|
|
3
|
+
import { Match, Schema, SchemaAST } from "effect";
|
|
3
4
|
// src/resumable.ts
|
|
4
5
|
/**
|
|
5
6
|
* The resumable builder: the application's `h`, whose event attributes say, in
|
|
@@ -16,8 +17,6 @@ import { Schema, SchemaAST } from "effect";
|
|
|
16
17
|
* In the browser the builder marks nothing: it is the application's `h`, with
|
|
17
18
|
* the hole forms turned into the closures Foldkit expects.
|
|
18
19
|
*/
|
|
19
|
-
/** The attribute prefix of an element's binding marker. */
|
|
20
|
-
const BINDING_ATTRIBUTE = "data-foldkit-plus-on-";
|
|
21
20
|
/**
|
|
22
21
|
* The DOM event each of Foldkit's event attributes listens to, read from
|
|
23
22
|
* Foldkit's own attribute table (0.163). `OnCustomEvent` names its event in
|
|
@@ -124,20 +123,13 @@ const UNNAMED_HANDLER = "*";
|
|
|
124
123
|
const FALLBACK_FIELD = "foldkit-plus-message";
|
|
125
124
|
/** The posted field that says how many placement wrappers the form's fields sit under. */
|
|
126
125
|
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
126
|
/** The value of a `KeepTyped` marker no resumable element took, while the server renders. */
|
|
133
127
|
const UNPLACED_KEEP = "?";
|
|
134
128
|
/**
|
|
135
|
-
* The `input` types
|
|
136
|
-
* nothing to keep on them.
|
|
129
|
+
* The `input` types that hold nothing a person types or ticks, so
|
|
130
|
+
* `KeepTyped` has nothing to keep on them.
|
|
137
131
|
*/
|
|
138
132
|
const UNTYPED_INPUTS = /* @__PURE__ */ new Set([
|
|
139
|
-
"checkbox",
|
|
140
|
-
"radio",
|
|
141
133
|
"file",
|
|
142
134
|
"hidden",
|
|
143
135
|
"button",
|
|
@@ -166,6 +158,7 @@ const NO_MODIFIERS = {
|
|
|
166
158
|
/** Each hole-form attribute, with its Message filled by a placeholder and the fields the event fills. */
|
|
167
159
|
const holes = /* @__PURE__ */ new WeakMap();
|
|
168
160
|
const isAttribute = (item) => "_tag" in item;
|
|
161
|
+
const eventOf = Match.type().pipe(Match.tag("OnCustomEvent", (custom) => custom.name), Match.orElse((other) => EVENT_OF[other._tag]));
|
|
169
162
|
const builders = /* @__PURE__ */ new WeakMap();
|
|
170
163
|
/** Each attribute `KeepTyped` made: a request to the element it is given, never written as it is. */
|
|
171
164
|
const keeps = /* @__PURE__ */ new WeakSet();
|
|
@@ -196,9 +189,10 @@ const builder = (h) => {
|
|
|
196
189
|
const element = id === void 0 ? tag : `${tag}#${id.value}`;
|
|
197
190
|
const tokens = /* @__PURE__ */ new Map();
|
|
198
191
|
const typed = /* @__PURE__ */ new Map();
|
|
192
|
+
const named = /* @__PURE__ */ new Map();
|
|
199
193
|
for (const item of attributes) {
|
|
200
194
|
if (!isAttribute(item)) continue;
|
|
201
|
-
const event = item
|
|
195
|
+
const event = eventOf(item);
|
|
202
196
|
if (event === void 0) continue;
|
|
203
197
|
if (now.mode === "collect" && now.region !== void 0) now.inStatic.push({
|
|
204
198
|
region: now.region,
|
|
@@ -231,20 +225,23 @@ const builder = (h) => {
|
|
|
231
225
|
list.push("*");
|
|
232
226
|
} else {
|
|
233
227
|
if (binding.hole !== void 0 && !typed.has(binding.attribute)) typed.set(binding.attribute, now.bindings.length);
|
|
228
|
+
if (!named.has(binding.attribute)) named.set(binding.attribute, now.bindings.length);
|
|
234
229
|
list.push(String(now.bindings.length));
|
|
235
230
|
now.bindings.push(binding);
|
|
236
231
|
}
|
|
237
232
|
}
|
|
238
233
|
const markers = [...tokens].map(([event, list]) => attribute(`${BINDING_ATTRIBUTE}${event}`, list.join(" ")));
|
|
234
|
+
const type = attributes.find((item) => isAttribute(item) && item._tag === "Type")?.value.toLowerCase();
|
|
235
|
+
const checkable = tag === "input" && (type === "checkbox" || type === "radio");
|
|
236
|
+
const field = tag === "textarea" || tag === "select" || tag === "input" && (type === void 0 || !UNTYPED_INPUTS.has(type));
|
|
237
|
+
const ordinal = checkable ? named.get("OnChange") ?? named.get("OnInput") ?? named.get("OnClick") : typed.get("OnInput") ?? typed.get("OnChange");
|
|
239
238
|
if (kept) {
|
|
240
|
-
|
|
241
|
-
|
|
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`);
|
|
239
|
+
if (!field) {
|
|
240
|
+
if (now.mode === "collect") now.unkeepable.push(`KeepTyped on ${type === void 0 ? element : `${element} of type ${type}`}, which holds nothing typed or ticked: keep an input that takes text, a checkbox, a radio, a textarea or a select`);
|
|
244
241
|
} 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`);
|
|
242
|
+
if (now.mode === "collect") now.unkeepable.push(`KeepTyped on ${element}, which has no ${checkable ? "OnChange, OnInput or OnClick naming a Message" : "OnInput or OnChange given a Message member"}, so nothing names the Message its typing replays as`);
|
|
246
243
|
} else markers.push(attribute(KEEP_ATTRIBUTE, String(ordinal)));
|
|
247
|
-
}
|
|
244
|
+
} else if (field && ordinal !== void 0 && now.mode === "collect") now.unkept.push(element);
|
|
248
245
|
return markers.length === 0 ? attributes : [...attributes, ...markers];
|
|
249
246
|
};
|
|
250
247
|
/**
|