@fieldia/widgets 0.9.2 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/package.json +2 -2
- package/src/index.d.mts +2 -0
- package/src/index.d.ts +2 -0
- package/src/index.js +4 -0
- package/src/index.js.map +1 -1
- package/src/index.mjs +2 -0
- package/src/index.mjs.map +1 -1
- package/src/lib/address.d.mts +4 -0
- package/src/lib/address.d.ts +4 -0
- package/src/lib/address.js +105 -0
- package/src/lib/address.js.map +1 -0
- package/src/lib/address.mjs +100 -0
- package/src/lib/address.mjs.map +1 -0
- package/src/lib/cards.d.mts +2 -0
- package/src/lib/cards.d.ts +2 -0
- package/src/lib/cards.js +152 -0
- package/src/lib/cards.js.map +1 -0
- package/src/lib/cards.mjs +148 -0
- package/src/lib/cards.mjs.map +1 -0
- package/src/lib/choice-images.d.mts +2 -0
- package/src/lib/choice-images.d.ts +2 -0
- package/src/lib/choice-images.js +99 -0
- package/src/lib/choice-images.js.map +1 -0
- package/src/lib/choice-images.mjs +95 -0
- package/src/lib/choice-images.mjs.map +1 -0
- package/src/lib/choice-rules.d.mts +22 -0
- package/src/lib/choice-rules.d.ts +22 -0
- package/src/lib/choice-rules.js +46 -0
- package/src/lib/choice-rules.js.map +1 -0
- package/src/lib/choice-rules.mjs +41 -0
- package/src/lib/choice-rules.mjs.map +1 -0
- package/src/lib/choice-tags.d.mts +17 -0
- package/src/lib/choice-tags.d.ts +17 -0
- package/src/lib/choice-tags.js +187 -0
- package/src/lib/choice-tags.js.map +1 -0
- package/src/lib/choice-tags.mjs +182 -0
- package/src/lib/choice-tags.mjs.map +1 -0
- package/src/lib/choices-from.d.mts +8 -0
- package/src/lib/choices-from.d.ts +8 -0
- package/src/lib/choices-from.js +63 -0
- package/src/lib/choices-from.js.map +1 -0
- package/src/lib/choices-from.mjs +60 -0
- package/src/lib/choices-from.mjs.map +1 -0
- package/src/lib/display.js +4 -3
- package/src/lib/display.js.map +1 -1
- package/src/lib/display.mjs +5 -4
- package/src/lib/display.mjs.map +1 -1
- package/src/lib/extras.js +8 -4
- package/src/lib/extras.js.map +1 -1
- package/src/lib/extras.mjs +8 -4
- package/src/lib/extras.mjs.map +1 -1
- package/src/lib/files.d.mts +2 -0
- package/src/lib/files.d.ts +2 -0
- package/src/lib/files.js +236 -78
- package/src/lib/files.js.map +1 -1
- package/src/lib/files.mjs +235 -78
- package/src/lib/files.mjs.map +1 -1
- package/src/lib/focus-trap.d.mts +7 -0
- package/src/lib/focus-trap.d.ts +7 -0
- package/src/lib/focus-trap.js +26 -0
- package/src/lib/focus-trap.js.map +1 -0
- package/src/lib/focus-trap.mjs +23 -0
- package/src/lib/focus-trap.mjs.map +1 -0
- package/src/lib/icons.js +1 -0
- package/src/lib/icons.js.map +1 -1
- package/src/lib/icons.mjs +1 -0
- package/src/lib/icons.mjs.map +1 -1
- package/src/lib/kind-parts.d.mts +56 -0
- package/src/lib/kind-parts.d.ts +56 -0
- package/src/lib/kind-parts.js +121 -0
- package/src/lib/kind-parts.js.map +1 -0
- package/src/lib/kind-parts.mjs +107 -0
- package/src/lib/kind-parts.mjs.map +1 -0
- package/src/lib/labels.d.mts +85 -0
- package/src/lib/labels.d.ts +85 -0
- package/src/lib/labels.js +111 -189
- package/src/lib/labels.js.map +1 -1
- package/src/lib/labels.mjs +111 -189
- package/src/lib/labels.mjs.map +1 -1
- package/src/lib/layout-styles.d.mts +11 -0
- package/src/lib/layout-styles.d.ts +11 -0
- package/src/lib/layout-styles.js +178 -0
- package/src/lib/layout-styles.js.map +1 -0
- package/src/lib/layout-styles.mjs +175 -0
- package/src/lib/layout-styles.mjs.map +1 -0
- package/src/lib/limits.d.mts +20 -0
- package/src/lib/limits.d.ts +20 -0
- package/src/lib/limits.js +71 -0
- package/src/lib/limits.js.map +1 -0
- package/src/lib/limits.mjs +66 -0
- package/src/lib/limits.mjs.map +1 -0
- package/src/lib/line-moves.d.mts +8 -0
- package/src/lib/line-moves.d.ts +8 -0
- package/src/lib/line-moves.js +20 -0
- package/src/lib/line-moves.js.map +1 -0
- package/src/lib/line-moves.mjs +17 -0
- package/src/lib/line-moves.mjs.map +1 -0
- package/src/lib/lines.js +85 -7
- package/src/lib/lines.js.map +1 -1
- package/src/lib/lines.mjs +86 -8
- package/src/lib/lines.mjs.map +1 -1
- package/src/lib/locales/all.d.mts +8 -0
- package/src/lib/locales/all.d.ts +8 -0
- package/src/lib/locales/all.js +13 -0
- package/src/lib/locales/all.js.map +1 -0
- package/src/lib/locales/all.mjs +10 -0
- package/src/lib/locales/all.mjs.map +1 -0
- package/src/lib/locales/ar.d.mts +3 -0
- package/src/lib/locales/ar.d.ts +3 -0
- package/src/lib/locales/ar.js +108 -0
- package/src/lib/locales/ar.js.map +1 -0
- package/src/lib/locales/ar.mjs +105 -0
- package/src/lib/locales/ar.mjs.map +1 -0
- package/src/lib/locales/de.d.mts +3 -0
- package/src/lib/locales/de.d.ts +3 -0
- package/src/lib/locales/de.js +108 -0
- package/src/lib/locales/de.js.map +1 -0
- package/src/lib/locales/de.mjs +105 -0
- package/src/lib/locales/de.mjs.map +1 -0
- package/src/lib/locales/fr.d.mts +3 -0
- package/src/lib/locales/fr.d.ts +3 -0
- package/src/lib/locales/fr.js +108 -0
- package/src/lib/locales/fr.js.map +1 -0
- package/src/lib/locales/fr.mjs +105 -0
- package/src/lib/locales/fr.mjs.map +1 -0
- package/src/lib/matrix.d.mts +10 -0
- package/src/lib/matrix.d.ts +10 -0
- package/src/lib/matrix.js +86 -0
- package/src/lib/matrix.js.map +1 -0
- package/src/lib/matrix.mjs +82 -0
- package/src/lib/matrix.mjs.map +1 -0
- package/src/lib/numbers.d.mts +7 -0
- package/src/lib/numbers.d.ts +7 -0
- package/src/lib/numbers.js +15 -0
- package/src/lib/numbers.js.map +1 -1
- package/src/lib/numbers.mjs +14 -0
- package/src/lib/numbers.mjs.map +1 -1
- package/src/lib/progress.js +8 -4
- package/src/lib/progress.js.map +1 -1
- package/src/lib/progress.mjs +8 -4
- package/src/lib/progress.mjs.map +1 -1
- package/src/lib/ranking.d.mts +2 -0
- package/src/lib/ranking.d.ts +2 -0
- package/src/lib/ranking.js +172 -0
- package/src/lib/ranking.js.map +1 -0
- package/src/lib/ranking.mjs +168 -0
- package/src/lib/ranking.mjs.map +1 -0
- package/src/lib/relations.d.mts +1 -1
- package/src/lib/relations.d.ts +1 -1
- package/src/lib/relations.js +43 -18
- package/src/lib/relations.js.map +1 -1
- package/src/lib/relations.mjs +43 -18
- package/src/lib/relations.mjs.map +1 -1
- package/src/lib/shuffle.d.mts +7 -0
- package/src/lib/shuffle.d.ts +7 -0
- package/src/lib/shuffle.js +60 -0
- package/src/lib/shuffle.js.map +1 -0
- package/src/lib/shuffle.mjs +57 -0
- package/src/lib/shuffle.mjs.map +1 -0
- package/src/lib/signature.d.mts +2 -0
- package/src/lib/signature.d.ts +2 -0
- package/src/lib/signature.js +223 -0
- package/src/lib/signature.js.map +1 -0
- package/src/lib/signature.mjs +219 -0
- package/src/lib/signature.mjs.map +1 -0
- package/src/lib/slider.d.mts +10 -0
- package/src/lib/slider.d.ts +10 -0
- package/src/lib/slider.js +57 -0
- package/src/lib/slider.js.map +1 -0
- package/src/lib/slider.mjs +53 -0
- package/src/lib/slider.mjs.map +1 -0
- package/src/lib/styles-choices.d.mts +7 -0
- package/src/lib/styles-choices.d.ts +7 -0
- package/src/lib/styles-choices.js +47 -0
- package/src/lib/styles-choices.js.map +1 -0
- package/src/lib/styles-choices.mjs +44 -0
- package/src/lib/styles-choices.mjs.map +1 -0
- package/src/lib/styles-inputs.d.mts +9 -0
- package/src/lib/styles-inputs.d.ts +9 -0
- package/src/lib/styles-inputs.js +41 -0
- package/src/lib/styles-inputs.js.map +1 -0
- package/src/lib/styles-inputs.mjs +38 -0
- package/src/lib/styles-inputs.mjs.map +1 -0
- package/src/lib/styles-kinds.d.mts +7 -0
- package/src/lib/styles-kinds.d.ts +7 -0
- package/src/lib/styles-kinds.js +119 -0
- package/src/lib/styles-kinds.js.map +1 -0
- package/src/lib/styles-kinds.mjs +116 -0
- package/src/lib/styles-kinds.mjs.map +1 -0
- package/src/lib/styles-parts.d.mts +16 -0
- package/src/lib/styles-parts.d.ts +16 -0
- package/src/lib/styles-parts.js +69 -0
- package/src/lib/styles-parts.js.map +1 -0
- package/src/lib/styles-parts.mjs +66 -0
- package/src/lib/styles-parts.mjs.map +1 -0
- package/src/lib/styles.d.mts +10 -12
- package/src/lib/styles.d.ts +10 -12
- package/src/lib/styles.js +259 -64
- package/src/lib/styles.js.map +1 -1
- package/src/lib/styles.mjs +258 -63
- package/src/lib/styles.mjs.map +1 -1
- package/src/lib/units.d.mts +10 -0
- package/src/lib/units.d.ts +10 -0
- package/src/lib/units.js +19 -0
- package/src/lib/units.js.map +1 -0
- package/src/lib/units.mjs +16 -0
- package/src/lib/units.mjs.map +1 -0
- package/src/lib/widgets.js +215 -57
- package/src/lib/widgets.js.map +1 -1
- package/src/lib/widgets.mjs +215 -57
- package/src/lib/widgets.mjs.map +1 -1
- package/src/lib/yes-no.d.mts +9 -0
- package/src/lib/yes-no.d.ts +9 -0
- package/src/lib/yes-no.js +58 -0
- package/src/lib/yes-no.js.map +1 -0
- package/src/lib/yes-no.mjs +54 -0
- package/src/lib/yes-no.mjs.map +1 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { announcer, describeState, fillIn, maker, wordsFor } from './kind-parts.mjs';
|
|
2
|
+
import { moveLineTo } from './line-moves.mjs';
|
|
3
|
+
import { lineForm } from './lines.mjs';
|
|
4
|
+
import { createWidget } from './widgets.mjs';
|
|
5
|
+
const count = (value) => (typeof value === 'number' && Number.isInteger(value) && value >= 0 ? value : undefined);
|
|
6
|
+
export const cardsWidget = ({ form, name, field, node, id, document, labels, locale, dialogs }) => {
|
|
7
|
+
const words = wordsFor(labels, locale);
|
|
8
|
+
const make = maker(document);
|
|
9
|
+
const def = field;
|
|
10
|
+
const options = node.options ?? {};
|
|
11
|
+
const min = count(options['min']) ?? 0;
|
|
12
|
+
const max = count(options['max']) ?? Infinity;
|
|
13
|
+
const itemLabel = typeof options['itemLabel'] === 'string' && options['itemLabel'].trim() ? options['itemLabel'].trim() : null;
|
|
14
|
+
const titleOf = (n) => (itemLabel ? `${itemLabel} ${n}` : fillIn(words.entry, { n }));
|
|
15
|
+
// The fields that keep the lines' order or say what a line is are not asked for.
|
|
16
|
+
const names = (node.columns ?? Object.keys(def.fields)).filter((f) => def.fields[f] && f !== def.sequenceField && f !== def.lineKinds?.field);
|
|
17
|
+
const list = make('div', { class: 'fd-repeat-list' });
|
|
18
|
+
const addButton = make('button', { type: 'button', class: 'fd-button fd-repeat-add' }, typeof options['addLabel'] === 'string' && options['addLabel'] ? options['addLabel'] : words.addAnother);
|
|
19
|
+
const voice = announcer(make);
|
|
20
|
+
const element = make('div', { id, class: 'fd-repeat', role: 'group' }, list, addButton, voice.element);
|
|
21
|
+
const cards = new Map();
|
|
22
|
+
const lines = () => form.getState().values[name] ?? [];
|
|
23
|
+
let readonly = false;
|
|
24
|
+
/** Where the cursor goes once the cards are drawn again. */
|
|
25
|
+
let focusNext = null;
|
|
26
|
+
// A new form starts with the cards it needs at least.
|
|
27
|
+
for (let have = lines().length; have < min; have++)
|
|
28
|
+
form.addLine(name);
|
|
29
|
+
addButton.addEventListener('click', () => {
|
|
30
|
+
if (readonly || lines().length >= max)
|
|
31
|
+
return;
|
|
32
|
+
const key = form.addLine(name);
|
|
33
|
+
focusNext = () => cards.get(key)?.fields[0]?.widget.focus();
|
|
34
|
+
settle();
|
|
35
|
+
});
|
|
36
|
+
function makeCard(line) {
|
|
37
|
+
const titleId = `${id}-${line.key}-title`;
|
|
38
|
+
const title = make('span', { id: titleId, class: 'fd-repeat-title' });
|
|
39
|
+
const remove = make('button', { type: 'button', class: 'fd-repeat-remove' }, '×');
|
|
40
|
+
const tool = (text, word, act) => {
|
|
41
|
+
const button = make('button', { type: 'button', class: 'fd-repeat-tool' }, text);
|
|
42
|
+
button.addEventListener('click', act);
|
|
43
|
+
return [button, word];
|
|
44
|
+
};
|
|
45
|
+
const at = () => lines().findIndex((l) => l.key === line.key);
|
|
46
|
+
const tools = [tool('↑', 'moveUp', () => move(line.key, at() - 1)), tool('↓', 'moveDown', () => move(line.key, at() + 1)), tool('⧉', 'copy', () => copy(line.key))];
|
|
47
|
+
const body = make('div', { class: 'fd-repeat-fields' });
|
|
48
|
+
const cardElement = make('div', { class: 'fd-repeat-card', role: 'group', 'aria-labelledby': titleId, 'data-line': line.key }, make('div', { class: 'fd-repeat-head' }, title, ...tools.map(([b]) => b), remove), body);
|
|
49
|
+
const fields = names.map((column) => {
|
|
50
|
+
const sub = def.fields[column];
|
|
51
|
+
const cellId = `${id}-${line.key}-${column}`;
|
|
52
|
+
const subNode = { type: 'field', id: `${node.id}.${line.key}.${column}`, field: column };
|
|
53
|
+
const widget = createWidget({ form: lineForm(form, name, line.key), name: column, field: sub, node: subNode, id: cellId, document, labels, locale, dialogs });
|
|
54
|
+
const label = make('label', { class: 'fd-repeat-label', for: cellId }, sub.label);
|
|
55
|
+
if (!['INPUT', 'SELECT', 'TEXTAREA'].includes(widget.element.tagName))
|
|
56
|
+
label.addEventListener('click', () => widget.focus());
|
|
57
|
+
const error = make('div', { class: 'fd-cell-error', hidden: '' });
|
|
58
|
+
body.append(make('div', { class: 'fd-repeat-field' }, label, widget.element, error));
|
|
59
|
+
return { name: column, def: sub, widget, error };
|
|
60
|
+
});
|
|
61
|
+
remove.addEventListener('click', () => {
|
|
62
|
+
const all = lines();
|
|
63
|
+
const at = all.findIndex((l) => l.key === line.key);
|
|
64
|
+
if (readonly || at === -1 || all.length <= min)
|
|
65
|
+
return;
|
|
66
|
+
const gone = title.textContent ?? '';
|
|
67
|
+
form.removeLine(name, line.key);
|
|
68
|
+
voice.say(fillIn(words.removed, { name: gone }));
|
|
69
|
+
// The card that took its place, else the one before, else "Add another".
|
|
70
|
+
const after = lines();
|
|
71
|
+
const next = after[Math.min(at, after.length - 1)];
|
|
72
|
+
focusNext = () => (next ? cards.get(next.key)?.fields[0]?.widget.focus() : addButton.focus());
|
|
73
|
+
settle();
|
|
74
|
+
});
|
|
75
|
+
return { element: cardElement, title, remove, tools, fields };
|
|
76
|
+
}
|
|
77
|
+
/** A card to another place, the focus kept on what had it, and where it went said aloud. */
|
|
78
|
+
function move(key, to) {
|
|
79
|
+
const from = lines().findIndex((l) => l.key === key);
|
|
80
|
+
if (readonly || to < 0 || to >= lines().length || to === from)
|
|
81
|
+
return;
|
|
82
|
+
const gone = cards.get(key)?.title.textContent ?? '';
|
|
83
|
+
moveLineTo(form, name, def, key, to);
|
|
84
|
+
// The focus stays on the button pressed; at an end, the other way takes it.
|
|
85
|
+
const way = (from > to && to > 0) || to === lines().length - 1 ? 0 : 1;
|
|
86
|
+
cards.get(key)?.tools[way][0].focus();
|
|
87
|
+
voice.say(fillIn(words.movedTo, { label: gone, n: to + 1, total: lines().length }));
|
|
88
|
+
}
|
|
89
|
+
/** A copy of a card, its answers too, right after it, the cursor in its first field. */
|
|
90
|
+
function copy(key) {
|
|
91
|
+
const all = lines();
|
|
92
|
+
const at = all.findIndex((l) => l.key === key);
|
|
93
|
+
if (readonly || at < 0 || all.length >= max)
|
|
94
|
+
return;
|
|
95
|
+
const values = { ...all[at].values };
|
|
96
|
+
if (def.sequenceField)
|
|
97
|
+
delete values[def.sequenceField];
|
|
98
|
+
const made = form.addLine(name, values);
|
|
99
|
+
moveLineTo(form, name, def, made, at + 1);
|
|
100
|
+
cards.get(made)?.fields[0]?.widget.focus();
|
|
101
|
+
}
|
|
102
|
+
function settle() {
|
|
103
|
+
const run = focusNext;
|
|
104
|
+
focusNext = null;
|
|
105
|
+
run?.();
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
element,
|
|
109
|
+
focus: () => ([...cards.values()].find((card) => card.element === list.firstElementChild)?.fields[0]?.widget ?? addButton).focus(),
|
|
110
|
+
update(state) {
|
|
111
|
+
readonly = state.readonly;
|
|
112
|
+
const current = state.value ?? [];
|
|
113
|
+
const errors = form.getState().errors;
|
|
114
|
+
const keep = new Set(current.map((l) => l.key));
|
|
115
|
+
for (const [key, card] of cards) {
|
|
116
|
+
if (keep.has(key))
|
|
117
|
+
continue;
|
|
118
|
+
card.element.remove();
|
|
119
|
+
for (const f of card.fields)
|
|
120
|
+
f.widget.destroy?.();
|
|
121
|
+
cards.delete(key);
|
|
122
|
+
}
|
|
123
|
+
current.forEach((line, index) => {
|
|
124
|
+
let card = cards.get(line.key);
|
|
125
|
+
if (!card)
|
|
126
|
+
cards.set(line.key, (card = makeCard(line)));
|
|
127
|
+
if (list.children[index] !== card.element)
|
|
128
|
+
list.insertBefore(card.element, list.children[index] ?? null);
|
|
129
|
+
card.title.textContent = titleOf(index + 1);
|
|
130
|
+
card.remove.setAttribute('aria-label', fillIn(words.remove, { name: card.title.textContent }));
|
|
131
|
+
card.remove.hidden = readonly || current.length <= min;
|
|
132
|
+
for (const [button, word] of card.tools) {
|
|
133
|
+
button.setAttribute('aria-label', fillIn(words[word], { label: card.title.textContent, name: card.title.textContent }));
|
|
134
|
+
button.hidden = readonly || (word === 'moveUp' ? index === 0 : word === 'moveDown' ? index === current.length - 1 : current.length >= max);
|
|
135
|
+
}
|
|
136
|
+
for (const f of card.fields) {
|
|
137
|
+
const message = errors[`${name}.${line.key}.${f.name}`];
|
|
138
|
+
f.error.hidden = !message;
|
|
139
|
+
f.error.textContent = message ?? '';
|
|
140
|
+
f.widget.update({ value: line.values[f.name], values: line.values, readonly: readonly || f.def.readonly === true, required: f.def.required === true, invalid: !!message });
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
addButton.hidden = readonly || current.length >= max;
|
|
144
|
+
describeState(element, state);
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
//# sourceMappingURL=cards.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cards.mjs","sourceRoot":"","sources":["../../../../../libs/wid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C,OAAO,EAAE,CAAC,CAAC;gBAC7K,CAAC;YACH,CAAC,CAAC,CAAC;YACH,SAAS,CAAC,MAAM,GAAG,QAAQ,IAAI,OAAO,CAAC,MAAM,IAAI,GAAG,CAAC;YACrD,aAAa,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAChC,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.imageChoiceWidget = void 0;
|
|
4
|
+
const choice_rules_1 = require("./choice-rules");
|
|
5
|
+
const kind_parts_1 = require("./kind-parts");
|
|
6
|
+
const shuffle_1 = require("./shuffle");
|
|
7
|
+
/**
|
|
8
|
+
* Pictures to choose from (`selection.image-choice`): each option a card of
|
|
9
|
+
* its `image` over its words. One answer is a radio group with one stop for
|
|
10
|
+
* Tab — the arrows move and pick, going round at the ends, Home and End go to
|
|
11
|
+
* the ends, and left is forward on a right-to-left page — with "Clear
|
|
12
|
+
* selection" when it need not be answered. Several answers, when the field
|
|
13
|
+
* takes several, are checkboxes, each its own stop. "Other" is not offered:
|
|
14
|
+
* an answer of one's own has no picture. `options.shuffle` shows the cards
|
|
15
|
+
* in an order of the form's own. Each picture is described by its option's
|
|
16
|
+
* `alt`. `options.showLabels: false` keeps the words out of sight (still each
|
|
17
|
+
* card's name), `imageSize` is small, medium or large, `imageFit: "whole"`
|
|
18
|
+
* shows the whole picture rather than filling the card, and `columns` lays
|
|
19
|
+
* the cards in columns or in a row.
|
|
20
|
+
*/
|
|
21
|
+
/** A frame with a hill and a sun: the tile of an option without a picture. */
|
|
22
|
+
const BLANK = '<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><rect x="3" y="4" width="18" height="16" rx="2"/><circle cx="9" cy="10" r="2"/><path d="M21 16l-5-5-9 9"/></svg>';
|
|
23
|
+
const imageChoiceWidget = ({ form, name, field, node, id, document, labels, locale }) => {
|
|
24
|
+
const words = (0, kind_parts_1.wordsFor)(labels, locale);
|
|
25
|
+
const make = (0, kind_parts_1.maker)(document);
|
|
26
|
+
const multiple = field.type === 'selection' && field.multiple === true;
|
|
27
|
+
const written = field.type === 'selection' ? field.options : [];
|
|
28
|
+
const options = (0, shuffle_1.shownOptions)(written, form, name, node);
|
|
29
|
+
const look = node.options ?? {};
|
|
30
|
+
const bare = look['showLabels'] === false;
|
|
31
|
+
const group = make('div', { id, class: `fd-image-choices${bare ? ' fd-image-choices-bare' : ''}`, role: multiple ? 'group' : 'radiogroup', 'data-size': look['imageSize'], 'data-fit': look['imageFit'] });
|
|
32
|
+
(0, choice_rules_1.layOut)(group, node);
|
|
33
|
+
const limit = multiple ? (0, choice_rules_1.limiter)(make, words, node) : null;
|
|
34
|
+
const cards = options.map((option) => {
|
|
35
|
+
const picture = option.image ? make('img', { src: option.image, alt: option.alt ?? '', loading: 'lazy', draggable: 'false' }) : make('span', { class: 'fd-image-card-blank' });
|
|
36
|
+
if (!option.image)
|
|
37
|
+
picture.innerHTML = BLANK; // a constant drawing, never words from the page
|
|
38
|
+
const card = make('button', { type: 'button', class: 'fd-image-card', role: multiple ? 'checkbox' : 'radio', 'aria-checked': 'false', 'aria-label': bare ? option.label : undefined }, make('span', { class: 'fd-image-card-picture' }, picture), make('span', { class: 'fd-image-card-words' }, option.label));
|
|
39
|
+
card.addEventListener('click', () => pick(option));
|
|
40
|
+
group.append(card);
|
|
41
|
+
return card;
|
|
42
|
+
});
|
|
43
|
+
const current = () => form.getState().values[name];
|
|
44
|
+
function pick(option) {
|
|
45
|
+
if (!multiple)
|
|
46
|
+
return form.setValue(name, option.value);
|
|
47
|
+
const now = Array.isArray(current()) ? current() : [];
|
|
48
|
+
const on = new Set(now.includes(option.value) ? now.filter((v) => v !== option.value) : (0, choice_rules_1.withAlone)(written, now, option.value));
|
|
49
|
+
// In the options' own order, as checkboxes keep them, however they are shown.
|
|
50
|
+
form.setValue(name, written.filter((o) => on.has(o.value)).map((o) => o.value));
|
|
51
|
+
}
|
|
52
|
+
let readonly = false;
|
|
53
|
+
if (!multiple) {
|
|
54
|
+
group.addEventListener('keydown', (event) => {
|
|
55
|
+
if (readonly)
|
|
56
|
+
return;
|
|
57
|
+
const at = cards.indexOf(event.target);
|
|
58
|
+
if (at === -1)
|
|
59
|
+
return;
|
|
60
|
+
const back = (0, kind_parts_1.rightToLeft)(group);
|
|
61
|
+
const steps = { ArrowDown: 1, ArrowUp: -1, ArrowRight: back ? -1 : 1, ArrowLeft: back ? 1 : -1 };
|
|
62
|
+
const to = event.key === 'Home' ? 0 : event.key === 'End' ? cards.length - 1 : event.key in steps ? (at + steps[event.key] + cards.length) % cards.length : -1;
|
|
63
|
+
if (to === -1)
|
|
64
|
+
return;
|
|
65
|
+
event.preventDefault();
|
|
66
|
+
pick(options[to]);
|
|
67
|
+
cards[to].focus();
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
const clear = multiple
|
|
71
|
+
? null
|
|
72
|
+
: (0, kind_parts_1.clearSelection)(document, words, () => {
|
|
73
|
+
form.setValue(name, null);
|
|
74
|
+
cards[0]?.focus();
|
|
75
|
+
});
|
|
76
|
+
if (limit?.element)
|
|
77
|
+
group.append(limit.element);
|
|
78
|
+
return {
|
|
79
|
+
element: clear ? make('div', { class: 'fd-choices-box' }, group, clear.button) : group,
|
|
80
|
+
focus: () => (cards.find((c) => c.getAttribute('aria-checked') === 'true') ?? cards[0])?.focus(),
|
|
81
|
+
update(state) {
|
|
82
|
+
readonly = state.readonly;
|
|
83
|
+
const chosen = new Set(Array.isArray(state.value) ? state.value : [state.value]);
|
|
84
|
+
const stop = multiple ? -1 : Math.max(0, options.findIndex((o) => chosen.has(o.value)));
|
|
85
|
+
const full = !!limit?.full(Array.isArray(state.value) ? state.value.length : 0);
|
|
86
|
+
cards.forEach((card, i) => {
|
|
87
|
+
const on = chosen.has(options[i].value);
|
|
88
|
+
card.setAttribute('aria-checked', String(on));
|
|
89
|
+
card.tabIndex = multiple || i === stop ? 0 : -1;
|
|
90
|
+
card.disabled = readonly || (full && !on && !options[i].exclusive);
|
|
91
|
+
});
|
|
92
|
+
clear?.allow(state);
|
|
93
|
+
clear?.show(options.some((o) => chosen.has(o.value)));
|
|
94
|
+
(0, kind_parts_1.describeState)(group, state);
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
exports.imageChoiceWidget = imageChoiceWidget;
|
|
99
|
+
//# sourceMappingURL=choice-images.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"choice-images.js","sourceRoot":"","sources":["../../../../../libs/widgets/src/lib/choice-images.ts"],"names":[],"mappings":";;;AACA,iDAA4D;AAC5D,6CAA2F;AAC3F,uCAAyC;AAGzC;;;;;;;;;;;;;GAaG;AAEH,8EAA8E;AAC9E,MAAM,KAAK,GAAG,gLAAgL,CAAC;AAExL,MAAM,iBAAiB,GAAkB,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE;IAC5G,MAAM,KAAK,GAAG,IAAA,qBAAQ,EAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACvC,MAAM,IAAI,GAAG,IAAA,kBAAK,EAAC,QAAQ,CAAC,CAAC;IAC7B,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,KAAK,WAAW,IAAI,KAAK,CAAC,QAAQ,KAAK,IAAI,CAAC;IACvE,MAAM,OAAO,GAAa,KAAK,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;IAC1E,MAAM,OAAO,GAAG,IAAA,sBAAY,EAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IACxD,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC;IAChC,MAAM,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
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { layOut, limiter, withAlone } from './choice-rules.mjs';
|
|
2
|
+
import { clearSelection, describeState, maker, rightToLeft, wordsFor } from './kind-parts.mjs';
|
|
3
|
+
import { shownOptions } from './shuffle.mjs';
|
|
4
|
+
/**
|
|
5
|
+
* Pictures to choose from (`selection.image-choice`): each option a card of
|
|
6
|
+
* its `image` over its words. One answer is a radio group with one stop for
|
|
7
|
+
* Tab — the arrows move and pick, going round at the ends, Home and End go to
|
|
8
|
+
* the ends, and left is forward on a right-to-left page — with "Clear
|
|
9
|
+
* selection" when it need not be answered. Several answers, when the field
|
|
10
|
+
* takes several, are checkboxes, each its own stop. "Other" is not offered:
|
|
11
|
+
* an answer of one's own has no picture. `options.shuffle` shows the cards
|
|
12
|
+
* in an order of the form's own. Each picture is described by its option's
|
|
13
|
+
* `alt`. `options.showLabels: false` keeps the words out of sight (still each
|
|
14
|
+
* card's name), `imageSize` is small, medium or large, `imageFit: "whole"`
|
|
15
|
+
* shows the whole picture rather than filling the card, and `columns` lays
|
|
16
|
+
* the cards in columns or in a row.
|
|
17
|
+
*/
|
|
18
|
+
/** A frame with a hill and a sun: the tile of an option without a picture. */
|
|
19
|
+
const BLANK = '<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><rect x="3" y="4" width="18" height="16" rx="2"/><circle cx="9" cy="10" r="2"/><path d="M21 16l-5-5-9 9"/></svg>';
|
|
20
|
+
export const imageChoiceWidget = ({ form, name, field, node, id, document, labels, locale }) => {
|
|
21
|
+
const words = wordsFor(labels, locale);
|
|
22
|
+
const make = maker(document);
|
|
23
|
+
const multiple = field.type === 'selection' && field.multiple === true;
|
|
24
|
+
const written = field.type === 'selection' ? field.options : [];
|
|
25
|
+
const options = shownOptions(written, form, name, node);
|
|
26
|
+
const look = node.options ?? {};
|
|
27
|
+
const bare = look['showLabels'] === false;
|
|
28
|
+
const group = make('div', { id, class: `fd-image-choices${bare ? ' fd-image-choices-bare' : ''}`, role: multiple ? 'group' : 'radiogroup', 'data-size': look['imageSize'], 'data-fit': look['imageFit'] });
|
|
29
|
+
layOut(group, node);
|
|
30
|
+
const limit = multiple ? limiter(make, words, node) : null;
|
|
31
|
+
const cards = options.map((option) => {
|
|
32
|
+
const picture = option.image ? make('img', { src: option.image, alt: option.alt ?? '', loading: 'lazy', draggable: 'false' }) : make('span', { class: 'fd-image-card-blank' });
|
|
33
|
+
if (!option.image)
|
|
34
|
+
picture.innerHTML = BLANK; // a constant drawing, never words from the page
|
|
35
|
+
const card = make('button', { type: 'button', class: 'fd-image-card', role: multiple ? 'checkbox' : 'radio', 'aria-checked': 'false', 'aria-label': bare ? option.label : undefined }, make('span', { class: 'fd-image-card-picture' }, picture), make('span', { class: 'fd-image-card-words' }, option.label));
|
|
36
|
+
card.addEventListener('click', () => pick(option));
|
|
37
|
+
group.append(card);
|
|
38
|
+
return card;
|
|
39
|
+
});
|
|
40
|
+
const current = () => form.getState().values[name];
|
|
41
|
+
function pick(option) {
|
|
42
|
+
if (!multiple)
|
|
43
|
+
return form.setValue(name, option.value);
|
|
44
|
+
const now = Array.isArray(current()) ? current() : [];
|
|
45
|
+
const on = new Set(now.includes(option.value) ? now.filter((v) => v !== option.value) : withAlone(written, now, option.value));
|
|
46
|
+
// In the options' own order, as checkboxes keep them, however they are shown.
|
|
47
|
+
form.setValue(name, written.filter((o) => on.has(o.value)).map((o) => o.value));
|
|
48
|
+
}
|
|
49
|
+
let readonly = false;
|
|
50
|
+
if (!multiple) {
|
|
51
|
+
group.addEventListener('keydown', (event) => {
|
|
52
|
+
if (readonly)
|
|
53
|
+
return;
|
|
54
|
+
const at = cards.indexOf(event.target);
|
|
55
|
+
if (at === -1)
|
|
56
|
+
return;
|
|
57
|
+
const back = rightToLeft(group);
|
|
58
|
+
const steps = { ArrowDown: 1, ArrowUp: -1, ArrowRight: back ? -1 : 1, ArrowLeft: back ? 1 : -1 };
|
|
59
|
+
const to = event.key === 'Home' ? 0 : event.key === 'End' ? cards.length - 1 : event.key in steps ? (at + steps[event.key] + cards.length) % cards.length : -1;
|
|
60
|
+
if (to === -1)
|
|
61
|
+
return;
|
|
62
|
+
event.preventDefault();
|
|
63
|
+
pick(options[to]);
|
|
64
|
+
cards[to].focus();
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
const clear = multiple
|
|
68
|
+
? null
|
|
69
|
+
: clearSelection(document, words, () => {
|
|
70
|
+
form.setValue(name, null);
|
|
71
|
+
cards[0]?.focus();
|
|
72
|
+
});
|
|
73
|
+
if (limit?.element)
|
|
74
|
+
group.append(limit.element);
|
|
75
|
+
return {
|
|
76
|
+
element: clear ? make('div', { class: 'fd-choices-box' }, group, clear.button) : group,
|
|
77
|
+
focus: () => (cards.find((c) => c.getAttribute('aria-checked') === 'true') ?? cards[0])?.focus(),
|
|
78
|
+
update(state) {
|
|
79
|
+
readonly = state.readonly;
|
|
80
|
+
const chosen = new Set(Array.isArray(state.value) ? state.value : [state.value]);
|
|
81
|
+
const stop = multiple ? -1 : Math.max(0, options.findIndex((o) => chosen.has(o.value)));
|
|
82
|
+
const full = !!limit?.full(Array.isArray(state.value) ? state.value.length : 0);
|
|
83
|
+
cards.forEach((card, i) => {
|
|
84
|
+
const on = chosen.has(options[i].value);
|
|
85
|
+
card.setAttribute('aria-checked', String(on));
|
|
86
|
+
card.tabIndex = multiple || i === stop ? 0 : -1;
|
|
87
|
+
card.disabled = readonly || (full && !on && !options[i].exclusive);
|
|
88
|
+
});
|
|
89
|
+
clear?.allow(state);
|
|
90
|
+
clear?.show(options.some((o) => chosen.has(o.value)));
|
|
91
|
+
describeState(group, state);
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
//# sourceMappingURL=choice-images.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"choice-images.mjs","sourceRoot":"","sources":["../../../../../libs/widgets/src/lib/choice-images.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,OAA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C,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAChF,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE;gBACxB,MAAM,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;gBACxC,IAAI,CAAC,YAAY,CAAC,cAAc,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;gBAC9C,IAAI,CAAC,QAAQ,GAAG,QAAQ,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBAChD,IAAI,CAAC,QAAQ,GAAG,QAAQ,IAAI,CAAC,IAAI,IAAI,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;YACrE,CAAC,CAAC,CAAC;YACH,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;YACpB,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACtD,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAC9B,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { FieldNode, Option } from '@fieldia/core';
|
|
2
|
+
import { type Make } from './kind-parts.mjs';
|
|
3
|
+
import type { WidgetLabels } from './labels.mjs';
|
|
4
|
+
/**
|
|
5
|
+
* What the choice kinds share beyond their looks: an option that goes alone
|
|
6
|
+
* ("None of these"), a limit on how many are ticked, and the options laid
|
|
7
|
+
* out in columns or in a row.
|
|
8
|
+
*/
|
|
9
|
+
/** The values once `value` is added: alone when it goes alone, else without those that do. */
|
|
10
|
+
export declare function withAlone(options: readonly Option[], now: readonly unknown[], value: unknown): unknown[];
|
|
11
|
+
/**
|
|
12
|
+
* The most a question takes, from an answer rule that always holds and stops
|
|
13
|
+
* the form: once that many are ticked the rest are turned off, and a polite
|
|
14
|
+
* "Up to 3" says why — as Form.io does, rather than complaining after.
|
|
15
|
+
*/
|
|
16
|
+
export declare function limiter(make: Make, words: WidgetLabels, node: FieldNode): {
|
|
17
|
+
element: HTMLSpanElement | null;
|
|
18
|
+
/** Whether `count` fills it, saying so when it does. */
|
|
19
|
+
full(count: number): boolean;
|
|
20
|
+
};
|
|
21
|
+
/** Columns (`options.columns`, 1 to 4) or all in a row (`"row"`); a phone stacks them again. */
|
|
22
|
+
export declare function layOut(group: HTMLElement, node: FieldNode): void;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { FieldNode, Option } from '@fieldia/core';
|
|
2
|
+
import { type Make } from './kind-parts';
|
|
3
|
+
import type { WidgetLabels } from './labels';
|
|
4
|
+
/**
|
|
5
|
+
* What the choice kinds share beyond their looks: an option that goes alone
|
|
6
|
+
* ("None of these"), a limit on how many are ticked, and the options laid
|
|
7
|
+
* out in columns or in a row.
|
|
8
|
+
*/
|
|
9
|
+
/** The values once `value` is added: alone when it goes alone, else without those that do. */
|
|
10
|
+
export declare function withAlone(options: readonly Option[], now: readonly unknown[], value: unknown): unknown[];
|
|
11
|
+
/**
|
|
12
|
+
* The most a question takes, from an answer rule that always holds and stops
|
|
13
|
+
* the form: once that many are ticked the rest are turned off, and a polite
|
|
14
|
+
* "Up to 3" says why — as Form.io does, rather than complaining after.
|
|
15
|
+
*/
|
|
16
|
+
export declare function limiter(make: Make, words: WidgetLabels, node: FieldNode): {
|
|
17
|
+
element: HTMLSpanElement | null;
|
|
18
|
+
/** Whether `count` fills it, saying so when it does. */
|
|
19
|
+
full(count: number): boolean;
|
|
20
|
+
};
|
|
21
|
+
/** Columns (`options.columns`, 1 to 4) or all in a row (`"row"`); a phone stacks them again. */
|
|
22
|
+
export declare function layOut(group: HTMLElement, node: FieldNode): void;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withAlone = withAlone;
|
|
4
|
+
exports.limiter = limiter;
|
|
5
|
+
exports.layOut = layOut;
|
|
6
|
+
const kind_parts_1 = require("./kind-parts");
|
|
7
|
+
/**
|
|
8
|
+
* What the choice kinds share beyond their looks: an option that goes alone
|
|
9
|
+
* ("None of these"), a limit on how many are ticked, and the options laid
|
|
10
|
+
* out in columns or in a row.
|
|
11
|
+
*/
|
|
12
|
+
/** The values once `value` is added: alone when it goes alone, else without those that do. */
|
|
13
|
+
function withAlone(options, now, value) {
|
|
14
|
+
const alone = (v) => options.some((o) => o.exclusive && o.value === v);
|
|
15
|
+
return alone(value) ? [value] : [...now.filter((v) => !alone(v)), value];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The most a question takes, from an answer rule that always holds and stops
|
|
19
|
+
* the form: once that many are ticked the rest are turned off, and a polite
|
|
20
|
+
* "Up to 3" says why — as Form.io does, rather than complaining after.
|
|
21
|
+
*/
|
|
22
|
+
function limiter(make, words, node) {
|
|
23
|
+
const most = node.validate?.find((r) => r.atMost !== undefined && (r.when ?? true) === true && r.level !== 'warning')?.atMost;
|
|
24
|
+
const element = most ? make('span', { class: 'fd-choice-limit', role: 'status' }) : null;
|
|
25
|
+
return {
|
|
26
|
+
element,
|
|
27
|
+
/** Whether `count` fills it, saying so when it does. */
|
|
28
|
+
full(count) {
|
|
29
|
+
const full = !!most && count >= most;
|
|
30
|
+
if (element)
|
|
31
|
+
(0, kind_parts_1.setText)(element, full ? (0, kind_parts_1.fillIn)(words.upTo, { n: most }) : '');
|
|
32
|
+
return full;
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/** Columns (`options.columns`, 1 to 4) or all in a row (`"row"`); a phone stacks them again. */
|
|
37
|
+
function layOut(group, node) {
|
|
38
|
+
const columns = node.options?.['columns'];
|
|
39
|
+
if (columns === 'row')
|
|
40
|
+
group.classList.add('fd-choices-row');
|
|
41
|
+
else if (typeof columns === 'number' && columns >= 1) {
|
|
42
|
+
group.classList.add('fd-choices-columns');
|
|
43
|
+
group.style.setProperty('--fd-choice-columns', String(Math.min(4, Math.round(columns))));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=choice-rules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"choice-rules.js","sourceRoot":"","sources":["../../../../../libs/widgets/src/lib/choice-rules.ts"],"names":[],"mappings":";;AAWA,8BAGC;AAOD,0BAYC;AAGD,wBAOC;AA1CD,6CAA0D;AAG1D;;;;GAIG;AAEH,8FAA8F;AAC9F,SAAgB,SAAS,CAAC,OAA0B,EAAE,GAAuB,EAAE,KAAc;IAC3F,MAAM,KAAK,GAAG,CAAC,CAAU,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC;IAChF,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AAC3E,CAAC;AAED;;;;GAIG;AACH,SAAgB,OAAO,CAAC,IAAU,EAAE,KAAmB,EAAE,IAAe;IACtE,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,SAAS,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,KAAK,KAAK,SAAS,CAAC,EAAE,MAA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es alone
|
|
4
|
+
* ("None of these"), a limit on how many are ticked, and the options laid
|
|
5
|
+
* out in columns or in a row.
|
|
6
|
+
*/
|
|
7
|
+
/** The values once `value` is added: alone when it goes alone, else without those that do. */
|
|
8
|
+
export function withAlone(options, now, value) {
|
|
9
|
+
const alone = (v) => options.some((o) => o.exclusive && o.value === v);
|
|
10
|
+
return alone(value) ? [value] : [...now.filter((v) => !alone(v)), value];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* The most a question takes, from an answer rule that always holds and stops
|
|
14
|
+
* the form: once that many are ticked the rest are turned off, and a polite
|
|
15
|
+
* "Up to 3" says why — as Form.io does, rather than complaining after.
|
|
16
|
+
*/
|
|
17
|
+
export function limiter(make, words, node) {
|
|
18
|
+
const most = node.validate?.find((r) => r.atMost !== undefined && (r.when ?? true) === true && r.level !== 'warning')?.atMost;
|
|
19
|
+
const element = most ? make('span', { class: 'fd-choice-limit', role: 'status' }) : null;
|
|
20
|
+
return {
|
|
21
|
+
element,
|
|
22
|
+
/** Whether `count` fills it, saying so when it does. */
|
|
23
|
+
full(count) {
|
|
24
|
+
const full = !!most && count >= most;
|
|
25
|
+
if (element)
|
|
26
|
+
setText(element, full ? fillIn(words.upTo, { n: most }) : '');
|
|
27
|
+
return full;
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** Columns (`options.columns`, 1 to 4) or all in a row (`"row"`); a phone stacks them again. */
|
|
32
|
+
export function layOut(group, node) {
|
|
33
|
+
const columns = node.options?.['columns'];
|
|
34
|
+
if (columns === 'row')
|
|
35
|
+
group.classList.add('fd-choices-row');
|
|
36
|
+
else if (typeof columns === 'number' && columns >= 1) {
|
|
37
|
+
group.classList.add('fd-choices-columns');
|
|
38
|
+
group.style.setProperty('--fd-choice-columns', String(Math.min(4, Math.round(columns))));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=choice-rules.mjs.map
|
|
@@ -0,0 +1 @@
|
|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AC,IAAI,IAAI,KAAK,IAAI,IAAI,CAAC;YACrC,IAAI,OAAO;gBAAE,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,IAAc,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YACrF,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC;AAED,gGAAgG;AAChG,MAAM,UAAU,MAAM,CAAC,KAAkB,EAAE,IAAe;IACxD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC,SAAS,CAAC,CAAC;IAC1C,IAAI,OAAO,KAAK,KAAK;QAAE,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;SACxD,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,IAAI,CAAC,EAAE,CAAC;QACrD,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;QAC1C,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,qBAAqB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3F,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { WidgetFactory } from './widgets.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Several answers from a list, as tags in a box (`selection.tags`): the box
|
|
4
|
+
* is an ARIA combobox whose list holds the options not chosen yet, those whose
|
|
5
|
+
* words hold what is typed. The arrows reach one and Enter adds it — or the
|
|
6
|
+
* first match, when none is reached — as does a click. A tag goes with its ×,
|
|
7
|
+
* or the last with Backspace in the empty box. The answer keeps the order the
|
|
8
|
+
* tags were added in; a value not among the options shows as its own words.
|
|
9
|
+
* With `ownAnswers`, words that match nothing are offered as an answer of
|
|
10
|
+
* their own; "None of these" goes alone.
|
|
11
|
+
*
|
|
12
|
+
* One answer, the same box (`searchWidget`): a dropdown that searches its
|
|
13
|
+
* list — the box shows the choice, typing finds others, and a box left half
|
|
14
|
+
* typed shows the choice again; emptied, it takes the choice away.
|
|
15
|
+
*/
|
|
16
|
+
export declare const choiceTagsWidget: WidgetFactory;
|
|
17
|
+
export declare const searchWidget: WidgetFactory;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { WidgetFactory } from './widgets';
|
|
2
|
+
/**
|
|
3
|
+
* Several answers from a list, as tags in a box (`selection.tags`): the box
|
|
4
|
+
* is an ARIA combobox whose list holds the options not chosen yet, those whose
|
|
5
|
+
* words hold what is typed. The arrows reach one and Enter adds it — or the
|
|
6
|
+
* first match, when none is reached — as does a click. A tag goes with its ×,
|
|
7
|
+
* or the last with Backspace in the empty box. The answer keeps the order the
|
|
8
|
+
* tags were added in; a value not among the options shows as its own words.
|
|
9
|
+
* With `ownAnswers`, words that match nothing are offered as an answer of
|
|
10
|
+
* their own; "None of these" goes alone.
|
|
11
|
+
*
|
|
12
|
+
* One answer, the same box (`searchWidget`): a dropdown that searches its
|
|
13
|
+
* list — the box shows the choice, typing finds others, and a box left half
|
|
14
|
+
* typed shows the choice again; emptied, it takes the choice away.
|
|
15
|
+
*/
|
|
16
|
+
export declare const choiceTagsWidget: WidgetFactory;
|
|
17
|
+
export declare const searchWidget: WidgetFactory;
|