brumate 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/README.md +2 -2
  2. package/check.d.ts +49 -0
  3. package/dist/{boot-D-IdPy7B.d.ts → boot-DLlRmD9z.d.ts} +11 -10
  4. package/dist/cli.js +275 -15
  5. package/dist/cli.js.map +1 -1
  6. package/dist/client-BvDsC6Qr.js +3463 -0
  7. package/dist/client-BvDsC6Qr.js.map +1 -0
  8. package/dist/client-DBwL2wKQ.d.ts +669 -0
  9. package/dist/{client-routes-JTbGtukf.js → client-routes-BtGpYCef.js} +60 -30
  10. package/dist/client-routes-BtGpYCef.js.map +1 -0
  11. package/dist/{cookies-Av5WFmcf.js → cookies-Cnbf4w-S.js} +15 -7
  12. package/dist/cookies-Cnbf4w-S.js.map +1 -0
  13. package/dist/{defer-D0bo1Gqx.js → defer-CKWZLv2K.js} +8 -4
  14. package/dist/defer-CKWZLv2K.js.map +1 -0
  15. package/dist/devtools-4uTPwR_v.js +597 -0
  16. package/dist/devtools-4uTPwR_v.js.map +1 -0
  17. package/dist/devtools-panel-Be9pxYgv.js +1994 -0
  18. package/dist/devtools-panel-Be9pxYgv.js.map +1 -0
  19. package/dist/events-LgLdp1R7.js +114 -0
  20. package/dist/events-LgLdp1R7.js.map +1 -0
  21. package/dist/features-CHY5Ekku.js +30 -0
  22. package/dist/features-CHY5Ekku.js.map +1 -0
  23. package/dist/files-WW4RlajL.js +506 -0
  24. package/dist/files-WW4RlajL.js.map +1 -0
  25. package/dist/forms-j1xPAR14.d.ts +281 -0
  26. package/dist/forms-nXK7-Lv_.js +440 -0
  27. package/dist/forms-nXK7-Lv_.js.map +1 -0
  28. package/dist/highlight.d.ts +17 -0
  29. package/dist/highlight.js +278 -0
  30. package/dist/highlight.js.map +1 -0
  31. package/dist/html-BtKRyi7g.js +305 -0
  32. package/dist/html-BtKRyi7g.js.map +1 -0
  33. package/dist/html-Bw9Qwu6F.d.ts +107 -0
  34. package/dist/index.d.ts +142 -11
  35. package/dist/index.js +641 -106
  36. package/dist/index.js.map +1 -1
  37. package/dist/{inspect-BJtACnQp.js → inspect-Y6y4uNZp.js} +4333 -681
  38. package/dist/inspect-Y6y4uNZp.js.map +1 -0
  39. package/dist/{loader-B18i3_-T.js → loader-BjKGJzLN.js} +21 -14
  40. package/dist/loader-BjKGJzLN.js.map +1 -0
  41. package/dist/logo-DQ_OYhBi.js +10 -0
  42. package/dist/logo-DQ_OYhBi.js.map +1 -0
  43. package/dist/{navigate-BwuZveDF.js → navigate-CfOr-TRF.js} +130 -24
  44. package/dist/navigate-CfOr-TRF.js.map +1 -0
  45. package/dist/nesting-DA5vJw9X.js +265 -0
  46. package/dist/nesting-DA5vJw9X.js.map +1 -0
  47. package/dist/produce-B7X9ori9.js +402 -0
  48. package/dist/produce-B7X9ori9.js.map +1 -0
  49. package/dist/produce-DIgHBVwL.d.ts +148 -0
  50. package/dist/{rpc-B-Zkn6Ch.js → rpc-Q-XkLwFh.js} +28 -13
  51. package/dist/rpc-Q-XkLwFh.js.map +1 -0
  52. package/dist/runtime/batch.js +9 -7
  53. package/dist/runtime/batch.js.map +1 -1
  54. package/dist/runtime/client.d.ts +4 -4
  55. package/dist/runtime/client.js +4 -4
  56. package/dist/runtime/devtools.d.ts +172 -5
  57. package/dist/runtime/devtools.js +3 -1
  58. package/dist/runtime/env.js +14 -2
  59. package/dist/runtime/env.js.map +1 -1
  60. package/dist/runtime/events.d.ts +38 -1
  61. package/dist/runtime/events.js +1 -1
  62. package/dist/runtime/forms.d.ts +2 -0
  63. package/dist/runtime/forms.js +1 -0
  64. package/dist/runtime/gather.d.ts +25 -0
  65. package/dist/runtime/gather.js +33 -0
  66. package/dist/runtime/gather.js.map +1 -0
  67. package/dist/runtime/hot.d.ts +1 -1
  68. package/dist/runtime/hot.js +5 -2
  69. package/dist/runtime/hot.js.map +1 -1
  70. package/dist/runtime/html.d.ts +2 -2
  71. package/dist/runtime/html.js +1 -1
  72. package/dist/runtime/loader.d.ts +2 -2
  73. package/dist/runtime/loader.js +2 -2
  74. package/dist/runtime/routes.js +4 -1
  75. package/dist/runtime/routes.js.map +1 -1
  76. package/dist/runtime/server.d.ts +5 -4
  77. package/dist/runtime/server.js +5 -5
  78. package/dist/runtime/signals.d.ts +75 -2
  79. package/dist/runtime/signals.js +44 -2
  80. package/dist/runtime/signals.js.map +1 -1
  81. package/dist/runtime/static-loader.d.ts +2 -2
  82. package/dist/runtime/static-loader.js +1 -1
  83. package/dist/runtime/testing.d.ts +18 -3
  84. package/dist/runtime/testing.js +150 -33
  85. package/dist/runtime/testing.js.map +1 -1
  86. package/dist/runtime/values.d.ts +2 -0
  87. package/dist/runtime/values.js +24 -0
  88. package/dist/runtime/values.js.map +1 -0
  89. package/dist/{server-BA9SJ2Vm.d.ts → server-BvPIg9pT.d.ts} +363 -32
  90. package/dist/{server-BqfM95r1.js → server-DjyOVJtJ.js} +1309 -220
  91. package/dist/server-DjyOVJtJ.js.map +1 -0
  92. package/dist/{static-loader-BzE9SRaj.d.ts → static-loader-BGgdp_Y5.d.ts} +2 -2
  93. package/dist/static-loader-BZR17hSw.js +312 -0
  94. package/dist/static-loader-BZR17hSw.js.map +1 -0
  95. package/dist/{stream-JaMHMdBD.js → stream-BP5AVmg5.js} +182 -17
  96. package/dist/stream-BP5AVmg5.js.map +1 -0
  97. package/dist/values-B8C7CLvG.d.ts +63 -0
  98. package/dist/vite.d.ts +20 -20
  99. package/dist/vite.js +2031 -539
  100. package/dist/vite.js.map +1 -1
  101. package/elements.d.ts +951 -0
  102. package/forms/forms.brm.ts +141 -0
  103. package/package.json +41 -3
  104. package/skills/brumate/SKILL.md +58 -0
  105. package/skills/brumate/references/errors.md +2078 -0
  106. package/skills/brumate/references/events.md +117 -0
  107. package/skills/brumate/references/signals.md +61 -0
  108. package/skills/brumate/references/state.md +235 -0
  109. package/skills/brumate/references/syntax.md +250 -0
  110. package/types.d.ts +4 -4
  111. package/dist/client-C0UCNL3J.js +0 -1643
  112. package/dist/client-C0UCNL3J.js.map +0 -1
  113. package/dist/client-MD0ZmcFR.d.ts +0 -354
  114. package/dist/client-routes-JTbGtukf.js.map +0 -1
  115. package/dist/cookies-Av5WFmcf.js.map +0 -1
  116. package/dist/defer-D0bo1Gqx.js.map +0 -1
  117. package/dist/devtools-C50VH8gZ.js +0 -113
  118. package/dist/devtools-C50VH8gZ.js.map +0 -1
  119. package/dist/devtools-panel-AYjfwPhj.js +0 -435
  120. package/dist/devtools-panel-AYjfwPhj.js.map +0 -1
  121. package/dist/events-BKWRqtMg.js +0 -52
  122. package/dist/events-BKWRqtMg.js.map +0 -1
  123. package/dist/files-Bnn1JqHx.js +0 -192
  124. package/dist/files-Bnn1JqHx.js.map +0 -1
  125. package/dist/html-bHZbkK-h.js +0 -170
  126. package/dist/html-bHZbkK-h.js.map +0 -1
  127. package/dist/html-y1q7-t7D.d.ts +0 -60
  128. package/dist/inspect-BJtACnQp.js.map +0 -1
  129. package/dist/loader-B18i3_-T.js.map +0 -1
  130. package/dist/navigate-BwuZveDF.js.map +0 -1
  131. package/dist/produce-CWfJ4byV.js +0 -167
  132. package/dist/produce-CWfJ4byV.js.map +0 -1
  133. package/dist/produce-D4K7qpaL.d.ts +0 -72
  134. package/dist/rpc-B-Zkn6Ch.js.map +0 -1
  135. package/dist/server-BqfM95r1.js.map +0 -1
  136. package/dist/static-loader-DOygOFj5.js +0 -216
  137. package/dist/static-loader-DOygOFj5.js.map +0 -1
  138. package/dist/stream-JaMHMdBD.js.map +0 -1
@@ -0,0 +1,440 @@
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
+ const result = await schema["~standard"].validate(value);
152
+ const issues = [];
153
+ for (const issue of result.issues ?? []) {
154
+ let path;
155
+ if (issue.path) {
156
+ path = [];
157
+ for (const segment of issue.path) {
158
+ const key = typeof segment === "object" ? segment.key : segment;
159
+ path.push(typeof key === "number" ? key : String(key));
160
+ }
161
+ }
162
+ issues.push({
163
+ message: String(issue.message),
164
+ path
165
+ });
166
+ }
167
+ return groupIssues(issues);
168
+ }
169
+ function isIndex(value) {
170
+ return Number.isInteger(value) && value >= 0 && value <= 999;
171
+ }
172
+ /**
173
+ * Reads the intent that a submit button posted, as JSON. Undefined for a
174
+ * value that is not an intent, such as one with a name that is not a path.
175
+ */
176
+ function parseIntent(text) {
177
+ let intent;
178
+ try {
179
+ intent = JSON.parse(text);
180
+ } catch {
181
+ return;
182
+ }
183
+ if (typeof intent !== "object" || intent === null) return;
184
+ const { type, name, index, from, to } = intent;
185
+ if (name !== void 0 && (typeof name !== "string" || !parsePath(name))) return;
186
+ switch (type) {
187
+ case "insert": return name !== void 0 && (index === void 0 || isIndex(index)) ? intent : void 0;
188
+ case "remove": return name !== void 0 && isIndex(index) ? intent : void 0;
189
+ case "reorder": return name !== void 0 && isIndex(from) && isIndex(to) ? intent : void 0;
190
+ case "reset": return intent;
191
+ case "validate": return name !== void 0 ? intent : void 0;
192
+ default: return;
193
+ }
194
+ }
195
+ /** The value of a submit button that posts an intent. */
196
+ function intentValue(intent) {
197
+ return JSON.stringify(intent);
198
+ }
199
+ /**
200
+ * Applies an intent to the posted values. Returns the new values, and the
201
+ * name of the list that it changed. Undefined when the intent does not fit
202
+ * the values, such as an index past the end of the list.
203
+ */
204
+ function applyIntent(value, intent) {
205
+ if (intent.type === "validate") return { value };
206
+ if (intent.type === "reset") return { value: intent.name === void 0 ? void 0 : setAt(value, parsePath(intent.name), void 0) };
207
+ const path = parsePath(intent.name);
208
+ const current = getAt(value, path) ?? [];
209
+ if (!Array.isArray(current)) return;
210
+ const items = [...current];
211
+ if (intent.type === "insert") {
212
+ const index = intent.index ?? items.length;
213
+ if (index > items.length || items.length > 999) return;
214
+ items.splice(index, 0, intent.defaultValue);
215
+ } else if (intent.type === "remove") {
216
+ if (intent.index >= items.length) return;
217
+ items.splice(intent.index, 1);
218
+ } else {
219
+ if (intent.from >= items.length || intent.to >= items.length) return;
220
+ items.splice(intent.to, 0, ...items.splice(intent.from, 1));
221
+ }
222
+ return {
223
+ value: setAt(value, path, items),
224
+ list: intent.name
225
+ };
226
+ }
227
+ function isFile(value) {
228
+ return typeof Blob !== "undefined" && value instanceof Blob;
229
+ }
230
+ function isPlainObject(value) {
231
+ return typeof value === "object" && value !== null && !Array.isArray(value) && !isFile(value) && !(value instanceof Date);
232
+ }
233
+ /** The attributes of a submit button that posts an intent. */
234
+ function intentButton(intent, press) {
235
+ const attrs = {
236
+ type: "submit",
237
+ name: INTENT,
238
+ value: intentValue(intent),
239
+ formnovalidate: true
240
+ };
241
+ if (press) attrs.onClick = press(intent);
242
+ return attrs;
243
+ }
244
+ /** The changes of the browser when they came after the last reply. */
245
+ function localSince(local, result) {
246
+ return local && local.reply === result?.id ? local : void 0;
247
+ }
248
+ /** A key for a new item, which no other item of the page has. */
249
+ let nextKey = 0;
250
+ /**
251
+ * Applies an intent in the browser to the values that the form holds now.
252
+ * The items of the list keep their keys, so their elements and what was
253
+ * typed in them stay, and a new item gets a new key. Undefined when the
254
+ * intent does not fit the values.
255
+ */
256
+ function applyLocalIntent(form, intent, local, result) {
257
+ if (!form || intent.type === "reset" || intent.type === "validate") return;
258
+ const values = formValues(new FormData(form), (name) => name === INTENT);
259
+ const applied = values.value && applyIntent(values.value, intent);
260
+ if (!applied) return;
261
+ const current = localSince(local, result);
262
+ const before = getAt(values.value, parsePath(intent.name));
263
+ const length = Array.isArray(before) ? before.length : 0;
264
+ let known = current?.keys[intent.name] ?? (result && !result.reset ? result.keys[intent.name] : void 0);
265
+ if (!known) {
266
+ known = [];
267
+ for (let index = 0; index < length; index++) known.push(String(index));
268
+ }
269
+ const keys = [...known];
270
+ if (intent.type === "insert") keys.splice(intent.index ?? keys.length, 0, `n${nextKey++}`);
271
+ else if (intent.type === "remove") keys.splice(intent.index, 1);
272
+ else keys.splice(intent.to, 0, ...keys.splice(intent.from, 1));
273
+ return {
274
+ reply: result?.id,
275
+ value: applied.value,
276
+ keys: {
277
+ ...current?.keys,
278
+ [intent.name]: keys
279
+ }
280
+ };
281
+ }
282
+ /**
283
+ * The fields of a form, from its default value and the reply of its last
284
+ * submit. A field exists for each key of the default value or of the posted
285
+ * value, so the default value names every field that the form shows.
286
+ */
287
+ function formFields(id, defaultValue, result, { checked, local, press } = {}) {
288
+ const changes = localSince(local, result);
289
+ let value;
290
+ if (changes) value = changes.value;
291
+ else if (result && !result.reset) value = result.value;
292
+ const submitted = result !== void 0;
293
+ const keys = {
294
+ ...result && !result.reset ? result.keys : {},
295
+ ...changes?.keys
296
+ };
297
+ const replied = {};
298
+ for (const [name, messages] of Object.entries(result && !result.reset ? result.errors : {})) {
299
+ let changed = false;
300
+ for (const list of Object.keys(changes?.keys ?? {})) if (name.startsWith(`${list}[`)) {
301
+ changed = true;
302
+ break;
303
+ }
304
+ if (!changed) replied[name] = messages;
305
+ }
306
+ const current = checkedSince(checked, result);
307
+ function shows(name) {
308
+ return current !== void 0 && (current.all || current.touched.includes(name));
309
+ }
310
+ function getErrors(name) {
311
+ const source = shows(name) ? current.errors : replied;
312
+ return Object.hasOwn(source, name) ? source[name] : void 0;
313
+ }
314
+ function state(path, shown) {
315
+ const name = formatPath(path);
316
+ const fieldId = `${id}-${name}`;
317
+ const errorId = `${fieldId}-error`;
318
+ const messages = getErrors(name);
319
+ const attrs = {
320
+ name,
321
+ id: fieldId
322
+ };
323
+ if (messages) {
324
+ attrs["aria-invalid"] = "true";
325
+ attrs["aria-describedby"] = errorId;
326
+ }
327
+ if (typeof shown === "string" || typeof shown === "number") attrs.value = String(shown);
328
+ else if (typeof shown === "boolean") attrs.checked = shown;
329
+ return {
330
+ name,
331
+ id: fieldId,
332
+ value: shown,
333
+ errors: messages,
334
+ attrs,
335
+ errorAttrs: submitted ? {
336
+ id: errorId,
337
+ role: "alert"
338
+ } : { id: errorId }
339
+ };
340
+ }
341
+ const posted = value !== void 0;
342
+ function field(path, fallback, sent) {
343
+ const shown = posted ? sent : fallback;
344
+ const own = state(path, shown);
345
+ if (Array.isArray(shown) || Array.isArray(fallback)) {
346
+ const items = Array.isArray(shown) ? shown : [];
347
+ const name = own.name;
348
+ const itemKeys = Object.hasOwn(keys, name) ? keys[name] : void 0;
349
+ const defaults = Array.isArray(fallback) ? fallback : [];
350
+ const list = new Array(items.length);
351
+ for (const [index, item] of items.entries()) {
352
+ if (!(index in items)) continue;
353
+ list[index] = Object.assign(field([...path, index], defaults[index] ?? defaults[0], item), {
354
+ key: itemKeys?.[index] ?? String(index),
355
+ index,
356
+ remove: intentButton({
357
+ type: "remove",
358
+ name,
359
+ index
360
+ }, press),
361
+ moveUp: intentButton({
362
+ type: "reorder",
363
+ name,
364
+ from: index,
365
+ to: Math.max(index - 1, 0)
366
+ }, press),
367
+ moveDown: intentButton({
368
+ type: "reorder",
369
+ name,
370
+ from: index,
371
+ to: Math.min(index + 1, items.length - 1)
372
+ }, press)
373
+ });
374
+ }
375
+ return Object.assign(own, {
376
+ list,
377
+ insert: intentButton({
378
+ type: "insert",
379
+ name
380
+ }, press)
381
+ });
382
+ }
383
+ if (isPlainObject(shown) || isPlainObject(fallback)) {
384
+ const defaults = isPlainObject(fallback) ? fallback : {};
385
+ const values = isPlainObject(sent) ? sent : {};
386
+ const fields = {};
387
+ 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);
388
+ return path.length === 0 ? fields : Object.assign(own, { fields });
389
+ }
390
+ return own;
391
+ }
392
+ return field([], defaultValue, value);
393
+ }
394
+ /** The check of the browser when it came after the last reply, or undefined when a reply came after it. */
395
+ function checkedSince(checked, result) {
396
+ return checked && checked.reply === result?.id ? checked : void 0;
397
+ }
398
+ /**
399
+ * The errors of the whole form: those that the browser found, when it
400
+ * checked every field since the last reply, or else those of the reply.
401
+ */
402
+ function getFormErrors(result, checked) {
403
+ const current = checkedSince(checked, result);
404
+ const errors = current?.all ? current.formErrors : result?.formErrors;
405
+ return errors && errors.length > 0 ? errors : void 0;
406
+ }
407
+ /**
408
+ * The next check of the browser, after the user leaves or changes a field.
409
+ * A field counts once the user leaves it. After a submit, every field counts.
410
+ * Undefined when the event changes nothing, such as typing in a field that
411
+ * the user has not left yet.
412
+ */
413
+ async function checkField(schema, form, name, left, checked, result) {
414
+ const current = checkedSince(checked, result);
415
+ const all = result !== void 0 && !result.reset;
416
+ const touched = current?.touched ?? [];
417
+ if (!form || !name || name === "__intent" || !left && !all && !touched.includes(name)) return;
418
+ return {
419
+ ...await validateForm(schema, new FormData(form)),
420
+ reply: result?.id,
421
+ touched: touched.includes(name) ? touched : [...touched, name],
422
+ all
423
+ };
424
+ }
425
+ /**
426
+ * The attributes of a submit button that the form presses on Enter. Without
427
+ * it, Enter in a field presses the first submit button of the form, which
428
+ * can be an intent button, such as "Remove". It is hidden from sight and
429
+ * from assistive technology, and cannot take focus.
430
+ */
431
+ const DEFAULT_SUBMIT = {
432
+ type: "submit",
433
+ tabindex: -1,
434
+ "aria-hidden": "true",
435
+ style: "position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap;border:0;padding:0;margin:-1px"
436
+ };
437
+ //#endregion
438
+ export { validateValues as S, localSince as _, applyIntent as a, setAt as b, checkedSince as c, formatPath as d, getAt as f, intentValue as g, intentButton as h, MAX_INDEX as i, formFields as l, groupIssues as m, FORBIDDEN as n, applyLocalIntent as o, getFormErrors as p, INTENT as r, checkField as s, DEFAULT_SUBMIT as t, formValues as u, parseIntent as v, validateForm as x, parsePath as y };
439
+
440
+ //# sourceMappingURL=forms-nXK7-Lv_.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forms-nXK7-Lv_.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 const issues: FormIssue[] = [];\n for (const issue of result.issues ?? []) {\n let path: (string | number)[] | undefined;\n if (issue.path) {\n path = [];\n for (const segment of issue.path) {\n const key = typeof segment === 'object' ? segment.key : segment;\n path.push(typeof key === 'number' ? key : String(key));\n }\n }\n issues.push({ message: String(issue.message), path });\n }\n return groupIssues(issues);\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\nfunction isIndex(value: unknown): value is number {\n return Number.isInteger(value) && (value as number) >= 0 && (value as number) <= MAX_INDEX;\n}\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\nfunction isFile(value: unknown): boolean {\n return typeof Blob !== 'undefined' && value instanceof Blob;\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return (\n typeof value === 'object' &&\n value !== null &&\n !Array.isArray(value) &&\n !isFile(value) &&\n !(value instanceof Date)\n );\n}\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 let known =\n current?.keys[intent.name] ?? (result && !result.reset ? result.keys[intent.name] : undefined);\n if (!known) {\n known = [];\n for (let index = 0; index < length; index++) {\n known.push(String(index));\n }\n }\n const keys = [...known];\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 let changed = false;\n for (const list of Object.keys(changes?.keys ?? {})) {\n if (name.startsWith(`${list}[`)) {\n changed = true;\n break;\n }\n }\n if (!changed) {\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 function shows(name: string): boolean {\n return current !== undefined && (current.all || current.touched.includes(name));\n }\n function getErrors(name: string): string[] | undefined {\n const source = shows(name) ? current!.errors : replied;\n return Object.hasOwn(source, name) ? source[name] : undefined;\n }\n\n function state(path: PathSegment[], shown: unknown): FieldState {\n const name = formatPath(path);\n const fieldId = `${id}-${name}`;\n const errorId = `${fieldId}-error`;\n const messages = getErrors(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 function 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 // oxlint-disable-next-line unicorn/no-new-array -- A list posted with gaps keeps them.\n const list: unknown[] = new Array(items.length);\n for (const [index, item] of items.entries()) {\n if (!(index in items)) {\n continue;\n }\n list[index] = 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 getFormErrors(\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,GAA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,SAAS,OAAO,OAAO,KAAK,EAAE,OAAO,CAAC;EACnE;EACA,OAAO;CACT;CAEA,OAAO,MAAM,CAAC,GAAG,cAAc,KAAK;AACtC;;AAGA,SAAgB,aACd,SACA,QAC2B;CAC3B,OAAO,WAAW,QAAQ,UAAU,QAAQ,KAAK,UAAU,KAAA;AAC7D;;;;;AAMA,SAAgB,cACd,QACA,SACsB;CACtB,MAAM,UAAU,aAAa,SAAS,MAAM;CAC5C,MAAM,SAAS,SAAS,MAAM,QAAQ,aAAa,QAAQ;CAC3D,OAAO,UAAU,OAAO,SAAS,IAAI,SAAS,KAAA;AAChD;;;;;;;AAQA,eAAsB,WACpB,QACA,MACA,MACA,MACA,SACA,QACoC;CACpC,MAAM,UAAU,aAAa,SAAS,MAAM;CAC5C,MAAM,MAAM,WAAW,KAAA,KAAa,CAAC,OAAO;CAC5C,MAAM,UAAU,SAAS,WAAW,CAAC;CACrC,IAAI,CAAC,QAAQ,CAAC,QAAQ,SAAA,cAAoB,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,SAAS,IAAI,GAC/E;CAGF,OAAO;EACL,GAAG,MAFgB,aAAa,QAAQ,IAAI,SAAS,IAAI,CAAC;EAG1D,OAAO,QAAQ;EACf,SAAS,QAAQ,SAAS,IAAI,IAAI,UAAU,CAAC,GAAG,SAAS,IAAI;EAC7D;CACF;AACF;;;;;;;AAQA,MAAa,iBAAiB;CAC5B,MAAM;CACN,UAAU;CACV,eAAe;CACf,OACE;AACJ"}
@@ -0,0 +1,17 @@
1
+ import { LanguageFactory, LanguageOptions, RenderOptions } from "@twinkleplop/core";
2
+ import { Grammar } from "@twinkleplop/core/compile";
3
+ //#region src/highlight.d.ts
4
+ export declare const rawGrammar: Grammar;
5
+ export declare const tokenize: LanguageFactory;
6
+ /** Returns a function that highlights `.brm` code as HTML. */
7
+ export declare function language(options?: LanguageOptions): (input: string, render?: RenderOptions) => string;
8
+ /**
9
+ * The colours of the GitHub theme of twinkleplop as CSS, for code under a
10
+ * `.twinkleplop` element. The devtools put it in their shadow root, where
11
+ * the stylesheets of the page do not reach.
12
+ */
13
+ export declare function themeCSS(theme?: "dark" | "light"): string;
14
+ /** Highlights code of a file by its extension: `.brm`, `.css`, or TypeScript and the rest. */
15
+ export declare function highlightFile(file: string, code: string, render?: RenderOptions): string;
16
+ //#endregion
17
+ //# sourceMappingURL=highlight.d.ts.map