@loadbare/app 0.8.0 → 0.8.1
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/build/skills-cli.d.ts +12 -0
- package/dist/build/skills-cli.d.ts.map +1 -0
- package/dist/build/skills-cli.js +81 -0
- package/dist/build/skills-cli.js.map +1 -0
- package/dist/build/skills.d.ts +47 -0
- package/dist/build/skills.d.ts.map +1 -0
- package/dist/build/skills.js +124 -0
- package/dist/build/skills.js.map +1 -0
- package/docs/reference/widgets.md +2 -2
- package/package.json +8 -4
- package/skills/loadbare-app/SKILL.md +258 -0
- package/skills/loadbare-app/references/TECHREF-1.0.md +1189 -0
- package/skills/loadbare-app/references/builder.md +134 -0
- package/skills/loadbare-app/references/chrome.md +158 -0
- package/skills/loadbare-app/references/css.md +44 -0
- package/skills/loadbare-app/references/custom-elements.md +397 -0
- package/skills/loadbare-app/references/data-binding.md +457 -0
- package/skills/loadbare-app/references/overview.md +38 -0
- package/skills/loadbare-app/references/page-files.md +194 -0
- package/skills/loadbare-app/references/server.md +142 -0
- package/skills/loadbare-app/references/widgets.md +174 -0
|
@@ -0,0 +1,1189 @@
|
|
|
1
|
+
# What 1.0 release means
|
|
2
|
+
|
|
3
|
+
This is the complete technical reference to the upcoming Release 1.0.
|
|
4
|
+
|
|
5
|
+
Method-of-work is to continually revise this document to what we want
|
|
6
|
+
to be true, then revise the code, docs, and tests to ensure it is true.
|
|
7
|
+
|
|
8
|
+
## Blockers
|
|
9
|
+
|
|
10
|
+
We cannot declare 1.0 until we determine if these blockers can be
|
|
11
|
+
added later w/o breaking changes. If we are reasonably confident
|
|
12
|
+
that they can be decided later w/o breaking changes, then we rename
|
|
13
|
+
them to "Out of Scope" or move them to the roadmap. Otherwise,
|
|
14
|
+
they must be resolved before we declare 1.0.
|
|
15
|
+
|
|
16
|
+
### Data types
|
|
17
|
+
|
|
18
|
+
Loadbare/app enforces no data types on values between the database and the
|
|
19
|
+
browser. A uniform and useful approach is difficult to discern, and we do
|
|
20
|
+
not want to pollute 1.0 with a potentially sub-optimal solution. Until then
|
|
21
|
+
a value is rendered by browser coercion when it lands on an HTML text
|
|
22
|
+
element, or by whatever the widget does when it lands on a widget.
|
|
23
|
+
|
|
24
|
+
We will then see if a useful solution emerges that Loadbare/app should
|
|
25
|
+
handle.
|
|
26
|
+
|
|
27
|
+
### Form controls
|
|
28
|
+
|
|
29
|
+
- **Checkboxes and radio buttons are not implemented.** A value does not
|
|
30
|
+
land on one and a form does not gather one. Landing needs a decision on
|
|
31
|
+
what counts as checked, which waits on [Data types](#data-types), and a
|
|
32
|
+
radio group is several elements answering to one cell.
|
|
33
|
+
|
|
34
|
+
### Run-time state attributes
|
|
35
|
+
|
|
36
|
+
The hub stamps `lb-row-count`, `lb-pending` and `lb-error` for a
|
|
37
|
+
stylesheet to read. Their consumer is CSS rather than code.
|
|
38
|
+
|
|
39
|
+
- **Decide `data-` against `lb-`.** These are the only names the hub writes
|
|
40
|
+
outside its own namespace, which is either a deliberate signal that CSS
|
|
41
|
+
owns them or an inconsistency.
|
|
42
|
+
- **Say what `lb-row-count` holds.** It is stamped and never explained.
|
|
43
|
+
- **Decide whether an unarrived value needs a signal.** The roadmap proposes
|
|
44
|
+
deriving it from an absent `lb-value`. Recommend confirming that and
|
|
45
|
+
adding nothing.
|
|
46
|
+
|
|
47
|
+
### The widget protocol
|
|
48
|
+
|
|
49
|
+
Loadbare/app owns every method name beginning with `lb` on a custom element.
|
|
50
|
+
That decision is firm; what the set contains is not.
|
|
51
|
+
|
|
52
|
+
- **Decide what the build does with an unknown `lb*` method.** An element
|
|
53
|
+
carrying a method beginning with `lb` that Loadbare/app does not define may
|
|
54
|
+
be an error, a warning, or ignored.
|
|
55
|
+
- **Decide whether a widget may receive a whole row.** A cell lands one
|
|
56
|
+
element at a time and offers no escape hatch. An optional `lbAcceptRow`
|
|
57
|
+
would sit beside `lbPlaceRow` and `lbRowsLanded`, and this is the most
|
|
58
|
+
likely first request from a widget author.
|
|
59
|
+
|
|
60
|
+
### Lists
|
|
61
|
+
|
|
62
|
+
Imagine we have an HTML `<select>` that displays a fixed list for all
|
|
63
|
+
rows in a table, such as `customer_type` for a table of customers. When
|
|
64
|
+
all customers can be any customer type, our system as written today
|
|
65
|
+
is fine, because all HTML `<select>` elements get the same list.
|
|
66
|
+
|
|
67
|
+
But it may be that the list of allowed values is dependent on other values
|
|
68
|
+
in the row.
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
- **Decide how a new row fills a nested list.** A row added to the outer
|
|
72
|
+
list starts with an empty nested list, which fills only when the nested
|
|
73
|
+
list's name lands again. See [Master-detail](#master-detail) for what a
|
|
74
|
+
nested list is for.
|
|
75
|
+
|
|
76
|
+
```html
|
|
77
|
+
<tbody lb-list="accounts">
|
|
78
|
+
<template lb-key="id"><tr>
|
|
79
|
+
<td lb-cell="name"></td>
|
|
80
|
+
<td><select lb-list="statuses"><template lb-key="id"><option lb-cell="label"></option></template></select></td>
|
|
81
|
+
</tr></template>
|
|
82
|
+
</tbody>
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### The server API
|
|
86
|
+
|
|
87
|
+
- **Give the chrome a way to state its own queries.** A widget in the chrome
|
|
88
|
+
bound to a query forces every page to declare that query, since the page
|
|
89
|
+
data run covers one page's set. `lb-navigation` shows the pattern from the
|
|
90
|
+
framework side, and an application has no equivalent. Recommend a
|
|
91
|
+
chrome-level query set on `createHub`.
|
|
92
|
+
- **State that only `createHub` implements `Hub`.** Otherwise a sixth
|
|
93
|
+
operation breaks anyone who wrote the interface by hand.
|
|
94
|
+
- **Decide the options-argument shape once.** Global hooks, transaction
|
|
95
|
+
wrapping, error handling and a CSRF token all want the same trailing
|
|
96
|
+
parameter on `createHub` and `hubRoutes`. Build none of them, but pick
|
|
97
|
+
where they go.
|
|
98
|
+
- **Land `staticRoutes`.** See NEXT.md. It closes the last place where an
|
|
99
|
+
application hand-writes facts the builder owns.
|
|
100
|
+
|
|
101
|
+
### The builder
|
|
102
|
+
|
|
103
|
+
- **Adopt a configuration file and fold `imports.ts` into it.** It holds
|
|
104
|
+
`out`, `minify` and `imports`, and lives where `imports.ts` lives now, so a
|
|
105
|
+
repository with several applications gets one per application. `--src`
|
|
106
|
+
stays a flag, since it is what locates the file. State the precedence
|
|
107
|
+
between a flag and a key once. Its key names join the permanent surface,
|
|
108
|
+
so this lands before 1.0 or not at all.
|
|
109
|
+
- **Decide whether a URL carries view parameters.** A URL names a page and
|
|
110
|
+
nothing finer — see [What a URL names](#what-a-url-names) — and a query
|
|
111
|
+
takes no argument from the browser. So a page has nowhere to keep which
|
|
112
|
+
record it shows, a filter, a sort, or a collapsed section: a reload or a
|
|
113
|
+
shared link loses them, and a filter is lost whenever an action re-runs its
|
|
114
|
+
query. Parameters on a page URL, as `<form method="get">` puts its fields
|
|
115
|
+
in the query string, are one answer. Deciding against them, and leaving
|
|
116
|
+
view state to the application, is another. Write whichever one down.
|
|
117
|
+
- **Decide CSS pairing.** Naming a stylesheet `<tag>.css` beside its
|
|
118
|
+
definition would let the builder ship only what survives expansion.
|
|
119
|
+
Recommend deferring the mechanism and reserving the configuration key, so
|
|
120
|
+
that it lands as an opt-in rather than as a silent drop.
|
|
121
|
+
- **Land the remaining validations.** One `lb-hub`, one empty `<main>`, and
|
|
122
|
+
every `lb-` attribute known. Recommend landing these now, because refusing
|
|
123
|
+
markup that used to build is the kind of change 1.0 gives up.
|
|
124
|
+
- **Confirm the three output names.** `app.html`, `client.js` and `app.css`
|
|
125
|
+
are about to be fixed in `staticRoutes` as well as in the builder.
|
|
126
|
+
|
|
127
|
+
### The internal surface
|
|
128
|
+
|
|
129
|
+
None of this is surface. It is listed here because trimming it is free
|
|
130
|
+
today and breaking after 1.0.
|
|
131
|
+
|
|
132
|
+
- **Drop `./build` from the exports map.** Nothing in the repository imports
|
|
133
|
+
it, and nothing outside the CLI should call `resolveElements` or
|
|
134
|
+
`clientEntrySource`.
|
|
135
|
+
- **Audit what the hub does.** It appears to have routines that go beyond
|
|
136
|
+
what the `lb-*` attribute namespace specifies.
|
|
137
|
+
- **Keep the rest as constants.** The endpoint, `index` and the timeout are
|
|
138
|
+
linkage between the builder and the hub rather than facts an application
|
|
139
|
+
varies. Adding a knob for any of them buys a second shape of application
|
|
140
|
+
to reason about.
|
|
141
|
+
- **Give the hub a configuration channel without using it.** `<lb-hub>` reads
|
|
142
|
+
no attributes at all, which is the free landing spot for the roadmap's
|
|
143
|
+
static-origin split and for a timeout an application eventually outgrows.
|
|
144
|
+
Reserve the idea, build nothing.
|
|
145
|
+
|
|
146
|
+
## The build
|
|
147
|
+
|
|
148
|
+
### Running the builder
|
|
149
|
+
|
|
150
|
+
```
|
|
151
|
+
loadbare-app-build [--src src] [--out dist] [--watch] [--minify]
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
`--src` names the tree the builder scans, and is defined under
|
|
155
|
+
[What the builder scans](#what-the-builder-scans).
|
|
156
|
+
|
|
157
|
+
`--out` names the directory the builder writes into, and defaults to `dist`.
|
|
158
|
+
Every output path in this document is written relative to it, so an
|
|
159
|
+
application that passes `--out` reads `dist/app.html` here as
|
|
160
|
+
`<out>/app.html`. See [Build outputs](#build-outputs).
|
|
161
|
+
|
|
162
|
+
`--watch` builds once, then rebuilds on every change to an `.html`, `.ts` or
|
|
163
|
+
`.css` file under `--src`. A build that throws is reported and the watch
|
|
164
|
+
continues. There is no dev server and no browser reload.
|
|
165
|
+
|
|
166
|
+
`--minify` minifies `client.js` and `app.css`. It leaves `app.html` alone,
|
|
167
|
+
which stays markup an application can read.
|
|
168
|
+
|
|
169
|
+
The builder bundles `client.js` from a `client-entry.ts` it generates into
|
|
170
|
+
`--out` and leaves there. Nothing reads it after the bundle, and an
|
|
171
|
+
application neither writes nor imports it.
|
|
172
|
+
|
|
173
|
+
Every `.css` file in every origin joins `app.css`. There is no widget, page
|
|
174
|
+
or chrome stylesheet: the builder concatenates them all, with nothing added,
|
|
175
|
+
removed or scoped, so what ships is what was authored. Within one origin
|
|
176
|
+
they are ordered by filename, the full path breaking a tie, and a
|
|
177
|
+
subdirectory never affects the order. Origins follow the cascade — this
|
|
178
|
+
package's own widgets, then each package named in `imports.ts`, then `--src`
|
|
179
|
+
last — so an application's own stylesheet always lands after the ones it
|
|
180
|
+
imported. A file named `00-global.css` sorts first by saying so.
|
|
181
|
+
|
|
182
|
+
### What the builder scans
|
|
183
|
+
|
|
184
|
+
#### The current project
|
|
185
|
+
|
|
186
|
+
The builder scans one directory named by its `--src` parameter,
|
|
187
|
+
which defaults to `src/`.
|
|
188
|
+
|
|
189
|
+
The sections below often state something like, "anywhere in
|
|
190
|
+
the `--src` tree", because Loadbare/app assigns semantic meaning
|
|
191
|
+
to file names, not subdir names.
|
|
192
|
+
|
|
193
|
+
#### Imported widget libraries
|
|
194
|
+
|
|
195
|
+
Any number of widget libraries can be used. They are named
|
|
196
|
+
in the file `imports.ts`, located anywhere in builder `--src`.
|
|
197
|
+
A project can leave out `imports.ts`, or have exactly one, but
|
|
198
|
+
two or more is an error.
|
|
199
|
+
|
|
200
|
+
```ts
|
|
201
|
+
// imports.ts, anywhere in --src
|
|
202
|
+
export default ["@namespace/widget-library"];
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
If the named package's `package.json` declares where the widgets
|
|
206
|
+
are, Loadbare scans that. Otherwise it scans the entire installed
|
|
207
|
+
directory. The declaration, if present, would look like this:
|
|
208
|
+
|
|
209
|
+
```json
|
|
210
|
+
"loadbare": { "widgets": "./dist" }
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### File names and the builder
|
|
214
|
+
|
|
215
|
+
The builder finds a file by its name. A subdirectory carries no meaning, so
|
|
216
|
+
the whole of `--src` is one flat namespace, as stated in
|
|
217
|
+
[What the builder scans](#what-the-builder-scans).
|
|
218
|
+
|
|
219
|
+
Three kinds of file hold HTML.
|
|
220
|
+
|
|
221
|
+
| File | Holds | Found in |
|
|
222
|
+
| ------------------ | ------------------------------------ | ------------ |
|
|
223
|
+
| `chrome.html` | The one HTML document | `--src` |
|
|
224
|
+
| `<stub>.page.html` | One page's markup, as a fragment | `--src` |
|
|
225
|
+
| `<tag-name>.html` | One widget definition, as a fragment | Every origin |
|
|
226
|
+
|
|
227
|
+
As stated in [Chrome](#chrome), `chrome.html` is a required singleton.
|
|
228
|
+
|
|
229
|
+
As stated in [Pages](#pages), the `<stub>` of a `.page.html` is the path the
|
|
230
|
+
page maps to. The builder puts all pages into `dist/app.html` as HTML `<template>` objects
|
|
231
|
+
that carry `lb-page="<stub>"`.
|
|
232
|
+
|
|
233
|
+
A widget file is exactly `<kebab-case-name>.html`. A [widget](#widgets) is
|
|
234
|
+
an HTML custom element, suitable for organizing large HTML trees, or adding
|
|
235
|
+
custom behavior, or both. A widget definition is named for the tag it expands.
|
|
236
|
+
|
|
237
|
+
Any other HTML file, one that is not `chrome.html`, or `<stub>.page.html` or
|
|
238
|
+
`<kebab-case-name>.html` will either:
|
|
239
|
+
- be an error if it looks like a widget with capitalization
|
|
240
|
+
- be skipped
|
|
241
|
+
|
|
242
|
+
## HTML
|
|
243
|
+
|
|
244
|
+
In a Loadbare/app application, HTML is static after the build, and once
|
|
245
|
+
it is sent to the browser on initial page load, no HTML is ever sent
|
|
246
|
+
again.
|
|
247
|
+
|
|
248
|
+
### Widget Expansion
|
|
249
|
+
|
|
250
|
+
The builder executes a process we call "expansion". When it finds
|
|
251
|
+
a custom element in the HTML it is processing, such as `<my-element>`,
|
|
252
|
+
it looks for the file `<my-element>.html`, and follows the expansion
|
|
253
|
+
rules to place the contents of `<my-element>.html`.
|
|
254
|
+
|
|
255
|
+
A custom element with no definition file is left alone. A custom element
|
|
256
|
+
with neither a definition nor a `.browser.ts` script is a build error, as
|
|
257
|
+
stated in [Widgets](#widgets).
|
|
258
|
+
|
|
259
|
+
#### Build time parameters
|
|
260
|
+
|
|
261
|
+
A build time parameter is supplied as an attribute on a custom element,
|
|
262
|
+
and is converted to a fixed value within the HTML by the builder.
|
|
263
|
+
|
|
264
|
+
The attribute value carries an `exp-` prefix, as in `exp-label`, and
|
|
265
|
+
the substitution locations use `{{label}}` (no exp-prefix) inside the
|
|
266
|
+
widget's HTML definition file:
|
|
267
|
+
|
|
268
|
+
```html
|
|
269
|
+
<!-- lb-input.html, the definition -->
|
|
270
|
+
<label>{{label}} <input readonly="{{readonly}}" /></label>
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
```html
|
|
274
|
+
<!-- a page -->
|
|
275
|
+
<lb-input lb-cell="name" exp-label="Name"></lb-input>
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
```html
|
|
279
|
+
<!-- dist/app.html -->
|
|
280
|
+
<lb-input lb-cell="name" exp-label="Name"
|
|
281
|
+
><label>Name <input /></label
|
|
282
|
+
></lb-input>
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
A definition states a default with `{{name|default}}`, as in
|
|
286
|
+
`{{button-label|OK}}`. Whitespace around the name and around the default is
|
|
287
|
+
discarded. The default is a literal.
|
|
288
|
+
|
|
289
|
+
| The attribute is assigned | Expansion defines | Result |
|
|
290
|
+
| ------------------------- | ------------------- | -------------------------------- |
|
|
291
|
+
| `exp-name="text"` | `{{name}}` | `text` |
|
|
292
|
+
| `exp-name=""` | `{{name}}` | An empty string |
|
|
293
|
+
| Nothing | `{{name\|default}}` | `default` |
|
|
294
|
+
| Nothing | `{{name}}` | Nothing, and the attribute drops |
|
|
295
|
+
| `exp-name` | No `{{name}}` | A build error |
|
|
296
|
+
|
|
297
|
+
Attributes without the `exp-` prefix are ignored during expansion.
|
|
298
|
+
|
|
299
|
+
A placeholder is the whole of an attribute value or the whole of a text node.
|
|
300
|
+
`title="Hello {{name}}"` ships literally.
|
|
301
|
+
|
|
302
|
+
A placeholder name carrying a capital is a build error.
|
|
303
|
+
|
|
304
|
+
A parameter value cannot become markup.
|
|
305
|
+
|
|
306
|
+
#### Slots and templates
|
|
307
|
+
|
|
308
|
+
A widget definition may contain any number of named templates and optionally
|
|
309
|
+
one slot.
|
|
310
|
+
|
|
311
|
+
This simplified definition of `lb-table` names two templates, `head` and
|
|
312
|
+
`foot`, and marks `<tbody>` as the slot. A page supplies whichever templates
|
|
313
|
+
it wants, and everything else it writes goes to the slot.
|
|
314
|
+
|
|
315
|
+
```html
|
|
316
|
+
<!-- lb-table.html, the definition -->
|
|
317
|
+
<table>
|
|
318
|
+
<caption>
|
|
319
|
+
{{caption}}
|
|
320
|
+
</caption>
|
|
321
|
+
<thead lb-template="head"></thead>
|
|
322
|
+
<tbody lb-slot></tbody>
|
|
323
|
+
<tfoot lb-template="foot"></tfoot>
|
|
324
|
+
</table>
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
When we use `lb-table` in HTML, the example below supplies the header
|
|
328
|
+
template and an unnamed template. The unnamed one names neither `head` nor
|
|
329
|
+
`foot`, so it goes to the slot. This usage writes no footer.
|
|
330
|
+
|
|
331
|
+
```html
|
|
332
|
+
<!-- a page -->
|
|
333
|
+
<lb-table lb-list="staff" exp-caption="Everyone, by team">
|
|
334
|
+
<template lb-template="head">
|
|
335
|
+
<tr><th>Name</th><th>Role</th></tr>
|
|
336
|
+
</template>
|
|
337
|
+
<template lb-key="id">
|
|
338
|
+
<tr><td lb-cell="name"></td><td lb-cell="role"></td></tr>
|
|
339
|
+
</template>
|
|
340
|
+
</lb-table>
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
When a named template is expanded, the `<template>` tag is discarded and its
|
|
344
|
+
contents are placed as children of the tag that names it. The built document
|
|
345
|
+
holds:
|
|
346
|
+
|
|
347
|
+
```html
|
|
348
|
+
<!-- dist/app.html -->
|
|
349
|
+
<lb-table lb-list="staff" exp-caption="Everyone, by team"
|
|
350
|
+
><table>
|
|
351
|
+
<caption>
|
|
352
|
+
Everyone, by team
|
|
353
|
+
</caption>
|
|
354
|
+
<thead>
|
|
355
|
+
<tr>
|
|
356
|
+
<th>Name</th>
|
|
357
|
+
<th>Role</th>
|
|
358
|
+
</tr>
|
|
359
|
+
</thead>
|
|
360
|
+
<tbody>
|
|
361
|
+
<template lb-key="id">
|
|
362
|
+
<tr>
|
|
363
|
+
<td lb-cell="name"></td>
|
|
364
|
+
<td lb-cell="role"></td>
|
|
365
|
+
</tr>
|
|
366
|
+
</template>
|
|
367
|
+
</tbody>
|
|
368
|
+
<tfoot></tfoot></table
|
|
369
|
+
></lb-table>
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
These are build errors:
|
|
373
|
+
|
|
374
|
+
- A definition with two templates of one name
|
|
375
|
+
- A definition with more than one `lb-slot`
|
|
376
|
+
- A page naming a template the definition does not have
|
|
377
|
+
- A page giving two templates for one name
|
|
378
|
+
- Content written in a widget whose definition has no slot
|
|
379
|
+
|
|
380
|
+
### Binding
|
|
381
|
+
|
|
382
|
+
Binding attributes determine how the hub updates the DOM, either by
|
|
383
|
+
directly updating a plain HTML element or instructing
|
|
384
|
+
custom widgets to update themselves.
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
| Attribute | Assigned By | Behavior |
|
|
388
|
+
| ------------ | ----------- | ----------------------------------------------------------------------------------------------- |
|
|
389
|
+
| lb-list | Developer | Scopes DOM children to a named set of rows; a nested lb-list or lb-row begins a new scope |
|
|
390
|
+
| lb-row | Developer | Scopes DOM children to one named row; a nested lb-list or lb-row begins a new scope |
|
|
391
|
+
| lb-cell | Developer | This DOM node displays this column of the row in scope |
|
|
392
|
+
| lb-show | Developer | This DOM node is present when this column of the row in scope is neither null nor false |
|
|
393
|
+
| lb-key | Developer | Names the column that identifies a row, on the row template inside an lb-list |
|
|
394
|
+
| lb-key-value | Hub | Stamped on a live row: that row's value of `lb-key` |
|
|
395
|
+
| lb-value | Hub | The value that landed on a cell; a widget updates itself from it and a stylesheet selects on it |
|
|
396
|
+
|
|
397
|
+
#### How a value lands
|
|
398
|
+
|
|
399
|
+
A cell lands one of three ways, and the element decides which. Every cell
|
|
400
|
+
that receives a value also carries it as `lb-value`.
|
|
401
|
+
|
|
402
|
+
| Element | Receives the value as |
|
|
403
|
+
| -------------------------------------- | --------------------------------- |
|
|
404
|
+
| A custom element, tag hyphenated | Its `lb-value` attribute |
|
|
405
|
+
| `<select>`, `<textarea>`, or `<input>` | Its `value`, and `lb-value` |
|
|
406
|
+
| Any other native element | Its `textContent`, and `lb-value` |
|
|
407
|
+
|
|
408
|
+
A widget owns whatever control it wraps, so it is handed the value and
|
|
409
|
+
renders it itself. A form control shows its state as its `value`, so a
|
|
410
|
+
`<select>` keeps its options. Any other native element has no behavior of its
|
|
411
|
+
own, so its value is its text.
|
|
412
|
+
|
|
413
|
+
A form gathers from the same controls it lands on, so a value read back on
|
|
414
|
+
submit is the one that landed.
|
|
415
|
+
|
|
416
|
+
An `<input>` of type `checkbox`, `radio`, or `file` receives nothing, not even
|
|
417
|
+
`lb-value`, and the hub reports it to the console. A form gathering one skips it the same way.
|
|
418
|
+
|
|
419
|
+
A `<select>` with no option for the value shows no selection.
|
|
420
|
+
|
|
421
|
+
Only the hyphen and these three form controls are recognized. The hub holds
|
|
422
|
+
no other knowledge of any particular element, and the hyphen also decides
|
|
423
|
+
that the hub leaves a widget's own clicks alone — see [Requests](#requests).
|
|
424
|
+
|
|
425
|
+
Nothing an application writes ever sets `lb-value`. Loadbare writes it, and
|
|
426
|
+
a widget or a stylesheet reads it.
|
|
427
|
+
|
|
428
|
+
Loadbare also removes it, when a successful insert resets the cells it
|
|
429
|
+
gathered — see [The round trip](#the-round-trip). A widget reads a removed
|
|
430
|
+
`lb-value` as "nothing landed here" and returns its control to its default,
|
|
431
|
+
the way a form control with no `value` attribute shows its default. A blank
|
|
432
|
+
`lb-value` is a value like any other.
|
|
433
|
+
|
|
434
|
+
The value arrives as the query produced it, with no conversion, so the
|
|
435
|
+
browser decides what a non-string looks like.
|
|
436
|
+
|
|
437
|
+
A cell holds one value. A set of values is a list of its own, never an array
|
|
438
|
+
in a cell.
|
|
439
|
+
|
|
440
|
+
A widget sees `attributeChangedCallback` for an `lb-value` already present
|
|
441
|
+
when it upgrades, so a widget cannot tell a first landing from a refresh,
|
|
442
|
+
and does not need to.
|
|
443
|
+
|
|
444
|
+
#### Displaying by condition
|
|
445
|
+
|
|
446
|
+
`lb-show` names the column that decides whether an element is present.
|
|
447
|
+
`null` and `false` are off, and every other value is on. No string is read,
|
|
448
|
+
so `"false"` is on, and a query spells a condition as a boolean or a null.
|
|
449
|
+
|
|
450
|
+
```html
|
|
451
|
+
<template lb-key="id">
|
|
452
|
+
<tr>
|
|
453
|
+
<td lb-cell="name"></td>
|
|
454
|
+
<td><button lb-action="lb-row-delete" lb-show="removable">Remove</button></td>
|
|
455
|
+
</tr>
|
|
456
|
+
</template>
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
It binds as `lb-cell` does, to the row on the nearest scoped ancestor, and on
|
|
460
|
+
an element that is itself a scope the column belongs to the row around it. A row
|
|
461
|
+
that does not carry the column leaves the element as it is.
|
|
462
|
+
|
|
463
|
+
An element that is off is moved into a `<template lb-show="column">` standing
|
|
464
|
+
where it stood, and moved back out when the column turns on. It is not
|
|
465
|
+
rendered, focused, clicked, announced or gathered. It is moved and never
|
|
466
|
+
rebuilt, so a widget keeps its instance. Landing reaches into that template,
|
|
467
|
+
and nothing else does, so the element and every cell and scope inside it
|
|
468
|
+
return current. A custom element sees `disconnectedCallback` then
|
|
469
|
+
`adoptedCallback` going in, and `adoptedCallback` then `connectedCallback`
|
|
470
|
+
coming out, and still receives `lb-value` while it is away.
|
|
471
|
+
|
|
472
|
+
The builder ships every `lb-show` element already inside its template, so
|
|
473
|
+
nothing conditional shows until its row lands. An absent element's template
|
|
474
|
+
keeps its place among its siblings, and a position selector counts it.
|
|
475
|
+
|
|
476
|
+
These are build errors: `lb-show` on a row template's root, with no row
|
|
477
|
+
around it (outside every scope, on a scope with none around it, or in a list
|
|
478
|
+
scope outside its row template), or on a `<template>`.
|
|
479
|
+
|
|
480
|
+
Hiding is presentation, and the server still refuses what a request may not
|
|
481
|
+
do.
|
|
482
|
+
|
|
483
|
+
#### Master-detail
|
|
484
|
+
|
|
485
|
+
A master is a row and its detail is a list, as two names answered side by
|
|
486
|
+
side. A cell never holds rows.
|
|
487
|
+
|
|
488
|
+
```html
|
|
489
|
+
<section lb-row="invoice">
|
|
490
|
+
<h2 lb-cell="number"></h2>
|
|
491
|
+
<span lb-cell="customer"></span>
|
|
492
|
+
</section>
|
|
493
|
+
|
|
494
|
+
<table>
|
|
495
|
+
<tbody lb-list="invoiceLines">
|
|
496
|
+
<template lb-key="id"><tr><td lb-cell="item"></td><td lb-cell="amount"></td></tr></template>
|
|
497
|
+
</tbody>
|
|
498
|
+
</table>
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
Many masters, each with its own detail, is one list of joined rows: each
|
|
502
|
+
detail row carries its master's columns. A widget's `lbPlaceRow` groups them
|
|
503
|
+
for display, as `lb-table` builds sections and `lb-options` builds
|
|
504
|
+
`<optgroup>`s.
|
|
505
|
+
|
|
506
|
+
A list nested in another list's rows receives the same rows in every outer
|
|
507
|
+
row. That serves a picker offering the same choices on every row, and is
|
|
508
|
+
not a way to show a different detail per row.
|
|
509
|
+
|
|
510
|
+
Which master a page shows is server state reached through `ctx`, since a
|
|
511
|
+
query takes no argument from the browser — see the blocker on view parameters.
|
|
512
|
+
|
|
513
|
+
### Requests
|
|
514
|
+
|
|
515
|
+
---- UNEDITED ----
|
|
516
|
+
|
|
517
|
+
Any element can carry the `lb-action` attribute. The hub listens for
|
|
518
|
+
events `click` and `submit`, and fires a server request when it catches
|
|
519
|
+
one of those events.
|
|
520
|
+
|
|
521
|
+
The hub does not act on `click` or `submit` on a custom widget, they
|
|
522
|
+
must fire their own event. The assumption is a custom widget is present
|
|
523
|
+
because custom behavior is desired, and we don't want the hub to conflict
|
|
524
|
+
with that custom behavior. A widget is told apart by the hyphen in its tag
|
|
525
|
+
name, the same test that decides how a value lands — see
|
|
526
|
+
[How a value lands](#how-a-value-lands).
|
|
527
|
+
|
|
528
|
+
| lb-action | Written on |
|
|
529
|
+
| -------------- | ------------------------------------------------- |
|
|
530
|
+
| lb-row-insert | a `<form>`, or a button in a `<tr>`, in a list |
|
|
531
|
+
| lb-row-delete | anything inside a live row |
|
|
532
|
+
| lb-row-update | a `<form>`, a button in a live row, or a widget cell |
|
|
533
|
+
| anything else | must be a named routine in the page's server code |
|
|
534
|
+
|
|
535
|
+
The wire format is not visible to the user, but uses the same lb-*
|
|
536
|
+
attributes minus their prefix, so that it is intelligible when working on
|
|
537
|
+
Loadbare/app itself.
|
|
538
|
+
|
|
539
|
+
The hub scopes every request, whether a native element or a widget
|
|
540
|
+
dispatched it. It reads the scope from the dispatching element before any
|
|
541
|
+
ancestor sees the event, and never overwrites a field the request already
|
|
542
|
+
carries.
|
|
543
|
+
|
|
544
|
+
| `action` | Filled from scope | Required |
|
|
545
|
+
| ---------------- | ------------------------------ | ---------------------- |
|
|
546
|
+
| a declared name | `list` or `row`, `key`, `cell` | nothing |
|
|
547
|
+
| `lb-row-insert` | `list` | `list`, and `values` |
|
|
548
|
+
| `lb-row-delete` | `list`, `key` | both |
|
|
549
|
+
| `lb-row-update` | `list`, `key` | both, and `values` |
|
|
550
|
+
|
|
551
|
+
An element's own `lb-list` or `lb-row` names what it displays, never where
|
|
552
|
+
its request goes. A request belongs to the scope around the element, the
|
|
553
|
+
way a control belongs to the form around it. `list` or `row` comes from the
|
|
554
|
+
nearest ancestor scope, `key` from the nearest live row inside that scope,
|
|
555
|
+
and `cell` from the dispatching element's own `lb-cell`.
|
|
556
|
+
A request missing a required field is not sent. The hub never fills
|
|
557
|
+
`value`. An `lb-row-insert` or `lb-row-update` from an element carrying
|
|
558
|
+
`lb-cell` is a record of one cell, the way a control has a value and a form
|
|
559
|
+
has values: `values` holds that cell alone, taken from the `value` the widget
|
|
560
|
+
sent or else read from the control it is or wraps, and `value` is not sent
|
|
561
|
+
beside it. A widget that sends a `value` from an element carrying no
|
|
562
|
+
`lb-cell` is refused, since nothing names the column. Any other
|
|
563
|
+
`lb-row-insert` or `lb-row-update` gathers the row it belongs
|
|
564
|
+
to: `values` holds every `lb-cell` with a control to read in the nearest
|
|
565
|
+
`<form>`, `<tr>` or live row around the dispatching element, itself
|
|
566
|
+
included, inside its scope. The cells are found the way a row lands, so a
|
|
567
|
+
cell inside a scope nested in the row is that scope's and is not gathered,
|
|
568
|
+
while an element carrying a scope and `lb-cell` both is the row's cell.
|
|
569
|
+
This is a button's form owner: what else sits
|
|
570
|
+
beside the element never changes what is sent. A `<tr>` counts because a
|
|
571
|
+
form cannot go around a table row's controls, so a new row in a table is its
|
|
572
|
+
own form; a live row counts because it is the row the key names. The scope
|
|
573
|
+
itself is never the row, since its cells belong to other rows. A request
|
|
574
|
+
from an element in no form or row is not sent, and the hub reports that its
|
|
575
|
+
cells belong in a `<form>`. A request that already carries `values` keeps
|
|
576
|
+
them, and one whose row has no cell to read is not sent. A click on a
|
|
577
|
+
native element that carries either operation and is a cell or
|
|
578
|
+
holds cells is not sent, since clicking into one of its controls
|
|
579
|
+
would send the row: put the action on a form, on a button, or on a widget
|
|
580
|
+
that decides when its cell has changed.
|
|
581
|
+
|
|
582
|
+
A widget dispatches the action and, where it wraps a control, that control's
|
|
583
|
+
value.
|
|
584
|
+
|
|
585
|
+
```
|
|
586
|
+
{ action: "lb-row-insert", list: "rosterList", values: {...} }
|
|
587
|
+
{ action: "lb-row-delete", list: "rosterList", key: "42" }
|
|
588
|
+
{ action: "lb-row-update", list: "rosterList", key: "42", values: {...} }
|
|
589
|
+
{ action: "lb-row-update", list: "rosterList", key: "42", values: { name: "Ann" } }
|
|
590
|
+
{ action: "selectTab", row: "prefs", cell: "active_tab", value: "two" }
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
#### The request event
|
|
594
|
+
|
|
595
|
+
The hub does not send a request the moment it catches a click or a submit.
|
|
596
|
+
It builds the request, dispatches it from the element that acted as a
|
|
597
|
+
bubbling `lb-request` event carrying the request as its `detail`, and a
|
|
598
|
+
listener on the hub sends it.
|
|
599
|
+
|
|
600
|
+
A widget uses that same event, and it is the only channel a widget has for
|
|
601
|
+
firing a request of its own. A native element and a hand-written widget
|
|
602
|
+
therefore produce identical events.
|
|
603
|
+
|
|
604
|
+
An ancestor sees the request on its way up and may stop it. The event is
|
|
605
|
+
not cancelable, so an interceptor calls `stopPropagation`, not
|
|
606
|
+
`preventDefault`. This is what makes a confirmation wrapper possible
|
|
607
|
+
without the wrapped element knowing about it.
|
|
608
|
+
|
|
609
|
+
#### The round trip
|
|
610
|
+
|
|
611
|
+
A request the hub sends has ten seconds to come back. Past that the hub
|
|
612
|
+
aborts it and treats it as a failure, since `fetch` imposes no deadline of
|
|
613
|
+
its own. An application cannot change the deadline.
|
|
614
|
+
|
|
615
|
+
A round trip fails on a server error, on a network failure, or on that
|
|
616
|
+
deadline, and all three set `lb-error` on the element that dispatched the
|
|
617
|
+
request — see [Request state](#request-state).
|
|
618
|
+
|
|
619
|
+
After a write succeeds, the cells it gathered show what the server holds.
|
|
620
|
+
An `lb-row-update` does this by landing the row on them. An
|
|
621
|
+
`lb-row-insert` does it by resetting them, the way `form.reset()` resets a
|
|
622
|
+
form, because the row they held now lives in the list. The hub resets
|
|
623
|
+
after it lands the response, and only what it gathered:
|
|
624
|
+
|
|
625
|
+
- Each control returns to its default: an `<input>` or `<textarea>` to its
|
|
626
|
+
`defaultValue`, a `<select>` to the options marked `selected`. A page
|
|
627
|
+
that wants a prefilled insert writes a `value` attribute, as in plain
|
|
628
|
+
HTML.
|
|
629
|
+
- A control showing something other than the value the hub read holds an
|
|
630
|
+
edit made during the round trip. That edit was not sent, and is left.
|
|
631
|
+
- `lb-value` comes off each reset cell, and off its control, before the
|
|
632
|
+
control resets — see [How a value lands](#how-a-value-lands).
|
|
633
|
+
- Values a widget supplied in the request were not gathered, and are not
|
|
634
|
+
reset.
|
|
635
|
+
- Nothing is dispatched, as `form.reset()` fires no `change`.
|
|
636
|
+
|
|
637
|
+
A failed insert resets nothing, so the entry can be corrected.
|
|
638
|
+
|
|
639
|
+
A navigation that fails to load its data sets nothing. No element
|
|
640
|
+
dispatched it, so there is nothing to stamp, and the hub reports it to the
|
|
641
|
+
console.
|
|
642
|
+
|
|
643
|
+
### Links
|
|
644
|
+
|
|
645
|
+
---- UNEDITED ----
|
|
646
|
+
|
|
647
|
+
An anchor carrying `lb-nav-link` navigates inside the application: the hub
|
|
648
|
+
catches the click, pushes the anchor's path onto history, and swaps the page
|
|
649
|
+
host in `<main>`. An anchor without it is left alone and behaves like any
|
|
650
|
+
other link, so leaving the application is the default and staying in it is
|
|
651
|
+
the opt-in.
|
|
652
|
+
|
|
653
|
+
| Attribute | Assigned By | Behavior |
|
|
654
|
+
| ----------- | ----------- | --------------------------------------------------------------------------------------- |
|
|
655
|
+
| lb-nav-link | Developer | On an `<a>`: the hub shows the page the anchor's path names, without loading a document |
|
|
656
|
+
|
|
657
|
+
The attribute takes no value. The hub looks for the nearest ancestor
|
|
658
|
+
link to determine the path.
|
|
659
|
+
|
|
660
|
+
Path space is flat. A path such as `/members` links to the `members.*` files
|
|
661
|
+
on the server.
|
|
662
|
+
|
|
663
|
+
The bare path `/` resolves to `index`.
|
|
664
|
+
|
|
665
|
+
A path that names no page is detected in the browser, after a successful
|
|
666
|
+
200: every route gets the same document, so there is no server-delivered
|
|
667
|
+
404. A chrome that declares an `lb-unknown-page` dialog gets it opened.
|
|
668
|
+
One that declares none gets a console error and nothing on screen. See
|
|
669
|
+
[Chrome](#chrome).
|
|
670
|
+
|
|
671
|
+
```html
|
|
672
|
+
<nav>
|
|
673
|
+
<a href="/" lb-nav-link>Home</a>
|
|
674
|
+
<a href="/members" lb-nav-link>Members</a>
|
|
675
|
+
<a href="https://example.com/docs">Docs</a>
|
|
676
|
+
</nav>
|
|
677
|
+
```
|
|
678
|
+
|
|
679
|
+
See also [Navigation Row lb-navigation](#lb-navigation).
|
|
680
|
+
|
|
681
|
+
#### What a URL names
|
|
682
|
+
|
|
683
|
+
A URL names a page, a place in the application. It never names a resource,
|
|
684
|
+
and Loadbare/app does not reproduce REST: `/accounts/42` is not a way to
|
|
685
|
+
reach account 42.
|
|
686
|
+
|
|
687
|
+
A page declares what it shows, its queries, and what it allows, its actions.
|
|
688
|
+
Loading a page runs its queries. A request performs an action at a position.
|
|
689
|
+
A row is addressed by `list` and `key`, taken from where the element sits,
|
|
690
|
+
which is how the database already names it. Nothing is fetched by URL, so an
|
|
691
|
+
application designs no endpoints, and the browser reaches only what a page
|
|
692
|
+
publishes.
|
|
693
|
+
|
|
694
|
+
Whether a page URL may carry parameters, so that a link can open the page on
|
|
695
|
+
one record, is undecided — see the blockers.
|
|
696
|
+
|
|
697
|
+
### lb-navigation
|
|
698
|
+
|
|
699
|
+
---- UNEDITED ----
|
|
700
|
+
|
|
701
|
+
Status: 1.0-RC.
|
|
702
|
+
|
|
703
|
+
Current page, published by the hub as a row. Can be bound anywhere just
|
|
704
|
+
like a server-produced result.
|
|
705
|
+
|
|
706
|
+
| Cell | Holds |
|
|
707
|
+
| ------------ | ------------------------------------------------------------------- |
|
|
708
|
+
| `page-label` | The text of the link to the current page, empty if no link names it |
|
|
709
|
+
| `page-uri` | The path as the browser has it, such as `/members` |
|
|
710
|
+
|
|
711
|
+
The `page-uri` is taken from the current URL. The `page-label` is taken from the first
|
|
712
|
+
`lb-nav-link` link in the document (presumably in a nav bar) that matches the URI.
|
|
713
|
+
|
|
714
|
+
The row lands before the page is looked up, so a path that names no page has
|
|
715
|
+
it too, and an `lb-unknown-page` dialog, where the chrome has one, displays
|
|
716
|
+
it by naming the row like any other subtree.
|
|
717
|
+
|
|
718
|
+
It lands only where a subtree names it. A chrome that displays no
|
|
719
|
+
navigation is not warned about a row with nowhere to go.
|
|
720
|
+
|
|
721
|
+
```html
|
|
722
|
+
<header lb-row="lb-navigation">
|
|
723
|
+
<h2 lb-cell="page-label"></h2>
|
|
724
|
+
</header>
|
|
725
|
+
```
|
|
726
|
+
|
|
727
|
+
See also [Links](#links).
|
|
728
|
+
|
|
729
|
+
## Application files
|
|
730
|
+
|
|
731
|
+
### Chrome
|
|
732
|
+
|
|
733
|
+
The Loadbare/app builder always requires exactly one file
|
|
734
|
+
named `chrome.html`, located anywhere in builder `--src`.
|
|
735
|
+
|
|
736
|
+
The chrome is the application's single HTML document. This is
|
|
737
|
+
where the standard landmarks go: header, nav, footer, main.
|
|
738
|
+
|
|
739
|
+
The file is an HTML document, which must contain:
|
|
740
|
+
- `<lb-hub>` inside `<body>`. The hub can only act on its children,
|
|
741
|
+
that is why it is usually nested right below `<body>`.
|
|
742
|
+
- One empty `<main>` inside `<lb-hub>`.
|
|
743
|
+
- The script tag for `/client.js`, the javascript bundle.
|
|
744
|
+
|
|
745
|
+
It may also contain:
|
|
746
|
+
- `/app.css`, the stylesheet bundle
|
|
747
|
+
- A `<dialog>` marked with attribute `lb-unknown-page`, which the hub
|
|
748
|
+
will display to the user if an attempt is made to navigate to an
|
|
749
|
+
unknown page. It goes inside `<lb-hub>`, like everything the hub acts
|
|
750
|
+
on; the builder rejects one placed elsewhere.
|
|
751
|
+
- The `hidden` attribute on `<body>`, which the hub removes once the first page has landed.
|
|
752
|
+
|
|
753
|
+
```html
|
|
754
|
+
<!-- src/chrome.html -->
|
|
755
|
+
<!doctype html>
|
|
756
|
+
<html lang="en">
|
|
757
|
+
<head>
|
|
758
|
+
<meta charset="utf-8" />
|
|
759
|
+
<title>Membership Roster</title>
|
|
760
|
+
<script src="/client.js" defer></script>
|
|
761
|
+
<link rel="stylesheet" href="/app.css" />
|
|
762
|
+
</head>
|
|
763
|
+
<body hidden>
|
|
764
|
+
<lb-hub>
|
|
765
|
+
<header lb-row="lb-navigation">
|
|
766
|
+
<h1>Membership Roster</h1>
|
|
767
|
+
<h2 lb-cell="page-label"></h2>
|
|
768
|
+
</header>
|
|
769
|
+
<nav>
|
|
770
|
+
<a href="/" lb-nav-link>Home</a>
|
|
771
|
+
<a href="/members" lb-nav-link>Members</a>
|
|
772
|
+
<a href="https://example.org/">Our website</a>
|
|
773
|
+
</nav>
|
|
774
|
+
<main></main>
|
|
775
|
+
<dialog lb-unknown-page lb-row="lb-navigation">
|
|
776
|
+
The URL <span lb-cell="page-uri"></span> is not in this app.
|
|
777
|
+
</dialog>
|
|
778
|
+
</lb-hub>
|
|
779
|
+
</body>
|
|
780
|
+
</html>
|
|
781
|
+
```
|
|
782
|
+
|
|
783
|
+
The `lb-row`, `lb-cell` and `lb-nav-link` attributes in that example are
|
|
784
|
+
ordinary Loadbare/app binding. See [Binding](#binding),
|
|
785
|
+
[Links](#links) and [lb-navigation](#lb-navigation).
|
|
786
|
+
|
|
787
|
+
### Pages
|
|
788
|
+
|
|
789
|
+
The page namespace is flat. Loadbare/app does not care where in the `--src`
|
|
790
|
+
the page files are located, but they must be unique across the application.
|
|
791
|
+
A page `/deep/path/to/mypage.html` is routed to `/mypage`.
|
|
792
|
+
|
|
793
|
+
Pages are grouped as
|
|
794
|
+
- <stub>.page.html is recognized as navigable and capable of
|
|
795
|
+
having associated queries and requests
|
|
796
|
+
- <stub>.queries.ts are the queries for a page
|
|
797
|
+
- <stub>.requests.ts respond to the requests from the browser
|
|
798
|
+
|
|
799
|
+
The <stub> value for a page must match the path used in links,
|
|
800
|
+
so that `<a href='/members' lb-nav-link>Members</a>` has matching
|
|
801
|
+
files `members.pages.html` et al.
|
|
802
|
+
|
|
803
|
+
#### Page HTML
|
|
804
|
+
|
|
805
|
+
The markup in `<stub>.page.html` is the same HTML as everywhere else
|
|
806
|
+
in a Loadbare/app application, see [HTML](#html).
|
|
807
|
+
|
|
808
|
+
The builder wraps each expanded page in `<template lb-page="<stub>">` and
|
|
809
|
+
puts it in the built document. The application never writes `lb-page`; the
|
|
810
|
+
hub reads it to find the page a path names.
|
|
811
|
+
|
|
812
|
+
## The server
|
|
813
|
+
|
|
814
|
+
A page's server half is two files, `<stub>.queries.ts` and
|
|
815
|
+
`<stub>.requests.ts`. Each pairs with `<stub>.page.html` by sharing its
|
|
816
|
+
stub, as stated in [Pages](#pages). Either may be absent, and one with no
|
|
817
|
+
matching page is a build error.
|
|
818
|
+
|
|
819
|
+
### The Express server
|
|
820
|
+
|
|
821
|
+
Loadbare/app ships no server. The application writes an ordinary Express
|
|
822
|
+
app. Express is a peer dependency, installed by the application.
|
|
823
|
+
|
|
824
|
+
The builder's artifacts oblige that server to handle four things: the
|
|
825
|
+
client script, the stylesheet, the hub's data channel, and the one HTML
|
|
826
|
+
document.
|
|
827
|
+
|
|
828
|
+
| Handle | With |
|
|
829
|
+
| ---------------------------- | ------------------- |
|
|
830
|
+
| `/client.js` | `dist/client.js` |
|
|
831
|
+
| `/app.css` | `dist/app.css` |
|
|
832
|
+
| `hubRoutes(hub, contextFor)` | The hub's own route |
|
|
833
|
+
| Every other GET | `dist/app.html` |
|
|
834
|
+
|
|
835
|
+
The builder writes `pages.ts` into `--out` whenever any page has a
|
|
836
|
+
`.queries.ts` or a `.requests.ts` file. It imports each of them, calls
|
|
837
|
+
`createHub()` once over the lot, and exports the result as `hub`. The
|
|
838
|
+
server imports that rather than maintaining the registry by hand.
|
|
839
|
+
|
|
840
|
+
```ts
|
|
841
|
+
// server.ts
|
|
842
|
+
import path from "node:path";
|
|
843
|
+
import { readFileSync } from "node:fs";
|
|
844
|
+
import express, { type Request } from "express";
|
|
845
|
+
import { hubRoutes } from "@loadbare/app/express";
|
|
846
|
+
import type { HubContext } from "@loadbare/app/server";
|
|
847
|
+
import { hub } from "./dist/pages";
|
|
848
|
+
import { openDb } from "./src/database";
|
|
849
|
+
|
|
850
|
+
const DIST = path.resolve("dist");
|
|
851
|
+
const app = express();
|
|
852
|
+
|
|
853
|
+
// All data requests are handled by the hub
|
|
854
|
+
// This example shows an application-specific openDB()
|
|
855
|
+
function contextFor(_req: Request): HubContext {
|
|
856
|
+
return { db: openDb() };
|
|
857
|
+
}
|
|
858
|
+
app.use(hubRoutes(hub, contextFor));
|
|
859
|
+
|
|
860
|
+
// Static assets, then the catch-all for app.html
|
|
861
|
+
app.get("/client.js", (_req, res) => res.sendFile(path.join(DIST, "client.js")));
|
|
862
|
+
app.get("/app.css", (_req, res) => res.sendFile(path.join(DIST, "app.css")));
|
|
863
|
+
app.get(/.*/, (_req, res) =>
|
|
864
|
+
res.type("html").send(readFileSync(path.join(DIST, "app.html"), "utf-8")),
|
|
865
|
+
);
|
|
866
|
+
|
|
867
|
+
app.listen(8787);
|
|
868
|
+
```
|
|
869
|
+
|
|
870
|
+
Explaining Express is beyond the scope of this technical reference. The
|
|
871
|
+
only real requirement is that the catch-all for app.html is at the end,
|
|
872
|
+
so it does not catch any other files.
|
|
873
|
+
|
|
874
|
+
Give the server the origin root. The hub reaches its own endpoints by
|
|
875
|
+
absolute path, so an application cannot be hosted under a subpath such as
|
|
876
|
+
`example.com/myapp/`, and anything proxying in front of the server passes
|
|
877
|
+
the whole path space through unchanged.
|
|
878
|
+
|
|
879
|
+
### Page Queries
|
|
880
|
+
|
|
881
|
+
`<stub>.queries.ts` exports one object named `queries`, typed `Queries`.
|
|
882
|
+
Each key is a query name, and the markup binds to that name through
|
|
883
|
+
`lb-list` or `lb-row`.
|
|
884
|
+
|
|
885
|
+
Cardinality belongs to the named query. One named query always returns a single
|
|
886
|
+
row or an array of rows. Build a query using `row()` or `list()` to return
|
|
887
|
+
the two shapes. A query cannot be built without one of these functions.
|
|
888
|
+
|
|
889
|
+
Queries names cannot begin with `lb-`, that namespace is reserved for
|
|
890
|
+
Loadbare/app queries the hub makes available in the browser, such
|
|
891
|
+
as [lb-navigation](#lb-navigation).
|
|
892
|
+
|
|
893
|
+
```ts
|
|
894
|
+
// members.queries.ts
|
|
895
|
+
import { list, row, type Queries } from "@loadbare/app/server";
|
|
896
|
+
|
|
897
|
+
export const queries: Queries = {
|
|
898
|
+
roster: list((ctx) => ctx.db.members()),
|
|
899
|
+
summary: row(async (ctx) => ({ count: String(await ctx.db.memberCount()) })),
|
|
900
|
+
};
|
|
901
|
+
```
|
|
902
|
+
|
|
903
|
+
Every query and every request receives `ctx`, the application's own request
|
|
904
|
+
context. The application builds it once per request and hands it to the hub,
|
|
905
|
+
see [The Express server](#the-express-server). Loadbare/app declares it empty
|
|
906
|
+
and never reads it, so a query finds exactly what the application put there,
|
|
907
|
+
which is usually a database handle opened for the authenticated caller.
|
|
908
|
+
|
|
909
|
+
Queries should not return deltas, deltas are handled in the `.requests.ts` file
|
|
910
|
+
as explained in the next section.
|
|
911
|
+
|
|
912
|
+
### Page Requests
|
|
913
|
+
|
|
914
|
+
`<stub>.requests.ts` exports one object named `requests`, typed `Requests`.
|
|
915
|
+
It has three optional keys.
|
|
916
|
+
|
|
917
|
+
| Key | Keyed by | Answers |
|
|
918
|
+
| ------------- | --------------------- | -------------------------------------------------- |
|
|
919
|
+
| `actions` | The `lb-action` value | Anything the page chooses to declare |
|
|
920
|
+
| `crud` | A query name | The three reserved `lb-action` values |
|
|
921
|
+
| `onPageEnter` | Nothing | Runs once on entering the page, before its queries |
|
|
922
|
+
|
|
923
|
+
|
|
924
|
+
The hub resolves an `lb-action` value against `actions`, and a reserved
|
|
925
|
+
operation against `crud` under the bound list name. A name with no entry
|
|
926
|
+
there logs a server console warning naming the page and the missing entry,
|
|
927
|
+
and answers 200 with `{}`. The browser applies `{}`, so no cell is set and
|
|
928
|
+
no row is added or removed, and `lb-pending` clears from the element that
|
|
929
|
+
sent the request. A request carrying no action answers 400, and a `run`
|
|
930
|
+
that throws answers 500.
|
|
931
|
+
|
|
932
|
+
Every entry under `actions` and `crud` has the same two members. `run`
|
|
933
|
+
performs the work, and `refresh` names the queries to re-run once the action
|
|
934
|
+
is complete.
|
|
935
|
+
|
|
936
|
+
`run` receives the same `ctx` and a `where`: the binding in scope when the
|
|
937
|
+
interaction happened, as `list`, `row`, `key`, `cell` and `value`. Under
|
|
938
|
+
`crud` the `where` carries only what that operation is typed to carry.
|
|
939
|
+
|
|
940
|
+
`run` may also return results of its own, which are laid over the refreshed
|
|
941
|
+
ones. That is how a delta reaches the browser: wrap it in `patch()`, naming
|
|
942
|
+
the rows that arrived or changed and the keys that went.
|
|
943
|
+
|
|
944
|
+
```ts
|
|
945
|
+
// members.requests.ts
|
|
946
|
+
import { patch, type Requests } from "@loadbare/app/server";
|
|
947
|
+
|
|
948
|
+
export const requests: Requests = {
|
|
949
|
+
actions: {
|
|
950
|
+
resetRoster: {
|
|
951
|
+
run: (ctx) => ctx.db.resetMembers(),
|
|
952
|
+
refresh: ["roster"],
|
|
953
|
+
},
|
|
954
|
+
},
|
|
955
|
+
crud: {
|
|
956
|
+
roster: {
|
|
957
|
+
rowDelete: {
|
|
958
|
+
run: async (ctx, where) => {
|
|
959
|
+
await ctx.db.deleteMember(where.key);
|
|
960
|
+
return { roster: patch({ drop: [where.key] }) };
|
|
961
|
+
},
|
|
962
|
+
refresh: [],
|
|
963
|
+
},
|
|
964
|
+
},
|
|
965
|
+
},
|
|
966
|
+
};
|
|
967
|
+
```
|
|
968
|
+
|
|
969
|
+
Each key under a `crud` entry is a reserved `lb-action` value with its prefix
|
|
970
|
+
stripped and the rest camel-cased, so the attribute, the wire and this key
|
|
971
|
+
are one vocabulary. All three operate on a list, because each needs a key and
|
|
972
|
+
a key exists only on a live row.
|
|
973
|
+
|
|
974
|
+
| `lb-action` | Key under `crud` | `where` carries |
|
|
975
|
+
| ---------------- | ---------------- | ---------------------- |
|
|
976
|
+
| `lb-row-delete` | `rowDelete` | `key` |
|
|
977
|
+
| `lb-row-insert` | `rowInsert` | `values` |
|
|
978
|
+
| `lb-row-update` | `rowUpdate` | `key`, `values` |
|
|
979
|
+
|
|
980
|
+
A `rowUpdate` sets the columns `values` names and leaves the rest as they
|
|
981
|
+
are, as an SQL `UPDATE` does. A form sends the cells it holds and a widget
|
|
982
|
+
cell sends itself, so one handler answers both.
|
|
983
|
+
|
|
984
|
+
## Widgets
|
|
985
|
+
|
|
986
|
+
---- UNEDITED ----
|
|
987
|
+
|
|
988
|
+
A widget is an HTML custom element following these fixed rules:
|
|
989
|
+
- Element name must contain a hyphen, as per hTML rules, like <my-custom-element>
|
|
990
|
+
- HTML code, if present, is `my-custom-element.html`
|
|
991
|
+
- TS code, if present, is in `my-custom-element.browser.ts`. The
|
|
992
|
+
'browser' segment is a safety feature, requiring the file to be
|
|
993
|
+
explicitly named as a browser file, to help prevent unfortunate
|
|
994
|
+
naming collisions where a server file happens to have the name of
|
|
995
|
+
a widget and gets built into the browser bundle.
|
|
996
|
+
|
|
997
|
+
A widget must have either one or the other of HTML and Typescript, and
|
|
998
|
+
it may have both. If it has neither, the builder reports an error.
|
|
999
|
+
|
|
1000
|
+
To use a widget from a library, add the library to `imports.ts` anywhere
|
|
1001
|
+
in the builders `--src`:
|
|
1002
|
+
|
|
1003
|
+
```ts
|
|
1004
|
+
export default ["@scope/library-name"];
|
|
1005
|
+
```
|
|
1006
|
+
|
|
1007
|
+
### Widget authoring
|
|
1008
|
+
|
|
1009
|
+
---- UNEDITED ----
|
|
1010
|
+
|
|
1011
|
+
The expansion grammar, `exp-`, `lb-slot`, `lb-template`, the reserved `LB-`
|
|
1012
|
+
namespace, then `lbPlaceRow` and `lbRowsLanded`. One bucket spanning build
|
|
1013
|
+
time and run time, because a widget is a definition and a script together.
|
|
1014
|
+
|
|
1015
|
+
#### Request state
|
|
1016
|
+
|
|
1017
|
+
The hub stamps these on the element that dispatched a request, which is the
|
|
1018
|
+
widget itself when a widget fired it. A widget observes them and reacts; it
|
|
1019
|
+
must name them in `observedAttributes` to see them change.
|
|
1020
|
+
|
|
1021
|
+
| Attribute | Written on | Holds |
|
|
1022
|
+
| -------------- | ----------------------- | --------------------------------------------------------------------------------------- |
|
|
1023
|
+
| `lb-pending` | The dispatching element | The round trip is in flight |
|
|
1024
|
+
| `lb-error` | The dispatching element | The last round trip failed, cleared on the next — see [The round trip](#the-round-trip) |
|
|
1025
|
+
| `lb-row-count` | A list scope | How many rows the scope is showing |
|
|
1026
|
+
|
|
1027
|
+
They are also stamped on plain HTML, where a stylesheet is the only
|
|
1028
|
+
consumer: dim a pending button, mark a failed one, and style an empty list
|
|
1029
|
+
against `lb-row-count` rather than carrying an empty-state element.
|
|
1030
|
+
|
|
1031
|
+
The hub reads one of them. A native `lb-action` element, a button or a
|
|
1032
|
+
form, that is performed again while it carries `lb-pending` is ignored: the
|
|
1033
|
+
click or submit is cancelled and nothing is sent. A pending native action is
|
|
1034
|
+
therefore disabled in fact, and a stylesheet only has to show it. A widget is
|
|
1035
|
+
not held back this way, because a widget that sends on change must have its
|
|
1036
|
+
latest value sent rather than dropped.
|
|
1037
|
+
|
|
1038
|
+
Alongside `lb-pending` the hub sets `aria-busy="true"` on the same element and
|
|
1039
|
+
removes it when the round trip settles, so assistive technology hears the
|
|
1040
|
+
state a stylesheet shows.
|
|
1041
|
+
|
|
1042
|
+
#### Row hooks
|
|
1043
|
+
|
|
1044
|
+
| Name | Implemented By | Behavior |
|
|
1045
|
+
| ------------------------------- | -------------- | ----------------------------------------------------------- |
|
|
1046
|
+
| `applyRow(root, row)` | Loadbare | Fills one scope from one row |
|
|
1047
|
+
| `lbPlaceRow(el, row, template)` | Developer | Optional on a list scope: where a row goes |
|
|
1048
|
+
| `lbRowsLanded()` | Developer | Optional on a list scope: scaffolding derived from the rows |
|
|
1049
|
+
|
|
1050
|
+
## Internal linkage
|
|
1051
|
+
|
|
1052
|
+
---- UNEDITED ----
|
|
1053
|
+
|
|
1054
|
+
The endpoint path, `index` for the bare path, the constant holding the
|
|
1055
|
+
request deadline, the generated client entry, and the `./build` export.
|
|
1056
|
+
Nobody outside this package reads any of it. The deadline itself is
|
|
1057
|
+
behavior an application sees — see [The round trip](#the-round-trip) — and
|
|
1058
|
+
giving it a knob later takes nothing away.
|
|
1059
|
+
|
|
1060
|
+
## Cross-reference
|
|
1061
|
+
|
|
1062
|
+
Every name Loadbare/app owns, in one place. Each row names the section
|
|
1063
|
+
that defines it. The definition lives there and only there.
|
|
1064
|
+
|
|
1065
|
+
### Builder flags
|
|
1066
|
+
|
|
1067
|
+
Loadbare/app owns every flag in this table.
|
|
1068
|
+
|
|
1069
|
+
| Flag | Default | Names | Defined in |
|
|
1070
|
+
| ---------- | ------- | ----------------------------------------- | ------------------------------------------------- |
|
|
1071
|
+
| `--src` | `src` | The application's own tree, scanned whole | [What the builder scans](#what-the-builder-scans) |
|
|
1072
|
+
| `--out` | `dist` | Where the builder writes | [Running the builder](#running-the-builder) |
|
|
1073
|
+
| `--watch` | off | Rebuild on change under `--src` | [Running the builder](#running-the-builder) |
|
|
1074
|
+
| `--minify` | off | Minify `client.js` and `app.css` | [Running the builder](#running-the-builder) |
|
|
1075
|
+
|
|
1076
|
+
### Reserved file names
|
|
1077
|
+
|
|
1078
|
+
Loadbare/app owns every file name and pattern in this table. A file so
|
|
1079
|
+
named carries its meaning wherever it sits in the `--src` tree, so an
|
|
1080
|
+
application must not use one of these names for anything else.
|
|
1081
|
+
|
|
1082
|
+
| File | How many | Holds | Defined in |
|
|
1083
|
+
| ----------------------- | ---------------------- | -------------------------------------------------------- | ------------------------------------------------------- |
|
|
1084
|
+
| `chrome.html` | Exactly one | The application's one HTML document | [Chrome](#chrome) |
|
|
1085
|
+
| `imports.ts` | Zero or one | Default-exports an array of widget library package names | [Imported widget libraries](#imported-widget-libraries) |
|
|
1086
|
+
| `<stub>.page.html` | One per page | One page's markup, as a fragment | [Pages](#pages) |
|
|
1087
|
+
| `<stub>.queries.ts` | Zero or one per page | That page's queries | [Page Queries](#page-queries) |
|
|
1088
|
+
| `<stub>.requests.ts` | Zero or one per page | That page's requests | [Page Requests](#page-requests) |
|
|
1089
|
+
| `<tag-name>.html` | Zero or one per widget | One widget definition, as a fragment | [Widgets](#widgets) |
|
|
1090
|
+
| `<tag-name>.browser.ts` | Zero or one per widget | One widget's script, `.js` also accepted | [Widgets](#widgets) |
|
|
1091
|
+
| `*.css` | Any number | A stylesheet, concatenated into `app.css` | [Running the builder](#running-the-builder) |
|
|
1092
|
+
|
|
1093
|
+
### Build outputs
|
|
1094
|
+
|
|
1095
|
+
Loadbare/app owns every file name in this table. The builder writes them
|
|
1096
|
+
into `--out`. Which of them exist depends on the application: `app.css`
|
|
1097
|
+
only when some origin has a stylesheet, `pages.ts` only when some page has a
|
|
1098
|
+
`.queries.ts` or a `.requests.ts`.
|
|
1099
|
+
|
|
1100
|
+
| Path | Written | Holds | Read by | Defined in |
|
|
1101
|
+
| ------------------ | ----------------- | ------------------------------------------------------------------ | ---------- | ------------------------------------------- |
|
|
1102
|
+
| `/app.html` | Always | The chrome, built | The server | [Chrome](#chrome) |
|
|
1103
|
+
| `/client.js` | Always | `<lb-hub>` and every widget the application uses | The chrome | [Chrome](#chrome) |
|
|
1104
|
+
| `/client-entry.ts` | Always | The generated entry `client.js` is bundled from | Nothing | [Running the builder](#running-the-builder) |
|
|
1105
|
+
| `/app.css` | With a stylesheet | Every stylesheet in the cascade, concatenated | The chrome | [Chrome](#chrome) |
|
|
1106
|
+
| `/pages.ts` | With page data | The one `createHub()` call, over every page's queries and requests | The server | [The Express server](#the-express-server) |
|
|
1107
|
+
|
|
1108
|
+
### Reserved package.json keys
|
|
1109
|
+
|
|
1110
|
+
Loadbare/app owns every key in this table. A widget library declares them.
|
|
1111
|
+
An application never does.
|
|
1112
|
+
|
|
1113
|
+
| Key | Value | Means | Defined in |
|
|
1114
|
+
| ------------------ | ------------------------- | ---------------------------------------------------------------------------- | ------------------------------------------------------- |
|
|
1115
|
+
| `loadbare.widgets` | A path inside the package | Where this package's widgets are. Absent means the whole installed directory | [Imported widget libraries](#imported-widget-libraries) |
|
|
1116
|
+
|
|
1117
|
+
### Reserved namespaces
|
|
1118
|
+
|
|
1119
|
+
Loadbare/app owns every namespace in this table. Ownership of a name and
|
|
1120
|
+
ownership of its behavior are stated separately, because they differ.
|
|
1121
|
+
|
|
1122
|
+
| Namespace | Applies to | Loadbare owns | Defined in |
|
|
1123
|
+
| --------- | -------------------------- | -------------------------------------------- | ----------------------------------------------- |
|
|
1124
|
+
| `lb-*` | HTML attributes | The names and their behavior | [The lb-* namespace](#the-lb--namespace) |
|
|
1125
|
+
| `exp-*` | HTML attributes | The behavior; widget authors pick the values | [Build time parameters](#build-time-parameters) |
|
|
1126
|
+
| `lb*` | Methods on custom elements | The names and their behavior | [Row hooks](#row-hooks) |
|
|
1127
|
+
|
|
1128
|
+
#### The lb-* namespace
|
|
1129
|
+
|
|
1130
|
+
Every HTML attribute beginning with `lb-` belongs to Loadbare/app. An
|
|
1131
|
+
application writes the ones this table names and invents none of its own,
|
|
1132
|
+
because a name Loadbare has not defined today it may define tomorrow.
|
|
1133
|
+
|
|
1134
|
+
The prefix reaches past HTML. A query name cannot begin with `lb-` either,
|
|
1135
|
+
which is what keeps the three operations apart from an application's own
|
|
1136
|
+
actions on the wire — see [Page Queries](#page-queries).
|
|
1137
|
+
|
|
1138
|
+
Each attribute is defined in one section, and this table says which.
|
|
1139
|
+
|
|
1140
|
+
| Attribute | Written by | Defined in |
|
|
1141
|
+
| ----------------- | ------------- | --------------------------------------------------- |
|
|
1142
|
+
| `lb-list` | Developer | [Binding](#binding) |
|
|
1143
|
+
| `lb-row` | Developer | [Binding](#binding) |
|
|
1144
|
+
| `lb-cell` | Developer | [Binding](#binding) |
|
|
1145
|
+
| `lb-show` | Developer | [Displaying by condition](#displaying-by-condition) |
|
|
1146
|
+
| `lb-key` | Developer | [Binding](#binding) |
|
|
1147
|
+
| `lb-key-value` | Hub | [Binding](#binding) |
|
|
1148
|
+
| `lb-value` | Hub | [How a value lands](#how-a-value-lands) |
|
|
1149
|
+
| `lb-action` | Developer | [Requests](#requests) |
|
|
1150
|
+
| `lb-nav-link` | Developer | [Links](#links) |
|
|
1151
|
+
| `lb-pending` | Hub | [Request state](#request-state) |
|
|
1152
|
+
| `lb-error` | Hub | [Request state](#request-state) |
|
|
1153
|
+
| `lb-row-count` | Hub | [Request state](#request-state) |
|
|
1154
|
+
| `lb-unknown-page` | Developer | [Chrome](#chrome) |
|
|
1155
|
+
| `lb-slot` | Widget author | [Slots and templates](#slots-and-templates) |
|
|
1156
|
+
| `lb-template` | Widget author | [Slots and templates](#slots-and-templates) |
|
|
1157
|
+
| `lb-page` | Builder | [Pages](#pages) |
|
|
1158
|
+
|
|
1159
|
+
An attribute the builder does not recognize is left alone today. Refusing
|
|
1160
|
+
one is on the list of validations still to land — see
|
|
1161
|
+
[The builder](#the-builder).
|
|
1162
|
+
|
|
1163
|
+
### Reserved tags
|
|
1164
|
+
|
|
1165
|
+
Loadbare/app owns every tag in this table. An application writes them and
|
|
1166
|
+
never defines them.
|
|
1167
|
+
|
|
1168
|
+
| Tag | Written in | Means | Defined in |
|
|
1169
|
+
| ---------- | ---------- | ------------------------------ | ----------------- |
|
|
1170
|
+
| `<lb-hub>` | The chrome | The application's live element | [Chrome](#chrome) |
|
|
1171
|
+
|
|
1172
|
+
### Reserved events
|
|
1173
|
+
|
|
1174
|
+
Loadbare/app owns every DOM event in this table, both the name and what its
|
|
1175
|
+
`detail` carries.
|
|
1176
|
+
|
|
1177
|
+
| Event | Dispatched from | Bubbles | Cancelable | Defined in |
|
|
1178
|
+
| ------------ | ---------------------- | ------- | ---------- | --------------------------------------- |
|
|
1179
|
+
| `lb-request` | The element that acted | Yes | No | [The request event](#the-request-event) |
|
|
1180
|
+
|
|
1181
|
+
### Reserved attributes
|
|
1182
|
+
|
|
1183
|
+
Loadbare/app owns every attribute in this table, both the name and its
|
|
1184
|
+
behavior.
|
|
1185
|
+
|
|
1186
|
+
| Attribute | Written on | Takes a value | Defined in |
|
|
1187
|
+
| ----------------- | ----------------------------------- | ------------- | ----------------- |
|
|
1188
|
+
| `lb-unknown-page` | A `<dialog>` in chrome | No | [Chrome](#chrome) |
|
|
1189
|
+
| `lb-page` | A `<template>`, by the builder only | Yes | [Pages](#pages) |
|