@mccaskie-labs/workbench-ui 0.3.0 → 0.3.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.
- package/CHANGELOG.md +6 -0
- package/dist/form-script.d.ts +4 -0
- package/dist/form-script.js +33 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @mccaskie-labs/workbench-ui
|
|
2
2
|
|
|
3
|
+
## 0.3.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- workbench-forms: `show: { when, is }` on any field shows it only while an earlier field holds one of some values. A field that isn't shown is neither checked nor stored (null), and `validate` returns it in the new `hidden` list. The kit's own form gains a conditional field, and tests 2, 4, 6 and 7 cover it. workbench-ui: `FORM_SCRIPT` hides a field's `data-wb-field` wrapper and disables its controls while its condition doesn't hold, updating as the person types.
|
|
8
|
+
|
|
3
9
|
## 0.3.0
|
|
4
10
|
|
|
5
11
|
- `FORM_SCRIPT`: the screen behaviour for forms checked by `workbench-forms` (Robert's form-validation standard §7 and §8): a problem shows when the person leaves the field and clears as they fix it, a failed submit focuses the first bad field and announces the count, an optional summary links each problem to its field, a date, amount or phone number that was read differently is shown back before it is stored, and reset clears everything. Styles for field errors, the summary, counters, text areas and the input width tokens (`wb-w-xs` to `wb-w-full`).
|
package/dist/form-script.d.ts
CHANGED
|
@@ -15,6 +15,10 @@
|
|
|
15
15
|
* - When a date, an amount or a phone number was read as something other than
|
|
16
16
|
* what was typed, the first submit writes it back and stops, so the person
|
|
17
17
|
* sees it before it is stored.
|
|
18
|
+
* - A field with a \`show\` condition is hidden while the condition doesn't
|
|
19
|
+
* hold: its wrapper (the element with \`data-wb-field="<name>"\`, or the
|
|
20
|
+
* control itself) gets \`hidden\`, its controls are disabled so they aren't
|
|
21
|
+
* sent, and its message clears. This updates as the person types.
|
|
18
22
|
* - Reset clears every message, the summary and the counters.
|
|
19
23
|
*
|
|
20
24
|
* Messages come only from the config (already in the visitor's language) and
|
package/dist/form-script.js
CHANGED
|
@@ -15,6 +15,10 @@
|
|
|
15
15
|
* - When a date, an amount or a phone number was read as something other than
|
|
16
16
|
* what was typed, the first submit writes it back and stops, so the person
|
|
17
17
|
* sees it before it is stored.
|
|
18
|
+
* - A field with a \`show\` condition is hidden while the condition doesn't
|
|
19
|
+
* hold: its wrapper (the element with \`data-wb-field="<name>"\`, or the
|
|
20
|
+
* control itself) gets \`hidden\`, its controls are disabled so they aren't
|
|
21
|
+
* sent, and its message clears. This updates as the person types.
|
|
18
22
|
* - Reset clears every message, the summary and the counters.
|
|
19
23
|
*
|
|
20
24
|
* Messages come only from the config (already in the visitor's language) and
|
|
@@ -124,6 +128,28 @@ export const FORM_SCRIPT = `(() => {
|
|
|
124
128
|
c.classList.toggle("over", n > Number(el.getAttribute("data-wb-max")));
|
|
125
129
|
}
|
|
126
130
|
};
|
|
131
|
+
const wrapper = (n) => form.querySelector('[data-wb-field="' + n + '"]');
|
|
132
|
+
const conditional = names.filter((n) => fields[n].show);
|
|
133
|
+
const visibility = (r) => {
|
|
134
|
+
if (!r || !Array.isArray(r.hidden)) return;
|
|
135
|
+
for (const n of conditional) {
|
|
136
|
+
const off = r.hidden.includes(n);
|
|
137
|
+
const w = wrapper(n);
|
|
138
|
+
if (w) w.hidden = off;
|
|
139
|
+
for (const c of controls(n)) {
|
|
140
|
+
// Only undo what this script did: a control the app rendered disabled stays disabled.
|
|
141
|
+
if (off && !c.disabled) { c.disabled = true; c.setAttribute("data-wb-hid", ""); }
|
|
142
|
+
else if (!off && c.hasAttribute("data-wb-hid")) { c.disabled = false; c.removeAttribute("data-wb-hid"); }
|
|
143
|
+
if (!w) c.hidden = off;
|
|
144
|
+
}
|
|
145
|
+
if (off) clear(n);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
if (conditional.length) {
|
|
149
|
+
visibility(check());
|
|
150
|
+
// The browser may restore field values after this ran (back, forward, reload) without an input event.
|
|
151
|
+
addEventListener("pageshow", () => visibility(check()));
|
|
152
|
+
}
|
|
127
153
|
counters();
|
|
128
154
|
// Pressing a submit button leaves the field too, but the submit shows every problem itself: a message
|
|
129
155
|
// appearing on the way would move the button out from under the pointer, and the press would be lost.
|
|
@@ -141,6 +167,7 @@ export const FORM_SCRIPT = `(() => {
|
|
|
141
167
|
if (pressing || isSubmit(e.relatedTarget)) return;
|
|
142
168
|
const r = check();
|
|
143
169
|
if (!r) return;
|
|
170
|
+
visibility(r);
|
|
144
171
|
const p = r.problems.find((x) => x.field === n);
|
|
145
172
|
if (p) show(p);
|
|
146
173
|
else { clear(n); writeBack(n, r.shown[n]); counters(); }
|
|
@@ -150,9 +177,12 @@ export const FORM_SCRIPT = `(() => {
|
|
|
150
177
|
counters();
|
|
151
178
|
const n = e.target && e.target.name;
|
|
152
179
|
if (!n || !names.includes(n)) return;
|
|
180
|
+
// A condition may name this field: show or hide the fields that depend on it.
|
|
181
|
+
const r0 = conditional.length ? check() : null;
|
|
182
|
+
if (r0) visibility(r0);
|
|
153
183
|
// Keystrokes only ever turn messages off: this field's, and any a condition on it no longer asks for.
|
|
154
184
|
if (!names.some(showing)) return;
|
|
155
|
-
const r = check();
|
|
185
|
+
const r = r0 || check();
|
|
156
186
|
if (!r) return;
|
|
157
187
|
for (const m of names) if (showing(m) && !r.problems.some((x) => x.field === m)) clear(m);
|
|
158
188
|
};
|
|
@@ -162,6 +192,7 @@ export const FORM_SCRIPT = `(() => {
|
|
|
162
192
|
pressing = false;
|
|
163
193
|
const r = check();
|
|
164
194
|
if (!r) return;
|
|
195
|
+
visibility(r);
|
|
165
196
|
for (const n of names) if (!r.problems.some((x) => x.field === n)) writeBack(n, r.shown[n]);
|
|
166
197
|
counters();
|
|
167
198
|
if (r.problems.length) {
|
|
@@ -204,7 +235,7 @@ export const FORM_SCRIPT = `(() => {
|
|
|
204
235
|
for (const n of names) clear(n);
|
|
205
236
|
if (summary) { summary.textContent = ""; summary.hidden = true; }
|
|
206
237
|
live.textContent = "";
|
|
207
|
-
setTimeout(counters, 0);
|
|
238
|
+
setTimeout(() => { counters(); if (conditional.length) visibility(check()); }, 0);
|
|
208
239
|
});
|
|
209
240
|
}
|
|
210
241
|
})();`;
|
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.1",
|
|
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",
|