@loadbare/widgets 0.2.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/LICENSE +201 -0
- package/README.md +34 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/lb-input.d.ts +2 -0
- package/dist/lb-input.d.ts.map +1 -0
- package/dist/lb-input.html +1 -0
- package/dist/lb-input.js +57 -0
- package/dist/lb-input.js.map +1 -0
- package/dist/lb-list.d.ts +2 -0
- package/dist/lb-list.d.ts.map +1 -0
- package/dist/lb-list.html +1 -0
- package/dist/lb-list.js +18 -0
- package/dist/lb-list.js.map +1 -0
- package/dist/lb-options.d.ts +26 -0
- package/dist/lb-options.d.ts.map +1 -0
- package/dist/lb-options.html +4 -0
- package/dist/lb-options.js +73 -0
- package/dist/lb-options.js.map +1 -0
- package/dist/lb-picker.d.ts +2 -0
- package/dist/lb-picker.d.ts.map +1 -0
- package/dist/lb-picker.html +7 -0
- package/dist/lb-picker.js +26 -0
- package/dist/lb-picker.js.map +1 -0
- package/dist/lb-select.d.ts +2 -0
- package/dist/lb-select.d.ts.map +1 -0
- package/dist/lb-select.html +4 -0
- package/dist/lb-select.js +44 -0
- package/dist/lb-select.js.map +1 -0
- package/dist/lb-table.d.ts +2 -0
- package/dist/lb-table.d.ts.map +1 -0
- package/dist/lb-table.html +8 -0
- package/dist/lb-table.js +114 -0
- package/dist/lb-table.js.map +1 -0
- package/docs/lb-input.md +72 -0
- package/docs/lb-list.md +61 -0
- package/docs/lb-options.md +67 -0
- package/docs/lb-picker.md +52 -0
- package/docs/lb-select.md +48 -0
- package/docs/lb-table.md +69 -0
- package/package.json +62 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright {yyyy} {name of copyright owner}
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Loadbare Widgets
|
|
2
|
+
|
|
3
|
+
This is a basic widget set, currently bare-bones proof of concept.
|
|
4
|
+
|
|
5
|
+
Inventory:
|
|
6
|
+
|
|
7
|
+
| Widget | Is |
|
|
8
|
+
| --- | --- |
|
|
9
|
+
| [`lb-input`](docs/lb-input.md) | an editable cell wrapping an `<input>` |
|
|
10
|
+
| [`lb-select`](docs/lb-select.md) | a `<select>` whose options the page writes |
|
|
11
|
+
| [`lb-list`](docs/lb-list.md) | the plain repeater |
|
|
12
|
+
| [`lb-options`](docs/lb-options.md) | a `<select>` whose options come from a query |
|
|
13
|
+
| [`lb-picker`](docs/lb-picker.md) | `lb-options` with the row template built in |
|
|
14
|
+
| [`lb-table`](docs/lb-table.md) | a `<table>` supplying its own scaffolding |
|
|
15
|
+
|
|
16
|
+
## Installing
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
npm install @loadbare/app @loadbare/widgets
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Then list the package in the application's `imports.ts`:
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
// src/imports.ts
|
|
26
|
+
export default ["@loadbare/widgets"];
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
You can now include the widgets in your HTML files.
|
|
30
|
+
|
|
31
|
+
Apart from the line in `src/imports.ts`, no other import statements
|
|
32
|
+
are required. The loadbare builder automatically bundles the HTML and
|
|
33
|
+
JS for any widget in the library that is actually used in the app.
|
|
34
|
+
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../widgets/index.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AACvB,OAAO,gBAAgB,CAAC;AACxB,OAAO,cAAc,CAAC;AACtB,OAAO,iBAAiB,CAAC;AACzB,OAAO,eAAe,CAAC;AACvB,OAAO,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../widgets/index.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AACvB,OAAO,gBAAgB,CAAC;AACxB,OAAO,cAAc,CAAC;AACtB,OAAO,iBAAiB,CAAC;AACzB,OAAO,eAAe,CAAC;AACvB,OAAO,gBAAgB,CAAC","sourcesContent":["import \"./lb-input.js\";\nimport \"./lb-select.js\";\nimport \"./lb-list.js\";\nimport \"./lb-options.js\";\nimport \"./lb-table.js\";\nimport \"./lb-picker.js\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lb-input.d.ts","sourceRoot":"","sources":["../widgets/lb-input.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<label>{{label}} <input readonly="{{readonly}}" /></label>
|
package/dist/lb-input.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/// <reference lib="dom" />
|
|
2
|
+
import { ATTR_CELL, ATTR_KEY, ATTR_QUERY, ATTR_VALUE, LB_EVENT_NAME, } from "@loadbare/app/constants";
|
|
3
|
+
/** The page asks for a request. A widget that was not asked stays quiet. */
|
|
4
|
+
const FIRE_ON_CHANGE = "data-fire-on-change";
|
|
5
|
+
/**
|
|
6
|
+
* A leaf cell wrapping an <input>. The hub writes one attribute name for
|
|
7
|
+
* every widget type, so the value lands in `lb-value` and the widget
|
|
8
|
+
* forwards it to the control it owns.
|
|
9
|
+
*
|
|
10
|
+
* The other direction of the same cell: `data-fire-on-change` asks for a
|
|
11
|
+
* `cell-change` on the input's own `change` event, bound by the same
|
|
12
|
+
* lb-query/lb-key/lb-cell the value arrived on.
|
|
13
|
+
*
|
|
14
|
+
* The page has to ask, because committing per field is one editing model
|
|
15
|
+
* and not the only one. An input inside an `lb-insert` or `lb-update` form
|
|
16
|
+
* is read again by the form on submit, so a widget that sent on its own
|
|
17
|
+
* would write the same edit twice and defeat the batch the form is for.
|
|
18
|
+
*/
|
|
19
|
+
class LbInput extends HTMLElement {
|
|
20
|
+
static observedAttributes = [ATTR_VALUE];
|
|
21
|
+
attributeChangedCallback(_name, _old, value) {
|
|
22
|
+
const input = this.querySelector("input");
|
|
23
|
+
if (!input) {
|
|
24
|
+
console.error(`lb-input: no <input> to receive the value`);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
input.value = value;
|
|
28
|
+
}
|
|
29
|
+
connectedCallback() {
|
|
30
|
+
this.addEventListener("change", () => {
|
|
31
|
+
if (!this.hasAttribute(FIRE_ON_CHANGE))
|
|
32
|
+
return;
|
|
33
|
+
const input = this.querySelector("input");
|
|
34
|
+
if (!input) {
|
|
35
|
+
console.error(`lb-input: change with no <input>, ignoring`);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const query = this.closest(`[${ATTR_QUERY}]`)?.getAttribute(ATTR_QUERY);
|
|
39
|
+
const key = this.closest(`[${ATTR_KEY}]`)?.getAttribute(ATTR_KEY);
|
|
40
|
+
const cell = this.getAttribute(ATTR_CELL);
|
|
41
|
+
if (!query || !key || !cell) {
|
|
42
|
+
console.error(`lb-input: change with no query/key/cell binding, ignoring`);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const detail = {
|
|
46
|
+
op: "cell-change",
|
|
47
|
+
query,
|
|
48
|
+
key,
|
|
49
|
+
cell,
|
|
50
|
+
value: input.value,
|
|
51
|
+
};
|
|
52
|
+
this.dispatchEvent(new CustomEvent(LB_EVENT_NAME, { bubbles: true, detail }));
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
customElements.define("lb-input", LbInput);
|
|
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YAClE,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;YAC1C,IAAI,CAAC,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;gBAC5B,OAAO,CAAC,KAAK,CACX,2DAA2D,CAC5D,CAAC;gBACF,OAAO;YACT,CAAC;YACD,MAAM,MAAM,GAAe;gBACzB,EAAE,EAAE,aAAa;gBACjB,KAAK;gBACL,GAAG;gBACH,IAAI;gBACJ,KAAK,EAAE,KAAK,CAAC,KAAK;aACnB,CAAC;YACF,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CAAC,aAAa,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAC1D,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;;AAGH,cAAc,CAAC,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC","sourcesContent":["/// <reference lib=\"dom\" />\n\nimport {\n ATTR_CELL,\n ATTR_KEY,\n ATTR_QUERY,\n ATTR_VALUE,\n LB_EVENT_NAME,\n} from \"@loadbare/app/constants\";\nimport type { HubRequest } from \"@loadbare/app/types\";\n\n/** The page asks for a request. A widget that was not asked stays quiet. */\nconst FIRE_ON_CHANGE = \"data-fire-on-change\";\n\n/**\n * A leaf cell wrapping an <input>. The hub writes one attribute name for\n * every widget type, so the value lands in `lb-value` and the widget\n * forwards it to the control it owns.\n *\n * The other direction of the same cell: `data-fire-on-change` asks for a\n * `cell-change` on the input's own `change` event, bound by the same\n * lb-query/lb-key/lb-cell the value arrived on.\n *\n * The page has to ask, because committing per field is one editing model\n * and not the only one. An input inside an `lb-insert` or `lb-update` form\n * is read again by the form on submit, so a widget that sent on its own\n * would write the same edit twice and defeat the batch the form is for.\n */\n\nclass LbInput extends HTMLElement {\n static observedAttributes = [ATTR_VALUE];\n\n attributeChangedCallback(_name: string, _old: string, value: string) {\n const input = this.querySelector(\"input\");\n if (!input) {\n console.error(`lb-input: no <input> to receive the value`);\n return;\n }\n input.value = value;\n }\n\n connectedCallback() {\n this.addEventListener(\"change\", () => {\n if (!this.hasAttribute(FIRE_ON_CHANGE)) return;\n const input = this.querySelector(\"input\");\n if (!input) {\n console.error(`lb-input: change with no <input>, ignoring`);\n return;\n }\n const query = this.closest(`[${ATTR_QUERY}]`)?.getAttribute(ATTR_QUERY);\n const key = this.closest(`[${ATTR_KEY}]`)?.getAttribute(ATTR_KEY);\n const cell = this.getAttribute(ATTR_CELL);\n if (!query || !key || !cell) {\n console.error(\n `lb-input: change with no query/key/cell binding, ignoring`,\n );\n return;\n }\n const detail: HubRequest = {\n op: \"cell-change\",\n query,\n key,\n cell,\n value: input.value,\n };\n this.dispatchEvent(\n new CustomEvent(LB_EVENT_NAME, { bubbles: true, detail }),\n );\n });\n }\n}\n\ncustomElements.define(\"lb-input\", LbInput);\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lb-list.d.ts","sourceRoot":"","sources":["../widgets/lb-list.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<div lb-slot></div>
|
package/dist/lb-list.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference lib="dom" />
|
|
2
|
+
import { applyRows } from "@loadbare/app/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);
|
|
18
|
+
//# sourceMappingURL=lb-list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lb-list.js","sourceRoot":"","sources":["../widgets/lb-list.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAG3B,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C;;;;;;;;GAQG;AACH,MAAM,MAAO,SAAQ,WAAW;IAC9B,UAAU,CAAC,MAAkB;QAC3B,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC1B,CAAC;CACF;AAED,cAAc,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC","sourcesContent":["/// <reference lib=\"dom\" />\n\nimport type { Projection, HubRowHost } from \"@loadbare/app/types\";\nimport { applyRows } from \"@loadbare/app/rows\";\n\n/**\n * The plain repeater: whatever the page author wrote inside is repeated once\n * per tuple, in the order the server sent.\n *\n * It exists because a projection has to land on a widget, and because a\n * `<table>` cannot be one — a custom element written inside `<tbody>` is\n * discarded by the parser, so the widget goes around the table and the\n * template goes inside it, where the content model already allows it.\n */\nclass LbList extends HTMLElement implements HubRowHost {\n acceptRows(result: Projection) {\n applyRows(this, result);\n }\n}\n\ncustomElements.define(\"lb-list\", LbList);\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Projection, HubRowHost } from "@loadbare/app/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
|
|
@@ -0,0 +1 @@
|
|
|
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,qBAAqB,CAAC;AAG7B;;;;;;;;;;;;;;;;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"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/// <reference lib="dom" />
|
|
2
|
+
import { ATTR_ACTION, ATTR_GROUP, ATTR_KEY, LB_EVENT_NAME, } from "@loadbare/app/constants";
|
|
3
|
+
import { applyRows } from "@loadbare/app/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);
|
|
73
|
+
//# sourceMappingURL=lb-options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lb-options.js","sourceRoot":"","sources":["../widgets/lb-options.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAE3B,OAAO,EACL,WAAW,EACX,UAAU,EACV,QAAQ,EACR,aAAa,GACd,MAAM,yBAAyB,CAAC;AAMjC,OAAO,EAAE,SAAS,EAAc,MAAM,oBAAoB,CAAC;AAE3D;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,SAAU,SAAQ,WAAW;IACxC,UAAU,CAAC,MAAkB;QAC3B,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QACpC,wEAAwE;QACxE,4BAA4B;QAC5B,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,gBAAgB,CAAC,UAAU,QAAQ,GAAG,CAAC,EAAE,CAAC;YAClE,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAE,CAAC,CAAC;QAC/D,CAAC;QACD,yDAAyD;QACzD,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,gBAAgB,CAAC,UAAU,CAAC,EAAE,CAAC;YACtD,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC;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I,GAAG,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;YAC5C,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,OAAO,CAAC,KAAK,CAAC,kBAAkB,WAAW,mBAAmB,CAAC,CAAC;gBAChE,OAAO;YACT,CAAC;YACD,MAAM,MAAM,GAAe,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;YACvE,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CAAC,aAAa,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAC1D,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED,cAAc,CAAC,MAAM,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC","sourcesContent":["/// <reference lib=\"dom\" />\n\nimport {\n ATTR_ACTION,\n ATTR_GROUP,\n ATTR_KEY,\n LB_EVENT_NAME,\n} from \"@loadbare/app/constants\";\nimport type {\n Projection,\n HubRequest,\n HubRowHost,\n} from \"@loadbare/app/types\";\nimport { applyRows, type Place } from \"@loadbare/app/rows\";\n\n/**\n * A `<select>` whose choices come from a query, and the case that shows why\n * placement belongs to the widget rather than to the framework.\n *\n * The rows arrive flat and keyed. Nothing on the wire knows about\n * `<optgroup>`, and nothing needs to: a group is a column like any other, and\n * turning a repeated column value into an element is exactly the local\n * knowledge a widget has and the hub does not. A table wanting section\n * headings would read the same `lb-group` and build something else.\n *\n * The identity of a row is the value of the option, so `lb-key` supplies\n * both and the page declares it once.\n *\n * Exported because `lb-picker` is this widget with its row template\n * supplied by the definition instead of by the page. Nothing about the\n * behavior changes, so nothing about the behavior is written twice.\n */\nexport class LbOptions extends HTMLElement implements HubRowHost {\n acceptRows(result: Projection) {\n applyRows(this, result, this.place);\n // The identity of the row is the value of the option, so nothing on the\n // page has to say so twice.\n for (const option of this.querySelectorAll(`option[${ATTR_KEY}]`)) {\n option.setAttribute(\"value\", option.getAttribute(ATTR_KEY)!);\n }\n // A group is derived, so it goes when its last row does.\n for (const group of this.querySelectorAll(\"optgroup\")) {\n if (!group.querySelector(\"option\")) group.remove();\n }\n }\n\n private place: Place = (row, tuple, template) => {\n const select = this.querySelector(\"select\")!;\n const groupCell = template.getAttribute(ATTR_GROUP);\n if (!groupCell) {\n select.insertBefore(row, template);\n return;\n }\n this.groupFor(select, template, tuple[groupCell] ?? \"\").append(row);\n };\n\n /** The group with this label, or a new one in front of the template. */\n private groupFor(select: Element, template: Element, label: string): Element {\n for (const group of select.querySelectorAll(\"optgroup\")) {\n if (group.label === label) return group;\n }\n const group = document.createElement(\"optgroup\");\n group.label = label;\n select.insertBefore(group, template);\n return group;\n }\n\n connectedCallback() {\n this.addEventListener(\"change\", () => {\n const select = this.querySelector(\"select\");\n if (!select) {\n console.error(`lb-options: change with no <select>, ignoring`);\n return;\n }\n const name = this.getAttribute(ATTR_ACTION);\n if (!name) {\n console.error(`lb-options: no ${ATTR_ACTION}, nothing to send`);\n return;\n }\n const detail: HubRequest = { op: \"action\", name, value: select.value };\n this.dispatchEvent(\n new CustomEvent(LB_EVENT_NAME, { bubbles: true, detail }),\n );\n });\n }\n}\n\ncustomElements.define(\"lb-options\", LbOptions);\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lb-picker.d.ts","sourceRoot":"","sources":["../widgets/lb-picker.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/// <reference lib="dom" />
|
|
2
|
+
import { LbOptions } from "./lb-options.js";
|
|
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);
|
|
26
|
+
//# sourceMappingURL=lb-picker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lb-picker.js","sourceRoot":"","sources":["../widgets/lb-picker.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAE3B,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,QAAS,SAAQ,SAAS;CAAG;AAEnC,cAAc,CAAC,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC","sourcesContent":["/// <reference lib=\"dom\" />\n\nimport { LbOptions } from \"./lb-options.js\";\n\n/**\n * The same `<select>` as `lb-options`, with the row template supplied by\n * the definition instead of by the page.\n *\n * A row template is markup, so writing it is the page author's job — until\n * every row is one option and the only thing that varies is which columns it\n * reads. Those are words, and words are parameters: `exp-key`, `exp-cell` and\n * `exp-group` fill the placeholders in the template the definition already\n * has, at build time, and the page writes one tag with no children.\n *\n * It is the same trade as anywhere else in expansion. A page author who wants\n * a second element in the row, or an option built from two columns, writes\n * `lb-options` and the template themselves. This one is for when they do\n * not.\n *\n * The behavior is inherited whole, because it is the same behavior: rows land\n * in groups, the key becomes the value, and a change sends the declared\n * action. A distinct class exists only because `customElements.define`\n * requires one constructor per name.\n */\nclass LbPicker extends LbOptions {}\n\ncustomElements.define(\"lb-picker\", LbPicker);\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lb-select.d.ts","sourceRoot":"","sources":["../widgets/lb-select.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/// <reference lib="dom" />
|
|
2
|
+
import { ATTR_ACTION, ATTR_VALUE, LB_EVENT_NAME, } from "@loadbare/app/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 binding 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);
|
|
44
|
+
//# sourceMappingURL=lb-select.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lb-select.js","sourceRoot":"","sources":["../widgets/lb-select.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAE3B,OAAO,EACL,WAAW,EACX,UAAU,EACV,aAAa,GACd,MAAM,yBAAyB,CAAC;AAGjC;;;;;;;;GAQG;AACH,MAAM,QAAS,SAAQ,WAAW;IAChC,MAAM,CAAC,kBAAkB,GAAG,CAAC,UAAU,CAAC,CAAC;IAEzC,wBAAwB,CAAC,KAAa,EAAE,IAAY,EAAE,KAAa;QACjE,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAC5C,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,CAAC,KAAK,CAAC,6CAA6C,CAAC,CAAC;YAC7D,OAAO;QACT,CAAC;QACD,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;IAED,iBAAiB;QACf,IAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE,GAAG,EAAE;YACnC,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;YAC5C,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,OAAO,CAAC,KAAK,CAAC,8CAA8C,CAAC,CAAC;gBAC9D,OAAO;YACT,CAAC;YACD,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;YAC5C,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,OAAO,CAAC,KAAK,CAAC,iBAAiB,WAAW,mBAAmB,CAAC,CAAC;gBAC/D,OAAO;YACT,CAAC;YACD,MAAM,MAAM,GAAe;gBACzB,EAAE,EAAE,QAAQ;gBACZ,IAAI;gBACJ,KAAK,EAAE,MAAM,CAAC,KAAK;aACpB,CAAC;YACF,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CAAC,aAAa,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAC1D,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;;AAGH,cAAc,CAAC,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC","sourcesContent":["/// <reference lib=\"dom\" />\n\nimport {\n ATTR_ACTION,\n ATTR_VALUE,\n LB_EVENT_NAME,\n} from \"@loadbare/app/constants\";\nimport type { HubRequest } from \"@loadbare/app/types\";\n\n/**\n * A leaf cell wrapping a <select>. It receives its value like any other cell,\n * and on change it sends the action the page declared for it — the request\n * vocabulary and the binding vocabulary running in both directions on one\n * widget.\n *\n * The choice is the interaction, so this is the case where an action carries\n * a value. The server still decides what that choice means.\n */\nclass LbSelect extends HTMLElement {\n static observedAttributes = [ATTR_VALUE];\n\n attributeChangedCallback(_name: string, _old: string, value: string) {\n const select = this.querySelector(\"select\");\n if (!select) {\n console.error(`lb-select: no <select> to receive the value`);\n return;\n }\n select.value = value;\n }\n\n connectedCallback() {\n this.addEventListener(\"change\", () => {\n const select = this.querySelector(\"select\");\n if (!select) {\n console.error(`lb-select: change with no <select>, ignoring`);\n return;\n }\n const name = this.getAttribute(ATTR_ACTION);\n if (!name) {\n console.error(`lb-select: no ${ATTR_ACTION}, nothing to send`);\n return;\n }\n const detail: HubRequest = {\n op: \"action\",\n name,\n value: select.value,\n };\n this.dispatchEvent(\n new CustomEvent(LB_EVENT_NAME, { bubbles: true, detail }),\n );\n });\n }\n}\n\ncustomElements.define(\"lb-select\", LbSelect);\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lb-table.d.ts","sourceRoot":"","sources":["../widgets/lb-table.ts"],"names":[],"mappings":""}
|
package/dist/lb-table.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/// <reference lib="dom" />
|
|
2
|
+
import { ATTR_CELL, ATTR_GROUP, ATTR_KEY, ATTR_SORT, } from "@loadbare/app/constants";
|
|
3
|
+
import { applyRows } from "@loadbare/app/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
|
+
* binds to 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);
|
|
114
|
+
//# sourceMappingURL=lb-table.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lb-table.js","sourceRoot":"","sources":["../widgets/lb-table.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAE3B,OAAO,EACL,SAAS,EACT,UAAU,EACV,QAAQ,EACR,SAA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CAAC,YAAY,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QACvC,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QAC1C,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QACvC,qEAAqE;QACrE,gDAAgD;QAChD,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,iBAAiB,EAAE,iBAAiB,IAAI,CAAC,CAAC;QAC1E,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QACzB,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACrB,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QACrC,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AAED,gDAAgD;AAChD,SAAS,MAAM,CAAC,GAAY,EAAE,IAAY;IACxC,MAAM,QAAQ,GAAG,IAAI,SAAS,KAAK,IAAI,IAAI,CAAC;IAC5C,MAAM,EAAE,GAAG,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IACrE,OAAO,EAAE,EAAE,WAAW,IAAI,EAAE,CAAC;AAC/B,CAAC;AAED,cAAc,CAAC,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC","sourcesContent":["/// <reference lib=\"dom\" />\n\nimport {\n ATTR_CELL,\n ATTR_GROUP,\n ATTR_KEY,\n ATTR_SORT,\n} from \"@loadbare/app/constants\";\nimport type { Projection, HubRowHost } from \"@loadbare/app/types\";\nimport { applyRows, type Place } from \"@loadbare/app/rows\";\n\n/**\n * A table that owns its own scaffolding, and the case that shows what a list\n * widget is for once the repeater exists.\n *\n * `lb-list` goes around a table the page author wrote. This one supplies\n * the table, and the page writes what only the page knows: the heading row\n * and the row template. That division is forced rather than chosen — a\n * `<thead>` written inside a custom element is not inside a table, so the\n * parser drops the tag and keeps the text. A `<template>` survives anywhere,\n * so the heading row arrives wrapped and expansion unwraps it into the\n * `lb-template` destination beside the slot.\n *\n * What it adds at run time is placement, and only placement. `lb-sort` names\n * the column rows are ordered by; `lb-group` names the column they are\n * sectioned by, and is the same attribute a grouped `<select>` reads, because\n * a table with section headings and an `<optgroup>` are asking the same thing\n * of the same data.\n *\n * The `foot` destination is the head's argument a second time and needs no\n * code here. A `<tfoot>` is a place on the page, not a row the hub delivers,\n * so what lands in it is an ordinary scope carrying its own `lb-query` — a\n * grand total is a second projection of the same table, and the hub resolves\n * it by name like any other. See demo/pages/ledger.html.\n */\n\n/**\n * The heading row of a section, carrying the value it stands for.\n *\n * The widget's own scaffolding, so it is HTML's namespace rather than\n * Loadbare App's: it is derived from rows the hub knows and is invisible to the hub\n * itself, exactly as the `<optgroup>` in `lb-options` is. Nothing\n * binds to it, so it carries no `lb-key` and no name from the vocabulary.\n */\nconst GROUP_ROW = \"data-group\";\n\nclass LbTable extends HTMLElement implements HubRowHost {\n acceptRows(result: Projection) {\n applyRows(this, result, this.place);\n // A section is derived, so it goes when its last row does.\n for (const heading of this.querySelectorAll(`tr[${GROUP_ROW}]`)) {\n if (this.section(heading).rows.length === 0) heading.remove();\n }\n }\n\n /**\n * Group first, then sort within the group.\n *\n * Inserting a row before the first one that sorts after it keeps the\n * section ordered, whatever else is in it — which is what lets a whole set\n * and a single patched row take the same path.\n */\n private place: Place = (row, tuple, template) => {\n const groupCell = template.getAttribute(ATTR_GROUP);\n const sortCell = template.getAttribute(ATTR_SORT);\n const heading = groupCell\n ? this.headingFor(template, tuple[groupCell] ?? \"\")\n : null;\n const { rows, end } = this.section(heading);\n\n const value = sortCell ? (tuple[sortCell] ?? \"\") : \"\";\n const after = sortCell\n ? rows.find((other) => other !== row && cellOf(other, sortCell) > value)\n : undefined;\n template.parentElement!.insertBefore(row, after ?? end);\n };\n\n /**\n * The rows of one section, and the node it ends at.\n *\n * A section runs from its heading to the next heading, or to the template\n * if there is none after it. Without grouping there is one section and it\n * is the whole body — the heading row the page wrote is skipped along the\n * way, because it carries no key and is therefore not a row.\n */\n private section(heading: Element | null): { rows: Element[]; end: Element } {\n const template = this.querySelector(\"template\")!;\n const rows: Element[] = [];\n let node = heading\n ? heading.nextElementSibling\n : template.parentElement!.firstElementChild;\n while (node && node !== template && !node.hasAttribute(GROUP_ROW)) {\n if (node.hasAttribute(ATTR_KEY)) rows.push(node);\n node = node.nextElementSibling;\n }\n return { rows, end: node ?? template };\n }\n\n /** The section with this label, or a new one in front of the template. */\n private headingFor(template: HTMLTemplateElement, label: string): Element {\n const body = template.parentElement!;\n for (const heading of body.querySelectorAll(`tr[${GROUP_ROW}]`)) {\n if (heading.getAttribute(GROUP_ROW) === label) return heading;\n }\n const heading = document.createElement(\"tr\");\n heading.setAttribute(GROUP_ROW, label);\n const cell = document.createElement(\"th\");\n cell.setAttribute(\"scope\", \"rowgroup\");\n // How wide the table is, from the row the page author wrote. Nothing\n // else knows, and nothing had to be told twice.\n cell.colSpan = template.content.firstElementChild?.childElementCount ?? 1;\n cell.textContent = label;\n heading.append(cell);\n body.insertBefore(heading, template);\n return heading;\n }\n}\n\n/** What a live row is showing in one column. */\nfunction cellOf(row: Element, cell: string): string {\n const selector = `[${ATTR_CELL}=\"${cell}\"]`;\n const el = row.matches(selector) ? row : row.querySelector(selector);\n return el?.textContent ?? \"\";\n}\n\ncustomElements.define(\"lb-table\", LbTable);\n"]}
|
package/docs/lb-input.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# `lb-input`
|
|
2
|
+
|
|
3
|
+
> Status: a barebones starter. Iterative use will drive improvements.
|
|
4
|
+
|
|
5
|
+
A wrapper for HTML Input.
|
|
6
|
+
|
|
7
|
+
Requires attributes `lb-cell` and `exp-label`.
|
|
8
|
+
|
|
9
|
+
```html
|
|
10
|
+
<lb-list lb-query="people">
|
|
11
|
+
<template lb-key="id">
|
|
12
|
+
<div>
|
|
13
|
+
<lb-input lb-cell="name" exp-label="Name" data-fire-on-change></lb-input>
|
|
14
|
+
<lb-input lb-cell="email" exp-label="Email" exp-readonly></lb-input>
|
|
15
|
+
</div>
|
|
16
|
+
</template>
|
|
17
|
+
</lb-list>
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Expansion Attributes
|
|
21
|
+
|
|
22
|
+
These are the parameters that control build-time expansion of the final HTML.
|
|
23
|
+
|
|
24
|
+
| Parameter | Fills |
|
|
25
|
+
|-----------------------|--------------------------------------------------|
|
|
26
|
+
| `exp-label` | the visible `<label>` text |
|
|
27
|
+
| `exp-readonly` | the input's `readonly` attribute |
|
|
28
|
+
|
|
29
|
+
Any value on `exp-readonly` makes the input readonly. Leaving the parameter
|
|
30
|
+
off drops the attribute.
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
## Behavioral Attributes
|
|
34
|
+
|
|
35
|
+
| Parameter | Fills |
|
|
36
|
+
|-----------------------|--------------------------------------------------|
|
|
37
|
+
| `data-fire-on-change` | if true, fires a request to the server on change |
|
|
38
|
+
|
|
39
|
+
## Binding
|
|
40
|
+
|
|
41
|
+
| Attribute | Read from | Names |
|
|
42
|
+
|------------|----------------------|------------------------------|
|
|
43
|
+
| `lb-cell` | the element itself | the column the input shows |
|
|
44
|
+
| `lb-key` | the nearest ancestor | the row |
|
|
45
|
+
| `lb-query` | the nearest ancestor | the query |
|
|
46
|
+
|
|
47
|
+
## Inside a form
|
|
48
|
+
|
|
49
|
+
An `lb-input` inside an `lb-insert` or `lb-update` form leaves
|
|
50
|
+
`data-fire-on-change` off. The form reads every `lb-cell` in it on submit and
|
|
51
|
+
sends one request for all of them, so an input that also sent its own would
|
|
52
|
+
write the same edit twice.
|
|
53
|
+
|
|
54
|
+
```html
|
|
55
|
+
<form lb-update>
|
|
56
|
+
<lb-input lb-cell="name" exp-label="Name"></lb-input>
|
|
57
|
+
<lb-input lb-cell="email" exp-label="Email"></lb-input>
|
|
58
|
+
<button type="submit">Save</button>
|
|
59
|
+
</form>
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Editing
|
|
63
|
+
|
|
64
|
+
By default an `lb-input` does not notify the hub when its value changes, as shown
|
|
65
|
+
in the form example above.
|
|
66
|
+
|
|
67
|
+
To fire a server event through the hub, add `data-fire-on-change`. The hub will
|
|
68
|
+
catch the event and fire a request to the server.
|
|
69
|
+
|
|
70
|
+
While the request is in flight the hub marks the `lb-input` with
|
|
71
|
+
`data-lb-pending`, and on failure with `data-lb-error`. Both are there for a
|
|
72
|
+
stylesheet to read.
|
package/docs/lb-list.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# `lb-list`
|
|
2
|
+
|
|
3
|
+
The plain repeater: a row per tuple, in the order the rows arrive.
|
|
4
|
+
|
|
5
|
+
Apply the `lb-query` attribute to name the query. Write a
|
|
6
|
+
`<template lb-key="...">` inside the tag, naming the column that identifies a
|
|
7
|
+
row, and apply `lb-cell` to each element in it.
|
|
8
|
+
|
|
9
|
+
```html
|
|
10
|
+
<lb-list lb-query="people">
|
|
11
|
+
<template lb-key="id">
|
|
12
|
+
<div>
|
|
13
|
+
<span lb-cell="name"></span>
|
|
14
|
+
<span lb-cell="email"></span>
|
|
15
|
+
</div>
|
|
16
|
+
</template>
|
|
17
|
+
</lb-list>
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Status
|
|
21
|
+
|
|
22
|
+
Barebones starter to prove out the publish/consume chain and identify necessary
|
|
23
|
+
improvements through iterative use.
|
|
24
|
+
|
|
25
|
+
## Parameters
|
|
26
|
+
|
|
27
|
+
None.
|
|
28
|
+
|
|
29
|
+
## Binding
|
|
30
|
+
|
|
31
|
+
| Attribute | Read from | Names |
|
|
32
|
+
|------------|----------------------------------|----------------------------------|
|
|
33
|
+
| `lb-query` | the element itself | the query whose rows land here |
|
|
34
|
+
| `lb-key` | the row template | the column that identifies a row |
|
|
35
|
+
| `lb-cell` | elements inside the row template | the column each element shows |
|
|
36
|
+
|
|
37
|
+
For ordering and section headings, see [`lb-table`](./lb-table.md).
|
|
38
|
+
|
|
39
|
+
## Repeating table rows
|
|
40
|
+
|
|
41
|
+
Put `lb-list` around the `<table>` and the `<template>` inside `<tbody>`. A
|
|
42
|
+
custom element written inside `<tbody>` is thrown away by the HTML parser.
|
|
43
|
+
|
|
44
|
+
```html
|
|
45
|
+
<lb-list lb-query="ledger">
|
|
46
|
+
<table>
|
|
47
|
+
<tbody>
|
|
48
|
+
<template lb-key="id">
|
|
49
|
+
<tr><td lb-cell="date"></td><td lb-cell="amount"></td></tr>
|
|
50
|
+
</template>
|
|
51
|
+
</tbody>
|
|
52
|
+
</table>
|
|
53
|
+
</lb-list>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
[`lb-table`](./lb-table.md) supplies the table itself.
|
|
57
|
+
|
|
58
|
+
## Styling an empty list
|
|
59
|
+
|
|
60
|
+
`lb-list` carries `data-rows` with the number of rows showing, for a
|
|
61
|
+
stylesheet to read.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# `lb-options`
|
|
2
|
+
|
|
3
|
+
A wrapper for HTML Select, with the `<option>`s coming from a query.
|
|
4
|
+
|
|
5
|
+
Apply the `lb-query` attribute to name the query, and `lb-action` to name the
|
|
6
|
+
action a change sends. Write a `<template lb-key="...">` inside the tag, and
|
|
7
|
+
apply `lb-cell` to the `<option>` itself — an `<option>` holds text, not
|
|
8
|
+
elements. Apply `lb-group` to the template to section the options.
|
|
9
|
+
|
|
10
|
+
Provide `exp-label`.
|
|
11
|
+
|
|
12
|
+
```html
|
|
13
|
+
<lb-options lb-query="statuses" exp-label="Status" lb-action="setStatus">
|
|
14
|
+
<template lb-key="id" lb-group="category">
|
|
15
|
+
<option lb-cell="label"></option>
|
|
16
|
+
</template>
|
|
17
|
+
</lb-options>
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Status
|
|
21
|
+
|
|
22
|
+
Barebones starter to prove out the publish/consume chain and identify necessary
|
|
23
|
+
improvements through iterative use.
|
|
24
|
+
|
|
25
|
+
## Parameters
|
|
26
|
+
|
|
27
|
+
| Parameter | Fills |
|
|
28
|
+
|-------------|----------------------------|
|
|
29
|
+
| `exp-label` | the visible `<label>` text |
|
|
30
|
+
|
|
31
|
+
## Binding
|
|
32
|
+
|
|
33
|
+
| Attribute | Read from | Names |
|
|
34
|
+
|-------------|--------------------|--------------------------------------|
|
|
35
|
+
| `lb-query` | the element itself | the query whose rows become options |
|
|
36
|
+
| `lb-action` | the element itself | the action a change sends |
|
|
37
|
+
| `lb-key` | the row template | the column that identifies a row |
|
|
38
|
+
| `lb-group` | the row template | the column that sections the options |
|
|
39
|
+
| `lb-cell` | the `<option>` | the column the option shows |
|
|
40
|
+
|
|
41
|
+
`lb-key` gives the option its `value`, so the page names that column once.
|
|
42
|
+
`lb-sort` is not read here.
|
|
43
|
+
|
|
44
|
+
## Grouping
|
|
45
|
+
|
|
46
|
+
`lb-group` names a column whose distinct values become `<optgroup>`s, each
|
|
47
|
+
labelled with the value.
|
|
48
|
+
|
|
49
|
+
## Choosing
|
|
50
|
+
|
|
51
|
+
Choosing an option notifies the hub, which fires a request to the server: the
|
|
52
|
+
action named by `lb-action`, carrying the key of the chosen row. Declare that
|
|
53
|
+
action on the server.
|
|
54
|
+
|
|
55
|
+
`lb-action` is required. Without it, a change does nothing.
|
|
56
|
+
|
|
57
|
+
While the request is in flight the hub marks the `lb-options` with
|
|
58
|
+
`data-lb-pending`, and on failure with `data-lb-error`. Both are there for a
|
|
59
|
+
stylesheet to read.
|
|
60
|
+
|
|
61
|
+
## Styling an empty list
|
|
62
|
+
|
|
63
|
+
`lb-options` carries `data-rows` with the number of options showing, for a
|
|
64
|
+
stylesheet to read.
|
|
65
|
+
|
|
66
|
+
For the case where every row is one option and only the column names vary,
|
|
67
|
+
see [`lb-picker`](./lb-picker.md).
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# `lb-picker`
|
|
2
|
+
|
|
3
|
+
[`lb-options`](./lb-options.md) with the row template built in, for when every
|
|
4
|
+
row is one option and only the column names vary. It takes no children.
|
|
5
|
+
|
|
6
|
+
Apply the `lb-query` attribute to name the query, and `lb-action` to name the
|
|
7
|
+
action a change sends.
|
|
8
|
+
|
|
9
|
+
Provide `exp-label`, `exp-key`, `exp-cell`, and optionally `exp-group`.
|
|
10
|
+
|
|
11
|
+
```html
|
|
12
|
+
<lb-picker
|
|
13
|
+
lb-query="statuses"
|
|
14
|
+
exp-label="Status"
|
|
15
|
+
exp-key="id"
|
|
16
|
+
exp-cell="label"
|
|
17
|
+
exp-group="category"
|
|
18
|
+
lb-action="setStatus"
|
|
19
|
+
></lb-picker>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Status
|
|
23
|
+
|
|
24
|
+
Barebones starter to prove out the publish/consume chain and identify necessary
|
|
25
|
+
improvements through iterative use.
|
|
26
|
+
|
|
27
|
+
## Parameters
|
|
28
|
+
|
|
29
|
+
| Parameter | Fills |
|
|
30
|
+
|-------------|--------------------------------------------------|
|
|
31
|
+
| `exp-label` | the visible `<label>` text |
|
|
32
|
+
| `exp-key` | the column that identifies a row |
|
|
33
|
+
| `exp-cell` | the column the option shows |
|
|
34
|
+
| `exp-group` | the column that sections the options, if grouped |
|
|
35
|
+
|
|
36
|
+
`exp-key` and `exp-cell` are required. Leaving `exp-group` off leaves the
|
|
37
|
+
options ungrouped.
|
|
38
|
+
|
|
39
|
+
## Binding
|
|
40
|
+
|
|
41
|
+
| Attribute | Read from | Names |
|
|
42
|
+
|-------------|--------------------|-------------------------------------|
|
|
43
|
+
| `lb-query` | the element itself | the query whose rows become options |
|
|
44
|
+
| `lb-action` | the element itself | the action a change sends |
|
|
45
|
+
|
|
46
|
+
## Choosing
|
|
47
|
+
|
|
48
|
+
The same as [`lb-options`](./lb-options.md): grouping, the key as the option's
|
|
49
|
+
value, `data-rows`, and the action on change.
|
|
50
|
+
|
|
51
|
+
Write `lb-options` and the template instead for a row that needs a second
|
|
52
|
+
element, or an option built from two columns.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# `lb-select`
|
|
2
|
+
|
|
3
|
+
A wrapper for HTML Select, with the `<option>`s written by hand.
|
|
4
|
+
|
|
5
|
+
Apply the `lb-cell` attribute to name the column, and `lb-action` to name the
|
|
6
|
+
action a change sends.
|
|
7
|
+
|
|
8
|
+
Provide `exp-label`.
|
|
9
|
+
|
|
10
|
+
```html
|
|
11
|
+
<lb-select lb-cell="status" exp-label="Status" lb-action="setStatus">
|
|
12
|
+
<option value="open">Open</option>
|
|
13
|
+
<option value="closed">Closed</option>
|
|
14
|
+
</lb-select>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Status
|
|
18
|
+
|
|
19
|
+
Barebones starter to prove out the publish/consume chain and identify necessary
|
|
20
|
+
improvements through iterative use.
|
|
21
|
+
|
|
22
|
+
## Parameters
|
|
23
|
+
|
|
24
|
+
| Parameter | Fills |
|
|
25
|
+
|-------------|----------------------------|
|
|
26
|
+
| `exp-label` | the visible `<label>` text |
|
|
27
|
+
|
|
28
|
+
## Binding
|
|
29
|
+
|
|
30
|
+
| Attribute | Read from | Names |
|
|
31
|
+
|-------------|--------------------|-----------------------------|
|
|
32
|
+
| `lb-cell` | the element itself | the column the select shows |
|
|
33
|
+
| `lb-action` | the element itself | the action a change sends |
|
|
34
|
+
|
|
35
|
+
## Choosing
|
|
36
|
+
|
|
37
|
+
Choosing an option notifies the hub, which fires a request to the server: the
|
|
38
|
+
action named by `lb-action`, carrying the chosen option's value. Declare that
|
|
39
|
+
action on the server.
|
|
40
|
+
|
|
41
|
+
`lb-action` is required. Without it, a change does nothing.
|
|
42
|
+
|
|
43
|
+
While the request is in flight the hub marks the `lb-select` with
|
|
44
|
+
`data-lb-pending`, and on failure with `data-lb-error`. Both are there for a
|
|
45
|
+
stylesheet to read.
|
|
46
|
+
|
|
47
|
+
For a `<select>` whose options come from a query, see
|
|
48
|
+
[`lb-options`](./lb-options.md) and [`lb-picker`](./lb-picker.md).
|
package/docs/lb-table.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# `lb-table`
|
|
2
|
+
|
|
3
|
+
A wrapper for HTML Table, supplying the `<table>` itself.
|
|
4
|
+
|
|
5
|
+
Apply the `lb-query` attribute to name the query. Write three `<template>`s
|
|
6
|
+
inside the tag: one marked `lb-template="head"` for the heading row, one
|
|
7
|
+
carrying `lb-key` for the row, and optionally one marked `lb-template="foot"`
|
|
8
|
+
for the footer. Apply `lb-sort` and `lb-group` to the row template to order
|
|
9
|
+
and section the rows.
|
|
10
|
+
|
|
11
|
+
Provide `exp-caption`.
|
|
12
|
+
|
|
13
|
+
```html
|
|
14
|
+
<lb-table lb-query="ledger" exp-caption="Ledger">
|
|
15
|
+
<template lb-template="head">
|
|
16
|
+
<tr><th>Date</th><th>Amount</th></tr>
|
|
17
|
+
</template>
|
|
18
|
+
<template lb-key="id" lb-sort="date" lb-group="month">
|
|
19
|
+
<tr><td lb-cell="date"></td><td lb-cell="amount"></td></tr>
|
|
20
|
+
</template>
|
|
21
|
+
<template lb-template="foot">
|
|
22
|
+
<tr lb-query="ledger-total"><td>Total</td><td lb-cell="total"></td></tr>
|
|
23
|
+
</template>
|
|
24
|
+
</lb-table>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Each part goes in a `<template>` because a `<thead>` or `<tr>` written
|
|
28
|
+
directly inside the tag is thrown away by the HTML parser.
|
|
29
|
+
|
|
30
|
+
## Status
|
|
31
|
+
|
|
32
|
+
Barebones starter to prove out the publish/consume chain and identify necessary
|
|
33
|
+
improvements through iterative use.
|
|
34
|
+
|
|
35
|
+
## Parameters
|
|
36
|
+
|
|
37
|
+
| Parameter | Fills |
|
|
38
|
+
|---------------|----------------------|
|
|
39
|
+
| `exp-caption` | the `<caption>` text |
|
|
40
|
+
|
|
41
|
+
## Binding
|
|
42
|
+
|
|
43
|
+
| Attribute | Read from | Names |
|
|
44
|
+
|------------|----------------------------------|------------------------------------|
|
|
45
|
+
| `lb-query` | the element itself | the query whose rows fill the body |
|
|
46
|
+
| `lb-key` | the row template | the column that identifies a row |
|
|
47
|
+
| `lb-sort` | the row template | the column rows are ordered by |
|
|
48
|
+
| `lb-group` | the row template | the column rows are sectioned by |
|
|
49
|
+
| `lb-cell` | elements inside the row template | the column each element shows |
|
|
50
|
+
|
|
51
|
+
## Sorting and grouping
|
|
52
|
+
|
|
53
|
+
`lb-sort` names the column rows are ordered by, comparing the text each row
|
|
54
|
+
shows. `lb-group` names the column they are sectioned by: each distinct value
|
|
55
|
+
gets a heading row of its own, spanning the width of the row template, and
|
|
56
|
+
rows sort within their section.
|
|
57
|
+
|
|
58
|
+
## The footer
|
|
59
|
+
|
|
60
|
+
The footer is an ordinary part of the page, not a row from the table's query.
|
|
61
|
+
Give it its own `lb-query` — a grand total is a second query, declared on the
|
|
62
|
+
server like any other.
|
|
63
|
+
|
|
64
|
+
## Styling an empty table
|
|
65
|
+
|
|
66
|
+
`lb-table` carries `data-rows` with the number of rows showing, for a
|
|
67
|
+
stylesheet to read.
|
|
68
|
+
|
|
69
|
+
For a repeater with no table of its own, see [`lb-list`](./lb-list.md).
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@loadbare/widgets",
|
|
3
|
+
"description": "The basic widget set for @loadbare/app: input, select, list, options, picker, table",
|
|
4
|
+
"version": "0.2.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist",
|
|
8
|
+
"docs",
|
|
9
|
+
"README.md"
|
|
10
|
+
],
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"loadbare": {
|
|
21
|
+
"widgets": "./dist"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "node scripts/build.mjs",
|
|
25
|
+
"test": "tsx --test \"tests/**/*.test.ts\"",
|
|
26
|
+
"typecheck": "tsc --noEmit",
|
|
27
|
+
"format": "prettier --write .",
|
|
28
|
+
"format:check": "prettier --check .",
|
|
29
|
+
"prepublishOnly": "npm run typecheck && npm run build && npm run test",
|
|
30
|
+
"preflight": "node scripts/preflight-release.mjs",
|
|
31
|
+
"release": "npm run preflight && npm publish",
|
|
32
|
+
"release:patch": "node scripts/bump-release.mjs patch",
|
|
33
|
+
"release:minor": "node scripts/bump-release.mjs minor",
|
|
34
|
+
"release:major": "node scripts/bump-release.mjs major"
|
|
35
|
+
},
|
|
36
|
+
"author": "Ken Downs",
|
|
37
|
+
"license": "Apache-2.0",
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git+https://gitlab.com/kendowns/loadbare.git",
|
|
41
|
+
"directory": "packages/widgets"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://gitlab.com/kendowns/loadbare",
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://gitlab.com/kendowns/loadbare/-/issues"
|
|
46
|
+
},
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": ">=22"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"@loadbare/app": "^0.4.0"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@loadbare/app": "^0.4.0",
|
|
55
|
+
"@types/jsdom": "^21.1.7",
|
|
56
|
+
"@types/node": "^22.0.0",
|
|
57
|
+
"jsdom": "^25.0.0",
|
|
58
|
+
"prettier": "^3.8.4",
|
|
59
|
+
"tsx": "^4.19.0",
|
|
60
|
+
"typescript": "^5.6.0"
|
|
61
|
+
}
|
|
62
|
+
}
|