brumate 0.1.1 → 0.3.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/dist/{boot-DN1ZU8Hg.d.ts → boot-C25Sa6vq.d.ts} +27 -2
- package/dist/cli.js +2 -2
- package/dist/client-BD6XT-s5.js +1968 -0
- package/dist/client-BD6XT-s5.js.map +1 -0
- package/dist/{client-DwJInP_a.d.ts → client-D0CqSxoO.d.ts} +211 -30
- package/dist/{client-routes-DakuM32C.js → client-routes-JTbGtukf.js} +28 -15
- package/dist/client-routes-JTbGtukf.js.map +1 -0
- package/dist/context-CTiSzQRc.js +27 -0
- package/dist/context-CTiSzQRc.js.map +1 -0
- package/dist/context-btHuB01Z.d.ts +42 -0
- package/dist/{cookies-Av5WFmcf.js → cookies-BzllthiF.js} +2 -1
- package/dist/cookies-BzllthiF.js.map +1 -0
- package/dist/defer-BbD7JQhj.js +56 -0
- package/dist/defer-BbD7JQhj.js.map +1 -0
- package/dist/devtools-CQgD7NPB.js +623 -0
- package/dist/devtools-CQgD7NPB.js.map +1 -0
- package/dist/devtools-panel-BVB-W5q4.js +1930 -0
- package/dist/devtools-panel-BVB-W5q4.js.map +1 -0
- package/dist/events-CSs7OwIC.js +85 -0
- package/dist/events-CSs7OwIC.js.map +1 -0
- package/dist/{files-DdT84mPy.js → files-BXSSrQgc.js} +34 -6
- package/dist/files-BXSSrQgc.js.map +1 -0
- package/dist/forms-Bg-CwGqX.js +406 -0
- package/dist/forms-Bg-CwGqX.js.map +1 -0
- package/dist/forms-Cl21hkHt.d.ts +281 -0
- package/dist/highlight.d.ts +17 -0
- package/dist/highlight.js +269 -0
- package/dist/highlight.js.map +1 -0
- package/dist/html-Bq1rFxX_.d.ts +92 -0
- package/dist/html-mNTKzaDD.js +241 -0
- package/dist/html-mNTKzaDD.js.map +1 -0
- package/dist/index.d.ts +123 -30
- package/dist/index.js +14 -6
- package/dist/index.js.map +1 -1
- package/dist/{inspect-BPchdWbU.js → inspect-BHpOw1LF.js} +1400 -121
- package/dist/inspect-BHpOw1LF.js.map +1 -0
- package/dist/{loader-Dc9OwY5I.js → loader-Dos_3NP0.js} +47 -11
- package/dist/loader-Dos_3NP0.js.map +1 -0
- package/dist/{navigate-CzLjnoPH.js → navigate-O78d_zGN.js} +115 -13
- package/dist/navigate-O78d_zGN.js.map +1 -0
- package/dist/produce-D0V0ICkz.d.ts +114 -0
- package/dist/produce-Doc91GkX.js +274 -0
- package/dist/produce-Doc91GkX.js.map +1 -0
- package/dist/routes-BZNt7DSZ.d.ts +38 -0
- package/dist/{rpc-9fSqL_YK.js → rpc-ygMRPmN4.js} +39 -23
- package/dist/rpc-ygMRPmN4.js.map +1 -0
- package/dist/runtime/batch.d.ts +23 -0
- package/dist/runtime/batch.js +69 -0
- package/dist/runtime/batch.js.map +1 -0
- package/dist/runtime/client.d.ts +5 -5
- package/dist/runtime/client.js +5 -1345
- package/dist/runtime/context.d.ts +2 -2
- package/dist/runtime/context.js +1 -1
- package/dist/runtime/devtools.d.ts +191 -5
- package/dist/runtime/devtools.js +1 -1
- package/dist/runtime/env.d.ts +44 -0
- package/dist/runtime/env.js +61 -0
- package/dist/runtime/env.js.map +1 -0
- package/dist/runtime/events.d.ts +42 -0
- package/dist/runtime/events.js +1 -0
- package/dist/runtime/forms.d.ts +2 -0
- package/dist/runtime/forms.js +1 -0
- package/dist/runtime/gather.d.ts +25 -0
- package/dist/runtime/gather.js +33 -0
- package/dist/runtime/gather.js.map +1 -0
- package/dist/runtime/hot.d.ts +1 -1
- package/dist/runtime/html.d.ts +2 -2
- package/dist/runtime/html.js +1 -1
- package/dist/runtime/loader.d.ts +2 -2
- package/dist/runtime/loader.js +2 -2
- package/dist/runtime/routes.d.ts +2 -21
- package/dist/runtime/routes.js +31 -1
- package/dist/runtime/routes.js.map +1 -1
- package/dist/runtime/server.d.ts +7 -5
- package/dist/runtime/server.js +6 -7
- package/dist/runtime/signals.d.ts +60 -3
- package/dist/runtime/signals.js +40 -2
- package/dist/runtime/signals.js.map +1 -1
- package/dist/runtime/static-loader.d.ts +2 -2
- package/dist/runtime/static-loader.js +1 -1
- package/dist/runtime/testing.d.ts +46 -5
- package/dist/runtime/testing.js +240 -33
- package/dist/runtime/testing.js.map +1 -1
- package/dist/runtime/values.d.ts +2 -0
- package/dist/runtime/values.js +24 -0
- package/dist/runtime/values.js.map +1 -0
- package/dist/secrets-BxagsJxJ.js +23 -0
- package/dist/secrets-BxagsJxJ.js.map +1 -0
- package/dist/server-CxVDYE_V.js +3417 -0
- package/dist/server-CxVDYE_V.js.map +1 -0
- package/dist/server-DuFYRXrd.d.ts +1460 -0
- package/dist/skew-FRmAy9iy.js +49 -0
- package/dist/skew-FRmAy9iy.js.map +1 -0
- package/dist/standard-schema-BNY82yX3.d.ts +63 -0
- package/dist/{static-loader-BcFh4ebX.d.ts → static-loader-Drpr0AzI.d.ts} +2 -2
- package/dist/static-loader-nZssh66R.js +333 -0
- package/dist/static-loader-nZssh66R.js.map +1 -0
- package/dist/stream-DCYZO4IF.js +424 -0
- package/dist/stream-DCYZO4IF.js.map +1 -0
- package/dist/values-B8C7CLvG.d.ts +63 -0
- package/dist/vite.d.ts +49 -1
- package/dist/vite.js +598 -68
- package/dist/vite.js.map +1 -1
- package/forms/forms.brm.ts +141 -0
- package/package.json +45 -3
- package/types.d.ts +9 -1
- package/dist/client-routes-DakuM32C.js.map +0 -1
- package/dist/context-BG8KCF3v.js +0 -15
- package/dist/context-BG8KCF3v.js.map +0 -1
- package/dist/context-aeo9esY9.d.ts +0 -16
- package/dist/cookies-Av5WFmcf.js.map +0 -1
- package/dist/devtools-BKjnHrnv.js +0 -113
- package/dist/devtools-BKjnHrnv.js.map +0 -1
- package/dist/devtools-panel-AWOn0VK2.js +0 -434
- package/dist/devtools-panel-AWOn0VK2.js.map +0 -1
- package/dist/files-DdT84mPy.js.map +0 -1
- package/dist/html-DEeoepg3.js +0 -152
- package/dist/html-DEeoepg3.js.map +0 -1
- package/dist/html-Du8jY2Cc.d.ts +0 -53
- package/dist/inspect-BPchdWbU.js.map +0 -1
- package/dist/loader-Dc9OwY5I.js.map +0 -1
- package/dist/navigate-CzLjnoPH.js.map +0 -1
- package/dist/produce-BRGHP7e0.js +0 -126
- package/dist/produce-BRGHP7e0.js.map +0 -1
- package/dist/produce-CtZ32UGG.d.ts +0 -60
- package/dist/rpc-9fSqL_YK.js.map +0 -1
- package/dist/runtime/client.js.map +0 -1
- package/dist/server-BxqjLUnV.d.ts +0 -753
- package/dist/server-DZsgnPKS.js +0 -1615
- package/dist/server-DZsgnPKS.js.map +0 -1
- package/dist/shared-CWYOd0H3.js +0 -40
- package/dist/shared-CWYOd0H3.js.map +0 -1
- package/dist/static-loader-ClNkHZGn.js +0 -185
- package/dist/static-loader-ClNkHZGn.js.map +0 -1
- package/dist/stream-bgNCMcaA.js +0 -280
- package/dist/stream-bgNCMcaA.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _ as functionId } from "./inspect-BHpOw1LF.js";
|
|
2
2
|
import { parseSync } from "oxc-parser";
|
|
3
3
|
import { readFile, readdir } from "node:fs/promises";
|
|
4
4
|
import path from "node:path";
|
|
@@ -13,9 +13,20 @@ function hasUseServer(source) {
|
|
|
13
13
|
function isScriptFile(path) {
|
|
14
14
|
return /\.[cm]?[jt]sx?$/.test(path) && !path.endsWith(".d.ts") && !/\.brm\.[cm]?[jt]s$/.test(path);
|
|
15
15
|
}
|
|
16
|
-
/**
|
|
17
|
-
function
|
|
18
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Tells a value that the file exports as a function: a function expression,
|
|
18
|
+
* or a call of `cached` or `idempotent` of `brumate/server`, which return a function.
|
|
19
|
+
*/
|
|
20
|
+
function functionTest(program) {
|
|
21
|
+
const wrappers = /* @__PURE__ */ new Set();
|
|
22
|
+
for (const statement of program.body) if (statement.type === "ImportDeclaration" && statement.source.value === "brumate/server") {
|
|
23
|
+
for (const specifier of statement.specifiers) if (specifier.type === "ImportSpecifier" && specifier.imported.type === "Identifier" && (specifier.imported.name === "cached" || specifier.imported.name === "idempotent")) wrappers.add(specifier.local.name);
|
|
24
|
+
}
|
|
25
|
+
return (node) => {
|
|
26
|
+
if (node?.type === "ArrowFunctionExpression" || node?.type === "FunctionExpression") return true;
|
|
27
|
+
const callee = node?.type === "CallExpression" ? node.callee : void 0;
|
|
28
|
+
return callee?.type === "Identifier" && wrappers.has(callee.name);
|
|
29
|
+
};
|
|
19
30
|
}
|
|
20
31
|
/**
|
|
21
32
|
* The names of the functions that a file of server functions exports.
|
|
@@ -28,6 +39,7 @@ function serverExports(source, filename) {
|
|
|
28
39
|
const functions = /* @__PURE__ */ new Set();
|
|
29
40
|
const values = /* @__PURE__ */ new Set();
|
|
30
41
|
const local = /* @__PURE__ */ new Map();
|
|
42
|
+
const isFunction = functionTest(program);
|
|
31
43
|
for (const statement of program.body) {
|
|
32
44
|
const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
|
|
33
45
|
if (declaration?.type === "FunctionDeclaration" && declaration.id) local.set(declaration.id.name, "function");
|
|
@@ -54,8 +66,23 @@ function serverExports(source, filename) {
|
|
|
54
66
|
}
|
|
55
67
|
} else if (statement.type === "ExportAllDeclaration") values.add("*");
|
|
56
68
|
if (values.size > 0) throw new Error(`A 'use server' file exports only functions, because the browser calls them on the server. ${[...values].join(", ")} of ${filename} is not one`);
|
|
69
|
+
functions.delete(MIDDLEWARE);
|
|
57
70
|
return [...functions];
|
|
58
71
|
}
|
|
72
|
+
/** The export of a file of server functions that runs before each of them. */
|
|
73
|
+
const MIDDLEWARE = "middleware";
|
|
74
|
+
/** True if a file of server functions exports `middleware`. */
|
|
75
|
+
function hasServerMiddleware(source, filename) {
|
|
76
|
+
const { program } = parseSync(filename, source, { lang: "ts" });
|
|
77
|
+
for (const statement of program.body) {
|
|
78
|
+
if (statement.type !== "ExportNamedDeclaration" || statement.exportKind === "type") continue;
|
|
79
|
+
const declaration = statement.declaration;
|
|
80
|
+
if (declaration?.type === "FunctionDeclaration" && declaration.id?.name === "middleware") return true;
|
|
81
|
+
if (declaration?.type === "VariableDeclaration" && declaration.declarations.some((declarator) => declarator.id.type === "Identifier" && declarator.id.name === "middleware")) return true;
|
|
82
|
+
if (statement.specifiers.some((specifier) => specifier.exportKind !== "type" && (specifier.exported.type === "Identifier" ? specifier.exported.name : specifier.exported.value) === "middleware")) return true;
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
59
86
|
/** The module that the browser gets in place of a file of server functions. */
|
|
60
87
|
function serverStubs(source, filename, id, hideNames = false) {
|
|
61
88
|
const lines = [`import { rpc } from ${JSON.stringify(CLIENT)};`];
|
|
@@ -72,6 +99,7 @@ function serverStubs(source, filename, id, hideNames = false) {
|
|
|
72
99
|
*/
|
|
73
100
|
function serverModule(source, filename, id) {
|
|
74
101
|
const { program } = parseSync(filename, source, { lang: "ts" });
|
|
102
|
+
const isFunction = functionTest(program);
|
|
75
103
|
const wrapped = /* @__PURE__ */ new Map();
|
|
76
104
|
const declarations = /* @__PURE__ */ new Map();
|
|
77
105
|
let code = source;
|
|
@@ -172,6 +200,6 @@ async function findScripts(root, exclude) {
|
|
|
172
200
|
return result.toSorted();
|
|
173
201
|
}
|
|
174
202
|
//#endregion
|
|
175
|
-
export {
|
|
203
|
+
export { hasServerMiddleware as a, serverExports as c, findServerFiles as i, serverModule as l, findFiles as n, hasUseServer as o, findScripts as r, isScriptFile as s, defaultExclude as t, serverStubs as u };
|
|
176
204
|
|
|
177
|
-
//# sourceMappingURL=files-
|
|
205
|
+
//# sourceMappingURL=files-BXSSrQgc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files-BXSSrQgc.js","names":[],"sources":["../src/server-files.ts","../src/files.ts"],"sourcesContent":["// Files of server functions. A `.ts` or `.js` file whose first statement is\n// `'use server'` holds functions that only run on the server. Its exports are\n// server functions: the browser gets a stub for each one, which calls the\n// server, and the code of the file never ships.\n\nimport { parseSync } from 'oxc-parser';\nimport { functionId } from './plan.ts';\n\n/** The import of the stubs, which call server functions with `rpc` of the core. */\nconst CLIENT = 'brumate/client';\n\n/** True for a file whose first statement is `'use server'`, after comments. */\nexport function hasUseServer(source: string): boolean {\n return /^(?:\\s|\\/\\/[^\\n]*\\n|\\/\\*[\\s\\S]*?\\*\\/)*(['\"])use server\\1/.test(source);\n}\n\n/** True for a path that can be a file of server functions. */\nexport function isScriptFile(path: string): boolean {\n return (\n /\\.[cm]?[jt]sx?$/.test(path) && !path.endsWith('.d.ts') && !/\\.brm\\.[cm]?[jt]s$/.test(path)\n );\n}\n\n/** True for a function expression or an arrow. */\ntype Program = ReturnType<typeof parseSync>['program'];\ntype Node = Program['body'][number] | { type: string; callee?: unknown } | null | undefined;\n\n/**\n * Tells a value that the file exports as a function: a function expression,\n * or a call of `cached` or `idempotent` of `brumate/server`, which return a function.\n */\nfunction functionTest(program: Program): (node: Node) => boolean {\n const wrappers = new Set<string>();\n for (const statement of program.body) {\n if (statement.type === 'ImportDeclaration' && statement.source.value === 'brumate/server') {\n for (const specifier of statement.specifiers) {\n if (\n specifier.type === 'ImportSpecifier' &&\n specifier.imported.type === 'Identifier' &&\n (specifier.imported.name === 'cached' || specifier.imported.name === 'idempotent')\n ) {\n wrappers.add(specifier.local.name);\n }\n }\n }\n }\n return (node) => {\n if (node?.type === 'ArrowFunctionExpression' || node?.type === 'FunctionExpression') {\n return true;\n }\n const callee =\n node?.type === 'CallExpression'\n ? (node.callee as { type: string; name?: string })\n : undefined;\n return callee?.type === 'Identifier' && wrappers.has(callee.name!);\n };\n}\n\n/**\n * The names of the functions that a file of server functions exports.\n * Throws for an export that is not a function, because the browser can only\n * call a server function through its stub.\n */\nexport function serverExports(source: string, filename: string): string[] {\n const { program, errors } = parseSync(filename, source, { lang: 'ts' });\n if (errors[0]) {\n throw new Error(`${errors[0].message} (${filename})`);\n }\n const functions = new Set<string>();\n const values = new Set<string>();\n const local = new Map<string, 'function' | 'value'>();\n const isFunction = functionTest(program);\n for (const statement of program.body) {\n const declaration =\n statement.type === 'ExportNamedDeclaration' ? statement.declaration : statement;\n if (declaration?.type === 'FunctionDeclaration' && declaration.id) {\n local.set(declaration.id.name, 'function');\n } else if (declaration?.type === 'VariableDeclaration') {\n for (const declarator of declaration.declarations) {\n if (declarator.id.type === 'Identifier') {\n local.set(declarator.id.name, isFunction(declarator.init) ? 'function' : 'value');\n }\n }\n }\n }\n for (const statement of program.body) {\n if (statement.type === 'ExportDefaultDeclaration') {\n const value = statement.declaration;\n if (value.type === 'FunctionDeclaration' || isFunction(value)) {\n functions.add('default');\n } else {\n values.add('default');\n }\n } else if (statement.type === 'ExportNamedDeclaration') {\n if (statement.exportKind === 'type') {\n continue;\n }\n const declaration = statement.declaration;\n if (declaration?.type === 'FunctionDeclaration' && declaration.id) {\n functions.add(declaration.id.name);\n } else if (declaration?.type === 'VariableDeclaration') {\n for (const declarator of declaration.declarations) {\n if (declarator.id.type === 'Identifier') {\n (isFunction(declarator.init) ? functions : values).add(declarator.id.name);\n }\n }\n } else if (declaration && !declaration.type.startsWith('TS')) {\n values.add('a class');\n }\n for (const specifier of statement.specifiers) {\n if (specifier.exportKind === 'type') {\n continue;\n }\n const name =\n specifier.exported.type === 'Identifier'\n ? specifier.exported.name\n : specifier.exported.value;\n const from = specifier.local.type === 'Identifier' ? specifier.local.name : '';\n (local.get(from) === 'function' && !statement.source ? functions : values).add(name);\n }\n } else if (statement.type === 'ExportAllDeclaration') {\n values.add('*');\n }\n }\n if (values.size > 0) {\n throw new Error(\n `A 'use server' file exports only functions, because the browser calls them on the server. ${[...values].join(', ')} of ${filename} is not one`,\n );\n }\n // The middleware of the file runs before its functions. The browser cannot call it.\n functions.delete(MIDDLEWARE);\n return [...functions];\n}\n\n/** The export of a file of server functions that runs before each of them. */\nexport const MIDDLEWARE = 'middleware';\n\n/** True if a file of server functions exports `middleware`. */\nexport function hasServerMiddleware(source: string, filename: string): boolean {\n const { program } = parseSync(filename, source, { lang: 'ts' });\n for (const statement of program.body) {\n if (statement.type !== 'ExportNamedDeclaration' || statement.exportKind === 'type') {\n continue;\n }\n const declaration = statement.declaration;\n if (declaration?.type === 'FunctionDeclaration' && declaration.id?.name === MIDDLEWARE) {\n return true;\n }\n if (\n declaration?.type === 'VariableDeclaration' &&\n declaration.declarations.some(\n (declarator) => declarator.id.type === 'Identifier' && declarator.id.name === MIDDLEWARE,\n )\n ) {\n return true;\n }\n if (\n statement.specifiers.some(\n (specifier) =>\n specifier.exportKind !== 'type' &&\n (specifier.exported.type === 'Identifier'\n ? specifier.exported.name\n : specifier.exported.value) === MIDDLEWARE,\n )\n ) {\n return true;\n }\n }\n return false;\n}\n\n/** The module that the browser gets in place of a file of server functions. */\nexport function serverStubs(\n source: string,\n filename: string,\n id: string,\n hideNames = false,\n): string {\n const lines = [`import { rpc } from ${JSON.stringify(CLIENT)};`];\n for (const name of serverExports(source, filename)) {\n const call = `(...args) => rpc(${JSON.stringify(functionId(id, name, hideNames))}, args)`;\n lines.push(name === 'default' ? `export default ${call};` : `export const ${name} = ${call};`);\n }\n return `${lines.join('\\n')}\\n`;\n}\n\n/**\n * The module that the server runs for a file of server functions: the file,\n * with each exported function wrapped, so its calls while a page renders\n * share a result when their arguments are the same. Offsets stay the same.\n */\nexport function serverModule(source: string, filename: string, id: string): string {\n const { program } = parseSync(filename, source, { lang: 'ts' });\n const isFunction = functionTest(program);\n // Local names of exported functions, with the name that each is exported as.\n const wrapped = new Map<string, string>();\n const declarations = new Map<string, 'function' | 'const'>();\n let code = source;\n for (const statement of program.body) {\n const declaration =\n statement.type === 'ExportNamedDeclaration' ? statement.declaration : statement;\n if (declaration?.type === 'FunctionDeclaration' && declaration.id) {\n declarations.set(declaration.id.name, 'function');\n } else if (declaration?.type === 'VariableDeclaration') {\n for (const declarator of declaration.declarations) {\n if (declarator.id.type === 'Identifier' && isFunction(declarator.init)) {\n declarations.set(declarator.id.name, 'const');\n }\n }\n }\n }\n const letOf = (declaration: { start: number; kind: string }): void => {\n // `const` becomes `let `, so the function can be wrapped and offsets stay the same.\n if (declaration.kind === 'const') {\n code = `${code.slice(0, declaration.start)}let ${code.slice(declaration.start + 5)}`;\n }\n };\n for (const statement of program.body) {\n if (\n statement.type !== 'ExportNamedDeclaration' ||\n statement.source ||\n statement.exportKind === 'type'\n ) {\n continue;\n }\n const declaration = statement.declaration;\n if (declaration?.type === 'FunctionDeclaration' && declaration.id) {\n wrapped.set(declaration.id.name, declaration.id.name);\n } else if (declaration?.type === 'VariableDeclaration') {\n for (const declarator of declaration.declarations) {\n if (declarator.id.type === 'Identifier' && isFunction(declarator.init)) {\n wrapped.set(declarator.id.name, declarator.id.name);\n letOf(declaration);\n }\n }\n }\n for (const specifier of statement.specifiers) {\n const local = specifier.local.type === 'Identifier' ? specifier.local.name : '';\n const exported =\n specifier.exported.type === 'Identifier'\n ? specifier.exported.name\n : specifier.exported.value;\n if (declarations.has(local)) {\n wrapped.set(local, exported);\n }\n }\n }\n // A `const` arrow that `export { name }` exports is declared with `let` too.\n for (const statement of program.body) {\n if (statement.type === 'VariableDeclaration') {\n for (const declarator of statement.declarations) {\n if (declarator.id.type === 'Identifier' && wrapped.has(declarator.id.name)) {\n letOf(statement);\n }\n }\n }\n }\n if (wrapped.size === 0) {\n return source;\n }\n const lines = [\"import { dedupe as __brumateDedupe } from 'brumate/server';\"];\n for (const [local, exported] of wrapped) {\n lines.push(`${local} = __brumateDedupe(${local}, ${JSON.stringify(`${id}#${exported}`)});`);\n }\n return `${code}\\n${lines.join('\\n')}\\n`;\n}\n","import { readFile, readdir } from 'node:fs/promises';\nimport path from 'node:path';\nimport { hasUseServer, isScriptFile } from './server-files.ts';\n\n/** Skips `node_modules`, `dist` and hidden directories when looking for `.brm` files. */\nexport function defaultExclude(directory: string): boolean {\n return directory === 'node_modules' || directory === 'dist' || directory.startsWith('.');\n}\n\n/** Finds every `.brm` file under a directory, as absolute paths with forward slashes. */\nexport async function findFiles(\n root: string,\n exclude: (directory: string) => boolean,\n): Promise<string[]> {\n const result: string[] = [];\n const visit = async (directory: string): Promise<void> => {\n const directories: Promise<void>[] = [];\n for (const entry of await readdir(directory, { withFileTypes: true })) {\n const file = path.join(directory, entry.name);\n if (entry.isDirectory()) {\n if (!exclude(entry.name)) {\n directories.push(visit(file));\n }\n } else if (entry.name.endsWith('.brm')) {\n result.push(file.split(path.sep).join('/'));\n }\n }\n await Promise.all(directories);\n };\n await visit(root);\n return result.toSorted();\n}\n\n/**\n * Finds every file of server functions under a directory: a script whose\n * first statement is `'use server'`.\n */\nexport async function findServerFiles(\n root: string,\n exclude: (directory: string) => boolean,\n): Promise<string[]> {\n const result: string[] = [];\n const visit = async (directory: string): Promise<void> => {\n const pending: Promise<void>[] = [];\n for (const entry of await readdir(directory, { withFileTypes: true })) {\n const file = path.join(directory, entry.name);\n if (entry.isDirectory()) {\n if (!exclude(entry.name)) {\n pending.push(visit(file));\n }\n } else if (isScriptFile(entry.name)) {\n pending.push(\n readFile(file, 'utf8').then((source) => {\n if (hasUseServer(source)) {\n result.push(file.split(path.sep).join('/'));\n }\n }),\n );\n }\n }\n await Promise.all(pending);\n };\n await visit(root);\n return result.toSorted();\n}\n\n/**\n * Finds every script under a directory, such as `.ts` and `.brm.ts` files, as\n * absolute paths with forward slashes, without reading them.\n */\nexport async function findScripts(\n root: string,\n exclude: (directory: string) => boolean,\n): Promise<string[]> {\n const result: string[] = [];\n const visit = async (directory: string): Promise<void> => {\n const directories: Promise<void>[] = [];\n for (const entry of await readdir(directory, { withFileTypes: true })) {\n const file = path.join(directory, entry.name);\n if (entry.isDirectory()) {\n if (!exclude(entry.name)) {\n directories.push(visit(file));\n }\n } else if (/\\.[cm]?[jt]sx?$/.test(entry.name) && !entry.name.endsWith('.d.ts')) {\n result.push(file.split(path.sep).join('/'));\n }\n }\n await Promise.all(directories);\n };\n await visit(root);\n return result.toSorted();\n}\n"],"mappings":";;;;;;AASA,MAAM,SAAS;;AAGf,SAAgB,aAAa,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AAM,IAAI;GAC5C,IAAI,MAAM,YAAY,GAChB;QAAA,CAAC,QAAQ,MAAM,IAAI,GACrB,QAAQ,KAAK,MAAM,IAAI,CAAC;GAAA,OAErB,IAAI,aAAa,MAAM,IAAI,GAChC,QAAQ,KACN,SAAS,MAAM,MAAM,CAAC,CAAC,MAAM,WAAW;IACtC,IAAI,aAAa,MAAM,GACrB,OAAO,KAAK,KAAK,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,GAAG,CAAC;GAE9C,CAAC,CACH;EAEJ;EACA,MAAM,QAAQ,IAAI,OAAO;CAC3B;CACA,MAAM,MAAM,IAAI;CAChB,OAAO,OAAO,SAAS;AACzB;;;;;AAMA,eAAsB,YACpB,MACA,SACmB;CACnB,MAAM,SAAmB,CAAC;CAC1B,MAAM,QAAQ,OAAO,cAAqC;EACxD,MAAM,cAA+B,CAAC;EACtC,KAAK,MAAM,SAAS,MAAM,QAAQ,WAAW,EAAE,eAAe,KAAK,CAAC,GAAG;GACrE,MAAM,OAAO,KAAK,KAAK,WAAW,MAAM,IAAI;GAC5C,IAAI,MAAM,YAAY,GAChB;QAAA,CAAC,QAAQ,MAAM,IAAI,GACrB,YAAY,KAAK,MAAM,IAAI,CAAC;GAAA,OAEzB,IAAI,kBAAkB,KAAK,MAAM,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,OAAO,GAC3E,OAAO,KAAK,KAAK,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,GAAG,CAAC;EAE9C;EACA,MAAM,QAAQ,IAAI,WAAW;CAC/B;CACA,MAAM,MAAM,IAAI;CAChB,OAAO,OAAO,SAAS;AACzB"}
|
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
//#region src/runtime/forms.ts
|
|
2
|
+
/** The name of the submit button that holds an intent. */
|
|
3
|
+
const INTENT = "__intent";
|
|
4
|
+
/** The largest index of a list item in a field name, so a form cannot make a huge array. */
|
|
5
|
+
const MAX_INDEX = 999;
|
|
6
|
+
/** Names that would change the prototype of an object, or reach the one of its constructor. */
|
|
7
|
+
const FORBIDDEN = /* @__PURE__ */ new Set([
|
|
8
|
+
"__proto__",
|
|
9
|
+
"constructor",
|
|
10
|
+
"prototype"
|
|
11
|
+
]);
|
|
12
|
+
/**
|
|
13
|
+
* The path of a field name: `items[0].name` is `['items', 0, 'name']`.
|
|
14
|
+
* Dots separate keys, and `[n]` is the index of a list item. A number
|
|
15
|
+
* between dots stays a key. Undefined for a name that is not a path, such
|
|
16
|
+
* as one with an empty key, an index above `MAX_INDEX`, or a key such as
|
|
17
|
+
* `__proto__`.
|
|
18
|
+
*/
|
|
19
|
+
function parsePath(name) {
|
|
20
|
+
const path = [];
|
|
21
|
+
for (const part of name.split(".")) {
|
|
22
|
+
const match = /^([^[\]]+)((?:\[\d+\])*)$/.exec(part);
|
|
23
|
+
if (!match || FORBIDDEN.has(match[1])) return;
|
|
24
|
+
path.push(match[1]);
|
|
25
|
+
for (const index of match[2].matchAll(/\[(\d+)\]/g)) {
|
|
26
|
+
const value = Number(index[1]);
|
|
27
|
+
if (value > 999 || index[1].length > 1 && index[1].startsWith("0")) return;
|
|
28
|
+
path.push(value);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return path;
|
|
32
|
+
}
|
|
33
|
+
/** The field name of a path: `['items', 0, 'name']` is `items[0].name`. */
|
|
34
|
+
function formatPath(path) {
|
|
35
|
+
let name = "";
|
|
36
|
+
for (const segment of path) if (typeof segment === "number") name += `[${segment}]`;
|
|
37
|
+
else name += name ? `.${segment}` : segment;
|
|
38
|
+
return name;
|
|
39
|
+
}
|
|
40
|
+
/** The value at a path, or undefined when a part of the path is missing. */
|
|
41
|
+
function getAt(value, path) {
|
|
42
|
+
let current = value;
|
|
43
|
+
for (const segment of path) {
|
|
44
|
+
if (typeof current !== "object" || current === null || !Object.hasOwn(current, segment)) return;
|
|
45
|
+
current = current[segment];
|
|
46
|
+
}
|
|
47
|
+
return current;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A copy of `value` with `next` at the path. The objects and lists along the
|
|
51
|
+
* path are copied, and the others are shared. A missing part becomes a list
|
|
52
|
+
* for an index and an object for a key.
|
|
53
|
+
*/
|
|
54
|
+
function setAt(value, path, next) {
|
|
55
|
+
if (path.length === 0) return next;
|
|
56
|
+
const [segment, ...rest] = path;
|
|
57
|
+
let copy;
|
|
58
|
+
if (Array.isArray(value)) copy = [...value];
|
|
59
|
+
else if (typeof value === "object" && value !== null) copy = { ...value };
|
|
60
|
+
else copy = typeof segment === "number" ? [] : {};
|
|
61
|
+
const child = Object.hasOwn(copy, segment) ? copy[segment] : void 0;
|
|
62
|
+
copy[segment] = setAt(child, rest, next);
|
|
63
|
+
return copy;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Turns the entries of a form into a plain object:
|
|
67
|
+
*
|
|
68
|
+
* - A name that appears once holds its value.
|
|
69
|
+
* - A name that appears more than once holds an array of its values.
|
|
70
|
+
* - A name that ends with `[]` always holds an array, under the name without `[]`.
|
|
71
|
+
* - Dots nest objects: `address.city` is `{ address: { city } }`.
|
|
72
|
+
* - An index in brackets makes a list: `items[0].name` is `{ items: [{ name }] }`.
|
|
73
|
+
* - Values stay strings and files.
|
|
74
|
+
*
|
|
75
|
+
* A name with an empty part, a part such as `__proto__`, an index above
|
|
76
|
+
* 999, or one that needs an object where another field holds a value, is
|
|
77
|
+
* an issue, and the schema does not run.
|
|
78
|
+
*/
|
|
79
|
+
function formValues(form, skip) {
|
|
80
|
+
const root = {};
|
|
81
|
+
const containers = /* @__PURE__ */ new Set([root]);
|
|
82
|
+
const repeated = /* @__PURE__ */ new Set();
|
|
83
|
+
const issues = [];
|
|
84
|
+
for (const [name, value] of form) {
|
|
85
|
+
if (skip?.(name)) continue;
|
|
86
|
+
const list = name.endsWith("[]");
|
|
87
|
+
const parts = parsePath(list ? name.slice(0, -2) : name);
|
|
88
|
+
if (!parts) {
|
|
89
|
+
issues.push({ message: "The form has a field name that is not allowed" });
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
let target = root;
|
|
93
|
+
let conflict = false;
|
|
94
|
+
for (const [index, part] of parts.slice(0, -1).entries()) {
|
|
95
|
+
const next = Object.hasOwn(target, part) ? target[part] : void 0;
|
|
96
|
+
if (Array.isArray(target) !== (typeof part === "number")) {
|
|
97
|
+
conflict = true;
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
if (next === void 0) {
|
|
101
|
+
const child = typeof parts[index + 1] === "number" ? [] : {};
|
|
102
|
+
containers.add(child);
|
|
103
|
+
target[part] = child;
|
|
104
|
+
target = child;
|
|
105
|
+
} else if (containers.has(next)) target = next;
|
|
106
|
+
else {
|
|
107
|
+
conflict = true;
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const last = parts.at(-1);
|
|
112
|
+
const current = Object.hasOwn(target, last) ? target[last] : void 0;
|
|
113
|
+
if (conflict || containers.has(current) || Array.isArray(target) !== (typeof last === "number")) issues.push({
|
|
114
|
+
message: `Field "${name}" conflicts with another field`,
|
|
115
|
+
path: parts
|
|
116
|
+
});
|
|
117
|
+
else if (repeated.has(current)) current.push(value);
|
|
118
|
+
else if (current !== void 0 || list) {
|
|
119
|
+
const values = current === void 0 ? [value] : [current, value];
|
|
120
|
+
repeated.add(values);
|
|
121
|
+
target[last] = values;
|
|
122
|
+
} else target[last] = value;
|
|
123
|
+
}
|
|
124
|
+
return issues.length > 0 ? { issues } : { value: root };
|
|
125
|
+
}
|
|
126
|
+
/** The errors of issues by field name, such as `items[0].name`, and those of the whole form. */
|
|
127
|
+
function groupIssues(issues) {
|
|
128
|
+
const errors = {};
|
|
129
|
+
const formErrors = [];
|
|
130
|
+
for (const issue of issues) {
|
|
131
|
+
const path = issue.path ?? [];
|
|
132
|
+
const name = path.length > 0 && typeof path[0] === "string" ? formatPath(path) : "";
|
|
133
|
+
if (name === "" || !parsePath(name)) formErrors.push(issue.message);
|
|
134
|
+
else (Object.hasOwn(errors, name) ? errors[name] : errors[name] = []).push(issue.message);
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
errors,
|
|
138
|
+
formErrors
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Validates the fields of a form in the browser, with the schema that the
|
|
143
|
+
* server uses, and groups the errors as `reply` does.
|
|
144
|
+
*/
|
|
145
|
+
async function validateForm(schema, form) {
|
|
146
|
+
const values = formValues(form, (name) => name === INTENT);
|
|
147
|
+
return values.issues ? groupIssues(values.issues) : validateValues(schema, values.value);
|
|
148
|
+
}
|
|
149
|
+
/** Validates the values of a form in the browser, and groups the errors as `reply` does. */
|
|
150
|
+
async function validateValues(schema, value) {
|
|
151
|
+
return groupIssues(((await schema["~standard"].validate(value)).issues ?? []).map((issue) => ({
|
|
152
|
+
message: String(issue.message),
|
|
153
|
+
path: issue.path?.map((segment) => {
|
|
154
|
+
const key = typeof segment === "object" ? segment.key : segment;
|
|
155
|
+
return typeof key === "number" ? key : String(key);
|
|
156
|
+
})
|
|
157
|
+
})));
|
|
158
|
+
}
|
|
159
|
+
const isIndex = (value) => Number.isInteger(value) && value >= 0 && value <= 999;
|
|
160
|
+
/**
|
|
161
|
+
* Reads the intent that a submit button posted, as JSON. Undefined for a
|
|
162
|
+
* value that is not an intent, such as one with a name that is not a path.
|
|
163
|
+
*/
|
|
164
|
+
function parseIntent(text) {
|
|
165
|
+
let intent;
|
|
166
|
+
try {
|
|
167
|
+
intent = JSON.parse(text);
|
|
168
|
+
} catch {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (typeof intent !== "object" || intent === null) return;
|
|
172
|
+
const { type, name, index, from, to } = intent;
|
|
173
|
+
if (name !== void 0 && (typeof name !== "string" || !parsePath(name))) return;
|
|
174
|
+
switch (type) {
|
|
175
|
+
case "insert": return name !== void 0 && (index === void 0 || isIndex(index)) ? intent : void 0;
|
|
176
|
+
case "remove": return name !== void 0 && isIndex(index) ? intent : void 0;
|
|
177
|
+
case "reorder": return name !== void 0 && isIndex(from) && isIndex(to) ? intent : void 0;
|
|
178
|
+
case "reset": return intent;
|
|
179
|
+
case "validate": return name !== void 0 ? intent : void 0;
|
|
180
|
+
default: return;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/** The value of a submit button that posts an intent. */
|
|
184
|
+
function intentValue(intent) {
|
|
185
|
+
return JSON.stringify(intent);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Applies an intent to the posted values. Returns the new values, and the
|
|
189
|
+
* name of the list that it changed. Undefined when the intent does not fit
|
|
190
|
+
* the values, such as an index past the end of the list.
|
|
191
|
+
*/
|
|
192
|
+
function applyIntent(value, intent) {
|
|
193
|
+
if (intent.type === "validate") return { value };
|
|
194
|
+
if (intent.type === "reset") return { value: intent.name === void 0 ? void 0 : setAt(value, parsePath(intent.name), void 0) };
|
|
195
|
+
const path = parsePath(intent.name);
|
|
196
|
+
const current = getAt(value, path) ?? [];
|
|
197
|
+
if (!Array.isArray(current)) return;
|
|
198
|
+
const items = [...current];
|
|
199
|
+
if (intent.type === "insert") {
|
|
200
|
+
const index = intent.index ?? items.length;
|
|
201
|
+
if (index > items.length || items.length > 999) return;
|
|
202
|
+
items.splice(index, 0, intent.defaultValue);
|
|
203
|
+
} else if (intent.type === "remove") {
|
|
204
|
+
if (intent.index >= items.length) return;
|
|
205
|
+
items.splice(intent.index, 1);
|
|
206
|
+
} else {
|
|
207
|
+
if (intent.from >= items.length || intent.to >= items.length) return;
|
|
208
|
+
items.splice(intent.to, 0, ...items.splice(intent.from, 1));
|
|
209
|
+
}
|
|
210
|
+
return {
|
|
211
|
+
value: setAt(value, path, items),
|
|
212
|
+
list: intent.name
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
const isFile = (value) => typeof Blob !== "undefined" && value instanceof Blob;
|
|
216
|
+
const isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value) && !isFile(value) && !(value instanceof Date);
|
|
217
|
+
/** The attributes of a submit button that posts an intent. */
|
|
218
|
+
function intentButton(intent, press) {
|
|
219
|
+
const attrs = {
|
|
220
|
+
type: "submit",
|
|
221
|
+
name: INTENT,
|
|
222
|
+
value: intentValue(intent),
|
|
223
|
+
formnovalidate: true
|
|
224
|
+
};
|
|
225
|
+
if (press) attrs.onClick = press(intent);
|
|
226
|
+
return attrs;
|
|
227
|
+
}
|
|
228
|
+
/** The changes of the browser when they came after the last reply. */
|
|
229
|
+
function localSince(local, result) {
|
|
230
|
+
return local && local.reply === result?.id ? local : void 0;
|
|
231
|
+
}
|
|
232
|
+
/** A key for a new item, which no other item of the page has. */
|
|
233
|
+
let nextKey = 0;
|
|
234
|
+
/**
|
|
235
|
+
* Applies an intent in the browser to the values that the form holds now.
|
|
236
|
+
* The items of the list keep their keys, so their elements and what was
|
|
237
|
+
* typed in them stay, and a new item gets a new key. Undefined when the
|
|
238
|
+
* intent does not fit the values.
|
|
239
|
+
*/
|
|
240
|
+
function applyLocalIntent(form, intent, local, result) {
|
|
241
|
+
if (!form || intent.type === "reset" || intent.type === "validate") return;
|
|
242
|
+
const values = formValues(new FormData(form), (name) => name === INTENT);
|
|
243
|
+
const applied = values.value && applyIntent(values.value, intent);
|
|
244
|
+
if (!applied) return;
|
|
245
|
+
const current = localSince(local, result);
|
|
246
|
+
const before = getAt(values.value, parsePath(intent.name));
|
|
247
|
+
const length = Array.isArray(before) ? before.length : 0;
|
|
248
|
+
const keys = [...current?.keys[intent.name] ?? (result && !result.reset ? result.keys[intent.name] : void 0) ?? Array.from({ length }, (_, index) => String(index))];
|
|
249
|
+
if (intent.type === "insert") keys.splice(intent.index ?? keys.length, 0, `n${nextKey++}`);
|
|
250
|
+
else if (intent.type === "remove") keys.splice(intent.index, 1);
|
|
251
|
+
else keys.splice(intent.to, 0, ...keys.splice(intent.from, 1));
|
|
252
|
+
return {
|
|
253
|
+
reply: result?.id,
|
|
254
|
+
value: applied.value,
|
|
255
|
+
keys: {
|
|
256
|
+
...current?.keys,
|
|
257
|
+
[intent.name]: keys
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* The fields of a form, from its default value and the reply of its last
|
|
263
|
+
* submit. A field exists for each key of the default value or of the posted
|
|
264
|
+
* value, so the default value names every field that the form shows.
|
|
265
|
+
*/
|
|
266
|
+
function formFields(id, defaultValue, result, { checked, local, press } = {}) {
|
|
267
|
+
const changes = localSince(local, result);
|
|
268
|
+
let value;
|
|
269
|
+
if (changes) value = changes.value;
|
|
270
|
+
else if (result && !result.reset) value = result.value;
|
|
271
|
+
const submitted = result !== void 0;
|
|
272
|
+
const keys = {
|
|
273
|
+
...result && !result.reset ? result.keys : {},
|
|
274
|
+
...changes?.keys
|
|
275
|
+
};
|
|
276
|
+
const replied = {};
|
|
277
|
+
for (const [name, messages] of Object.entries(result && !result.reset ? result.errors : {})) if (!Object.keys(changes?.keys ?? {}).some((list) => name.startsWith(`${list}[`))) replied[name] = messages;
|
|
278
|
+
const current = checkedSince(checked, result);
|
|
279
|
+
const shows = (name) => current !== void 0 && (current.all || current.touched.includes(name));
|
|
280
|
+
const errorsOf = (name) => {
|
|
281
|
+
const source = shows(name) ? current.errors : replied;
|
|
282
|
+
return Object.hasOwn(source, name) ? source[name] : void 0;
|
|
283
|
+
};
|
|
284
|
+
const state = (path, shown) => {
|
|
285
|
+
const name = formatPath(path);
|
|
286
|
+
const fieldId = `${id}-${name}`;
|
|
287
|
+
const errorId = `${fieldId}-error`;
|
|
288
|
+
const messages = errorsOf(name);
|
|
289
|
+
const attrs = {
|
|
290
|
+
name,
|
|
291
|
+
id: fieldId
|
|
292
|
+
};
|
|
293
|
+
if (messages) {
|
|
294
|
+
attrs["aria-invalid"] = "true";
|
|
295
|
+
attrs["aria-describedby"] = errorId;
|
|
296
|
+
}
|
|
297
|
+
if (typeof shown === "string" || typeof shown === "number") attrs.value = String(shown);
|
|
298
|
+
else if (typeof shown === "boolean") attrs.checked = shown;
|
|
299
|
+
return {
|
|
300
|
+
name,
|
|
301
|
+
id: fieldId,
|
|
302
|
+
value: shown,
|
|
303
|
+
errors: messages,
|
|
304
|
+
attrs,
|
|
305
|
+
errorAttrs: submitted ? {
|
|
306
|
+
id: errorId,
|
|
307
|
+
role: "alert"
|
|
308
|
+
} : { id: errorId }
|
|
309
|
+
};
|
|
310
|
+
};
|
|
311
|
+
const posted = value !== void 0;
|
|
312
|
+
const field = (path, fallback, sent) => {
|
|
313
|
+
const shown = posted ? sent : fallback;
|
|
314
|
+
const own = state(path, shown);
|
|
315
|
+
if (Array.isArray(shown) || Array.isArray(fallback)) {
|
|
316
|
+
const items = Array.isArray(shown) ? shown : [];
|
|
317
|
+
const name = own.name;
|
|
318
|
+
const itemKeys = Object.hasOwn(keys, name) ? keys[name] : void 0;
|
|
319
|
+
const defaults = Array.isArray(fallback) ? fallback : [];
|
|
320
|
+
const list = items.map((item, index) => Object.assign(field([...path, index], defaults[index] ?? defaults[0], item), {
|
|
321
|
+
key: itemKeys?.[index] ?? String(index),
|
|
322
|
+
index,
|
|
323
|
+
remove: intentButton({
|
|
324
|
+
type: "remove",
|
|
325
|
+
name,
|
|
326
|
+
index
|
|
327
|
+
}, press),
|
|
328
|
+
moveUp: intentButton({
|
|
329
|
+
type: "reorder",
|
|
330
|
+
name,
|
|
331
|
+
from: index,
|
|
332
|
+
to: Math.max(index - 1, 0)
|
|
333
|
+
}, press),
|
|
334
|
+
moveDown: intentButton({
|
|
335
|
+
type: "reorder",
|
|
336
|
+
name,
|
|
337
|
+
from: index,
|
|
338
|
+
to: Math.min(index + 1, items.length - 1)
|
|
339
|
+
}, press)
|
|
340
|
+
}));
|
|
341
|
+
return Object.assign(own, {
|
|
342
|
+
list,
|
|
343
|
+
insert: intentButton({
|
|
344
|
+
type: "insert",
|
|
345
|
+
name
|
|
346
|
+
}, press)
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
if (isPlainObject(shown) || isPlainObject(fallback)) {
|
|
350
|
+
const defaults = isPlainObject(fallback) ? fallback : {};
|
|
351
|
+
const values = isPlainObject(sent) ? sent : {};
|
|
352
|
+
const fields = {};
|
|
353
|
+
for (const key of /* @__PURE__ */ new Set([...Object.keys(defaults), ...Object.keys(posted ? values : {})])) fields[key] = field([...path, key], Object.hasOwn(defaults, key) ? defaults[key] : void 0, Object.hasOwn(values, key) ? values[key] : void 0);
|
|
354
|
+
return path.length === 0 ? fields : Object.assign(own, { fields });
|
|
355
|
+
}
|
|
356
|
+
return own;
|
|
357
|
+
};
|
|
358
|
+
return field([], defaultValue, value);
|
|
359
|
+
}
|
|
360
|
+
/** The check of the browser when it came after the last reply, or undefined when a reply came after it. */
|
|
361
|
+
function checkedSince(checked, result) {
|
|
362
|
+
return checked && checked.reply === result?.id ? checked : void 0;
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* The errors of the whole form: those that the browser found, when it
|
|
366
|
+
* checked every field since the last reply, or else those of the reply.
|
|
367
|
+
*/
|
|
368
|
+
function formErrorsOf(result, checked) {
|
|
369
|
+
const current = checkedSince(checked, result);
|
|
370
|
+
const errors = current?.all ? current.formErrors : result?.formErrors;
|
|
371
|
+
return errors && errors.length > 0 ? errors : void 0;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* The next check of the browser, after the user leaves or changes a field.
|
|
375
|
+
* A field counts once the user leaves it. After a submit, every field counts.
|
|
376
|
+
* Undefined when the event changes nothing, such as typing in a field that
|
|
377
|
+
* the user has not left yet.
|
|
378
|
+
*/
|
|
379
|
+
async function checkField(schema, form, name, left, checked, result) {
|
|
380
|
+
const current = checkedSince(checked, result);
|
|
381
|
+
const all = result !== void 0 && !result.reset;
|
|
382
|
+
const touched = current?.touched ?? [];
|
|
383
|
+
if (!form || !name || name === "__intent" || !left && !all && !touched.includes(name)) return;
|
|
384
|
+
return {
|
|
385
|
+
...await validateForm(schema, new FormData(form)),
|
|
386
|
+
reply: result?.id,
|
|
387
|
+
touched: touched.includes(name) ? touched : [...touched, name],
|
|
388
|
+
all
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* The attributes of a submit button that the form presses on Enter. Without
|
|
393
|
+
* it, Enter in a field presses the first submit button of the form, which
|
|
394
|
+
* can be an intent button, such as "Remove". It is hidden from sight and
|
|
395
|
+
* from assistive technology, and cannot take focus.
|
|
396
|
+
*/
|
|
397
|
+
const DEFAULT_SUBMIT = {
|
|
398
|
+
type: "submit",
|
|
399
|
+
tabindex: -1,
|
|
400
|
+
"aria-hidden": "true",
|
|
401
|
+
style: "position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap;border:0;padding:0;margin:-1px"
|
|
402
|
+
};
|
|
403
|
+
//#endregion
|
|
404
|
+
export { validateValues as S, localSince as _, applyIntent as a, setAt as b, checkedSince as c, formValues as d, formatPath as f, intentValue as g, intentButton as h, MAX_INDEX as i, formErrorsOf as l, groupIssues as m, FORBIDDEN as n, applyLocalIntent as o, getAt as p, INTENT as r, checkField as s, DEFAULT_SUBMIT as t, formFields as u, parseIntent as v, validateForm as x, parsePath as y };
|
|
405
|
+
|
|
406
|
+
//# sourceMappingURL=forms-Bg-CwGqX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"forms-Bg-CwGqX.js","names":[],"sources":["../src/runtime/forms.ts"],"sourcesContent":["// The parts of progressive forms that the server and the browser share: the\n// paths of field names, intents, the reply of a submission, and the state of\n// the fields that `createForm` shows. Nothing here reads the server, so the\n// code of `brumate/forms` can run it in the browser.\n\n/** A part of the path of a field: a key of an object, or an index of a list. */\nexport type PathSegment = string | number;\n\n/** The name of the submit button that holds an intent. */\nexport const INTENT = '__intent';\n\n/** The largest index of a list item in a field name, so a form cannot make a huge array. */\nexport const MAX_INDEX = 999;\n\n/** Names that would change the prototype of an object, or reach the one of its constructor. */\nexport const FORBIDDEN: ReadonlySet<string> = new Set(['__proto__', 'constructor', 'prototype']);\n\n/**\n * The path of a field name: `items[0].name` is `['items', 0, 'name']`.\n * Dots separate keys, and `[n]` is the index of a list item. A number\n * between dots stays a key. Undefined for a name that is not a path, such\n * as one with an empty key, an index above `MAX_INDEX`, or a key such as\n * `__proto__`.\n */\nexport function parsePath(name: string): PathSegment[] | undefined {\n const path: PathSegment[] = [];\n for (const part of name.split('.')) {\n const match = /^([^[\\]]+)((?:\\[\\d+\\])*)$/.exec(part);\n if (!match || FORBIDDEN.has(match[1]!)) {\n return undefined;\n }\n path.push(match[1]!);\n for (const index of match[2]!.matchAll(/\\[(\\d+)\\]/g)) {\n const value = Number(index[1]);\n if (value > MAX_INDEX || (index[1]!.length > 1 && index[1]!.startsWith('0'))) {\n return undefined;\n }\n path.push(value);\n }\n }\n return path;\n}\n\n/** The field name of a path: `['items', 0, 'name']` is `items[0].name`. */\nexport function formatPath(path: readonly PathSegment[]): string {\n let name = '';\n for (const segment of path) {\n if (typeof segment === 'number') {\n name += `[${segment}]`;\n } else {\n name += name ? `.${segment}` : segment;\n }\n }\n return name;\n}\n\n/** The value at a path, or undefined when a part of the path is missing. */\nexport function getAt(value: unknown, path: readonly PathSegment[]): unknown {\n let current = value;\n for (const segment of path) {\n if (typeof current !== 'object' || current === null || !Object.hasOwn(current, segment)) {\n return undefined;\n }\n current = (current as Record<PathSegment, unknown>)[segment];\n }\n return current;\n}\n\n/**\n * A copy of `value` with `next` at the path. The objects and lists along the\n * path are copied, and the others are shared. A missing part becomes a list\n * for an index and an object for a key.\n */\nexport function setAt(value: unknown, path: readonly PathSegment[], next: unknown): unknown {\n if (path.length === 0) {\n return next;\n }\n const [segment, ...rest] = path as [PathSegment, ...PathSegment[]];\n let copy: Record<PathSegment, unknown> | unknown[];\n if (Array.isArray(value)) {\n copy = [...(value as unknown[])];\n } else if (typeof value === 'object' && value !== null) {\n copy = { ...value };\n } else {\n copy = typeof segment === 'number' ? [] : {};\n }\n const child = Object.hasOwn(copy, segment)\n ? (copy as Record<PathSegment, unknown>)[segment]\n : undefined;\n (copy as Record<PathSegment, unknown>)[segment] = setAt(child, rest, next);\n return copy;\n}\n\n/** A problem that a schema found in the values of a form. */\nexport interface FormIssue {\n message: string;\n path?: PathSegment[];\n}\n\n/** The errors of a form: those of each field by field name, and those of the whole form. */\nexport interface FormErrors {\n errors: Record<string, string[]>;\n formErrors: string[];\n}\n\n/**\n * Turns the entries of a form into a plain object:\n *\n * - A name that appears once holds its value.\n * - A name that appears more than once holds an array of its values.\n * - A name that ends with `[]` always holds an array, under the name without `[]`.\n * - Dots nest objects: `address.city` is `{ address: { city } }`.\n * - An index in brackets makes a list: `items[0].name` is `{ items: [{ name }] }`.\n * - Values stay strings and files.\n *\n * A name with an empty part, a part such as `__proto__`, an index above\n * 999, or one that needs an object where another field holds a value, is\n * an issue, and the schema does not run.\n */\nexport function formValues(\n form: FormData,\n skip?: (name: string) => boolean,\n):\n | { value: Record<string, unknown>; issues?: undefined }\n | { value?: undefined; issues: FormIssue[] } {\n const root: Record<string, unknown> = {};\n // The objects and lists of items that this function made, so a field value is never taken for one.\n const containers = new Set<unknown>([root]);\n // The arrays of the values of a repeated name.\n const repeated = new Set<unknown>();\n const issues: FormIssue[] = [];\n for (const [name, value] of form) {\n if (skip?.(name)) {\n continue;\n }\n const list = name.endsWith('[]');\n const parts = parsePath(list ? name.slice(0, -2) : name);\n if (!parts) {\n issues.push({ message: 'The form has a field name that is not allowed' });\n continue;\n }\n let target = root as Record<PathSegment, unknown>;\n let conflict = false;\n for (const [index, part] of parts.slice(0, -1).entries()) {\n const next = Object.hasOwn(target, part) ? target[part] : undefined;\n // A list takes only indexes, and an object only keys.\n if (Array.isArray(target) !== (typeof part === 'number')) {\n conflict = true;\n break;\n }\n if (next === undefined) {\n const child = typeof parts[index + 1] === 'number' ? [] : {};\n containers.add(child);\n target[part] = child;\n target = child as Record<PathSegment, unknown>;\n } else if (containers.has(next)) {\n target = next as Record<PathSegment, unknown>;\n } else {\n conflict = true;\n break;\n }\n }\n const last = parts.at(-1)!;\n const current = Object.hasOwn(target, last) ? target[last] : undefined;\n if (\n conflict ||\n containers.has(current) ||\n Array.isArray(target) !== (typeof last === 'number')\n ) {\n issues.push({ message: `Field \"${name}\" conflicts with another field`, path: parts });\n } else if (repeated.has(current)) {\n (current as unknown[]).push(value);\n } else if (current !== undefined || list) {\n const values = current === undefined ? [value] : [current, value];\n repeated.add(values);\n target[last] = values;\n } else {\n target[last] = value;\n }\n }\n return issues.length > 0 ? { issues } : { value: root };\n}\n\n/** The errors of issues by field name, such as `items[0].name`, and those of the whole form. */\nexport function groupIssues(issues: readonly FormIssue[]): FormErrors {\n const errors: Record<string, string[]> = {};\n const formErrors: string[] = [];\n for (const issue of issues) {\n const path = issue.path ?? [];\n const name = path.length > 0 && typeof path[0] === 'string' ? formatPath(path) : '';\n if (name === '' || !parsePath(name)) {\n formErrors.push(issue.message);\n } else {\n (Object.hasOwn(errors, name) ? errors[name]! : (errors[name] = [])).push(issue.message);\n }\n }\n return { errors, formErrors };\n}\n\n/** The schema of a form, as `createForm` reads it: a Standard Schema of version 1. */\ninterface FormSchema {\n readonly '~standard': {\n readonly validate: (value: unknown) => unknown;\n };\n}\n\n/**\n * Validates the fields of a form in the browser, with the schema that the\n * server uses, and groups the errors as `reply` does.\n */\nexport async function validateForm(schema: FormSchema, form: FormData): Promise<FormErrors> {\n const values = formValues(form, (name) => name === INTENT);\n return values.issues ? groupIssues(values.issues) : validateValues(schema, values.value);\n}\n\n/** Validates the values of a form in the browser, and groups the errors as `reply` does. */\nexport async function validateValues(schema: FormSchema, value: unknown): Promise<FormErrors> {\n const result = (await schema['~standard'].validate(value)) as {\n issues?: readonly { message: string; path?: readonly (PathSegment | { key: PropertyKey })[] }[];\n };\n return groupIssues(\n (result.issues ?? []).map((issue) => ({\n message: String(issue.message),\n path: issue.path?.map((segment) => {\n const key = typeof segment === 'object' ? segment.key : segment;\n return typeof key === 'number' ? key : String(key);\n }),\n })),\n );\n}\n\n/**\n * The errors that the browser found since the last reply: the fields that\n * the user left or changed, and the errors of the form at that time.\n */\nexport interface CheckedErrors extends FormErrors {\n /** The ID of the reply that the check came after, or undefined before the first submit. */\n reply: string | undefined;\n /** The names of the fields that the user left, whose errors show. */\n touched: string[];\n /** True when the errors of every field show, as after a submit. */\n all: boolean;\n}\n\n/**\n * A change that a submit button asks for, instead of a submit. The server\n * applies it to the posted values, and answers with them.\n *\n * - `insert` adds an item to a list, at `index` or at its end.\n * - `remove` removes the item at `index`.\n * - `reorder` moves the item at `from` to `to`.\n * - `reset` sets a field, or the whole form, back to its default value.\n * - `validate` answers with the errors of one field.\n */\nexport type Intent =\n | { type: 'insert'; name: string; index?: number; defaultValue?: unknown }\n | { type: 'remove'; name: string; index: number }\n | { type: 'reorder'; name: string; from: number; to: number }\n | { type: 'reset'; name?: string }\n | { type: 'validate'; name: string };\n\nconst isIndex = (value: unknown): value is number =>\n Number.isInteger(value) && (value as number) >= 0 && (value as number) <= MAX_INDEX;\n\n/**\n * Reads the intent that a submit button posted, as JSON. Undefined for a\n * value that is not an intent, such as one with a name that is not a path.\n */\nexport function parseIntent(text: string): Intent | undefined {\n let intent: unknown;\n try {\n intent = JSON.parse(text);\n } catch {\n return undefined;\n }\n if (typeof intent !== 'object' || intent === null) {\n return undefined;\n }\n const { type, name, index, from, to } = intent as Record<string, unknown>;\n if (name !== undefined && (typeof name !== 'string' || !parsePath(name))) {\n return undefined;\n }\n switch (type) {\n case 'insert':\n return name !== undefined && (index === undefined || isIndex(index))\n ? (intent as Intent)\n : undefined;\n case 'remove':\n return name !== undefined && isIndex(index) ? (intent as Intent) : undefined;\n case 'reorder':\n return name !== undefined && isIndex(from) && isIndex(to) ? (intent as Intent) : undefined;\n case 'reset':\n return intent as Intent;\n case 'validate':\n return name !== undefined ? (intent as Intent) : undefined;\n default:\n return undefined;\n }\n}\n\n/** The value of a submit button that posts an intent. */\nexport function intentValue(intent: Intent): string {\n return JSON.stringify(intent);\n}\n\n/**\n * Applies an intent to the posted values. Returns the new values, and the\n * name of the list that it changed. Undefined when the intent does not fit\n * the values, such as an index past the end of the list.\n */\nexport function applyIntent(\n value: unknown,\n intent: Intent,\n): { value: unknown; list?: string } | undefined {\n if (intent.type === 'validate') {\n return { value };\n }\n if (intent.type === 'reset') {\n return {\n value:\n intent.name === undefined ? undefined : setAt(value, parsePath(intent.name)!, undefined),\n };\n }\n const path = parsePath(intent.name)!;\n const current = getAt(value, path) ?? [];\n if (!Array.isArray(current)) {\n return undefined;\n }\n const items = [...current];\n if (intent.type === 'insert') {\n const index = intent.index ?? items.length;\n if (index > items.length || items.length > MAX_INDEX) {\n return undefined;\n }\n items.splice(index, 0, intent.defaultValue);\n } else if (intent.type === 'remove') {\n if (intent.index >= items.length) {\n return undefined;\n }\n items.splice(intent.index, 1);\n } else {\n if (intent.from >= items.length || intent.to >= items.length) {\n return undefined;\n }\n items.splice(intent.to, 0, ...items.splice(intent.from, 1));\n }\n return { value: setAt(value, path, items), list: intent.name };\n}\n\n/**\n * What a server function of a form answers, for `createForm` to show. It is\n * plain data, so it goes through `$action` and the state of the page.\n */\nexport interface SubmissionResult {\n /** `success` when the values passed the schema, `error` when not, and `intent` for an intent. */\n status: 'success' | 'error' | 'intent';\n /**\n * The values as posted, after the intent, for the fields to show again.\n * Files and hidden fields are left out. Undefined after a reset, so the\n * fields show their default values.\n */\n value?: unknown;\n /** The errors of each field, by field name, such as `items[0].name`. */\n errors: Record<string, string[]>;\n /** The errors of the whole form. */\n formErrors: string[];\n /**\n * The keys of the items of a list that an intent changed, by field name.\n * They are new, so `#for … by` renders the items again, and an element\n * never shows another item. Other lists keep the index as the key.\n */\n keys: Record<string, string[]>;\n /** True when the form goes back to its default values, such as after a save. */\n reset?: boolean;\n /** A new ID for each reply, which keys of new items start with. */\n id: string;\n}\n\n/** The attributes of a submit button that posts an intent. They work without scripts. */\nexport interface IntentAttributes {\n type: 'submit';\n name: typeof INTENT;\n value: string;\n formnovalidate: true;\n /** With scripts, applies the intent in the browser instead of posting the form. */\n onClick?: (event: MouseEvent) => unknown;\n}\n\n/**\n * The changes of lists that the browser made since the last reply: the\n * values of the form after them, and the keys of the items of each list.\n */\nexport interface LocalChanges {\n /** The ID of the reply that the changes came after, or undefined before the first submit. */\n reply: string | undefined;\n value: unknown;\n /** The keys of the items of each list that changed, by field name. */\n keys: Record<string, string[]>;\n}\n\n/** What `formFields` reads besides the reply: the state of the browser, and the handler of intents. */\nexport interface FormState {\n checked?: CheckedErrors;\n local?: LocalChanges;\n /** The click handler of an intent button. */\n press?: (intent: Intent) => (event: MouseEvent) => unknown;\n}\n\n/** The attributes of a field that `createForm` gives. */\nexport interface FieldAttributes {\n name: string;\n id: string;\n 'aria-invalid'?: 'true';\n 'aria-describedby'?: string;\n value?: string;\n checked?: boolean;\n}\n\n/** The state of a field: its name, its value and its errors. */\nexport interface FieldState<T = unknown> {\n /** The field name, such as `items[0].name`. */\n name: string;\n /** The ID of the input, for a `<label for>`. */\n id: string;\n /** The value that the field shows: the posted value after a submit, or the default value. */\n value: T | undefined;\n /** The errors of the field, or undefined when it has none. */\n errors: string[] | undefined;\n /** The attributes of the input: `name`, `id`, the ARIA state of its errors and its value. */\n attrs: FieldAttributes;\n /** The attributes of the element that shows the errors: its ID, and `role=\"alert\"` after a submit. */\n errorAttrs: { id: string; role?: 'alert' };\n}\n\n/** An item of a list field. */\nexport type ListItem<T> = Field<T> & {\n /** A key that stays with the item when others are added or removed, for `#for … by`. */\n key: string;\n index: number;\n /** The attributes of a button that removes the item. */\n remove: IntentAttributes;\n /** The attributes of a button that moves the item up, or down. */\n moveUp: IntentAttributes;\n moveDown: IntentAttributes;\n};\n\n/** A field, typed by its value: a list has its items, and an object its fields. */\nexport type Field<T> = FieldState<T> &\n (NonNullable<T> extends readonly (infer Item)[]\n ? {\n list: ListItem<Item>[];\n /** The attributes of a button that adds an item at the end of the list. */\n insert: IntentAttributes;\n }\n : NonNullable<T> extends Date | File | Blob\n ? unknown\n : NonNullable<T> extends object\n ? { fields: Fields<NonNullable<T>> }\n : unknown);\n\n/** The fields of an object, by key. */\nexport type Fields<T> = { [K in keyof T]-?: Field<T[K]> };\n\nconst isFile = (value: unknown): boolean => typeof Blob !== 'undefined' && value instanceof Blob;\n\nconst isPlainObject = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' &&\n value !== null &&\n !Array.isArray(value) &&\n !isFile(value) &&\n !(value instanceof Date);\n\n/** The attributes of a submit button that posts an intent. */\nexport function intentButton(\n intent: Intent,\n press?: (intent: Intent) => (event: MouseEvent) => unknown,\n): IntentAttributes {\n const attrs: IntentAttributes = {\n type: 'submit',\n name: INTENT,\n value: intentValue(intent),\n formnovalidate: true,\n };\n if (press) {\n attrs.onClick = press(intent);\n }\n return attrs;\n}\n\n/** The changes of the browser when they came after the last reply. */\nexport function localSince(\n local: LocalChanges | undefined,\n result: SubmissionResult | undefined,\n): LocalChanges | undefined {\n return local && local.reply === result?.id ? local : undefined;\n}\n\n/** A key for a new item, which no other item of the page has. */\nlet nextKey = 0;\n\n/**\n * Applies an intent in the browser to the values that the form holds now.\n * The items of the list keep their keys, so their elements and what was\n * typed in them stay, and a new item gets a new key. Undefined when the\n * intent does not fit the values.\n */\nexport function applyLocalIntent(\n form: HTMLFormElement | null,\n intent: Intent,\n local: LocalChanges | undefined,\n result: SubmissionResult | undefined,\n): LocalChanges | undefined {\n if (!form || intent.type === 'reset' || intent.type === 'validate') {\n return undefined;\n }\n const values = formValues(new FormData(form), (name) => name === INTENT);\n const applied = values.value && applyIntent(values.value, intent);\n if (!applied) {\n return undefined;\n }\n const current = localSince(local, result);\n const before = getAt(values.value, parsePath(intent.name)!);\n const length = Array.isArray(before) ? before.length : 0;\n const keys = [\n ...(current?.keys[intent.name] ??\n (result && !result.reset ? result.keys[intent.name] : undefined) ??\n Array.from({ length }, (_, index) => String(index))),\n ];\n if (intent.type === 'insert') {\n keys.splice(intent.index ?? keys.length, 0, `n${nextKey++}`);\n } else if (intent.type === 'remove') {\n keys.splice(intent.index, 1);\n } else {\n keys.splice(intent.to, 0, ...keys.splice(intent.from, 1));\n }\n return {\n reply: result?.id,\n value: applied.value,\n keys: { ...current?.keys, [intent.name]: keys },\n };\n}\n\n/**\n * The fields of a form, from its default value and the reply of its last\n * submit. A field exists for each key of the default value or of the posted\n * value, so the default value names every field that the form shows.\n */\nexport function formFields<T>(\n id: string,\n defaultValue: T | undefined,\n result: SubmissionResult | undefined,\n { checked, local, press }: FormState = {},\n): Fields<T> {\n const changes = localSince(local, result);\n let value: unknown;\n if (changes) {\n value = changes.value;\n } else if (result && !result.reset) {\n value = result.value;\n }\n const submitted = result !== undefined;\n const keys = { ...(result && !result.reset ? result.keys : {}), ...changes?.keys };\n // The errors of the reply for the items of a list that the browser changed are of other items.\n const replied: Record<string, string[]> = {};\n for (const [name, messages] of Object.entries(result && !result.reset ? result.errors : {})) {\n if (!Object.keys(changes?.keys ?? {}).some((list) => name.startsWith(`${list}[`))) {\n replied[name] = messages;\n }\n }\n // The errors that the browser found replace those of the reply, for the fields that it checked.\n const current = checkedSince(checked, result);\n const shows = (name: string): boolean =>\n current !== undefined && (current.all || current.touched.includes(name));\n const errorsOf = (name: string): string[] | undefined => {\n const source = shows(name) ? current!.errors : replied;\n return Object.hasOwn(source, name) ? source[name] : undefined;\n };\n\n const state = (path: PathSegment[], shown: unknown): FieldState => {\n const name = formatPath(path);\n const fieldId = `${id}-${name}`;\n const errorId = `${fieldId}-error`;\n const messages = errorsOf(name);\n const attrs: FieldAttributes = { name, id: fieldId };\n if (messages) {\n attrs['aria-invalid'] = 'true';\n attrs['aria-describedby'] = errorId;\n }\n if (typeof shown === 'string' || typeof shown === 'number') {\n attrs.value = String(shown);\n } else if (typeof shown === 'boolean') {\n attrs.checked = shown;\n }\n return {\n name,\n id: fieldId,\n value: shown,\n errors: messages,\n attrs,\n errorAttrs: submitted ? { id: errorId, role: 'alert' } : { id: errorId },\n };\n };\n\n // After a submit, the fields show what was posted, and a field that was not posted, such as a\n // checkbox that was not checked, is empty. The default value still gives the shape.\n const posted = value !== undefined;\n const field = (path: PathSegment[], fallback: unknown, sent: unknown): unknown => {\n const shown = posted ? sent : fallback;\n const own = state(path, shown);\n // A list stays a list when nothing of it was posted, such as a list with no items.\n if (Array.isArray(shown) || Array.isArray(fallback)) {\n const items = Array.isArray(shown) ? shown : [];\n const name = own.name;\n const itemKeys = Object.hasOwn(keys, name) ? keys[name] : undefined;\n const defaults: unknown[] = Array.isArray(fallback) ? fallback : [];\n const list = items.map((item, index) =>\n Object.assign(\n // A new item takes the shape of the first default item.\n field([...path, index], defaults[index] ?? defaults[0], item) as object,\n {\n key: itemKeys?.[index] ?? String(index),\n index,\n remove: intentButton({ type: 'remove', name, index }, press),\n moveUp: intentButton(\n {\n type: 'reorder',\n name,\n from: index,\n to: Math.max(index - 1, 0),\n },\n press,\n ),\n moveDown: intentButton(\n {\n type: 'reorder',\n name,\n from: index,\n to: Math.min(index + 1, items.length - 1),\n },\n press,\n ),\n },\n ),\n );\n return Object.assign(own, { list, insert: intentButton({ type: 'insert', name }, press) });\n }\n if (isPlainObject(shown) || isPlainObject(fallback)) {\n const defaults = isPlainObject(fallback) ? fallback : {};\n const values = isPlainObject(sent) ? sent : {};\n const fields: Record<string, unknown> = {};\n for (const key of new Set([...Object.keys(defaults), ...Object.keys(posted ? values : {})])) {\n fields[key] = field(\n [...path, key],\n Object.hasOwn(defaults, key) ? defaults[key] : undefined,\n Object.hasOwn(values, key) ? values[key] : undefined,\n );\n }\n return path.length === 0 ? fields : Object.assign(own, { fields });\n }\n return own;\n };\n\n return field([], defaultValue, value) as Fields<T>;\n}\n\n/** The check of the browser when it came after the last reply, or undefined when a reply came after it. */\nexport function checkedSince(\n checked: CheckedErrors | undefined,\n result: SubmissionResult | undefined,\n): CheckedErrors | undefined {\n return checked && checked.reply === result?.id ? checked : undefined;\n}\n\n/**\n * The errors of the whole form: those that the browser found, when it\n * checked every field since the last reply, or else those of the reply.\n */\nexport function formErrorsOf(\n result: SubmissionResult | undefined,\n checked: CheckedErrors | undefined,\n): string[] | undefined {\n const current = checkedSince(checked, result);\n const errors = current?.all ? current.formErrors : result?.formErrors;\n return errors && errors.length > 0 ? errors : undefined;\n}\n\n/**\n * The next check of the browser, after the user leaves or changes a field.\n * A field counts once the user leaves it. After a submit, every field counts.\n * Undefined when the event changes nothing, such as typing in a field that\n * the user has not left yet.\n */\nexport async function checkField(\n schema: FormSchema,\n form: HTMLFormElement | null,\n name: string,\n left: boolean,\n checked: CheckedErrors | undefined,\n result: SubmissionResult | undefined,\n): Promise<CheckedErrors | undefined> {\n const current = checkedSince(checked, result);\n const all = result !== undefined && !result.reset;\n const touched = current?.touched ?? [];\n if (!form || !name || name === INTENT || (!left && !all && !touched.includes(name))) {\n return undefined;\n }\n const report = await validateForm(schema, new FormData(form));\n return {\n ...report,\n reply: result?.id,\n touched: touched.includes(name) ? touched : [...touched, name],\n all,\n };\n}\n\n/**\n * The attributes of a submit button that the form presses on Enter. Without\n * it, Enter in a field presses the first submit button of the form, which\n * can be an intent button, such as \"Remove\". It is hidden from sight and\n * from assistive technology, and cannot take focus.\n */\nexport const DEFAULT_SUBMIT = {\n type: 'submit',\n tabindex: -1,\n 'aria-hidden': 'true',\n style:\n 'position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap;border:0;padding:0;margin:-1px',\n} as const;\n"],"mappings":";;AASA,MAAa,SAAS;;AAGtB,MAAa,YAAY;;AAGzB,MAAa,4BAAiC,IAAI,IAAI;CAAC;CAAa;CAAe;AAAW,CAAC;;;;;;;;AAS/F,SAAgB,UAAU,MAAyC;CACjE,MAAM,OAAsB,CAAC;CAC7B,KAAK,MAAM,QAAQ,KAAK,MAAM,GAAG,GAAG;EAClC,MAAM,QAAQ,4BAA4B,KAAK,IAAI;EACnD,IAAI,CAAC,SAAS,UAAU,IAAI,MAAM,EAAG,GACnC;EAEF,KAAK,KAAK,MAAM,EAAG;EACnB,KAAK,MAAM,SAAS,MAAM,EAAE,CAAE,SAAS,YAAY,GAAG;GACpD,MAAM,QAAQ,OAAO,MAAM,EAAE;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