@loadbare/app 0.5.6 → 0.7.0

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