@loadbare/app 0.5.5 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -4
- package/dist/build/assemble.d.ts +1 -1
- package/dist/build/assemble.d.ts.map +1 -1
- package/dist/build/assemble.js +80 -7
- package/dist/build/cli.d.ts +2 -2
- package/dist/build/cli.js +2 -2
- package/dist/build/expand.d.ts.map +1 -1
- package/dist/build/expand.js +30 -34
- package/dist/build/locations.d.ts +3 -3
- package/dist/build/locations.d.ts.map +1 -1
- package/dist/build/locations.js +15 -3
- package/dist/build/origins.d.ts +0 -13
- package/dist/build/origins.d.ts.map +1 -1
- package/dist/build/origins.js +32 -8
- package/dist/build/pages.d.ts +3 -3
- package/dist/build/pages.d.ts.map +1 -1
- package/dist/build/pages.js +9 -7
- package/dist/core/lb-constants.d.ts +17 -12
- package/dist/core/lb-constants.d.ts.map +1 -1
- package/dist/core/lb-constants.js +106 -43
- package/dist/core/lb-types.d.ts +103 -62
- package/dist/core/lb-types.d.ts.map +1 -1
- package/dist/core/lb-types.js +11 -3
- package/dist/hub/lb-apply.d.ts +18 -4
- package/dist/hub/lb-apply.d.ts.map +1 -1
- package/dist/hub/lb-apply.js +184 -34
- package/dist/hub/lb-hub.browser.d.ts +1 -1
- package/dist/hub/lb-hub.browser.d.ts.map +1 -1
- package/dist/hub/lb-hub.browser.js +165 -83
- package/dist/server/lb-express.d.ts +7 -4
- package/dist/server/lb-express.d.ts.map +1 -1
- package/dist/server/lb-express.js +45 -33
- package/dist/server/lb-server.d.ts +67 -45
- package/dist/server/lb-server.d.ts.map +1 -1
- package/dist/server/lb-server.js +55 -18
- package/dist/tests/assemble.test.js +154 -2
- package/dist/tests/expand.test.js +30 -3
- package/dist/tests/helpers/hub.d.ts +73 -0
- package/dist/tests/helpers/hub.d.ts.map +1 -0
- package/dist/tests/helpers/hub.js +151 -0
- package/dist/tests/lb-apply.test.js +86 -62
- package/dist/tests/lb-express.test.d.ts +1 -1
- package/dist/tests/lb-express.test.js +43 -38
- package/dist/tests/lb-hub.test.d.ts +14 -0
- package/dist/tests/lb-hub.test.d.ts.map +1 -0
- package/dist/tests/lb-hub.test.js +319 -0
- package/dist/tests/{lb-rows.test.d.ts → lb-list.test.d.ts} +1 -1
- package/dist/tests/lb-list.test.d.ts.map +1 -0
- package/dist/tests/{lb-rows.test.js → lb-list.test.js} +109 -106
- package/dist/tests/lb-server.test.js +151 -100
- package/dist/tests/origins.test.js +19 -1
- package/dist/tests/pages.test.d.ts +1 -1
- package/dist/tests/pages.test.js +64 -14
- package/docs/TECHREF-1.0.md +1000 -0
- package/docs/reference/builder.md +4 -4
- package/docs/reference/chrome.md +56 -5
- package/docs/reference/custom-elements.md +59 -36
- package/docs/reference/data-binding.md +142 -84
- package/docs/reference/overview.md +1 -1
- package/docs/reference/page-files.md +64 -49
- package/docs/reference/server.md +7 -6
- package/docs/reference/widgets.md +43 -32
- package/docs/roadmap.md +68 -22
- package/docs/testing.md +47 -17
- package/docs/theory.md +2 -2
- package/docs/tutorials/010-pages-and-navigation.md +14 -8
- package/docs/tutorials/040-displaying-data.md +9 -9
- package/docs/tutorials/050-actions.md +5 -5
- package/docs/tutorials/060-custom-element-code.md +1 -1
- package/docs/tutorials/065-conditional-rendering.md +4 -4
- package/docs/tutorials/070-displaying-a-list.md +24 -47
- package/docs/tutorials/072-inserting-into-a-list.md +17 -17
- package/docs/tutorials/074-deleting-from-a-list.md +15 -17
- package/docs/tutorials/076-updating-a-list-item.md +20 -22
- package/docs/tutorials/080-widget-requests.md +27 -23
- package/docs/tutorials/090-using-widget-libraries.md +23 -1
- package/package.json +1 -2
- package/dist/hub/lb-rows.d.ts +0 -18
- package/dist/hub/lb-rows.d.ts.map +0 -1
- package/dist/hub/lb-rows.js +0 -106
- package/dist/tests/lb-rows.test.d.ts.map +0 -1
package/dist/hub/lb-rows.js
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/// <reference lib="dom" />
|
|
2
|
-
/**
|
|
3
|
-
* The row machinery a list widget shares — see docs/reference/custom-elements.md,
|
|
4
|
-
* "Accepting rows".
|
|
5
|
-
*
|
|
6
|
-
* A widget owns where a row goes and nothing else. Cloning the template,
|
|
7
|
-
* matching a tuple to the row already showing it, and filling that row are
|
|
8
|
-
* the same in every list, so they are here, and a widget that sorts or groups
|
|
9
|
-
* supplies one function rather than a second implementation of all of it.
|
|
10
|
-
*/
|
|
11
|
-
import { ATTR_KEY, ATTR_ROW_COUNT } from "../core/lb-constants";
|
|
12
|
-
import { applyTuple } from "./lb-apply";
|
|
13
|
-
const before = (row, _tuple, template) => {
|
|
14
|
-
template.parentElement.insertBefore(row, template);
|
|
15
|
-
};
|
|
16
|
-
/** The row template: the one the page author wrote inside this widget. */
|
|
17
|
-
function templateIn(scope) {
|
|
18
|
-
const template = scope.querySelector("template");
|
|
19
|
-
if (!template) {
|
|
20
|
-
console.error(`lb-rows: <${scope.localName}> has no <template> to clone`);
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
if (!template.getAttribute(ATTR_KEY)) {
|
|
24
|
-
console.error(`lb-rows: the <template> in <${scope.localName}> has no ${ATTR_KEY} ` +
|
|
25
|
-
`naming the column that identifies a row`);
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
return template;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* The rows already showing, by the key value each carries.
|
|
32
|
-
*
|
|
33
|
-
* `lb-key` names the key column on the template and carries the key value on
|
|
34
|
-
* a live row. One name in two positions, and never ambiguous, because a
|
|
35
|
-
* template is not a row.
|
|
36
|
-
*/
|
|
37
|
-
function showing(scope, template) {
|
|
38
|
-
const rows = new Map();
|
|
39
|
-
for (const el of scope.querySelectorAll(`[${ATTR_KEY}]`)) {
|
|
40
|
-
if (el !== template)
|
|
41
|
-
rows.set(el.getAttribute(ATTR_KEY), el);
|
|
42
|
-
}
|
|
43
|
-
return rows;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Land a projection in a widget's subtree.
|
|
47
|
-
*
|
|
48
|
-
* `rows` is the whole set, so it decides membership and order: every row is
|
|
49
|
-
* placed in the order given, and a row whose key did not arrive is gone.
|
|
50
|
-
* `patch` disturbs only what it names — a row it did not mention keeps its
|
|
51
|
-
* contents and its position.
|
|
52
|
-
*/
|
|
53
|
-
export function applyRows(scope, result, place = before) {
|
|
54
|
-
const template = templateIn(scope);
|
|
55
|
-
if (!template)
|
|
56
|
-
return;
|
|
57
|
-
const keyCell = template.getAttribute(ATTR_KEY);
|
|
58
|
-
const rows = showing(scope, template);
|
|
59
|
-
const upsert = (tuple) => {
|
|
60
|
-
const key = tuple[keyCell];
|
|
61
|
-
if (key === undefined) {
|
|
62
|
-
console.error(`lb-rows: a tuple for <${scope.localName}> has no '${keyCell}' cell`);
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
let row = rows.get(key);
|
|
66
|
-
const fresh = row === undefined;
|
|
67
|
-
if (!row) {
|
|
68
|
-
row = template.content.firstElementChild.cloneNode(true);
|
|
69
|
-
row.setAttribute(ATTR_KEY, key);
|
|
70
|
-
rows.set(key, row);
|
|
71
|
-
}
|
|
72
|
-
// Fill before insertion. The attributes are already there when the row
|
|
73
|
-
// upgrades, which is the same thing that makes hydration and refresh one
|
|
74
|
-
// operation everywhere else.
|
|
75
|
-
applyTuple(row, tuple);
|
|
76
|
-
if (fresh || result.op === "rows")
|
|
77
|
-
place(row, tuple, template);
|
|
78
|
-
return key;
|
|
79
|
-
};
|
|
80
|
-
if (result.op === "rows") {
|
|
81
|
-
const arrived = new Set();
|
|
82
|
-
for (const tuple of result.rows) {
|
|
83
|
-
const key = upsert(tuple);
|
|
84
|
-
if (key !== null)
|
|
85
|
-
arrived.add(key);
|
|
86
|
-
}
|
|
87
|
-
for (const [key, row] of rows)
|
|
88
|
-
if (!arrived.has(key))
|
|
89
|
-
row.remove();
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
for (const tuple of result.rows ?? [])
|
|
93
|
-
upsert(tuple);
|
|
94
|
-
for (const key of result.drop ?? [])
|
|
95
|
-
rows.get(key)?.remove();
|
|
96
|
-
}
|
|
97
|
-
// How many rows are showing, counted from the DOM rather than from either
|
|
98
|
-
// branch above, so a set and a patch report the same fact the same way.
|
|
99
|
-
//
|
|
100
|
-
// It is stamped here because only this function knows the count: it is the
|
|
101
|
-
// one conditional a page cannot be sent, since the server answers with rows
|
|
102
|
-
// and says nothing about how many survived reconciliation. A page says what
|
|
103
|
-
// an empty list looks like in a stylesheet, and no list widget carries code
|
|
104
|
-
// for it. See docs/reference/data-binding.md.
|
|
105
|
-
scope.setAttribute(ATTR_ROW_COUNT, String(showing(scope, template).size));
|
|
106
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lb-rows.test.d.ts","sourceRoot":"","sources":["../../tests/lb-rows.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG"}
|