@loadbare/app 0.11.0 → 0.12.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/build/assemble.d.ts.map +1 -1
- package/dist/build/assemble.js +5 -1
- package/dist/build/assemble.js.map +1 -1
- package/dist/core/lb-constants.d.ts +2 -0
- package/dist/core/lb-constants.d.ts.map +1 -1
- package/dist/core/lb-constants.js +8 -0
- package/dist/core/lb-constants.js.map +1 -1
- package/dist/core/lb-types.d.ts +11 -0
- package/dist/core/lb-types.d.ts.map +1 -1
- package/dist/core/lb-types.js.map +1 -1
- package/dist/hub/lb-apply.d.ts +7 -1
- package/dist/hub/lb-apply.d.ts.map +1 -1
- package/dist/hub/lb-apply.js +106 -3
- package/dist/hub/lb-apply.js.map +1 -1
- package/dist/hub/lb-hub.browser.d.ts.map +1 -1
- package/dist/hub/lb-hub.browser.js +116 -31
- package/dist/hub/lb-hub.browser.js.map +1 -1
- package/dist/server/lb-server.d.ts.map +1 -1
- package/dist/server/lb-server.js +17 -0
- package/dist/server/lb-server.js.map +1 -1
- package/docs/TECHREF-1.0.md +101 -9
- package/docs/comparison.md +5 -1
- package/docs/reference/chrome.md +15 -0
- package/docs/reference/custom-elements.md +62 -0
- package/docs/reference/data-binding.md +36 -0
- package/docs/reference/page-files.md +30 -2
- package/package.json +1 -1
- package/skills/loadbare-app/SKILL.md +58 -4
- package/skills/loadbare-app/references/TECHREF-1.0.md +101 -9
- package/skills/loadbare-app/references/chrome.md +15 -0
- package/skills/loadbare-app/references/custom-elements.md +62 -0
- package/skills/loadbare-app/references/data-binding.md +36 -0
- package/skills/loadbare-app/references/page-files.md +30 -2
|
@@ -159,7 +159,9 @@ row template lands on the element itself. A `rows` query with no row
|
|
|
159
159
|
template lands nothing, which is what an insert form naming its query is. A
|
|
160
160
|
condition is `lb-show="<column>"`: write every possibility into the page and
|
|
161
161
|
let a column decide which is present. The column is a boolean or null; the
|
|
162
|
-
string `"false"` counts as present.
|
|
162
|
+
string `"false"` counts as present. `lb-show="!<column>"` is present when
|
|
163
|
+
the column is not, so one column decides both sides and the query never
|
|
164
|
+
sends a flag and its opposite.
|
|
163
165
|
|
|
164
166
|
**`{{placeholder}}` is build time only.** It reads an `exp-` attribute on
|
|
165
167
|
the tag, never data. Write it as an entire attribute value or an entire
|
|
@@ -176,7 +178,9 @@ from it.
|
|
|
176
178
|
query under two names. Many masters with their details is one `rows` query
|
|
177
179
|
of joined rows, grouped for display by a custom element's `lbPlaceRow`. A
|
|
178
180
|
query nested inside another query's row template receives the same rows in
|
|
179
|
-
every outer row; use it for a picker, never for per-row detail.
|
|
181
|
+
every outer row; use it for a picker, never for per-row detail. A new outer
|
|
182
|
+
row is filled from the nested query's last answer, whatever order they land
|
|
183
|
+
in.
|
|
180
184
|
|
|
181
185
|
**Every request has one shape.** `lb-request` names the request, and the
|
|
182
186
|
hub sends `{ name, query, key, values }` as present: `query` from the
|
|
@@ -201,6 +205,12 @@ elsewhere with the HTML `form` attribute. Checkboxes, radio buttons and
|
|
|
201
205
|
file inputs are not controls here: they receive no value and are not
|
|
202
206
|
gathered.
|
|
203
207
|
|
|
208
|
+
**A form that adds to a set chosen elsewhere is written once, outside every
|
|
209
|
+
row.** A form cannot sit inside another form or in a table row, so a dialog
|
|
210
|
+
that creates an account while a posting's picker is choosing one goes at the
|
|
211
|
+
end of the page, and each row opens it with `commandfor`. The dialog learns
|
|
212
|
+
the new key from `lb-request-done`.
|
|
213
|
+
|
|
204
214
|
**Three requests are Loadbare's.** `lb-row-insert` needs `query` and
|
|
205
215
|
`values`, `lb-row-update` needs `query`, `key` and `values`, and
|
|
206
216
|
`lb-row-delete` needs `query` and `key`. The page permits each under
|
|
@@ -216,8 +226,33 @@ page may edit.
|
|
|
216
226
|
|
|
217
227
|
**Return a patch when the change has a known extent.** `patch({ rows })`
|
|
218
228
|
for rows added or edited, `patch({ drop })` for keys removed, with
|
|
219
|
-
`refresh: []`.
|
|
220
|
-
|
|
229
|
+
`refresh: []`. A refreshed `rows` query sends every row, and the hub places
|
|
230
|
+
every row again, which moves each element and takes focus from the control
|
|
231
|
+
the user is in. List a query in `refresh` only when its membership or order
|
|
232
|
+
changed in a way the handler cannot name. Never list one only to fill the
|
|
233
|
+
picker in a row the request adds: its answer did not change, and the hub
|
|
234
|
+
fills a new row from the last one.
|
|
235
|
+
|
|
236
|
+
**The usual reasons for a refresh each have a patch.**
|
|
237
|
+
- A placeholder row standing in for an empty set or section: drop its key
|
|
238
|
+
in the patch that adds the first real row, and add it back in the patch
|
|
239
|
+
that drops the last.
|
|
240
|
+
- A row whose position changes: the rows host places it, as `lb-table` does
|
|
241
|
+
by `data-sort`.
|
|
242
|
+
- A row whose other columns change with the edit: re-read the row and patch
|
|
243
|
+
it.
|
|
244
|
+
- Rows the database removes with a deleted one: select their keys before
|
|
245
|
+
the delete and drop them too.
|
|
246
|
+
|
|
247
|
+
An update or a delete names its row by key, and removing a row never
|
|
248
|
+
reorders the rest, so each always has a patch: `createHub` refuses at
|
|
249
|
+
startup a `rowUpdate` or `rowDelete` whose `refresh` names its own `rows`
|
|
250
|
+
query. An insert may refresh its own query, and should only when the new
|
|
251
|
+
row's place matters and nothing places it: a patched row lands where its
|
|
252
|
+
host puts it, in order under `lb-table` with `data-sort`, last in plain
|
|
253
|
+
markup and in `lb-options`.
|
|
254
|
+
Each handler's `refresh` is its own, and every query in it needs its own
|
|
255
|
+
reason. A list shared by several handlers is a warning sign.
|
|
221
256
|
|
|
222
257
|
**A page's queries are its view model, not a data layer.** Each answers
|
|
223
258
|
one page's elements in the form they show: formatted dates and amounts, and
|
|
@@ -247,6 +282,12 @@ puts parms onto `ctx`, and a query reads them there. Read them from
|
|
|
247
282
|
request. A parm is user input, so validate it where it is read. Do not
|
|
248
283
|
keep a selection in server state set by a handler.
|
|
249
284
|
|
|
285
|
+
**Where focus starts is the hub's.** On entering a page, once its queries
|
|
286
|
+
have landed, the hub focuses the first control in `<main>` the user can
|
|
287
|
+
operate; a change of query parm leaves focus where it is. Order the page so
|
|
288
|
+
that control is the one to start in, and write no `autofocus` and no script
|
|
289
|
+
that focuses on load.
|
|
290
|
+
|
|
250
291
|
**A handler moves the URL with `url()`.** After an insert, only the server
|
|
251
292
|
knows the new key; after a delete, only the server knows the parm should
|
|
252
293
|
go. Have `run` return `url({ acct: String(id) })`, or `url({ acct: "" })`
|
|
@@ -292,6 +333,19 @@ on every move. Listen on the element itself in the constructor, look a
|
|
|
292
333
|
child up when it is needed, and in a control take up `lb-column-value` once,
|
|
293
334
|
on first connect, since a value can land before the element upgrades.
|
|
294
335
|
|
|
336
|
+
**The hub and a custom element talk in four ways, one per kind of
|
|
337
|
+
message.** State the hub gives an element is an attribute stamp, or `value`
|
|
338
|
+
on a control. Work the hub needs done while landing is an optional `lb`
|
|
339
|
+
method: `lbPlaceRow`, `lbRowsLanded`. A moment is a bubbling event: an
|
|
340
|
+
element sends `lb-request`, and the hub answers on the same element with
|
|
341
|
+
`lb-request-done`, carrying the request and the response items that landed,
|
|
342
|
+
or the error. Listen for `lb-request-done` on whichever ancestor needs the
|
|
343
|
+
outcome, such as a dialog choosing the row its form just created.
|
|
344
|
+
|
|
345
|
+
**A widget that holds rows may sit under `lb-show`.** Rows that land while
|
|
346
|
+
it is away are placed by its `lbPlaceRow` once it first appears, so hide a
|
|
347
|
+
table with `lb-show`, not with a stylesheet rule.
|
|
348
|
+
|
|
295
349
|
**Name a custom element script `<tag>.browser.ts`.** A plain `<tag>.ts`
|
|
296
350
|
stays on the server and the tag goes unregistered.
|
|
297
351
|
|
|
@@ -64,10 +64,9 @@ fine, because every `<select>` receives the same rows.
|
|
|
64
64
|
|
|
65
65
|
But the allowed values may depend on other values in the row.
|
|
66
66
|
|
|
67
|
-
- **Decide
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
what a nested query is for.
|
|
67
|
+
- **Decide whether a nested query's rows may depend on its row.** A nested
|
|
68
|
+
query has one answer, which every live row receives. See
|
|
69
|
+
[Master-detail](#master-detail) for what a nested query is for.
|
|
71
70
|
|
|
72
71
|
```html
|
|
73
72
|
<tbody lb-query="accounts">
|
|
@@ -78,6 +77,24 @@ But the allowed values may depend on other values in the row.
|
|
|
78
77
|
</tbody>
|
|
79
78
|
```
|
|
80
79
|
|
|
80
|
+
### Who creates and orders rows
|
|
81
|
+
|
|
82
|
+
The hub creates every live row from a row template and places it in the
|
|
83
|
+
query's order, unless the element holding the rows has `lbPlaceRow`, in
|
|
84
|
+
which case the custom element decides where each row goes. Custom elements
|
|
85
|
+
also create rows of their own: `lb-table` clones a ghost row per section and
|
|
86
|
+
builds each section's heading. Neither side owns creation or order.
|
|
87
|
+
|
|
88
|
+
- **Decide who creates rows and who orders them.** A patch cannot say where
|
|
89
|
+
a new row goes, so it lands where the host puts it: in order under
|
|
90
|
+
`lb-table` with `data-sort`, last in plain markup and in `lb-options`.
|
|
91
|
+
Whether an insert may answer with a patch therefore depends on markup the
|
|
92
|
+
server cannot see, and the server cannot refuse an insert that refreshes
|
|
93
|
+
its own query the way it refuses an update or a delete.
|
|
94
|
+
- **Decide whether landing all rows moves rows already in place.** It moves
|
|
95
|
+
every row today, which takes focus from the control the user is in, and
|
|
96
|
+
`lbPlaceRow` does the same.
|
|
97
|
+
|
|
81
98
|
### The server API
|
|
82
99
|
|
|
83
100
|
- **Give the chrome a way to state its own queries.** A custom element in
|
|
@@ -425,7 +442,7 @@ query.
|
|
|
425
442
|
| ----------- | -------- | -------------------------------------------------- |
|
|
426
443
|
| `lb-query` | a query | Puts its rows in the element's content |
|
|
427
444
|
| `lb-column` | a column | Sets the element from that column |
|
|
428
|
-
| `lb-show` | a column | Removes it while the named column is null or false |
|
|
445
|
+
| `lb-show` | a column | Removes it while the named column is null or false; `!column` reverses it |
|
|
429
446
|
|
|
430
447
|
| Stamp | The hub stamps it with |
|
|
431
448
|
| -------------------- | -------------------------------- |
|
|
@@ -558,6 +575,10 @@ so `"false"` is on, and a query spells a condition as a boolean or a null.
|
|
|
558
575
|
</template>
|
|
559
576
|
```
|
|
560
577
|
|
|
578
|
+
Write `!` before the column to reverse it: `lb-show="!chosen"` is present
|
|
579
|
+
while `chosen` is null or false. One column then decides both of two
|
|
580
|
+
elements, rather than a column and its opposite, which could disagree.
|
|
581
|
+
|
|
561
582
|
It reads from the nearest ancestor row, as `lb-column` does, and on an
|
|
562
583
|
element that carries `lb-query` the column belongs to the row around it. A
|
|
563
584
|
row that does not carry the column leaves the element as it is.
|
|
@@ -578,7 +599,8 @@ nothing conditional shows until its row lands. An absent element's template
|
|
|
578
599
|
keeps its place among its siblings, and a position selector counts it.
|
|
579
600
|
|
|
580
601
|
These are build errors: `lb-show` on a row template's root, `lb-show` with
|
|
581
|
-
no `lb-query` around it,
|
|
602
|
+
no `lb-query` around it, `lb-show` on a `<template>`, and `lb-show="!"` or
|
|
603
|
+
`lb-show="!!column"`.
|
|
582
604
|
|
|
583
605
|
Hiding is presentation, and the server still refuses what a request may not
|
|
584
606
|
do.
|
|
@@ -608,7 +630,9 @@ each detail row carries its master's columns. A custom element's
|
|
|
608
630
|
|
|
609
631
|
A query nested in another query's row template receives the same rows in
|
|
610
632
|
every live row. That serves a picker offering the same choices on every
|
|
611
|
-
row, and is not a way to show a different detail per row.
|
|
633
|
+
row, and is not a way to show a different detail per row. A live row added
|
|
634
|
+
later is filled from the nested query's last answer, so a request that adds
|
|
635
|
+
one does not refresh the nested query to fill it.
|
|
612
636
|
|
|
613
637
|
Which master a page shows is a query parm, which a query reads off `ctx`
|
|
614
638
|
since it takes no argument from the browser — see [Query parms](#query-parms).
|
|
@@ -767,6 +791,18 @@ interceptor calls `stopPropagation`, not `preventDefault`. This is what
|
|
|
767
791
|
makes a confirmation wrapper possible without the wrapped element knowing
|
|
768
792
|
about it.
|
|
769
793
|
|
|
794
|
+
Once what the request brought back has landed, or its round trip has failed,
|
|
795
|
+
the hub dispatches the bubbling `lb-request-done` event from the same
|
|
796
|
+
element. Its `detail`, `HubRequestDone` in `@loadbare/app/types`, holds
|
|
797
|
+
the request as the hub sent it and `items`, every response item that landed
|
|
798
|
+
because of it, in order. An answer that moved the URL contributes its
|
|
799
|
+
`lb-url` item and the page load. `error` is set instead when the round trip
|
|
800
|
+
failed. By then `lb-request-pending` is gone, and a listener sees the page
|
|
801
|
+
as the answer left it. A request the hub or an ancestor stopped was never
|
|
802
|
+
sent, and gets no `lb-request-done`. An element the answer removed from the
|
|
803
|
+
document, such as the row a delete took away, dispatches the event where it
|
|
804
|
+
now is, and no ancestor it had on the page hears it.
|
|
805
|
+
|
|
770
806
|
#### Request state
|
|
771
807
|
|
|
772
808
|
The hub stamps `lb-request-pending` on the element that issued a request
|
|
@@ -804,6 +840,14 @@ A page load that fails lands nothing and is reported to the console. A load
|
|
|
804
840
|
started by a request for `lb-url` stamps the element that issued it, as any
|
|
805
841
|
request stamps its element.
|
|
806
842
|
|
|
843
|
+
A response answers for the URL its request was sent from, path and query
|
|
844
|
+
string both. One that returns after the URL has moved lands nothing, since
|
|
845
|
+
it describes what the user is no longer looking at: a request's answer,
|
|
846
|
+
including any `url()` it carries, and a page load overtaken by a newer one.
|
|
847
|
+
A write whose answer is dropped this way has still happened. Its
|
|
848
|
+
`lb-request-done` carries no items and no error, and an insert still resets
|
|
849
|
+
its form.
|
|
850
|
+
|
|
807
851
|
### The URL
|
|
808
852
|
|
|
809
853
|
---- UNEDITED ----
|
|
@@ -834,6 +878,14 @@ server runs its `onPageEnter`, then its queries. When a query parm takes a
|
|
|
834
878
|
new value, the hub reloads the page's queries, and keeps the page's DOM, so
|
|
835
879
|
live rows that come back keep their place.
|
|
836
880
|
|
|
881
|
+
Once an entered page's queries have landed, the hub focuses the first
|
|
882
|
+
element in `<main>` the user can operate: not disabled, not in a closed
|
|
883
|
+
`<dialog>`, not `inert`, not `hidden`, not in an absent `lb-show` branch,
|
|
884
|
+
and one that takes the focus. Entering is a cold load, a new `lb-path`,
|
|
885
|
+
and Back or Forward to another page. A change of query parm enters no
|
|
886
|
+
page, and focus stays where it is, as it does when it is already in
|
|
887
|
+
`<main>`.
|
|
888
|
+
|
|
837
889
|
The page's title is the text of the page file's `<title>`, which the builder
|
|
838
890
|
stamps on the page as `lb-page-title`. The hub sets the document title to
|
|
839
891
|
`lb-page-label` when it is not null.
|
|
@@ -1003,8 +1055,8 @@ rowInsert: {
|
|
|
1003
1055
|
carries the `lb-url` item alone, and the hub loads the page itself. A
|
|
1004
1056
|
failure there is a page load's, and is not stamped on the element that
|
|
1005
1057
|
issued the request.
|
|
1006
|
-
- A user who has
|
|
1007
|
-
URL they are on.
|
|
1058
|
+
- A user who has moved by the time the response arrives, to another page or
|
|
1059
|
+
to other query parms, keeps the URL they are on.
|
|
1008
1060
|
|
|
1009
1061
|
The page is loaded with a second context, built by `contextFor` from the new
|
|
1010
1062
|
parms — see [The Express server](#the-express-server).
|
|
@@ -1027,6 +1079,7 @@ to build on any of these:
|
|
|
1027
1079
|
`<lb-hub>`.
|
|
1028
1080
|
- `lb-show` on a `<template>`, on a row template's root, or with no
|
|
1029
1081
|
`lb-query` around it.
|
|
1082
|
+
- `lb-show="!"` or `lb-show="!!column"`, which reverse no column.
|
|
1030
1083
|
|
|
1031
1084
|
`lb-column` with no ancestor row is allowed: the hub gathers from it.
|
|
1032
1085
|
|
|
@@ -1276,6 +1329,9 @@ request carrying no name answers 400, and a `run` that throws answers 500.
|
|
|
1276
1329
|
|
|
1277
1330
|
Every handler under `handlers` and `crud` has the same two members. `run`
|
|
1278
1331
|
performs the work, and `refresh` names the queries to re-run once it has.
|
|
1332
|
+
A query belongs there when its answer changed, never to fill an element the
|
|
1333
|
+
request's answer creates: that element is filled from the last answer its
|
|
1334
|
+
query landed.
|
|
1279
1335
|
|
|
1280
1336
|
`run` receives the same `ctx` and the request less its name: `query`, `key`
|
|
1281
1337
|
and `values`, as present.
|
|
@@ -1284,6 +1340,15 @@ and `values`, as present.
|
|
|
1284
1340
|
the refreshed ones. That is how a delta reaches the browser: wrap it in
|
|
1285
1341
|
`patch()`, naming the rows that arrived or changed and the keys that went.
|
|
1286
1342
|
|
|
1343
|
+
A refreshed `rows` query sends every row, and the hub places every row
|
|
1344
|
+
again, which moves each element and takes focus from the control the user
|
|
1345
|
+
is in. An update or a delete names its row by key, and removing a row
|
|
1346
|
+
never reorders the rest, so its handler always knows what changed:
|
|
1347
|
+
`createHub` refuses at startup a `crud` `rowUpdate` or `rowDelete` on a
|
|
1348
|
+
`rows` query whose `refresh` names that same query. A `row` query sends one
|
|
1349
|
+
row and may refresh itself. An insert may refresh its own query; see
|
|
1350
|
+
[Who creates and orders rows](#who-creates-and-orders-rows).
|
|
1351
|
+
|
|
1287
1352
|
`run` may instead return `url()`, a new row for `lb-url`, naming query parms
|
|
1288
1353
|
only the write can know, such as the key of a row it inserted. The page
|
|
1289
1354
|
then loads at them in the same round trip, in place of the refresh set — see
|
|
@@ -1397,6 +1462,25 @@ export default ["@scope/library-name"];
|
|
|
1397
1462
|
Import every attribute name from `@loadbare/app/constants` — see
|
|
1398
1463
|
[Constants](#constants). Never write one as a string literal.
|
|
1399
1464
|
|
|
1465
|
+
### What the hub and an element say to each other
|
|
1466
|
+
|
|
1467
|
+
Each direction has one mechanism for each kind of message:
|
|
1468
|
+
|
|
1469
|
+
| Direction | What | How | Today |
|
|
1470
|
+
| -------------- | ------------------------------------------- | ---------------------------- | ------------------------------------------------ |
|
|
1471
|
+
| Hub to element | State that lasts | An attribute the hub stamps | `lb-column-value`, `lb-key-value`, `lb-query-row-count`, `lb-request-pending`, `lb-request-error` |
|
|
1472
|
+
| Hub to element | State the platform already names | A property | A control's `value` |
|
|
1473
|
+
| Hub to element | Work the hub needs done now, while landing | An optional `lb` method | `lbPlaceRow`, `lbRowsLanded` |
|
|
1474
|
+
| Hub to element | A moment an element started | A bubbling event | `lb-request-done` |
|
|
1475
|
+
| Element to hub | A moment | A bubbling event | `lb-request`, and `change`, `click` and `submit` |
|
|
1476
|
+
|
|
1477
|
+
State is an attribute, because a stylesheet can select on it and an element
|
|
1478
|
+
that upgrades late still finds it. A method is for work the hub cannot go
|
|
1479
|
+
on without, since it acts on one element at one point in landing and nothing
|
|
1480
|
+
else can do it. A moment is an event, because the element that cares is
|
|
1481
|
+
often an ancestor of the one it concerns, and an event reaches it with no
|
|
1482
|
+
knowledge of either.
|
|
1483
|
+
|
|
1400
1484
|
### Controls
|
|
1401
1485
|
|
|
1402
1486
|
A form-associated custom element with a `value` property that fires
|
|
@@ -1450,6 +1534,11 @@ The hub calls both on a custom element with `lb-query` and a row template.
|
|
|
1450
1534
|
Both are optional. The `RowsHost` interface in `@loadbare/app/types`
|
|
1451
1535
|
declares them.
|
|
1452
1536
|
|
|
1537
|
+
A custom element the builder shipped absent under `lb-show` has not
|
|
1538
|
+
upgraded while its column is off, and rows that land on it then are placed
|
|
1539
|
+
without it. When the column first turns on and it upgrades, the hub lands
|
|
1540
|
+
the query's last answer on it again, as all rows, so both hooks run.
|
|
1541
|
+
|
|
1453
1542
|
`applyRow(root, row)`, exported by `@loadbare/app`, fills `root` from one
|
|
1454
1543
|
row, the same operation that fills a live row.
|
|
1455
1544
|
|
|
@@ -1593,6 +1682,7 @@ Loadbare/app owns every DOM event in this table, both the name and what its
|
|
|
1593
1682
|
| Event | Dispatched from | Bubbles | Cancelable | Defined in |
|
|
1594
1683
|
| ------------ | -------------------------------- | ------- | ---------- | --------------------------------------- |
|
|
1595
1684
|
| `lb-request` | The element that committed | Yes | No | [The request event](#the-request-event) |
|
|
1685
|
+
| `lb-request-done` | The element that committed | Yes | No | [The request event](#the-request-event) |
|
|
1596
1686
|
|
|
1597
1687
|
### Reserved methods
|
|
1598
1688
|
|
|
@@ -1628,6 +1718,8 @@ imports them rather than writing a string.
|
|
|
1628
1718
|
| `ATTR_PAGE_TITLE` | `lb-page-title` |
|
|
1629
1719
|
| `DEVELOPER_ATTRIBUTES` | The seven attributes a developer writes |
|
|
1630
1720
|
| `LB_EVENT_NAME` | `lb-request` |
|
|
1721
|
+
| `LB_DONE_EVENT_NAME` | `lb-request-done` |
|
|
1722
|
+
| `SHOW_NOT` | `!`, written before a column in `lb-show` |
|
|
1631
1723
|
| `LB_RESERVED_PREFIX` | `lb-` |
|
|
1632
1724
|
| `REQUEST_ROW_INSERT` | `lb-row-insert` |
|
|
1633
1725
|
| `REQUEST_ROW_UPDATE` | `lb-row-update` |
|
|
@@ -108,6 +108,21 @@ tab and the browser history show the page.
|
|
|
108
108
|
`lb-url` is the one query a page may use that the server does not declare. A
|
|
109
109
|
page names it the same way, anywhere inside the hub.
|
|
110
110
|
|
|
111
|
+
### Where focus starts
|
|
112
|
+
|
|
113
|
+
On entering a page, once its queries have landed, the hub focuses the first
|
|
114
|
+
element in `<main>` the user can operate, so a keyboard user starts in the
|
|
115
|
+
page rather than on the document. The chrome comes first in the document,
|
|
116
|
+
and is passed over. So is anything disabled, in a closed `<dialog>`,
|
|
117
|
+
`inert`, `hidden`, in an absent `lb-show` branch, or that does not take
|
|
118
|
+
the focus when asked. A widget's native control counts, so write no
|
|
119
|
+
`autofocus` to restate this.
|
|
120
|
+
|
|
121
|
+
A page is entered on a cold load, a new `lb-path` from a link or from a
|
|
122
|
+
handler's `url()`, and Back or Forward to another page. A change of query
|
|
123
|
+
parm enters no page: the user who chose a record in a picker stays in the
|
|
124
|
+
picker. Focus the user has already put in `<main>` is left there.
|
|
125
|
+
|
|
111
126
|
### Links
|
|
112
127
|
|
|
113
128
|
Write `lb-url-link` on an `<a>` to move between pages:
|
|
@@ -268,6 +268,8 @@ one as a string literal:
|
|
|
268
268
|
| `REQUEST_ROW_INSERT`, `REQUEST_ROW_UPDATE`, `REQUEST_ROW_DELETE` | The requests Loadbare provides |
|
|
269
269
|
| `LB_ROW_REQUESTS` | All three, in one array |
|
|
270
270
|
| `LB_EVENT_NAME` | `lb-request`, the event every request travels as |
|
|
271
|
+
| `LB_DONE_EVENT_NAME` | `lb-request-done`, the event that says how it turned out |
|
|
272
|
+
| `SHOW_NOT` | `!`, written before a column in `lb-show` |
|
|
271
273
|
| `URL_QUERY` | `lb-url` |
|
|
272
274
|
| `URL_COLUMN_PATH`, `URL_COLUMN_PAGE_LABEL`, `URL_COLUMN_PAGE_UNKNOWN` | `lb-path`, `lb-page-label`, `lb-page-unknown` |
|
|
273
275
|
| `LB_RESERVED_PREFIX` | `lb-` |
|
|
@@ -278,6 +280,24 @@ writes them in markup, and the hub and the builder write their stamps.
|
|
|
278
280
|
Loadbare reserves method names beginning with `lb` on a custom element, for
|
|
279
281
|
the methods it calls; see [Holding rows](#holding-rows).
|
|
280
282
|
|
|
283
|
+
### What the hub and an element say to each other
|
|
284
|
+
|
|
285
|
+
Each direction has one mechanism for each kind of message:
|
|
286
|
+
|
|
287
|
+
| Direction | What | How | Today |
|
|
288
|
+
|----------------|--------------------------------------------|-----------------------------|-------|
|
|
289
|
+
| Hub to element | State that lasts | An attribute the hub stamps | `lb-column-value`, `lb-key-value`, `lb-query-row-count`, `lb-request-pending`, `lb-request-error` |
|
|
290
|
+
| Hub to element | State the platform already names | A property | A control's `value` |
|
|
291
|
+
| Hub to element | Work the hub needs done now, while landing | An optional `lb` method | `lbPlaceRow`, `lbRowsLanded` |
|
|
292
|
+
| Hub to element | A moment an element started | A bubbling event | `lb-request-done` |
|
|
293
|
+
| Element to hub | A moment | A bubbling event | `lb-request`, and `change`, `click` and `submit` |
|
|
294
|
+
|
|
295
|
+
State is an attribute: a stylesheet can select on it, and an element that
|
|
296
|
+
upgrades late still finds it. A method is for work the hub cannot go on
|
|
297
|
+
without, done by one element at one point in landing. A moment is an event,
|
|
298
|
+
because the element that cares is often an ancestor of the one it concerns,
|
|
299
|
+
and an event reaches it knowing neither.
|
|
300
|
+
|
|
281
301
|
### When its code runs
|
|
282
302
|
|
|
283
303
|
The hub creates, places and parks elements, and each of those reaches a
|
|
@@ -450,6 +470,39 @@ missing a field its name needs, and stamps the dispatching element with
|
|
|
450
470
|
|
|
451
471
|
Let the event bubble, so an ancestor can stop it before the hub sends it.
|
|
452
472
|
|
|
473
|
+
### Hearing how it turned out
|
|
474
|
+
|
|
475
|
+
Once what a request brought back has landed, or its round trip has failed,
|
|
476
|
+
the hub dispatches `lb-request-done` from the element that committed. It
|
|
477
|
+
bubbles, so the element that cares need not be the one that committed: a
|
|
478
|
+
dialog hears it from the form inside it.
|
|
479
|
+
|
|
480
|
+
```ts
|
|
481
|
+
import { LB_DONE_EVENT_NAME } from "@loadbare/app/constants";
|
|
482
|
+
import type { HubRequestDone } from "@loadbare/app/types";
|
|
483
|
+
|
|
484
|
+
this.addEventListener(LB_DONE_EVENT_NAME, (e) => {
|
|
485
|
+
const { request, items, error } = (e as CustomEvent<HubRequestDone>).detail;
|
|
486
|
+
if (error) return;
|
|
487
|
+
const item = items.find((i) => i.query === request.query);
|
|
488
|
+
const created = item?.patch?.rows?.[0];
|
|
489
|
+
if (created) this.choose(String(created[item!.key]));
|
|
490
|
+
});
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
`items` is every response item that landed because of the request, in
|
|
494
|
+
order. An answer that moved the URL contributes its `lb-url` item, which
|
|
495
|
+
carries a key only the server knew, and the page load. `error` is set when
|
|
496
|
+
the round trip failed, and then nothing landed. A new row's key is in the
|
|
497
|
+
answer only when the handler returned it in a patch: a refresh sends all
|
|
498
|
+
rows, and nothing marks which one is new.
|
|
499
|
+
|
|
500
|
+
By the time the event is dispatched, `lb-request-pending` is gone and the
|
|
501
|
+
page is as the answer left it. A request that was never sent, because the
|
|
502
|
+
hub or an ancestor stopped it, gets no `lb-request-done`. An element the
|
|
503
|
+
answer removed, such as the row a delete took away, dispatches the event
|
|
504
|
+
outside the document, and no ancestor it had there hears it.
|
|
505
|
+
|
|
453
506
|
### Holding rows
|
|
454
507
|
|
|
455
508
|
The hub lands every row template itself. A plain element carrying `lb-query`
|
|
@@ -498,6 +551,15 @@ template, in arrival order. `lb-options.browser.ts` and
|
|
|
498
551
|
`lb-table.browser.ts` in [`@loadbare/widgets`](./widgets.md) are two
|
|
499
552
|
different placements over the same landing.
|
|
500
553
|
|
|
554
|
+
A custom element the builder shipped absent under `lb-show` has not
|
|
555
|
+
upgraded while its column is off, so it has no `lbPlaceRow` when rows land
|
|
556
|
+
on it then, and the hub places them before the template. When the column
|
|
557
|
+
first turns on and the element upgrades, the hub lands the query's last
|
|
558
|
+
answer on it again, as all rows, so every row goes through `lbPlaceRow` and
|
|
559
|
+
`lbRowsLanded` runs. Once upgraded it stays so: when its branch goes away and
|
|
560
|
+
comes back, it has placed every row that landed meanwhile, and nothing is
|
|
561
|
+
landed again.
|
|
562
|
+
|
|
501
563
|
A custom element that walks its own rows finds them with `LIVE_ROW` from
|
|
502
564
|
`@loadbare/app/constants`, never by `lb-key-value`: an element a `row` lands
|
|
503
565
|
on carries a key too, and may sit among the rows, as a total in a table's
|
|
@@ -168,6 +168,28 @@ a row goes and add scaffolding around the rows; see
|
|
|
168
168
|
[Holding rows](./custom-elements.md#holding-rows) and
|
|
169
169
|
[The Basic Widget Library](./widgets.md).
|
|
170
170
|
|
|
171
|
+
### What arrives later
|
|
172
|
+
|
|
173
|
+
The hub keeps each query's last answer until the page changes, with any
|
|
174
|
+
patch since applied to it. An element that names a query and arrives after
|
|
175
|
+
that query's answer is filled from what was kept, at the end of the landing
|
|
176
|
+
that follows its arrival. Such an element is a picker in a new live row, or
|
|
177
|
+
scaffolding a custom element builds around its rows, such as a ghost row. So
|
|
178
|
+
a query nested in another query's rows need not land again, or land after
|
|
179
|
+
the outer query, for a new outer row to show its choices.
|
|
180
|
+
|
|
181
|
+
A custom element the builder shipped absent has not upgraded while its
|
|
182
|
+
`lb-show` column is off, so rows that land on it then are not placed by it.
|
|
183
|
+
When the column first turns on and the element upgrades, the hub lands the
|
|
184
|
+
kept answer on it again, and every row goes through its `lbPlaceRow`. So a
|
|
185
|
+
table that groups its rows can sit under `lb-show`. See
|
|
186
|
+
[Holding rows](./custom-elements.md#holding-rows).
|
|
187
|
+
|
|
188
|
+
Nothing is answered from what the hub kept: a request always goes to the
|
|
189
|
+
server, and a query re-runs only when a response names it. A patch that
|
|
190
|
+
arrives before all of a query's rows is not kept, since it is not the whole
|
|
191
|
+
of anything.
|
|
192
|
+
|
|
171
193
|
A `rows` query on an element with no row template lands nothing. That is the
|
|
172
194
|
insert form above: it sits inside `lb-query="roster"` so its request is for
|
|
173
195
|
`roster`, and it shows none of its rows.
|
|
@@ -225,6 +247,14 @@ have the query answer with a boolean or a null. A row that does not carry
|
|
|
225
247
|
the column leaves the element as it is, so a query answers with the column
|
|
226
248
|
in every row.
|
|
227
249
|
|
|
250
|
+
Write `!` before the column to reverse it. One column then decides between
|
|
251
|
+
two elements, rather than a column and its opposite, which could disagree:
|
|
252
|
+
|
|
253
|
+
```html
|
|
254
|
+
<h2 lb-show="chosen" lb-column="title"></h2>
|
|
255
|
+
<p lb-show="!chosen">Choose a batch.</p>
|
|
256
|
+
```
|
|
257
|
+
|
|
228
258
|
`lb-show` reads from the nearest ancestor row, as `lb-column` does. On an
|
|
229
259
|
element that also carries `lb-query`, the column belongs to the row around
|
|
230
260
|
it, so this picker takes its choices from `groups` and whether it is present
|
|
@@ -463,6 +493,11 @@ An ancestor may stop the event, and the request is not sent. A custom
|
|
|
463
493
|
element may dispatch the event itself; see
|
|
464
494
|
[Sending a request](./custom-elements.md#sending-a-request).
|
|
465
495
|
|
|
496
|
+
Once the answer has landed, or the round trip has failed, the hub dispatches
|
|
497
|
+
a bubbling `lb-request-done` event from the same element, carrying the
|
|
498
|
+
request and what landed because of it, or the error; see
|
|
499
|
+
[Hearing how it turned out](./custom-elements.md#hearing-how-it-turned-out).
|
|
500
|
+
|
|
466
501
|
## The URL
|
|
467
502
|
|
|
468
503
|
The hub serves one query of its own, `lb-url`: one row holding the path, the
|
|
@@ -495,3 +530,4 @@ expansion, and refuses to build:
|
|
|
495
530
|
- `lb-url-unknown` on anything but a `<dialog>`, or outside `<lb-hub>`
|
|
496
531
|
- `lb-show` on a `<template>`, or on a row template's root
|
|
497
532
|
- `lb-show` with no `lb-query` around it
|
|
533
|
+
- `lb-show="!"` or `lb-show="!!column"`, which reverse no column
|
|
@@ -223,6 +223,9 @@ Every value in `values` is a string, as a control's value is.
|
|
|
223
223
|
### refresh and patch
|
|
224
224
|
|
|
225
225
|
List in `refresh` every query whose whole answer the request changed.
|
|
226
|
+
Never list one only to fill what the request's answer creates, such as the
|
|
227
|
+
picker in a new row: the hub fills that from the query's last answer. See
|
|
228
|
+
[What arrives later](./data-binding.md#what-arrives-later).
|
|
226
229
|
|
|
227
230
|
Return answers from `run` to state a narrower change than re-running a query
|
|
228
231
|
would. What `run` returns is keyed by query name and laid over the refreshed
|
|
@@ -236,8 +239,33 @@ queries:
|
|
|
236
239
|
| `patch({ drop: [...] })` | These keys are gone; the rest stand |
|
|
237
240
|
|
|
238
241
|
Return a patch for a change the request knows the extent of — one row added,
|
|
239
|
-
one row dropped, one row edited — and leave `refresh` empty.
|
|
240
|
-
|
|
242
|
+
one row dropped, one row edited — and leave `refresh` empty. A refreshed
|
|
243
|
+
`rows` query sends every row, and the hub places every row again, which moves
|
|
244
|
+
each element and takes focus from the control the user is in.
|
|
245
|
+
|
|
246
|
+
A change that seems to need a refresh usually has a patch:
|
|
247
|
+
|
|
248
|
+
- A placeholder row standing in for an empty set or section: drop its key in
|
|
249
|
+
the patch that adds the first real row, and add it back in the patch that
|
|
250
|
+
drops the last.
|
|
251
|
+
- A row whose position changes: the rows host places it, as
|
|
252
|
+
[`lb-table`](./widgets.md#lb-table) does by `data-sort`.
|
|
253
|
+
- A row whose other columns change with the edit: re-read the row and patch
|
|
254
|
+
it.
|
|
255
|
+
- Rows the database removes with a deleted one: select their keys before the
|
|
256
|
+
delete and drop them too.
|
|
257
|
+
|
|
258
|
+
An update or a delete always has a patch, since it names its row by key and
|
|
259
|
+
removing a row never reorders the rest. `createHub` refuses at startup a
|
|
260
|
+
`crud` `rowUpdate` or `rowDelete` on a `rows` query whose `refresh` names
|
|
261
|
+
that same query. An insert may refresh its own query: where a new row goes
|
|
262
|
+
depends on whether its host places it, which the server cannot see.
|
|
263
|
+
|
|
264
|
+
Each request's `refresh` is its own, and every query in it needs its own
|
|
265
|
+
reason. A list shared by several requests is a warning sign.
|
|
266
|
+
|
|
267
|
+
Re-run the query when membership or order changed in a way the request
|
|
268
|
+
cannot name:
|
|
241
269
|
|
|
242
270
|
```ts
|
|
243
271
|
resetRoster: {
|