brumate 0.7.2 → 0.8.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-CMy0f_iC.d.ts → boot-BkUdiYOF.d.ts} +2 -2
- package/dist/cli.js +3 -2
- package/dist/cli.js.map +1 -1
- package/dist/{client-COm1iA6w.js → client-B0FXW5Kw.js} +48 -14
- package/dist/client-B0FXW5Kw.js.map +1 -0
- package/dist/{client-DnFF9_lv.d.ts → client-Cq6aTiDs.d.ts} +15 -7
- package/dist/{defer-Cesb-k2Q.js → defer-BMIMP4Hq.js} +2 -2
- package/dist/{defer-Cesb-k2Q.js.map → defer-BMIMP4Hq.js.map} +1 -1
- package/dist/{devtools-C9IEkgc1.js → devtools-B4prrxht.js} +257 -118
- package/dist/devtools-B4prrxht.js.map +1 -0
- package/dist/devtools-calls-DGW6nLZ2.js +249 -0
- package/dist/devtools-calls-DGW6nLZ2.js.map +1 -0
- package/dist/devtools-panel-B1nF1KB7.js +3978 -0
- package/dist/devtools-panel-B1nF1KB7.js.map +1 -0
- package/dist/error-catalog-DakxjSgj.js +308 -0
- package/dist/error-catalog-DakxjSgj.js.map +1 -0
- package/dist/error-catalog-VxLbz-6p.js +1 -0
- package/dist/{files-BuQvpBwF.js → files-D5GtxwEQ.js} +2 -2
- package/dist/{files-BuQvpBwF.js.map → files-D5GtxwEQ.js.map} +1 -1
- package/dist/index.d.ts +73 -18
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/dist/{inspect-BSHv1_25.js → inspect-CGl5Y8q6.js} +581 -399
- package/dist/inspect-CGl5Y8q6.js.map +1 -0
- package/dist/{loader-CLKrJMqw.js → loader-BsaSuIoG.js} +4 -4
- package/dist/{loader-CLKrJMqw.js.map → loader-BsaSuIoG.js.map} +1 -1
- package/dist/{navigate-OHb0Uw1P.js → navigate-BlowKvhB.js} +13 -6
- package/dist/navigate-BlowKvhB.js.map +1 -0
- package/dist/{rpc-BAKbRWOT.js → rpc-C1jYVNAe.js} +5 -4
- package/dist/rpc-C1jYVNAe.js.map +1 -0
- package/dist/runtime/bundles.d.ts +1 -1
- package/dist/runtime/client.d.ts +2 -2
- package/dist/runtime/client.js +4 -3
- package/dist/runtime/devtools.d.ts +59 -1
- package/dist/runtime/devtools.js +1 -1
- package/dist/runtime/hot.d.ts +1 -1
- package/dist/runtime/hot.js +6 -2
- package/dist/runtime/hot.js.map +1 -1
- package/dist/runtime/loader.d.ts +2 -2
- package/dist/runtime/loader.js +2 -2
- package/dist/runtime/server.d.ts +1 -1
- package/dist/runtime/server.js +3 -2
- package/dist/runtime/signals.d.ts +1 -1
- package/dist/runtime/static-loader.d.ts +2 -2
- package/dist/runtime/static-loader.js +1 -1
- package/dist/runtime/store.d.ts +2 -2
- package/dist/runtime/store.js +1 -1
- package/dist/runtime/testing.d.ts +2 -2
- package/dist/runtime/testing.js +2 -2
- package/dist/search-params-Wg-0FsMj.js +148 -0
- package/dist/search-params-Wg-0FsMj.js.map +1 -0
- package/dist/{stream-RXLadXx1.js → serial-ioa17MuY.js} +67 -168
- package/dist/serial-ioa17MuY.js.map +1 -0
- package/dist/serial-ribg9NAj.js +1 -0
- package/dist/{server-BVObWh-w.js → server-BUuf7XPZ.js} +61 -16
- package/dist/server-BUuf7XPZ.js.map +1 -0
- package/dist/{server-0rS5vUW1.d.ts → server-DesBZv5g.d.ts} +8 -3
- package/dist/{search-params-C64liRBj.js → shared-CX_YacDm.js} +3 -148
- package/dist/shared-CX_YacDm.js.map +1 -0
- package/dist/{signals-DBnq9QRW.d.ts → signals-7VVD9C_H.d.ts} +2 -2
- package/dist/{static-loader-CxANokZ4.js → static-loader-C_en-4v8.js} +2 -2
- package/dist/{static-loader-CxANokZ4.js.map → static-loader-C_en-4v8.js.map} +1 -1
- package/dist/{static-loader-BYbXVJDY.d.ts → static-loader-UKnK11Em.d.ts} +2 -2
- package/dist/{store-xlTzAM_r.d.ts → store-9_oa0HG1.d.ts} +15 -2
- package/dist/{store-BIBAYZo-.js → store-Cy4EEyZ7.js} +148 -2
- package/dist/store-Cy4EEyZ7.js.map +1 -0
- package/dist/stream-read-BTsYstJY.js +22 -0
- package/dist/stream-read-BTsYstJY.js.map +1 -0
- package/dist/stream-read-Dek3HnqO.js +1 -0
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +37 -5
- package/dist/vite.js.map +1 -1
- package/package.json +7 -4
- package/skills/brumate/SKILL.md +6 -2
- package/skills/brumate/references/errors.md +21 -2
- package/skills/brumate/references/state.md +31 -0
- package/skills/brumate/references/syntax.md +45 -1
- package/dist/client-COm1iA6w.js.map +0 -1
- package/dist/devtools-C9IEkgc1.js.map +0 -1
- package/dist/devtools-panel-Doit__YG.js +0 -2018
- package/dist/devtools-panel-Doit__YG.js.map +0 -1
- package/dist/inspect-BSHv1_25.js.map +0 -1
- package/dist/navigate-OHb0Uw1P.js.map +0 -1
- package/dist/rpc-BAKbRWOT.js.map +0 -1
- package/dist/search-params-C64liRBj.js.map +0 -1
- package/dist/server-BVObWh-w.js.map +0 -1
- package/dist/store-BIBAYZo-.js.map +0 -1
- package/dist/stream-RXLadXx1.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brumate",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.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",
|
|
@@ -20,7 +20,9 @@
|
|
|
20
20
|
"elements.d.ts",
|
|
21
21
|
"check.d.ts",
|
|
22
22
|
"forms",
|
|
23
|
-
"skills"
|
|
23
|
+
"skills",
|
|
24
|
+
"!skills/tasks",
|
|
25
|
+
"!skills/run-tasks.mjs"
|
|
24
26
|
],
|
|
25
27
|
"type": "module",
|
|
26
28
|
"exports": {
|
|
@@ -131,6 +133,7 @@
|
|
|
131
133
|
"access": "public"
|
|
132
134
|
},
|
|
133
135
|
"dependencies": {
|
|
136
|
+
"@seroval/transport": "^0.1.0",
|
|
134
137
|
"@twinkleplop/core": "0.3.1",
|
|
135
138
|
"@twinkleplop/css": "0.1.7",
|
|
136
139
|
"@twinkleplop/theme-github": "0.2.4",
|
|
@@ -138,8 +141,8 @@
|
|
|
138
141
|
"oxc-parser": "^0.154.0",
|
|
139
142
|
"postcss": "^8.5.31",
|
|
140
143
|
"postcss-selector-parser": "^7.1.6",
|
|
141
|
-
"seroval": "^1.
|
|
142
|
-
"seroval-plugins": "^1.
|
|
144
|
+
"seroval": "^1.8.0",
|
|
145
|
+
"seroval-plugins": "^1.8.0"
|
|
143
146
|
},
|
|
144
147
|
"devDependencies": {
|
|
145
148
|
"@oxc-project/types": "^0.154.0",
|
package/skills/brumate/SKILL.md
CHANGED
|
@@ -28,6 +28,7 @@ A `.brm` file is a component: scripts for its state, an optional `<style>`, and
|
|
|
28
28
|
- Never change a value in place. `todos.push(todo)` updates nothing. Assign a new value, or use `$produce(todos, (draft) => { … })`.
|
|
29
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
30
|
- Use the shorthands: `<a {href}>`, `<button {onClick}>`, `<input {...rest}>`.
|
|
31
|
+
- A block body can hold a `<style>` at its top level, after its optional `<script>`. It styles the elements of the block and of the blocks inside it, and its `${}` reads the item and the signals of the block script. The `<style>` of the file is the style of the outermost block, so one rule covers both, and `<style global>` and `:global(…)` work in any block.
|
|
31
32
|
- 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
33
|
- A `#for` has a key: `#for (item, index of items by item.id) { … }`. Without `by`, each item is its own key.
|
|
33
34
|
- `$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'`.
|
|
@@ -38,15 +39,18 @@ A `.brm` file is a component: scripts for its state, an optional `<style>`, and
|
|
|
38
39
|
- Markup is never a value in code or in an attribute. Use `#template name(parameters) { … }` and call it as `{name(arguments)}`.
|
|
39
40
|
- 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
41
|
- 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.
|
|
42
|
+
- A store computed from other stores is `derived(sources, fn)` of `brumate/store`, read with `$store`. It is one-way, and never goes in a provided value or a prop.
|
|
43
|
+
- An inline script is `raw('<script nonce=… data-rerun>…</script>')` in `#head`, with `getEvent().nonce` of `brumate/server` as the nonce. `data-rerun` runs it after each client navigation.
|
|
44
|
+
- The light and dark choice of the page is `ColorScheme` and `colorScheme()` of `@brumate/ui`, not a signal and an effect.
|
|
41
45
|
- Do not use `$ref`, `$watch`, `$settled`, `$cleanup`, `$get`, `$set`, or modifiers such as `onSubmit:prevent`.
|
|
42
46
|
|
|
43
47
|
## References
|
|
44
48
|
|
|
45
49
|
Read the file for the part of the work that you do.
|
|
46
50
|
|
|
47
|
-
- [references/syntax.md](references/syntax.md): the parts of a file, attributes, props, children, templates
|
|
51
|
+
- [references/syntax.md](references/syntax.md): the parts of a file, attributes, props, children, templates, control flow, head scripts and `ColorScheme`.
|
|
48
52
|
- [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
|
|
53
|
+
- [references/state.md](references/state.md): signals, memos, async data, effects, `$client`, refs, context and derived stores.
|
|
50
54
|
- [references/events.md](references/events.md): handlers, the wrappers of `brumate/events`, and `$handler`.
|
|
51
55
|
- [references/errors.md](references/errors.md): every compile error, its cause, and the form to write instead.
|
|
52
56
|
|
|
@@ -116,9 +116,9 @@ https://brumate-docs.vercel.app/docs/errors#brm010
|
|
|
116
116
|
}
|
|
117
117
|
```
|
|
118
118
|
|
|
119
|
-
## BRM011: <style> must be at the top level
|
|
119
|
+
## BRM011: <style> must be at the top level of the file or of a block
|
|
120
120
|
|
|
121
|
-
A `<style>` is inside an element
|
|
121
|
+
A `<style>` is inside an element.
|
|
122
122
|
|
|
123
123
|
https://brumate-docs.vercel.app/docs/errors#brm011
|
|
124
124
|
|
|
@@ -558,6 +558,25 @@ https://brumate-docs.vercel.app/docs/errors#brm189
|
|
|
558
558
|
</style>
|
|
559
559
|
```
|
|
560
560
|
|
|
561
|
+
## BRM207: #reveal has no style of its own
|
|
562
|
+
|
|
563
|
+
A `<style>` is in the body of a `#reveal`, which only orders the bodies inside it.
|
|
564
|
+
|
|
565
|
+
https://brumate-docs.vercel.app/docs/errors#brm207
|
|
566
|
+
|
|
567
|
+
```brm fragment
|
|
568
|
+
<style>
|
|
569
|
+
p {
|
|
570
|
+
color: red;
|
|
571
|
+
}
|
|
572
|
+
</style>
|
|
573
|
+
#reveal {
|
|
574
|
+
#loading {
|
|
575
|
+
<p>Loaded</p>
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
```
|
|
579
|
+
|
|
561
580
|
## BRM190: global takes no value, as in <style global>
|
|
562
581
|
|
|
563
582
|
A `<style global>` gives `global` a value.
|
|
@@ -234,3 +234,34 @@ A memo can hold a promise, such as the result of a server function. Markup and o
|
|
|
234
234
|
```
|
|
235
235
|
|
|
236
236
|
`createContext` comes from `brumate/context`: `export const Theme = createContext<'light' | 'dark'>('theme');` in a `.ts` file. It takes only a key and has no default. A component reads the context of the nearest component above it, children included, and `$getContext` throws when none provides it. Give a fallback for a read that may have no provider: `$getContext(Theme, 'light')`.
|
|
237
|
+
|
|
238
|
+
## Derived stores
|
|
239
|
+
|
|
240
|
+
A value at module level, outside any component, that is computed from stores is `derived(sources, fn)` of `brumate/store`. Inside a component, use a `$memo`. A component reads it with `$store`.
|
|
241
|
+
|
|
242
|
+
```ts module="cart.ts"
|
|
243
|
+
import { derived, store } from 'brumate/store';
|
|
244
|
+
import type { Store, StoreLike } from 'brumate/store';
|
|
245
|
+
|
|
246
|
+
export const cart: Store<number[]> = store([12, 8]);
|
|
247
|
+
|
|
248
|
+
export const total: StoreLike<number> = derived(cart, (items) =>
|
|
249
|
+
items.reduce((sum, price) => sum + price, 0),
|
|
250
|
+
);
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
```brm uses
|
|
254
|
+
<script>
|
|
255
|
+
import { $store } from 'brumate/signals';
|
|
256
|
+
import { cart, total } from './cart.ts';
|
|
257
|
+
|
|
258
|
+
const sum = $store(total);
|
|
259
|
+
</script>
|
|
260
|
+
|
|
261
|
+
<button onClick=(() => cart.set([...cart.get(), 5]))>Add 5</button>
|
|
262
|
+
<p>Total {sum}</p>
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
- `sources` is a store or an array of stores, and `fn` gets the value or an array of values: `derived([cart, total], ([items, sum]) => …)`. With two or three parameters, `fn(values, set, update)` calls `set(value)`.
|
|
266
|
+
- The result has no `set`. Read it with `const`: `let x = $store(total)` throws a `TypeError`.
|
|
267
|
+
- It is not part of the page state. Read it from an import or `<script module>`. Never put it in a provided value or a prop.
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
- `<script>` runs once for each instance, on the server. `<script module>` runs once per module, and its exports can be imported.
|
|
26
|
-
- `<style>` is scoped to the component. `<style global>` is not: its rules apply to the whole page, such as `body` or `.toolbar button`, with no `:global(…)` around them. `lang="scss"` and `lang="less"` work in both. Both are top level
|
|
26
|
+
- `<style>` is scoped to the component. `<style global>` is not: its rules apply to the whole page, such as `body` or `.toolbar button`, with no `:global(…)` around them. `lang="scss"` and `lang="less"` work in both. Both are allowed at the top level of the file and of a block body.
|
|
27
27
|
- A file has at most one of each script. Markup can come before or after them.
|
|
28
28
|
- Markup in a script, an expression or an attribute value is an error. Use a `#template`.
|
|
29
29
|
|
|
@@ -182,6 +182,7 @@ A file uses another component by importing it, and renders it with a capitalized
|
|
|
182
182
|
```
|
|
183
183
|
|
|
184
184
|
- The body of a block can start with a `<script>` of its own, which runs for each instance, such as each item of a `#for`. It can declare signals and functions.
|
|
185
|
+
- The body of a block can hold a `<style>` at its top level. It matches the elements of the body and of the bodies inside it, and its `${}` reads the item, the signals of the block script and the values of the component. A change updates only the instance that reads it. The `<style>` of the file is the style of the outermost block, so the same rule covers it, and `<style global>` and `:global(…)` work in a block as at the top level.
|
|
185
186
|
- `#for (item of list) { … }` has no `by` for a list that needs no key: each item is its own key. Use `by item.id` when items are objects that change.
|
|
186
187
|
- Write `} #else if (…) {` and `} #else {` on the line of the closing brace, as the style. The compiler accepts `#else` on the next line too.
|
|
187
188
|
- `#for (item of list) window(32) { … }` renders only the items in view, for a long list. `32` is the height of an item.
|
|
@@ -217,6 +218,22 @@ A file uses another component by importing it, and renders it with a capitalized
|
|
|
217
218
|
- `$id()` gives an ID that is the same on the server and in the browser: `const field = $id();`, then `<label for=field>` and `<input id=field>`.
|
|
218
219
|
- `<script>` can export nothing. A value that other files import goes in `<script module>`.
|
|
219
220
|
- `#head { <title>{title}</title> <meta name="description" content="…"> }` sets the head of the page. A `<title>` outside `#head` is an error.
|
|
221
|
+
- A script in the head is HTML in a string, since `<script>` is not markup in a `.brm` file. Send it with `raw()` from `brumate/html`, and give it the nonce of the render, which is `undefined` without one: `getEvent().nonce` of `brumate/server`. A client navigation does not run a head script again. Add `data-rerun` to one that must run after each navigation.
|
|
222
|
+
|
|
223
|
+
```brm
|
|
224
|
+
<script>
|
|
225
|
+
import { getEvent } from 'brumate/server';
|
|
226
|
+
import { raw } from 'brumate/html';
|
|
227
|
+
|
|
228
|
+
const nonce = getEvent().nonce;
|
|
229
|
+
const attribute = nonce ? ` nonce="${nonce}"` : '';
|
|
230
|
+
</script>
|
|
231
|
+
|
|
232
|
+
#head {
|
|
233
|
+
{raw(`<script${attribute} data-rerun>document.documentElement.dataset.visits = '1'</script>`)}
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
220
237
|
- A value that changes in a `<textarea>` or `<title>` must be its whole content: `<textarea>{text}</textarea>`.
|
|
221
238
|
|
|
222
239
|
## Modules of reactive logic
|
|
@@ -248,3 +265,30 @@ export function counter(start: number) {
|
|
|
248
265
|
|
|
249
266
|
- The function ends with `return { … }`, an object of plain keys, and returns nowhere else.
|
|
250
267
|
- A component calls it at the top level of its script, and destructures the result with plain names.
|
|
268
|
+
|
|
269
|
+
## Parts of @brumate/ui
|
|
270
|
+
|
|
271
|
+
The light, dark or system choice of the page is `ColorScheme` of `@brumate/ui`. It keeps the choice in a cookie, so the server renders the first response with it. `colorScheme()` reads and changes it from a component inside, at the top level of its script.
|
|
272
|
+
|
|
273
|
+
```brm
|
|
274
|
+
<script>
|
|
275
|
+
import ColorScheme from '@brumate/ui/ColorScheme.brm';
|
|
276
|
+
import ThemeToggle from './ThemeToggle.brm';
|
|
277
|
+
</script>
|
|
278
|
+
|
|
279
|
+
<ColorScheme class="app" cookieName="theme"><ThemeToggle /></ColorScheme>
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
```brm uses
|
|
283
|
+
<script>
|
|
284
|
+
import { colorScheme } from '@brumate/ui/color-scheme.brm.ts';
|
|
285
|
+
|
|
286
|
+
const { value, resolved, setValue } = colorScheme();
|
|
287
|
+
</script>
|
|
288
|
+
|
|
289
|
+
<button onClick=(() => setValue(resolved === 'dark' ? 'light' : 'dark'))>Scheme: {value}</button>
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
- `value` is `light`, `dark` or `system`. `resolved` is `light` or `dark`, and undefined for `system` until the browser knows the preference.
|
|
293
|
+
- Destructure what `colorScheme()` returns. Outside a `ColorScheme`, `setValue` does nothing.
|
|
294
|
+
- `as="html"` in the root layout puts the class on `<html>`.
|