brumate 0.3.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.
- package/README.md +2 -2
- package/check.d.ts +49 -0
- package/dist/{boot-C25Sa6vq.d.ts → boot-DLlRmD9z.d.ts} +8 -10
- package/dist/cli.js +275 -15
- package/dist/cli.js.map +1 -1
- package/dist/client-BvDsC6Qr.js +3463 -0
- package/dist/client-BvDsC6Qr.js.map +1 -0
- package/dist/{client-D0CqSxoO.d.ts → client-DBwL2wKQ.d.ts} +390 -181
- package/dist/{client-routes-JTbGtukf.js → client-routes-BtGpYCef.js} +60 -30
- package/dist/client-routes-BtGpYCef.js.map +1 -0
- package/dist/{cookies-BzllthiF.js → cookies-Cnbf4w-S.js} +14 -7
- package/dist/cookies-Cnbf4w-S.js.map +1 -0
- package/dist/{defer-BbD7JQhj.js → defer-CKWZLv2K.js} +4 -4
- package/dist/defer-CKWZLv2K.js.map +1 -0
- package/dist/{devtools-CQgD7NPB.js → devtools-4uTPwR_v.js} +56 -82
- package/dist/devtools-4uTPwR_v.js.map +1 -0
- package/dist/{devtools-panel-BVB-W5q4.js → devtools-panel-Be9pxYgv.js} +397 -333
- package/dist/devtools-panel-Be9pxYgv.js.map +1 -0
- package/dist/{events-CSs7OwIC.js → events-LgLdp1R7.js} +34 -5
- package/dist/events-LgLdp1R7.js.map +1 -0
- package/dist/features-CHY5Ekku.js +30 -0
- package/dist/features-CHY5Ekku.js.map +1 -0
- package/dist/files-WW4RlajL.js +506 -0
- package/dist/files-WW4RlajL.js.map +1 -0
- package/dist/{forms-Cl21hkHt.d.ts → forms-j1xPAR14.d.ts} +3 -3
- package/dist/{forms-Bg-CwGqX.js → forms-nXK7-Lv_.js} +78 -44
- package/dist/forms-nXK7-Lv_.js.map +1 -0
- package/dist/highlight.js +31 -22
- package/dist/highlight.js.map +1 -1
- package/dist/{html-mNTKzaDD.js → html-BtKRyi7g.js} +86 -22
- package/dist/html-BtKRyi7g.js.map +1 -0
- package/dist/{html-Bq1rFxX_.d.ts → html-Bw9Qwu6F.d.ts} +20 -5
- package/dist/index.d.ts +96 -10
- package/dist/index.js +639 -104
- package/dist/index.js.map +1 -1
- package/dist/{inspect-BHpOw1LF.js → inspect-Y6y4uNZp.js} +3751 -676
- package/dist/inspect-Y6y4uNZp.js.map +1 -0
- package/dist/{loader-Dos_3NP0.js → loader-BjKGJzLN.js} +20 -14
- package/dist/loader-BjKGJzLN.js.map +1 -0
- package/dist/logo-DQ_OYhBi.js +10 -0
- package/dist/logo-DQ_OYhBi.js.map +1 -0
- package/dist/{navigate-O78d_zGN.js → navigate-CfOr-TRF.js} +94 -31
- package/dist/navigate-CfOr-TRF.js.map +1 -0
- package/dist/nesting-DA5vJw9X.js +265 -0
- package/dist/nesting-DA5vJw9X.js.map +1 -0
- package/dist/{produce-Doc91GkX.js → produce-B7X9ori9.js} +137 -9
- package/dist/produce-B7X9ori9.js.map +1 -0
- package/dist/{produce-D0V0ICkz.d.ts → produce-DIgHBVwL.d.ts} +39 -5
- package/dist/{rpc-ygMRPmN4.js → rpc-Q-XkLwFh.js} +11 -6
- package/dist/rpc-Q-XkLwFh.js.map +1 -0
- package/dist/runtime/batch.js +9 -7
- package/dist/runtime/batch.js.map +1 -1
- package/dist/runtime/client.d.ts +4 -4
- package/dist/runtime/client.js +4 -4
- package/dist/runtime/devtools.d.ts +11 -29
- package/dist/runtime/devtools.js +3 -1
- package/dist/runtime/env.js +14 -2
- package/dist/runtime/env.js.map +1 -1
- package/dist/runtime/events.d.ts +23 -1
- package/dist/runtime/events.js +1 -1
- package/dist/runtime/forms.d.ts +2 -2
- package/dist/runtime/forms.js +1 -1
- package/dist/runtime/hot.d.ts +1 -1
- package/dist/runtime/hot.js +5 -2
- package/dist/runtime/hot.js.map +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.js +4 -1
- package/dist/runtime/routes.js.map +1 -1
- package/dist/runtime/server.d.ts +5 -5
- package/dist/runtime/server.js +5 -5
- package/dist/runtime/signals.d.ts +38 -1
- package/dist/runtime/signals.js +33 -1
- 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 +18 -3
- package/dist/runtime/testing.js +150 -33
- package/dist/runtime/testing.js.map +1 -1
- package/dist/{server-DuFYRXrd.d.ts → server-BvPIg9pT.d.ts} +84 -22
- package/dist/{server-CxVDYE_V.js → server-DjyOVJtJ.js} +598 -164
- package/dist/server-DjyOVJtJ.js.map +1 -0
- package/dist/{static-loader-Drpr0AzI.d.ts → static-loader-BGgdp_Y5.d.ts} +2 -2
- package/dist/{static-loader-nZssh66R.js → static-loader-BZR17hSw.js} +78 -99
- package/dist/static-loader-BZR17hSw.js.map +1 -0
- package/dist/{stream-DCYZO4IF.js → stream-BP5AVmg5.js} +102 -16
- package/dist/stream-BP5AVmg5.js.map +1 -0
- package/dist/vite.d.ts +13 -20
- package/dist/vite.js +1890 -548
- package/dist/vite.js.map +1 -1
- package/elements.d.ts +951 -0
- package/forms/forms.brm.ts +3 -3
- package/package.json +12 -3
- package/skills/brumate/SKILL.md +58 -0
- package/skills/brumate/references/errors.md +2078 -0
- package/skills/brumate/references/events.md +117 -0
- package/skills/brumate/references/signals.md +61 -0
- package/skills/brumate/references/state.md +235 -0
- package/skills/brumate/references/syntax.md +250 -0
- package/types.d.ts +4 -4
- package/dist/client-BD6XT-s5.js +0 -1968
- package/dist/client-BD6XT-s5.js.map +0 -1
- package/dist/client-routes-JTbGtukf.js.map +0 -1
- package/dist/cookies-BzllthiF.js.map +0 -1
- package/dist/defer-BbD7JQhj.js.map +0 -1
- package/dist/devtools-CQgD7NPB.js.map +0 -1
- package/dist/devtools-panel-BVB-W5q4.js.map +0 -1
- package/dist/events-CSs7OwIC.js.map +0 -1
- package/dist/files-BXSSrQgc.js +0 -205
- package/dist/files-BXSSrQgc.js.map +0 -1
- package/dist/forms-Bg-CwGqX.js.map +0 -1
- package/dist/html-mNTKzaDD.js.map +0 -1
- package/dist/inspect-BHpOw1LF.js.map +0 -1
- package/dist/loader-Dos_3NP0.js.map +0 -1
- package/dist/navigate-O78d_zGN.js.map +0 -1
- package/dist/produce-Doc91GkX.js.map +0 -1
- package/dist/rpc-ygMRPmN4.js.map +0 -1
- package/dist/server-CxVDYE_V.js.map +0 -1
- package/dist/static-loader-nZssh66R.js.map +0 -1
- package/dist/stream-DCYZO4IF.js.map +0 -1
package/forms/forms.brm.ts
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
applyLocalIntent,
|
|
10
10
|
checkField,
|
|
11
11
|
checkedSince,
|
|
12
|
-
|
|
12
|
+
getFormErrors,
|
|
13
13
|
formFields,
|
|
14
14
|
validateValues,
|
|
15
15
|
} from 'brumate/forms/core';
|
|
@@ -105,7 +105,7 @@ export function createForm<S extends StandardSchemaV1, D = StandardSchemaV1.Infe
|
|
|
105
105
|
press,
|
|
106
106
|
}),
|
|
107
107
|
);
|
|
108
|
-
const errors = $memo(
|
|
108
|
+
const errors = $memo(getFormErrors(result, checked));
|
|
109
109
|
|
|
110
110
|
// Validates with the schema when the user leaves a field, and as the user types in a field
|
|
111
111
|
// that shows its errors. The code of the schema loads with the first of these events.
|
|
@@ -135,7 +135,7 @@ export function createForm<S extends StandardSchemaV1, D = StandardSchemaV1.Infe
|
|
|
135
135
|
result,
|
|
136
136
|
fields,
|
|
137
137
|
errors,
|
|
138
|
-
attrs: { id,
|
|
138
|
+
attrs: { id, onFocusOut: $handler(check), onInput: $handler(check) },
|
|
139
139
|
defaultSubmit: DEFAULT_SUBMIT,
|
|
140
140
|
};
|
|
141
141
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brumate",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "A component language and compiler for resumable web apps",
|
|
5
5
|
"homepage": "https://github.com/lxsmnsyc/brumate",
|
|
6
6
|
"bugs": "https://github.com/lxsmnsyc/brumate/issues",
|
|
@@ -17,7 +17,10 @@
|
|
|
17
17
|
"files": [
|
|
18
18
|
"dist",
|
|
19
19
|
"types.d.ts",
|
|
20
|
-
"
|
|
20
|
+
"elements.d.ts",
|
|
21
|
+
"check.d.ts",
|
|
22
|
+
"forms",
|
|
23
|
+
"skills"
|
|
21
24
|
],
|
|
22
25
|
"type": "module",
|
|
23
26
|
"exports": {
|
|
@@ -108,6 +111,12 @@
|
|
|
108
111
|
"types": "./dist/runtime/env.d.ts",
|
|
109
112
|
"default": "./dist/runtime/env.js"
|
|
110
113
|
},
|
|
114
|
+
"./elements": {
|
|
115
|
+
"types": "./elements.d.ts"
|
|
116
|
+
},
|
|
117
|
+
"./check": {
|
|
118
|
+
"types": "./check.d.ts"
|
|
119
|
+
},
|
|
111
120
|
"./package.json": "./package.json"
|
|
112
121
|
},
|
|
113
122
|
"publishConfig": {
|
|
@@ -162,6 +171,6 @@
|
|
|
162
171
|
"scripts": {
|
|
163
172
|
"build": "tsdown",
|
|
164
173
|
"test": "vitest run",
|
|
165
|
-
"typecheck": "tsc --noEmit"
|
|
174
|
+
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.elements.json"
|
|
166
175
|
}
|
|
167
176
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: brumate
|
|
3
|
+
description: Writes and fixes brumate components, the `.brm` files, with their state, events, control flow and server functions. Use it when a task creates or edits a `.brm` file, or reads an error of the brumate compiler.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Writing .brm files
|
|
7
|
+
|
|
8
|
+
A `.brm` file is a component: scripts for its state, an optional `<style>`, and markup. The server renders it, and the browser gets only the code that an event, an effect or a changing value reaches. Write it as below, because the compiler reads the form of the code, and it reports the rest as an error.
|
|
9
|
+
|
|
10
|
+
```brm
|
|
11
|
+
<script>
|
|
12
|
+
import { $memo, $signal } from 'brumate/signals';
|
|
13
|
+
|
|
14
|
+
let count = $signal(0);
|
|
15
|
+
const double = $memo(count * 2);
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<button onClick=(() => count++)>Clicked {count} times</button>
|
|
19
|
+
<p>Double: {double}</p>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Rules that agents get wrong
|
|
23
|
+
|
|
24
|
+
- Compile-time functions come from `brumate/signals`: `$signal`, `$memo`, `$props`, `$effect`, `$client`, `$id`, `$bind` and the others. Import each one that the file calls.
|
|
25
|
+
- A signal is `let name = $signal(value)`. A memo is `const name = $memo(expression)`. Read and write them as plain variables: `count++`, `name = 'Ada'`. There is no `.value`.
|
|
26
|
+
- Never write a signal in the setup code of the script. Only handlers, effects, `$client` callbacks and functions that they call write. Give the start value in the call: `$signal(5)`.
|
|
27
|
+
- Keep only data in signals and memos: strings, numbers, booleans, `null`, plain objects and arrays, `Date`, `Map`, `Set`, `URL`, typed arrays and the like. Never put a function, a class instance or a regular expression in one, because the server cannot send it to the browser. Use a plain function in the script, or a function prop, and send a regular expression as its source. A class that the app sends needs a plugin in the serial entry (`src/serial.ts`). See `website/docs/reference-serialization.md`.
|
|
28
|
+
- Never change a value in place. `todos.push(todo)` updates nothing. Assign a new value, or use `$produce(todos, (draft) => { … })`.
|
|
29
|
+
- An attribute value is a quoted string, a plain name, a property path or a call, or an expression in parentheses. A value with an operator, such as `?:`, `+`, `>` or `&&`, or an arrow function, needs parentheses: `disabled=(count > 3)`. A bare `title=!closed` and `data-a=-1` work.
|
|
30
|
+
- Use the shorthands: `<a {href}>`, `<button {onClick}>`, `<input {...rest}>`.
|
|
31
|
+
- Write a branch on the line of the closing brace, as the style: `} #else if (…) {` and `} #else {`. The compiler also accepts `#else` on the next line.
|
|
32
|
+
- A `#for` has a key: `#for (item, index of items by item.id) { … }`. Without `by`, each item is its own key.
|
|
33
|
+
- `$effect` never runs on mount. Its first run is after the first change of a value it reads. Code that must run when the page loads or comes into view is `$client(callback, trigger)`. The default trigger is `'visible'`.
|
|
34
|
+
- Reach for a handler first, then `$memo`, and `$effect` last. An effect is only for work outside the page's state, such as an element method, a cookie, `document.title`, a timer or a library. Never write an effect that only sets a signal from other signals: that value is a `$memo`, or a write in the handler.
|
|
35
|
+
- An element that browser code needs is `ref=$bind(name)`, where `name` is a signal. A bare `ref=name` is an error.
|
|
36
|
+
- To let a child write a value, destructure its prop with `let` and type it `Bindable<T>`. The parent passes `$bind(signal)`.
|
|
37
|
+
- A component never receives a signal. A function prop writes the parent's value: `onChange=((next) => (count = next))`.
|
|
38
|
+
- Markup is never a value in code or in an attribute. Use `#template name(parameters) { … }` and call it as `{name(arguments)}`.
|
|
39
|
+
- Browser wrappers of a handler come from `brumate/events`: `prevent`, `stop`, `once`, `capture`, `transition`. Write them in the attribute, with keys as string literals. `prevent(handler, 'Enter')` prevents only Enter with Ctrl, Meta and Alt up. `'Mod+ArrowDown'` names Ctrl or Meta. Calling `event.preventDefault()` in a handler is too late.
|
|
40
|
+
- A server function is an `async` function with `'use server'` on its first line. It reads no variable of the instance script. Pass values as arguments.
|
|
41
|
+
- Do not use `$ref`, `$watch`, `$settled`, `$cleanup`, `$store`, `$get`, `$set`, or modifiers such as `onSubmit:prevent`.
|
|
42
|
+
|
|
43
|
+
## References
|
|
44
|
+
|
|
45
|
+
Read the file for the part of the work that you do.
|
|
46
|
+
|
|
47
|
+
- [references/syntax.md](references/syntax.md): the parts of a file, attributes, props, children, templates and control flow.
|
|
48
|
+
- [references/signals.md](references/signals.md): every function of `brumate/signals`, with what it returns and where it goes.
|
|
49
|
+
- [references/state.md](references/state.md): signals, memos, async data, effects, `$client` and refs.
|
|
50
|
+
- [references/events.md](references/events.md): handlers, the wrappers of `brumate/events`, and `$handler`.
|
|
51
|
+
- [references/errors.md](references/errors.md): every compile error, its cause, and the form to write instead.
|
|
52
|
+
|
|
53
|
+
## Checking your work
|
|
54
|
+
|
|
55
|
+
- `npx brumate-tsc --noEmit` type-checks the project, `.brm` files included.
|
|
56
|
+
- `npx brumate check --json` compiles every `.brm` file and runs the type check. It prints one JSON object per problem, with `file`, `range`, `message`, `code` and `link`, and exits with 1 on an error.
|
|
57
|
+
- A compile error names the file, the line and the column, and ends with a code such as `[BRM012]`. Look its message or its code up in [references/errors.md](references/errors.md).
|
|
58
|
+
- The docs of brumate, in `website/docs` of its repository, cover each topic in full.
|