@mccaskie-labs/workbench-ui 0.3.1 → 0.3.2
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/CHANGELOG.md +6 -0
- package/dist/form-script.js +10 -4
- package/dist/style.js +3 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @mccaskie-labs/workbench-ui
|
|
2
2
|
|
|
3
|
+
## 0.3.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- renderForm draws a form's labels, controls, hints, messages, summary and config block from its definition in one stacked layout, matching FORM_SCRIPT, so apps no longer write form markup by hand. The generator adds the layout's words (ui.form.optional, ui.form.choose, ui.form.none). workbench-ui: a visible "none of these" box counts only when ticked, and STYLE styles the layout's classes.
|
|
8
|
+
|
|
3
9
|
## 0.3.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/dist/form-script.js
CHANGED
|
@@ -59,7 +59,9 @@ export const FORM_SCRIPT = `(() => {
|
|
|
59
59
|
else if (el.checked) picked.push(el.value);
|
|
60
60
|
}
|
|
61
61
|
if (picked.length) return picked;
|
|
62
|
-
|
|
62
|
+
// "None of these" is a ticked box (renderForm) or a hidden input the page always sends.
|
|
63
|
+
const none = form.elements.namedItem(n + "__none");
|
|
64
|
+
return none && (none.type !== "checkbox" || none.checked) ? [] : null;
|
|
63
65
|
}
|
|
64
66
|
const radios = els.filter((el) => el.type === "radio");
|
|
65
67
|
if (radios.length) { const on = radios.find((el) => el.checked); return on ? on.value : undefined; }
|
|
@@ -106,6 +108,8 @@ export const FORM_SCRIPT = `(() => {
|
|
|
106
108
|
if (el) el.textContent = "";
|
|
107
109
|
for (const c of controls(n)) c.removeAttribute("aria-invalid");
|
|
108
110
|
};
|
|
111
|
+
// A "none of these" box belongs to its field: its events are the field's.
|
|
112
|
+
const field = (n) => (n && n.endsWith("__none") ? n.slice(0, -6) : n);
|
|
109
113
|
const showing = (n) => controls(n).some((c) => c.getAttribute("aria-invalid") === "true");
|
|
110
114
|
const check = () => {
|
|
111
115
|
const input = {};
|
|
@@ -115,6 +119,8 @@ export const FORM_SCRIPT = `(() => {
|
|
|
115
119
|
let live = form.querySelector(".wb-live");
|
|
116
120
|
if (!live) { live = document.createElement("p"); live.className = "wb-live"; live.setAttribute("role", "status"); live.setAttribute("aria-live", "polite"); form.prepend(live); }
|
|
117
121
|
const summary = form.hasAttribute("data-wb-summary") ? (form.querySelector(".wb-summary") || form.insertBefore(Object.assign(document.createElement("div"), { className: "wb-summary", tabIndex: -1 }), form.firstChild)) : null;
|
|
122
|
+
// A summary the server drew after a failed submit takes focus, so it is read out once.
|
|
123
|
+
if (summary && !summary.hidden && summary.textContent.trim()) summary.focus();
|
|
118
124
|
const say = (key, count) => { const text = Object.prototype.hasOwnProperty.call(messages, key) ? fill(messages[key], { count }) : ""; live.textContent = ""; setTimeout(() => { live.textContent = text; }, 50); return text; };
|
|
119
125
|
const counters = () => {
|
|
120
126
|
for (const el of form.querySelectorAll("[data-wb-max]")) {
|
|
@@ -160,10 +166,10 @@ export const FORM_SCRIPT = `(() => {
|
|
|
160
166
|
if (isSubmit(b)) { pressing = true; setTimeout(() => { pressing = false; }, 1000); }
|
|
161
167
|
});
|
|
162
168
|
form.addEventListener("focusout", (e) => {
|
|
163
|
-
const n = e.target && e.target.name;
|
|
169
|
+
const n = field(e.target && e.target.name);
|
|
164
170
|
if (!n || !names.includes(n)) return;
|
|
165
171
|
// Leaving one box of a group for another of the same field isn't leaving the field.
|
|
166
|
-
if (e.relatedTarget && e.relatedTarget.name === n) return;
|
|
172
|
+
if (e.relatedTarget && field(e.relatedTarget.name) === n) return;
|
|
167
173
|
if (pressing || isSubmit(e.relatedTarget)) return;
|
|
168
174
|
const r = check();
|
|
169
175
|
if (!r) return;
|
|
@@ -175,7 +181,7 @@ export const FORM_SCRIPT = `(() => {
|
|
|
175
181
|
const edited = (e) => {
|
|
176
182
|
held = false;
|
|
177
183
|
counters();
|
|
178
|
-
const n = e.target && e.target.name;
|
|
184
|
+
const n = field(e.target && e.target.name);
|
|
179
185
|
if (!n || !names.includes(n)) return;
|
|
180
186
|
// A condition may name this field: show or hide the fields that depend on it.
|
|
181
187
|
const r0 = conditional.length ? check() : null;
|
package/dist/style.js
CHANGED
|
@@ -166,6 +166,9 @@ input:not([type=hidden]):not([type=checkbox]):not([type=radio]){min-height:2.75r
|
|
|
166
166
|
.wb-summary{margin:0 0 1rem;padding:.6rem .75rem;border-left:3px solid var(--fail);background:var(--fail-bg);border-radius:6px}
|
|
167
167
|
.wb-summary[hidden],.wb-summary:empty{display:none}
|
|
168
168
|
.wb-summary p{margin:0 0 .3rem;font-weight:600}.wb-summary ul{margin:0;padding-left:1.1rem}
|
|
169
|
+
.wb-field{margin:0 0 1rem}.wb-field>label,.wb-field legend{display:block;font-weight:600;margin:0 0 .3rem}
|
|
170
|
+
.wb-field fieldset{border:0;margin:0;padding:0;min-width:0}.wb-option{display:flex;gap:.5rem;align-items:center;min-height:2.75rem;font-weight:400}
|
|
171
|
+
.wb-optional{font-weight:400;color:var(--muted)}.wb-hint{margin:0 0 .35rem;color:var(--muted);font-size:.875rem}
|
|
169
172
|
.wb-live{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
|
|
170
173
|
@media (max-width:640px){nav.links{margin-left:0}th,td{padding:.55rem .7rem}table.kv th{width:auto}}
|
|
171
174
|
`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mccaskie-labs/workbench-ui",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Workbench pages: one dark look, a top bar with the environment tag, cards, outcome pills, and one format for times, money and durations.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|