@loadbare/app 0.4.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. package/README.md +53 -82
  2. package/dist/build/assemble.d.ts +7 -5
  3. package/dist/build/assemble.d.ts.map +1 -1
  4. package/dist/build/assemble.js +29 -9
  5. package/dist/build/cli.d.ts +20 -12
  6. package/dist/build/cli.d.ts.map +1 -1
  7. package/dist/build/cli.js +34 -16
  8. package/dist/build/elements.d.ts +15 -29
  9. package/dist/build/elements.d.ts.map +1 -1
  10. package/dist/build/elements.js +25 -111
  11. package/dist/build/expand.d.ts +1 -1
  12. package/dist/build/expand.js +1 -1
  13. package/dist/build/format.d.ts +6 -3
  14. package/dist/build/format.d.ts.map +1 -1
  15. package/dist/build/format.js +6 -3
  16. package/dist/build/locations.d.ts +14 -37
  17. package/dist/build/locations.d.ts.map +1 -1
  18. package/dist/build/locations.js +31 -69
  19. package/dist/build/origins.d.ts +109 -0
  20. package/dist/build/origins.d.ts.map +1 -0
  21. package/dist/build/origins.js +270 -0
  22. package/dist/core/lb-constants.d.ts +1 -0
  23. package/dist/core/lb-constants.d.ts.map +1 -1
  24. package/dist/core/lb-constants.js +15 -8
  25. package/dist/core/lb-types.d.ts +2 -2
  26. package/dist/core/lb-types.d.ts.map +1 -1
  27. package/dist/hub/lb-apply.js +1 -1
  28. package/dist/hub/lb-hub.d.ts.map +1 -1
  29. package/dist/hub/lb-hub.js +44 -17
  30. package/dist/hub/lb-rows.d.ts.map +1 -1
  31. package/dist/hub/lb-rows.js +3 -3
  32. package/dist/server/lb-express.d.ts.map +1 -1
  33. package/dist/server/lb-server.d.ts +5 -4
  34. package/dist/server/lb-server.d.ts.map +1 -1
  35. package/dist/tests/assemble.test.js +11 -4
  36. package/dist/tests/elements.test.js +47 -51
  37. package/dist/tests/expand.test.d.ts +1 -1
  38. package/dist/tests/expand.test.js +2 -2
  39. package/dist/tests/fixtures/elements/collision/imports.d.ts +3 -0
  40. package/dist/tests/fixtures/elements/collision/imports.d.ts.map +1 -0
  41. package/dist/tests/fixtures/elements/collision/imports.js +1 -0
  42. package/dist/tests/fixtures/elements/manifest/imports.d.ts +3 -0
  43. package/dist/tests/fixtures/elements/manifest/imports.d.ts.map +1 -0
  44. package/dist/tests/fixtures/elements/manifest/imports.js +1 -0
  45. package/dist/tests/fixtures/elements/manifest-bad-entry/imports.d.ts +3 -0
  46. package/dist/tests/fixtures/elements/manifest-bad-entry/imports.d.ts.map +1 -0
  47. package/dist/tests/fixtures/elements/manifest-bad-entry/imports.js +1 -0
  48. package/dist/tests/fixtures/elements/{collision/elements.d.ts → manifest-not-array/imports.d.ts} +1 -1
  49. package/dist/tests/fixtures/elements/manifest-not-array/imports.d.ts.map +1 -0
  50. package/dist/tests/fixtures/elements/manifest-not-array/imports.js +1 -0
  51. package/dist/tests/fixtures/elements/pkg/acme-widget.d.ts +2 -0
  52. package/dist/tests/fixtures/elements/pkg/acme-widget.d.ts.map +1 -0
  53. package/dist/tests/fixtures/elements/pkg/acme-widget.js +1 -0
  54. package/dist/tests/lb-express.test.js +1 -1
  55. package/dist/tests/origins.test.d.ts +10 -0
  56. package/dist/tests/origins.test.d.ts.map +1 -0
  57. package/dist/tests/origins.test.js +326 -0
  58. package/dist/tests/pages.test.js +3 -3
  59. package/dist/tests/styles.test.js +7 -4
  60. package/docs/reference/builder.md +128 -0
  61. package/docs/reference/chrome.md +75 -0
  62. package/docs/reference/css.md +44 -0
  63. package/docs/reference/custom-elements.md +327 -0
  64. package/docs/reference/data-binding.md +240 -0
  65. package/docs/reference/overview.md +38 -0
  66. package/docs/reference/page-files.md +175 -0
  67. package/docs/reference/server.md +123 -0
  68. package/docs/reference/widgets.md +163 -0
  69. package/docs/roadmap.md +130 -0
  70. package/docs/testing.md +228 -0
  71. package/docs/theory.md +344 -223
  72. package/docs/tutorials/000-getting-started.md +86 -0
  73. package/docs/tutorials/010-pages-and-navigation.md +129 -0
  74. package/docs/tutorials/020-css.md +103 -0
  75. package/docs/tutorials/030-html-decomposition.md +79 -0
  76. package/docs/tutorials/040-displaying-data.md +169 -0
  77. package/docs/tutorials/050-actions.md +77 -0
  78. package/docs/tutorials/060-custom-element-code.md +73 -0
  79. package/docs/tutorials/065-conditional-rendering.md +161 -0
  80. package/docs/tutorials/070-displaying-a-list.md +137 -0
  81. package/docs/tutorials/072-inserting-into-a-list.md +88 -0
  82. package/docs/tutorials/074-deleting-from-a-list.md +77 -0
  83. package/docs/tutorials/076-updating-a-list-item.md +86 -0
  84. package/docs/tutorials/080-widget-requests.md +124 -0
  85. package/docs/tutorials/090-using-widget-libraries.md +75 -0
  86. package/package.json +10 -18
  87. package/dist/client.js +0 -522
  88. package/dist/demo-static/src/widgets/app-box.d.ts +0 -15
  89. package/dist/demo-static/src/widgets/app-box.d.ts.map +0 -1
  90. package/dist/demo-static/src/widgets/app-box.js +0 -19
  91. package/dist/tests/fixtures/elements/collision/elements.d.ts.map +0 -1
  92. package/dist/tests/fixtures/elements/collision/elements.js +0 -3
  93. package/dist/tests/fixtures/elements/manifest/elements.d.ts +0 -5
  94. package/dist/tests/fixtures/elements/manifest/elements.d.ts.map +0 -1
  95. package/dist/tests/fixtures/elements/manifest/elements.js +0 -3
  96. package/dist/tests/fixtures/elements/manifest-bad-tag/elements.d.ts +0 -5
  97. package/dist/tests/fixtures/elements/manifest-bad-tag/elements.d.ts.map +0 -1
  98. package/dist/tests/fixtures/elements/manifest-bad-tag/elements.js +0 -3
  99. package/dist/tests/fixtures/elements/manifest-bad-value/elements.d.ts +0 -5
  100. package/dist/tests/fixtures/elements/manifest-bad-value/elements.d.ts.map +0 -1
  101. package/dist/tests/fixtures/elements/manifest-bad-value/elements.js +0 -3
  102. package/dist/tests/golden.test.d.ts +0 -19
  103. package/dist/tests/golden.test.d.ts.map +0 -1
  104. package/dist/tests/golden.test.js +0 -60
  105. package/dist/tests/helpers/window.d.ts +0 -43
  106. package/dist/tests/helpers/window.d.ts.map +0 -1
  107. package/dist/tests/helpers/window.js +0 -78
  108. package/dist/tests/lb-input.test.d.ts +0 -9
  109. package/dist/tests/lb-input.test.d.ts.map +0 -1
  110. package/dist/tests/lb-input.test.js +0 -78
  111. package/dist/tests/lb-list.test.d.ts +0 -12
  112. package/dist/tests/lb-list.test.d.ts.map +0 -1
  113. package/dist/tests/lb-list.test.js +0 -44
  114. package/dist/tests/lb-options.test.d.ts +0 -10
  115. package/dist/tests/lb-options.test.d.ts.map +0 -1
  116. package/dist/tests/lb-options.test.js +0 -121
  117. package/dist/tests/lb-picker.test.d.ts +0 -14
  118. package/dist/tests/lb-picker.test.d.ts.map +0 -1
  119. package/dist/tests/lb-picker.test.js +0 -59
  120. package/dist/tests/lb-select.test.d.ts +0 -9
  121. package/dist/tests/lb-select.test.d.ts.map +0 -1
  122. package/dist/tests/lb-select.test.js +0 -71
  123. package/dist/tests/lb-table.test.d.ts +0 -15
  124. package/dist/tests/lb-table.test.d.ts.map +0 -1
  125. package/dist/tests/lb-table.test.js +0 -205
  126. package/dist/widgets/index.d.ts +0 -7
  127. package/dist/widgets/index.d.ts.map +0 -1
  128. package/dist/widgets/index.js +0 -6
  129. package/dist/widgets/lb-input.d.ts +0 -2
  130. package/dist/widgets/lb-input.d.ts.map +0 -1
  131. package/dist/widgets/lb-input.js +0 -48
  132. package/dist/widgets/lb-list.d.ts +0 -2
  133. package/dist/widgets/lb-list.d.ts.map +0 -1
  134. package/dist/widgets/lb-list.js +0 -17
  135. package/dist/widgets/lb-options.d.ts +0 -26
  136. package/dist/widgets/lb-options.d.ts.map +0 -1
  137. package/dist/widgets/lb-options.js +0 -72
  138. package/dist/widgets/lb-picker.d.ts +0 -2
  139. package/dist/widgets/lb-picker.d.ts.map +0 -1
  140. package/dist/widgets/lb-picker.js +0 -25
  141. package/dist/widgets/lb-select.d.ts +0 -2
  142. package/dist/widgets/lb-select.d.ts.map +0 -1
  143. package/dist/widgets/lb-select.js +0 -43
  144. package/dist/widgets/lb-table.d.ts +0 -2
  145. package/dist/widgets/lb-table.d.ts.map +0 -1
  146. package/dist/widgets/lb-table.js +0 -113
  147. package/docs/application-chrome.md +0 -36
  148. package/docs/building-html-pages.md +0 -130
  149. package/docs/getting-started.md +0 -120
  150. package/docs/guide.md +0 -1164
  151. package/docs/hosting.md +0 -218
  152. package/docs/latent-risks.md +0 -20
  153. package/widgets/index.ts +0 -6
  154. package/widgets/lb-input.html +0 -1
  155. package/widgets/lb-input.ts +0 -64
  156. package/widgets/lb-list.html +0 -1
  157. package/widgets/lb-list.ts +0 -21
  158. package/widgets/lb-options.html +0 -4
  159. package/widgets/lb-options.ts +0 -88
  160. package/widgets/lb-picker.html +0 -7
  161. package/widgets/lb-picker.ts +0 -27
  162. package/widgets/lb-select.html +0 -4
  163. package/widgets/lb-select.ts +0 -55
  164. package/widgets/lb-table.html +0 -8
  165. package/widgets/lb-table.ts +0 -126
@@ -1,15 +0,0 @@
1
- /**
2
- * lb-table — see docs/testing.md, tier 4.
3
- *
4
- * What this widget adds at run time is placement, and only placement:
5
- * `lb-sort` names the column rows are ordered by, `lb-group` names the
6
- * column they are sectioned by. Both answers are local, which is the whole
7
- * argument for the Place callback existing.
8
- *
9
- * The markup below is what widgets/lb-table.html expands to once the page
10
- * has supplied its head and its row template — a real <thead> holding a real
11
- * <tr>, because expansion unwrapped the templates that carried them past the
12
- * parser.
13
- */
14
- export {};
15
- //# sourceMappingURL=lb-table.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lb-table.test.d.ts","sourceRoot":"","sources":["../../tests/lb-table.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG"}
@@ -1,205 +0,0 @@
1
- /**
2
- * lb-table — see docs/testing.md, tier 4.
3
- *
4
- * What this widget adds at run time is placement, and only placement:
5
- * `lb-sort` names the column rows are ordered by, `lb-group` names the
6
- * column they are sectioned by. Both answers are local, which is the whole
7
- * argument for the Place callback existing.
8
- *
9
- * The markup below is what widgets/lb-table.html expands to once the page
10
- * has supplied its head and its row template — a real <thead> holding a real
11
- * <tr>, because expansion unwrapped the templates that carried them past the
12
- * parser.
13
- */
14
- import assert from "node:assert/strict";
15
- import { describe, it } from "node:test";
16
- import { installWindow, mount } from "./helpers/window";
17
- installWindow();
18
- await import("../widgets/lb-table");
19
- const CELLS = `<td lb-cell="name"></td><td lb-cell="amount"></td>`;
20
- /** A lb-table whose row template carries the placement attributes given. */
21
- function table(placement = "") {
22
- return mount(`<lb-table><table>` +
23
- `<thead><tr><th>Name</th><th>Amount</th></tr></thead>` +
24
- `<tbody><template lb-key="id" ${placement}><tr>${CELLS}</tr></template></tbody>` +
25
- `</table></lb-table>`);
26
- }
27
- const rows = (list) => ({ op: "rows", rows: list });
28
- const patch = (change) => ({ op: "patch", ...change });
29
- /** The body, row by row: a section heading as its label, a row as its cells. */
30
- function shown(widget) {
31
- return [...widget.querySelectorAll("tbody > tr")].map((tr) => tr.hasAttribute("data-group")
32
- ? `— ${tr.textContent.trim()}`
33
- : [...tr.children].map((td) => td.textContent).join("/"));
34
- }
35
- describe("lb-table without placement", () => {
36
- it("lands rows in the body, in the order sent", () => {
37
- const widget = table();
38
- widget.acceptRows(rows([
39
- { id: "1", name: "Ada", amount: "10" },
40
- { id: "2", name: "Bab", amount: "20" },
41
- ]));
42
- assert.deepEqual(shown(widget), ["Ada/10", "Bab/20"]);
43
- });
44
- it("leaves the head the page wrote alone", () => {
45
- const widget = table();
46
- widget.acceptRows(rows([{ id: "1", name: "Ada", amount: "10" }]));
47
- assert.equal(widget.querySelectorAll("thead tr").length, 1);
48
- assert.equal(widget.querySelector("thead th").textContent, "Name");
49
- });
50
- it("counts its rows for the stylesheet", () => {
51
- const widget = table();
52
- widget.acceptRows(rows([{ id: "1", name: "Ada", amount: "10" }]));
53
- assert.equal(widget.getAttribute("data-rows"), "1");
54
- });
55
- });
56
- describe("lb-table sorting", () => {
57
- it("orders rows by the column lb-sort names", () => {
58
- const widget = table(`lb-sort="name"`);
59
- widget.acceptRows(rows([
60
- { id: "1", name: "Cai", amount: "30" },
61
- { id: "2", name: "Ada", amount: "10" },
62
- { id: "3", name: "Bab", amount: "20" },
63
- ]));
64
- assert.deepEqual(shown(widget), ["Ada/10", "Bab/20", "Cai/30"]);
65
- });
66
- it("puts a patched-in row in its place rather than at the end", () => {
67
- // A whole set and a single patched row take the same path, which is the
68
- // reason placement is a callback rather than a branch.
69
- const widget = table(`lb-sort="name"`);
70
- widget.acceptRows(rows([
71
- { id: "1", name: "Ada", amount: "10" },
72
- { id: "3", name: "Cai", amount: "30" },
73
- ]));
74
- widget.acceptRows(patch({ rows: [{ id: "2", name: "Bab", amount: "20" }] }));
75
- assert.deepEqual(shown(widget), ["Ada/10", "Bab/20", "Cai/30"]);
76
- });
77
- it("leaves a row whose sort column changed where it was", () => {
78
- // Today's behavior, and the gap NEEDED-FOR-1.0 names: a patch never
79
- // re-places a row that already exists. The row's contents are current and
80
- // its position is stale. This test flips when that item closes.
81
- const widget = table(`lb-sort="name"`);
82
- widget.acceptRows(rows([
83
- { id: "1", name: "Ada", amount: "10" },
84
- { id: "2", name: "Bab", amount: "20" },
85
- ]));
86
- widget.acceptRows(patch({ rows: [{ id: "1", name: "Zed", amount: "10" }] }));
87
- assert.deepEqual(shown(widget), ["Zed/10", "Bab/20"]);
88
- });
89
- it("sorts a whole set again, however it was reached", () => {
90
- const widget = table(`lb-sort="name"`);
91
- widget.acceptRows(rows([
92
- { id: "1", name: "Ada", amount: "10" },
93
- { id: "2", name: "Bab", amount: "20" },
94
- ]));
95
- widget.acceptRows(patch({ rows: [{ id: "1", name: "Zed", amount: "10" }] }));
96
- widget.acceptRows(rows([
97
- { id: "1", name: "Zed", amount: "10" },
98
- { id: "2", name: "Bab", amount: "20" },
99
- ]));
100
- assert.deepEqual(shown(widget), ["Bab/20", "Zed/10"]);
101
- });
102
- });
103
- describe("lb-table grouping", () => {
104
- it("builds a section heading per distinct value", () => {
105
- const widget = table(`lb-group="dept"`);
106
- widget.acceptRows(rows([
107
- { id: "1", name: "Ada", amount: "10", dept: "Core" },
108
- { id: "2", name: "Bab", amount: "20", dept: "Ops" },
109
- { id: "3", name: "Cai", amount: "30", dept: "Core" },
110
- ]));
111
- assert.deepEqual(shown(widget), [
112
- "— Core",
113
- "Ada/10",
114
- "Cai/30",
115
- "— Ops",
116
- "Bab/20",
117
- ]);
118
- });
119
- it("spans the heading across the row the page wrote", () => {
120
- // How wide the table is, from the row template. Nothing else knows, and
121
- // nothing had to be told twice.
122
- const widget = table(`lb-group="dept"`);
123
- widget.acceptRows(rows([{ id: "1", name: "Ada", amount: "10", dept: "Core" }]));
124
- const th = widget.querySelector("tr[data-group] th");
125
- assert.equal(th.colSpan, 2);
126
- assert.equal(th.getAttribute("scope"), "rowgroup");
127
- });
128
- it("removes a section when its last row goes", () => {
129
- const widget = table(`lb-group="dept"`);
130
- widget.acceptRows(rows([
131
- { id: "1", name: "Ada", amount: "10", dept: "Core" },
132
- { id: "2", name: "Bab", amount: "20", dept: "Ops" },
133
- ]));
134
- widget.acceptRows(patch({ drop: ["2"] }));
135
- assert.deepEqual(shown(widget), ["— Core", "Ada/10"]);
136
- });
137
- it("sorts within a section, not across the table", () => {
138
- const widget = table(`lb-group="dept" lb-sort="name"`);
139
- widget.acceptRows(rows([
140
- { id: "1", name: "Zed", amount: "10", dept: "Core" },
141
- { id: "2", name: "Ada", amount: "20", dept: "Ops" },
142
- { id: "3", name: "Bab", amount: "30", dept: "Core" },
143
- ]));
144
- assert.deepEqual(shown(widget), [
145
- "— Core",
146
- "Bab/30",
147
- "Zed/10",
148
- "— Ops",
149
- "Ada/20",
150
- ]);
151
- });
152
- it("patches a row into the right place in its section", () => {
153
- const widget = table(`lb-group="dept" lb-sort="name"`);
154
- widget.acceptRows(rows([
155
- { id: "1", name: "Ada", amount: "10", dept: "Core" },
156
- { id: "2", name: "Cai", amount: "30", dept: "Core" },
157
- { id: "3", name: "Eve", amount: "50", dept: "Ops" },
158
- ]));
159
- widget.acceptRows(patch({ rows: [{ id: "4", name: "Bab", amount: "20", dept: "Core" }] }));
160
- assert.deepEqual(shown(widget), [
161
- "— Core",
162
- "Ada/10",
163
- "Bab/20",
164
- "Cai/30",
165
- "— Ops",
166
- "Eve/50",
167
- ]);
168
- });
169
- it("sections a tuple with no value for the column under the empty label", () => {
170
- const widget = table(`lb-group="dept"`);
171
- widget.acceptRows(rows([{ id: "1", name: "Ada", amount: "10" }]));
172
- assert.deepEqual(shown(widget), ["— ", "Ada/10"]);
173
- });
174
- it("does not count a section heading as a row", () => {
175
- // A heading carries no lb-key, so it is scaffolding rather than a row —
176
- // and the count a stylesheet reads has to say so.
177
- const widget = table(`lb-group="dept"`);
178
- widget.acceptRows(rows([
179
- { id: "1", name: "Ada", amount: "10", dept: "Core" },
180
- { id: "2", name: "Bab", amount: "20", dept: "Ops" },
181
- ]));
182
- assert.equal(widget.getAttribute("data-rows"), "2");
183
- });
184
- it("empties to no rows and no sections", () => {
185
- const widget = table(`lb-group="dept"`);
186
- widget.acceptRows(rows([{ id: "1", name: "Ada", amount: "10", dept: "Core" }]));
187
- widget.acceptRows(rows([]));
188
- assert.deepEqual(shown(widget), []);
189
- assert.equal(widget.getAttribute("data-rows"), "0");
190
- });
191
- });
192
- describe("a table's foot", () => {
193
- it("is an ordinary scope, untouched by the row machinery", () => {
194
- // A <tfoot> is a place on the page, not a row the hub delivers. What
195
- // lands in it is a second projection of the same table, resolved by name
196
- // like any other — see demo/pages/ledger.html.
197
- const widget = mount(`<lb-table><table>` +
198
- `<tbody><template lb-key="id"><tr>${CELLS}</tr></template></tbody>` +
199
- `<tfoot><tr lb-query="total"><th lb-cell="name"></th><td lb-cell="amount"></td></tr></tfoot>` +
200
- `</table></lb-table>`);
201
- widget.acceptRows(rows([{ id: "1", name: "Ada", amount: "10" }]));
202
- assert.equal(widget.querySelectorAll("tfoot tr").length, 1);
203
- assert.equal(widget.getAttribute("data-rows"), "1", "the foot is not a row");
204
- });
205
- });
@@ -1,7 +0,0 @@
1
- import "./lb-input";
2
- import "./lb-select";
3
- import "./lb-list";
4
- import "./lb-options";
5
- import "./lb-table";
6
- import "./lb-picker";
7
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../widgets/index.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,CAAC;AACpB,OAAO,aAAa,CAAC;AACrB,OAAO,WAAW,CAAC;AACnB,OAAO,cAAc,CAAC;AACtB,OAAO,YAAY,CAAC;AACpB,OAAO,aAAa,CAAC"}
@@ -1,6 +0,0 @@
1
- import "./lb-input";
2
- import "./lb-select";
3
- import "./lb-list";
4
- import "./lb-options";
5
- import "./lb-table";
6
- import "./lb-picker";
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=lb-input.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lb-input.d.ts","sourceRoot":"","sources":["../../widgets/lb-input.ts"],"names":[],"mappings":""}
@@ -1,48 +0,0 @@
1
- /// <reference lib="dom" />
2
- import { ATTR_CELL, ATTR_KEY, ATTR_QUERY, ATTR_VALUE, LB_EVENT_NAME, } from "../core/lb-constants";
3
- /**
4
- * A leaf cell wrapping an <input>. The hub writes one attribute name for
5
- * every widget type, so the value lands in `lb-value` and the widget
6
- * forwards it to the control it owns.
7
- *
8
- * The other direction of the same cell: on change it sends `cell-change`,
9
- * addressed by the same lb-query/lb-key/lb-cell coordinates the value
10
- * arrived on. A `readonly` input never fires `change` from user input, so a
11
- * readonly cell sends nothing on its own.
12
- */
13
- class LbInput extends HTMLElement {
14
- static observedAttributes = [ATTR_VALUE];
15
- attributeChangedCallback(_name, _old, value) {
16
- const input = this.querySelector("input");
17
- if (!input) {
18
- console.error(`lb-input: no <input> to receive the value`);
19
- return;
20
- }
21
- input.value = value;
22
- }
23
- connectedCallback() {
24
- this.addEventListener("change", () => {
25
- const input = this.querySelector("input");
26
- if (!input) {
27
- console.error(`lb-input: change with no <input>, ignoring`);
28
- return;
29
- }
30
- const query = this.closest(`[${ATTR_QUERY}]`)?.getAttribute(ATTR_QUERY);
31
- const key = this.closest(`[${ATTR_KEY}]`)?.getAttribute(ATTR_KEY);
32
- const cell = this.getAttribute(ATTR_CELL);
33
- if (!query || !key || !cell) {
34
- console.error(`lb-input: change with no query/key/cell coordinates, ignoring`);
35
- return;
36
- }
37
- const detail = {
38
- op: "cell-change",
39
- query,
40
- key,
41
- cell,
42
- value: input.value,
43
- };
44
- this.dispatchEvent(new CustomEvent(LB_EVENT_NAME, { bubbles: true, detail }));
45
- });
46
- }
47
- }
48
- customElements.define("lb-input", LbInput);
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=lb-list.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lb-list.d.ts","sourceRoot":"","sources":["../../widgets/lb-list.ts"],"names":[],"mappings":""}
@@ -1,17 +0,0 @@
1
- /// <reference lib="dom" />
2
- import { applyRows } from "../hub/lb-rows";
3
- /**
4
- * The plain repeater: whatever the page author wrote inside is repeated once
5
- * per tuple, in the order the server sent.
6
- *
7
- * It exists because a projection has to land on a widget, and because a
8
- * `<table>` cannot be one — a custom element written inside `<tbody>` is
9
- * discarded by the parser, so the widget goes around the table and the
10
- * template goes inside it, where the content model already allows it.
11
- */
12
- class LbList extends HTMLElement {
13
- acceptRows(result) {
14
- applyRows(this, result);
15
- }
16
- }
17
- customElements.define("lb-list", LbList);
@@ -1,26 +0,0 @@
1
- import type { Projection, HubRowHost } from "../core/lb-types";
2
- /**
3
- * A `<select>` whose choices come from a query, and the case that shows why
4
- * placement belongs to the widget rather than to the framework.
5
- *
6
- * The rows arrive flat and keyed. Nothing on the wire knows about
7
- * `<optgroup>`, and nothing needs to: a group is a column like any other, and
8
- * turning a repeated column value into an element is exactly the local
9
- * knowledge a widget has and the hub does not. A table wanting section
10
- * headings would read the same `lb-group` and build something else.
11
- *
12
- * The identity of a row is the value of the option, so `lb-key` supplies
13
- * both and the page declares it once.
14
- *
15
- * Exported because `lb-picker` is this widget with its row template
16
- * supplied by the definition instead of by the page. Nothing about the
17
- * behavior changes, so nothing about the behavior is written twice.
18
- */
19
- export declare class LbOptions extends HTMLElement implements HubRowHost {
20
- acceptRows(result: Projection): void;
21
- private place;
22
- /** The group with this label, or a new one in front of the template. */
23
- private groupFor;
24
- connectedCallback(): void;
25
- }
26
- //# sourceMappingURL=lb-options.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lb-options.d.ts","sourceRoot":"","sources":["../../widgets/lb-options.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,UAAU,EAEV,UAAU,EACX,MAAM,kBAAkB,CAAC;AAG1B;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,SAAU,SAAQ,WAAY,YAAW,UAAU;IAC9D,UAAU,CAAC,MAAM,EAAE,UAAU;IAa7B,OAAO,CAAC,KAAK,CAQX;IAEF,wEAAwE;IACxE,OAAO,CAAC,QAAQ;IAUhB,iBAAiB;CAkBlB"}
@@ -1,72 +0,0 @@
1
- /// <reference lib="dom" />
2
- import { ATTR_ACTION, ATTR_GROUP, ATTR_KEY, LB_EVENT_NAME, } from "../core/lb-constants";
3
- import { applyRows } from "../hub/lb-rows";
4
- /**
5
- * A `<select>` whose choices come from a query, and the case that shows why
6
- * placement belongs to the widget rather than to the framework.
7
- *
8
- * The rows arrive flat and keyed. Nothing on the wire knows about
9
- * `<optgroup>`, and nothing needs to: a group is a column like any other, and
10
- * turning a repeated column value into an element is exactly the local
11
- * knowledge a widget has and the hub does not. A table wanting section
12
- * headings would read the same `lb-group` and build something else.
13
- *
14
- * The identity of a row is the value of the option, so `lb-key` supplies
15
- * both and the page declares it once.
16
- *
17
- * Exported because `lb-picker` is this widget with its row template
18
- * supplied by the definition instead of by the page. Nothing about the
19
- * behavior changes, so nothing about the behavior is written twice.
20
- */
21
- export class LbOptions extends HTMLElement {
22
- acceptRows(result) {
23
- applyRows(this, result, this.place);
24
- // The identity of the row is the value of the option, so nothing on the
25
- // page has to say so twice.
26
- for (const option of this.querySelectorAll(`option[${ATTR_KEY}]`)) {
27
- option.setAttribute("value", option.getAttribute(ATTR_KEY));
28
- }
29
- // A group is derived, so it goes when its last row does.
30
- for (const group of this.querySelectorAll("optgroup")) {
31
- if (!group.querySelector("option"))
32
- group.remove();
33
- }
34
- }
35
- place = (row, tuple, template) => {
36
- const select = this.querySelector("select");
37
- const groupCell = template.getAttribute(ATTR_GROUP);
38
- if (!groupCell) {
39
- select.insertBefore(row, template);
40
- return;
41
- }
42
- this.groupFor(select, template, tuple[groupCell] ?? "").append(row);
43
- };
44
- /** The group with this label, or a new one in front of the template. */
45
- groupFor(select, template, label) {
46
- for (const group of select.querySelectorAll("optgroup")) {
47
- if (group.label === label)
48
- return group;
49
- }
50
- const group = document.createElement("optgroup");
51
- group.label = label;
52
- select.insertBefore(group, template);
53
- return group;
54
- }
55
- connectedCallback() {
56
- this.addEventListener("change", () => {
57
- const select = this.querySelector("select");
58
- if (!select) {
59
- console.error(`lb-options: change with no <select>, ignoring`);
60
- return;
61
- }
62
- const name = this.getAttribute(ATTR_ACTION);
63
- if (!name) {
64
- console.error(`lb-options: no ${ATTR_ACTION}, nothing to send`);
65
- return;
66
- }
67
- const detail = { op: "action", name, value: select.value };
68
- this.dispatchEvent(new CustomEvent(LB_EVENT_NAME, { bubbles: true, detail }));
69
- });
70
- }
71
- }
72
- customElements.define("lb-options", LbOptions);
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=lb-picker.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lb-picker.d.ts","sourceRoot":"","sources":["../../widgets/lb-picker.ts"],"names":[],"mappings":""}
@@ -1,25 +0,0 @@
1
- /// <reference lib="dom" />
2
- import { LbOptions } from "./lb-options";
3
- /**
4
- * The same `<select>` as `lb-options`, with the row template supplied by
5
- * the definition instead of by the page.
6
- *
7
- * A row template is markup, so writing it is the page author's job — until
8
- * every row is one option and the only thing that varies is which columns it
9
- * reads. Those are words, and words are parameters: `exp-key`, `exp-cell` and
10
- * `exp-group` fill the placeholders in the template the definition already
11
- * has, at build time, and the page writes one tag with no children.
12
- *
13
- * It is the same trade as anywhere else in expansion. A page author who wants
14
- * a second element in the row, or an option built from two columns, writes
15
- * `lb-options` and the template themselves. This one is for when they do
16
- * not.
17
- *
18
- * The behavior is inherited whole, because it is the same behavior: rows land
19
- * in groups, the key becomes the value, and a change sends the declared
20
- * action. A distinct class exists only because `customElements.define`
21
- * requires one constructor per name.
22
- */
23
- class LbPicker extends LbOptions {
24
- }
25
- customElements.define("lb-picker", LbPicker);
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=lb-select.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lb-select.d.ts","sourceRoot":"","sources":["../../widgets/lb-select.ts"],"names":[],"mappings":""}
@@ -1,43 +0,0 @@
1
- /// <reference lib="dom" />
2
- import { ATTR_ACTION, ATTR_VALUE, LB_EVENT_NAME, } from "../core/lb-constants";
3
- /**
4
- * A leaf cell wrapping a <select>. It receives its value like any other cell,
5
- * and on change it sends the action the page declared for it — the request
6
- * vocabulary and the addressing vocabulary running in both directions on one
7
- * widget.
8
- *
9
- * The choice is the interaction, so this is the case where an action carries
10
- * a value. The server still decides what that choice means.
11
- */
12
- class LbSelect extends HTMLElement {
13
- static observedAttributes = [ATTR_VALUE];
14
- attributeChangedCallback(_name, _old, value) {
15
- const select = this.querySelector("select");
16
- if (!select) {
17
- console.error(`lb-select: no <select> to receive the value`);
18
- return;
19
- }
20
- select.value = value;
21
- }
22
- connectedCallback() {
23
- this.addEventListener("change", () => {
24
- const select = this.querySelector("select");
25
- if (!select) {
26
- console.error(`lb-select: change with no <select>, ignoring`);
27
- return;
28
- }
29
- const name = this.getAttribute(ATTR_ACTION);
30
- if (!name) {
31
- console.error(`lb-select: no ${ATTR_ACTION}, nothing to send`);
32
- return;
33
- }
34
- const detail = {
35
- op: "action",
36
- name,
37
- value: select.value,
38
- };
39
- this.dispatchEvent(new CustomEvent(LB_EVENT_NAME, { bubbles: true, detail }));
40
- });
41
- }
42
- }
43
- customElements.define("lb-select", LbSelect);
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=lb-table.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lb-table.d.ts","sourceRoot":"","sources":["../../widgets/lb-table.ts"],"names":[],"mappings":""}
@@ -1,113 +0,0 @@
1
- /// <reference lib="dom" />
2
- import { ATTR_CELL, ATTR_GROUP, ATTR_KEY, ATTR_SORT, } from "../core/lb-constants";
3
- import { applyRows } from "../hub/lb-rows";
4
- /**
5
- * A table that owns its own scaffolding, and the case that shows what a list
6
- * widget is for once the repeater exists.
7
- *
8
- * `lb-list` goes around a table the page author wrote. This one supplies
9
- * the table, and the page writes what only the page knows: the heading row
10
- * and the row template. That division is forced rather than chosen — a
11
- * `<thead>` written inside a custom element is not inside a table, so the
12
- * parser drops the tag and keeps the text. A `<template>` survives anywhere,
13
- * so the heading row arrives wrapped and expansion unwraps it into the
14
- * `lb-template` destination beside the slot.
15
- *
16
- * What it adds at run time is placement, and only placement. `lb-sort` names
17
- * the column rows are ordered by; `lb-group` names the column they are
18
- * sectioned by, and is the same attribute a grouped `<select>` reads, because
19
- * a table with section headings and an `<optgroup>` are asking the same thing
20
- * of the same data.
21
- *
22
- * The `foot` destination is the head's argument a second time and needs no
23
- * code here. A `<tfoot>` is a place on the page, not a row the hub delivers,
24
- * so what lands in it is an ordinary scope carrying its own `lb-query` — a
25
- * grand total is a second projection of the same table, and the hub resolves
26
- * it by name like any other. See demo/pages/ledger.html.
27
- */
28
- /**
29
- * The heading row of a section, carrying the value it stands for.
30
- *
31
- * The widget's own scaffolding, so it is HTML's namespace rather than
32
- * Loadbare App's: it is derived from rows the hub knows and is invisible to the hub
33
- * itself, exactly as the `<optgroup>` in `lb-options` is. Nothing
34
- * addresses it, so it carries no `lb-key` and no name from the vocabulary.
35
- */
36
- const GROUP_ROW = "data-group";
37
- class LbTable extends HTMLElement {
38
- acceptRows(result) {
39
- applyRows(this, result, this.place);
40
- // A section is derived, so it goes when its last row does.
41
- for (const heading of this.querySelectorAll(`tr[${GROUP_ROW}]`)) {
42
- if (this.section(heading).rows.length === 0)
43
- heading.remove();
44
- }
45
- }
46
- /**
47
- * Group first, then sort within the group.
48
- *
49
- * Inserting a row before the first one that sorts after it keeps the
50
- * section ordered, whatever else is in it — which is what lets a whole set
51
- * and a single patched row take the same path.
52
- */
53
- place = (row, tuple, template) => {
54
- const groupCell = template.getAttribute(ATTR_GROUP);
55
- const sortCell = template.getAttribute(ATTR_SORT);
56
- const heading = groupCell
57
- ? this.headingFor(template, tuple[groupCell] ?? "")
58
- : null;
59
- const { rows, end } = this.section(heading);
60
- const value = sortCell ? (tuple[sortCell] ?? "") : "";
61
- const after = sortCell
62
- ? rows.find((other) => other !== row && cellOf(other, sortCell) > value)
63
- : undefined;
64
- template.parentElement.insertBefore(row, after ?? end);
65
- };
66
- /**
67
- * The rows of one section, and the node it ends at.
68
- *
69
- * A section runs from its heading to the next heading, or to the template
70
- * if there is none after it. Without grouping there is one section and it
71
- * is the whole body — the heading row the page wrote is skipped along the
72
- * way, because it carries no key and is therefore not a row.
73
- */
74
- section(heading) {
75
- const template = this.querySelector("template");
76
- const rows = [];
77
- let node = heading
78
- ? heading.nextElementSibling
79
- : template.parentElement.firstElementChild;
80
- while (node && node !== template && !node.hasAttribute(GROUP_ROW)) {
81
- if (node.hasAttribute(ATTR_KEY))
82
- rows.push(node);
83
- node = node.nextElementSibling;
84
- }
85
- return { rows, end: node ?? template };
86
- }
87
- /** The section with this label, or a new one in front of the template. */
88
- headingFor(template, label) {
89
- const body = template.parentElement;
90
- for (const heading of body.querySelectorAll(`tr[${GROUP_ROW}]`)) {
91
- if (heading.getAttribute(GROUP_ROW) === label)
92
- return heading;
93
- }
94
- const heading = document.createElement("tr");
95
- heading.setAttribute(GROUP_ROW, label);
96
- const cell = document.createElement("th");
97
- cell.setAttribute("scope", "rowgroup");
98
- // How wide the table is, from the row the page author wrote. Nothing
99
- // else knows, and nothing had to be told twice.
100
- cell.colSpan = template.content.firstElementChild?.childElementCount ?? 1;
101
- cell.textContent = label;
102
- heading.append(cell);
103
- body.insertBefore(heading, template);
104
- return heading;
105
- }
106
- }
107
- /** What a live row is showing in one column. */
108
- function cellOf(row, cell) {
109
- const selector = `[${ATTR_CELL}="${cell}"]`;
110
- const el = row.matches(selector) ? row : row.querySelector(selector);
111
- return el?.textContent ?? "";
112
- }
113
- customElements.define("lb-table", LbTable);