contour-ds 1.8.1 → 1.9.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 +227 -378
- package/dist/agent-cookbook.json +960 -0
- package/dist/agent-examples.json +65 -0
- package/dist/agent-map-wiring.json +152 -0
- package/dist/build-manifest.json +320 -179
- package/dist/contour-wc-content.esm.js +479 -3665
- package/dist/contour-wc-content.esm.min.js +1 -1
- package/dist/contour-wc-core.esm.js +3724 -0
- package/dist/contour-wc-core.esm.min.js +1 -0
- package/dist/contour-wc-dashboard.esm.js +2713 -4381
- package/dist/contour-wc-dashboard.esm.min.js +1 -1
- package/dist/contour-wc-data.esm.js +2658 -4346
- package/dist/contour-wc-data.esm.min.js +1 -1
- package/dist/contour-wc-docs.esm.js +218 -3547
- package/dist/contour-wc-docs.esm.min.js +1 -1
- package/dist/contour-wc-feedback.esm.js +483 -3658
- package/dist/contour-wc-feedback.esm.min.js +1 -1
- package/dist/contour-wc-forms.esm.js +503 -3754
- package/dist/contour-wc-forms.esm.min.js +1 -1
- package/dist/contour-wc-interaction.esm.js +379 -3616
- package/dist/contour-wc-interaction.esm.min.js +1 -1
- package/dist/contour-wc-layout.esm.js +234 -3563
- package/dist/contour-wc-layout.esm.min.js +1 -1
- package/dist/contour-wc-map.esm.js +949 -3743
- package/dist/contour-wc-map.esm.min.js +1 -1
- package/dist/contour-wc-misc.esm.js +237 -3556
- package/dist/contour-wc-misc.esm.min.js +1 -1
- package/dist/contour-wc-navigation.esm.js +2235 -5237
- package/dist/contour-wc-navigation.esm.min.js +1 -1
- package/dist/contour-wc-ui.esm.js +4638 -7128
- package/dist/contour-wc-ui.esm.min.js +1 -1
- package/dist/contour-wc.esm.js +11971 -7727
- package/dist/contour-wc.esm.min.js +1 -1
- package/dist/contour-wc.js +11971 -7727
- package/dist/contour-wc.min.js +1 -1
- package/dist/contour.a11y.json +402 -0
- package/dist/contour.code-snippets +96 -74
- package/dist/contour.components.json +2591 -741
- package/dist/contour.css +2624 -1888
- package/dist/contour.d.ts +421 -228
- package/dist/contour.esm.js +433 -18
- package/dist/contour.esm.min.js +1 -1
- package/dist/contour.html-data.json +1231 -199
- package/dist/contour.js +433 -18
- package/dist/contour.min.css +1 -1
- package/dist/contour.min.js +1 -1
- package/dist/contour.react.d.ts +100 -98
- package/dist/contour.single.html +2 -2
- package/dist/contour.single.min.css +1 -1
- package/dist/contour.themes.json +56 -12
- package/dist/contour.tokens.json +482 -255
- package/dist/contour.vue.d.ts +100 -98
- package/dist/contour.web-types.json +1226 -226
- package/dist/custom-elements.json +7649 -2237
- package/dist/docs/actions.md +15 -6
- package/dist/docs/affordances.md +18 -96
- package/dist/docs/apireference.md +9 -5
- package/dist/docs/colour.md +10 -4
- package/dist/docs/componentindex.md +9 -26
- package/dist/docs/data.md +36 -60
- package/dist/docs/docs.md +10 -12
- package/dist/docs/feedback.md +30 -12
- package/dist/docs/field.md +28 -13
- package/dist/docs/forms.md +35 -19
- package/dist/docs/index.json +63 -56
- package/dist/docs/install.md +12 -7
- package/dist/docs/landing.md +7 -4
- package/dist/docs/mapengine.md +18 -13
- package/dist/docs/motion.md +12 -6
- package/dist/docs/navigation.md +31 -7
- package/dist/docs/overlays.md +32 -25
- package/dist/docs/overview.md +3 -2
- package/dist/docs/patterns.md +19 -9
- package/dist/docs/playground.md +9 -22
- package/dist/docs/principles.md +8 -6
- package/dist/docs/recipes.md +113 -14
- package/dist/docs/space.md +10 -6
- package/dist/docs/status.md +12 -25
- package/dist/docs/surfaces.md +17 -22
- package/dist/docs/theming.md +18 -32
- package/dist/docs/type.md +12 -5
- package/dist/docs/webcomponents.md +66 -38
- package/dist/hljs.css +1 -20
- package/dist/map-chrome.mapbox.css +68 -92
- package/dist/map-chrome.maplibre.css +68 -92
- package/dist/registry/items/contour-core.json +2 -2
- package/dist/registry/items/contour-data.json +2 -2
- package/dist/registry/items/contour-docs.json +2 -2
- package/dist/registry/items/contour-landing.json +2 -2
- package/dist/registry/registry.json +8 -8
- package/dist/surfaces/contour-core.min.css +1 -1
- package/dist/surfaces/contour-data.min.css +1 -1
- package/dist/surfaces/contour-docs.min.css +1 -1
- package/dist/surfaces/contour-landing.min.css +1 -1
- package/dist/svg/icons.svg +367 -0
- package/dist/wc/behaviours.mjs +190 -148
- package/dist/wc/content.mjs +273 -129
- package/dist/wc/core.mjs +598 -395
- package/dist/wc/dashboard.mjs +64 -44
- package/dist/wc/data-chart.mjs +1333 -0
- package/dist/wc/data-export.mjs +391 -0
- package/dist/wc/data-gauge.mjs +779 -0
- package/dist/wc/data-geo.mjs +696 -0
- package/dist/wc/data-glyphs.mjs +133 -0
- package/dist/wc/data-legend.mjs +431 -0
- package/dist/wc/data-readout.mjs +227 -0
- package/dist/wc/data-series.mjs +1004 -0
- package/dist/wc/data-table.mjs +751 -0
- package/dist/wc/data.mjs +15 -4322
- package/dist/wc/docs.mjs +12 -11
- package/dist/wc/feedback.mjs +277 -122
- package/dist/wc/forms-controls.mjs +635 -0
- package/dist/wc/forms-field.mjs +547 -0
- package/dist/wc/forms-groups.mjs +347 -0
- package/dist/wc/forms-input.mjs +292 -0
- package/dist/wc/forms.mjs +10 -1751
- package/dist/wc/glyph.mjs +204 -0
- package/dist/wc/index.mjs +11 -9
- package/dist/wc/interaction.mjs +173 -80
- package/dist/wc/layout.mjs +28 -27
- package/dist/wc/map.mjs +743 -207
- package/dist/wc/misc.mjs +31 -20
- package/dist/wc/navigation-menu.mjs +735 -0
- package/dist/wc/navigation-shell.mjs +495 -0
- package/dist/wc/navigation-tree.mjs +995 -0
- package/dist/wc/navigation.mjs +9 -1905
- package/dist/wc/registration.mjs +1 -8
- package/dist/wc/shadow.mjs +206 -110
- package/dist/wc/states.mjs +54 -75
- package/dist/wc/svg.mjs +118 -47
- package/dist/wc/ui-atoms.mjs +608 -0
- package/dist/wc/ui-data.mjs +1404 -0
- package/dist/wc/ui-feedback.mjs +419 -0
- package/dist/wc/ui-inputs.mjs +1570 -0
- package/dist/wc/ui-menus.mjs +307 -0
- package/dist/wc/ui-overlays.mjs +1605 -0
- package/integrations/README.md +23 -5
- package/integrations/ai/CLAUDE.md +3 -0
- package/integrations/ai/COPILOT.md +14 -0
- package/integrations/ai/GEMINI.md +14 -0
- package/integrations/ai/WINDSURF.md +14 -0
- package/integrations/ai/v0-prompt.md +13 -1
- package/integrations/native/README.md +0 -3
- package/integrations/tailwind/contour-theme.css +66 -7
- package/integrations/validate-markup.mjs +172 -0
- package/package.json +77 -42
- package/dist/wc/ui.mjs +0 -5072
package/dist/wc/forms.mjs
CHANGED
|
@@ -1,1752 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import { ContourBase, define, contourId, cssLength , warnBadJson, labelText, applyLabel } from './core.mjs';
|
|
15
|
-
import { wireCombobox } from './behaviours.mjs';
|
|
16
|
-
import { loadRemote, remoteData, renderStates, renderEmpty, wireStates } from './states.mjs';
|
|
17
|
-
/**
|
|
18
|
-
* Combobox: a filterable, keyboard-navigable listbox backed by a JSON `options`
|
|
19
|
-
* attribute or authored `<li>` options. Supports single and multi-select
|
|
20
|
-
* (`multiple`), fixed-row virtualization (`virtual`), async/remote options
|
|
21
|
-
* (`src`, `loading`, `error`, `retry`, `empty`, `skeleton`), a clear button and
|
|
22
|
-
* form association. Emits `contour:select` on commit and `contour:input` on
|
|
23
|
-
* filter. ArrowUp/Down/Home/End rove the cursor; Enter commits; Escape closes.
|
|
24
|
-
*/
|
|
25
|
-
class ContourCombobox extends ContourBase {
|
|
26
|
-
static get observed() { return ["options", "placeholder", "label", "value", "multiple", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "empty", "skeleton", "virtual", "disabled", "required", "name"]; }
|
|
27
|
-
static get formAssociated() { return true; }
|
|
28
|
-
static get properties() { return { options: { attribute: "options" }, placeholder: { attribute: "placeholder" }, label: { attribute: "label" }, value: { attribute: "value" }, multiple: { attribute: "multiple", type: Boolean }, virtual: { attribute: "virtual", type: Boolean }, src: { attribute: "src" }, disabled: { attribute: "disabled", type: Boolean }, required: { attribute: "required", type: Boolean }, name: { attribute: "name" } }; }
|
|
29
|
-
render() {
|
|
30
|
-
this.classList.add("c-combobox");
|
|
31
|
-
// The authored default, captured before any commit reflects into the
|
|
32
|
-
// attribute: form reset restores THIS, not the last committed value.
|
|
33
|
-
if (this._comboboxDefault === undefined) this._comboboxDefault = this.getAttribute("value");
|
|
34
|
-
wireStates(this);
|
|
35
|
-
loadRemote(this, "options");
|
|
36
|
-
if (renderStates(this, "combobox")) return;
|
|
37
|
-
const options = remoteData(this, "options");
|
|
38
|
-
// Slot composition: authored <li> options win over the JSON attribute.
|
|
39
|
-
const authored = Array.from(this.children).filter((n) => !n.classList || (!n.classList.contains("c-combobox__input") && !n.classList.contains("c-combobox__list")));
|
|
40
|
-
if ((options) && !authored.length) {
|
|
41
|
-
try {
|
|
42
|
-
const parsed = options ? JSON.parse(options) : [];
|
|
43
|
-
this._comboboxOptions = parsed;
|
|
44
|
-
const input = this.ensure(".c-combobox__input", () => { const el = document.createElement("input"); el.className = "c-combobox__input"; el.type = "text"; return el; });
|
|
45
|
-
input.type = "text";
|
|
46
|
-
input.placeholder = this.getAttribute("placeholder") || "Search…";
|
|
47
|
-
input.setAttribute("aria-label", this.getAttribute("label") || "Search");
|
|
48
|
-
// Reflect the native constraint state so the platform validates the
|
|
49
|
-
// field and FormData sees the name.
|
|
50
|
-
if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
|
|
51
|
-
else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
|
|
52
|
-
if (this.hasAttribute("required")) { input.setAttribute("required", ""); input.setAttribute("aria-required", "true"); }
|
|
53
|
-
else { input.removeAttribute("required"); input.removeAttribute("aria-required"); }
|
|
54
|
-
if (this.hasAttribute("name")) input.setAttribute("name", this.getAttribute("name"));
|
|
55
|
-
const val = this.getAttribute("value");
|
|
56
|
-
if (val !== null) {
|
|
57
|
-
// The attribute holds the submitted value; the field shows the
|
|
58
|
-
// matching option's label so the two can differ (value "us" -> "United States").
|
|
59
|
-
const match = parsed.find((o) => String(typeof o === "string" ? o : o.value) === String(val));
|
|
60
|
-
input.value = match ? String(typeof match === "string" ? match : match.label) : val;
|
|
61
|
-
}
|
|
62
|
-
const list = this.ensure(".c-combobox__list", () => { const el = document.createElement("ul"); el.className = "c-combobox__list"; el.setAttribute("hidden", ""); return el; });
|
|
63
|
-
list.innerHTML = "";
|
|
64
|
-
list.setAttribute("hidden", "");
|
|
65
|
-
this._comboboxVirtual = this.hasAttribute("virtual") && parsed.length > 100;
|
|
66
|
-
if (this._comboboxVirtual) {
|
|
67
|
-
list.classList.add("c-combobox__list--virtual");
|
|
68
|
-
list.style.maxBlockSize = "20rem";
|
|
69
|
-
list.style.overflow = "auto";
|
|
70
|
-
this._renderComboboxWindow("", true);
|
|
71
|
-
} else {
|
|
72
|
-
list.classList.remove("c-combobox__list--virtual");
|
|
73
|
-
list.style.maxBlockSize = "";
|
|
74
|
-
list.style.overflow = "";
|
|
75
|
-
this._renderComboboxWindow("", true);
|
|
76
|
-
}
|
|
77
|
-
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
78
|
-
} else if (!authored.length && !options) {
|
|
79
|
-
renderEmpty(this, "combobox");
|
|
80
|
-
}
|
|
81
|
-
// Clear button (F-11).
|
|
82
|
-
if (this.getAttribute("value")) {
|
|
83
|
-
this.ensure(".c-combobox__clear", () => {
|
|
84
|
-
const btn = document.createElement("button");
|
|
85
|
-
btn.className = "c-combobox__clear";
|
|
86
|
-
btn.type = "button";
|
|
87
|
-
btn.setAttribute("aria-label", "Clear");
|
|
88
|
-
btn.textContent = "×";
|
|
89
|
-
return btn;
|
|
90
|
-
});
|
|
91
|
-
} else {
|
|
92
|
-
const btn = this.querySelector(".c-combobox__clear");
|
|
93
|
-
if (btn) btn.remove();
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
_renderComboboxWindow(query = "", reset = false) {
|
|
97
|
-
const list = this.querySelector(".c-combobox__list");
|
|
98
|
-
const options = this._comboboxOptions || [];
|
|
99
|
-
if (!list) return;
|
|
100
|
-
const q = String(query || "").toLowerCase();
|
|
101
|
-
const filtered = options.map((opt, index) => ({
|
|
102
|
-
opt,
|
|
103
|
-
index,
|
|
104
|
-
label: typeof opt === "string" ? opt : opt.label,
|
|
105
|
-
value: typeof opt === "string" ? opt : opt.value,
|
|
106
|
-
})).filter((item) => !q || String(item.label).toLowerCase().includes(q));
|
|
107
|
-
this._comboboxFiltered = filtered;
|
|
108
|
-
const rowHeight = cssLength("--combobox-row-height", 32);
|
|
109
|
-
const windowSize = 20;
|
|
110
|
-
const overscan = 6;
|
|
111
|
-
const oldScrollTop = list.scrollTop;
|
|
112
|
-
const start = this._comboboxVirtual && !reset
|
|
113
|
-
? Math.min(Math.max(0, filtered.length - windowSize), Math.max(0, Math.floor(oldScrollTop / rowHeight) - overscan))
|
|
114
|
-
: 0;
|
|
115
|
-
this._comboboxWindowStart = start;
|
|
116
|
-
const end = this._comboboxVirtual ? Math.min(filtered.length, start + windowSize + overscan * 2) : filtered.length;
|
|
117
|
-
const selectedVals = (this.getAttribute("value") || "").split(",").map((v) => v.trim()).filter(Boolean);
|
|
118
|
-
list.innerHTML = "";
|
|
119
|
-
const addSpacer = (height) => {
|
|
120
|
-
const spacer = document.createElement("li");
|
|
121
|
-
spacer.setAttribute("aria-hidden", "true");
|
|
122
|
-
spacer.style.blockSize = `${height}px`;
|
|
123
|
-
list.appendChild(spacer);
|
|
124
|
-
};
|
|
125
|
-
if (this._comboboxVirtual) addSpacer(start * rowHeight);
|
|
126
|
-
if (!filtered.length) {
|
|
127
|
-
const empty = document.createElement("li");
|
|
128
|
-
empty.className = "c-combobox__empty";
|
|
129
|
-
empty.setAttribute("role", "status");
|
|
130
|
-
empty.textContent = this.getAttribute("empty") || "No matches";
|
|
131
|
-
list.appendChild(empty);
|
|
132
|
-
}
|
|
133
|
-
if (this.hasAttribute("multiple")) list.setAttribute("aria-multiselectable", "true");
|
|
134
|
-
else list.removeAttribute("aria-multiselectable");
|
|
135
|
-
filtered.slice(start, end).forEach((item) => {
|
|
136
|
-
const li = document.createElement("li");
|
|
137
|
-
li.className = "c-combobox__option";
|
|
138
|
-
li.dataset.optionIndex = String(item.index);
|
|
139
|
-
li.dataset.optionValue = String(item.value != null ? item.value : item.label);
|
|
140
|
-
li.setAttribute("role", "option");
|
|
141
|
-
const label = String(item.label);
|
|
142
|
-
const q = String(query || "").toLowerCase();
|
|
143
|
-
if (q && label.toLowerCase().includes(q)) {
|
|
144
|
-
const idx = label.toLowerCase().indexOf(q);
|
|
145
|
-
const before = label.slice(0, idx);
|
|
146
|
-
const match = label.slice(idx, idx + q.length);
|
|
147
|
-
const after = label.slice(idx + q.length);
|
|
148
|
-
li.innerHTML = "";
|
|
149
|
-
if (before) li.appendChild(document.createTextNode(before));
|
|
150
|
-
const mark = document.createElement("mark");
|
|
151
|
-
mark.className = "c-combobox__match";
|
|
152
|
-
mark.textContent = match;
|
|
153
|
-
li.appendChild(mark);
|
|
154
|
-
if (after) li.appendChild(document.createTextNode(after));
|
|
155
|
-
} else {
|
|
156
|
-
li.textContent = label;
|
|
157
|
-
}
|
|
158
|
-
const isSelected = this.hasAttribute("multiple") && selectedVals.includes(String(item.value));
|
|
159
|
-
li.setAttribute("aria-selected", String(isSelected));
|
|
160
|
-
if (isSelected) li.classList.add("c-combobox__option--selected");
|
|
161
|
-
list.appendChild(li);
|
|
162
|
-
});
|
|
163
|
-
if (this._comboboxVirtual) addSpacer(Math.max(0, filtered.length - end) * rowHeight);
|
|
164
|
-
if (this._comboboxVirtual && !reset) list.scrollTop = oldScrollTop;
|
|
165
|
-
}
|
|
166
|
-
_syncFormValue() {
|
|
167
|
-
if (!this._internals) return;
|
|
168
|
-
// The committed value lives on the host attribute, not in the text field
|
|
169
|
-
// (which shows the option label), so the form submits the value.
|
|
170
|
-
const raw = this.getAttribute("value");
|
|
171
|
-
const value = raw != null && raw !== "" ? raw : null;
|
|
172
|
-
this._internals.setFormValue(value);
|
|
173
|
-
this._syncValidity(this.hasAttribute("required") && !value);
|
|
174
|
-
}
|
|
175
|
-
enhance() {
|
|
176
|
-
wireCombobox(this);
|
|
177
|
-
// Form sync (D-02): commit writes the input value; mirror it into the
|
|
178
|
-
// form association so the host actually submits.
|
|
179
|
-
if (this._internals && !this._wiredComboboxForm) {
|
|
180
|
-
this._wiredComboboxForm = true;
|
|
181
|
-
this._syncFormValue();
|
|
182
|
-
this.addEventListener("contour:select", (e) => {
|
|
183
|
-
const v = e && e.detail && (e.detail.value || e.detail.label);
|
|
184
|
-
if (v != null) this.setAttribute("value", String(v));
|
|
185
|
-
this._syncFormValue();
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
if (!this._wiredComboboxClear) {
|
|
189
|
-
this._wiredComboboxClear = true;
|
|
190
|
-
this.addEventListener("click", (e) => {
|
|
191
|
-
const btn = e.target && e.target.closest ? e.target.closest(".c-combobox__clear") : null;
|
|
192
|
-
if (!btn || !this.contains(btn)) return;
|
|
193
|
-
e.preventDefault();
|
|
194
|
-
this.removeAttribute("value");
|
|
195
|
-
const input = this.querySelector(".c-combobox__input");
|
|
196
|
-
if (input) input.value = "";
|
|
197
|
-
this._syncFormValue();
|
|
198
|
-
this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { name: this.getAttribute("name"), value: null, checked: null } }));
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
formResetCallback() {
|
|
203
|
-
// Restore the authored default and let render map it back to the
|
|
204
|
-
// option's LABEL — the generic base reset wrote the raw value into the
|
|
205
|
-
// text field, which shows labels, not values.
|
|
206
|
-
this._contourResetting = true;
|
|
207
|
-
try {
|
|
208
|
-
const def = this._comboboxDefault ?? null;
|
|
209
|
-
if (def === null) this.removeAttribute("value");
|
|
210
|
-
else this.setAttribute("value", def);
|
|
211
|
-
this._syncFormValue();
|
|
212
|
-
} finally {
|
|
213
|
-
this._contourResetting = false;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
define("contour-combobox", ContourCombobox);
|
|
218
|
-
/**
|
|
219
|
-
* Field: a labelled form control wrapper. Renders an `<input>`/`<textarea>`/
|
|
220
|
-
* `<select>` (or adopts an authored one), associates a label via `for`/`id`,
|
|
221
|
-
* and attaches hint and error text with `aria-describedby`. Drives inline
|
|
222
|
-
* validation on blur (`aria-invalid`, `is-invalid`) and keeps the form value in
|
|
223
|
-
* sync via `_internals.setFormValue`. Emits `contour:input` / `contour:change`.
|
|
224
|
-
*/
|
|
225
|
-
class ContourField extends ContourBase {
|
|
226
|
-
static get observed() { return ["label", "hint", "error", "placeholder", "type", "required", "name", "value", "disabled", "custom-error"]; }
|
|
227
|
-
static get formAssociated() { return true; }
|
|
228
|
-
static get properties() { return { label: { attribute: "label" }, hint: { attribute: "hint" }, error: { attribute: "error" }, placeholder: { attribute: "placeholder" }, type: { attribute: "type" }, required: { attribute: "required", type: Boolean }, name: { attribute: "name" }, value: { attribute: "value" }, disabled: { attribute: "disabled", type: Boolean }, customError: { attribute: "custom-error" } }; }
|
|
229
|
-
render() {
|
|
230
|
-
this.classList.add("c-field");
|
|
231
|
-
const label = this.getAttribute("label");
|
|
232
|
-
const hint = this.getAttribute("hint");
|
|
233
|
-
const error = this.getAttribute("error");
|
|
234
|
-
const placeholder = this.getAttribute("placeholder") || "";
|
|
235
|
-
if (label) {
|
|
236
|
-
const lbl = this.ensure(".c-field__label", () => { const el = document.createElement("label"); el.className = "c-field__label"; return el; });
|
|
237
|
-
lbl.textContent = label;
|
|
238
|
-
} else {
|
|
239
|
-
const lbl = this.querySelector(".c-field__label");
|
|
240
|
-
if (lbl) lbl.remove();
|
|
241
|
-
}
|
|
242
|
-
const input = this.ensure("input.c-input, textarea, select", () => {
|
|
243
|
-
const el = document.createElement("input");
|
|
244
|
-
el.className = "c-input";
|
|
245
|
-
return el;
|
|
246
|
-
});
|
|
247
|
-
input.type = this.getAttribute("type") || "text";
|
|
248
|
-
input.placeholder = placeholder;
|
|
249
|
-
// Stable across renders: a fresh id per render breaks the base class's
|
|
250
|
-
// keyed value/focus matching for a field with no `name` (R20 T-02).
|
|
251
|
-
if (!input.id) input.id = this._fieldInputId || (this._fieldInputId = contourId("contour-field"));
|
|
252
|
-
// Associate the label with the input so the control is labelled.
|
|
253
|
-
const lbl = this.querySelector(".c-field__label");
|
|
254
|
-
if (lbl) { if (!input.id) input.id = contourId("contour-field"); lbl.setAttribute("for", input.id); input.setAttribute("aria-label", lbl.textContent); }
|
|
255
|
-
else if (!input.hasAttribute("aria-label")) input.setAttribute("aria-label", "Field");
|
|
256
|
-
if (hint) {
|
|
257
|
-
const h = this.ensure(".c-field__hint", () => { const el = document.createElement("span"); el.className = "c-field__hint"; return el; });
|
|
258
|
-
h.textContent = hint;
|
|
259
|
-
} else {
|
|
260
|
-
const h = this.querySelector(".c-field__hint");
|
|
261
|
-
if (h) h.remove();
|
|
262
|
-
}
|
|
263
|
-
if (error) {
|
|
264
|
-
const e = this.ensure(".c-field__error", () => { const el = document.createElement("span"); el.className = "c-field__error"; return el; });
|
|
265
|
-
e.textContent = error;
|
|
266
|
-
} else {
|
|
267
|
-
const e = this.querySelector(".c-field__error");
|
|
268
|
-
if (e) e.remove();
|
|
269
|
-
}
|
|
270
|
-
// R22 WC4-26: custom-error attribute — declarative setCustomValidity().
|
|
271
|
-
// When set, the input's validation message is overridden and the field
|
|
272
|
-
// is marked invalid, matching the platform's customError semantics.
|
|
273
|
-
const customError = this.getAttribute("custom-error");
|
|
274
|
-
if (customError !== null) {
|
|
275
|
-
input.setAttribute("aria-invalid", "true");
|
|
276
|
-
this.classList.add("is-invalid");
|
|
277
|
-
this.setAttribute("data-invalid", "");
|
|
278
|
-
let errEl = this.querySelector(".c-field__error");
|
|
279
|
-
if (!errEl) {
|
|
280
|
-
errEl = document.createElement("span");
|
|
281
|
-
errEl.className = "c-field__error";
|
|
282
|
-
this.appendChild(errEl);
|
|
283
|
-
}
|
|
284
|
-
errEl.textContent = customError;
|
|
285
|
-
if (!errEl.id) errEl.id = contourId("err");
|
|
286
|
-
input.setAttribute("aria-describedby", (input.getAttribute("aria-describedby") || "").split(" ").filter((x) => x && x !== errEl.id).concat(errEl.id).join(" "));
|
|
287
|
-
}
|
|
288
|
-
// ARIA: link the input to its hint and its error message (parity with the
|
|
289
|
-
// shadow layer's bootstrap). The ids are generated so a screen reader does
|
|
290
|
-
// not hear one message without the other.
|
|
291
|
-
const hintEl = this.querySelector(".c-field__hint");
|
|
292
|
-
const errEl = this.querySelector(".c-field__error");
|
|
293
|
-
const describedBy = [];
|
|
294
|
-
if (hintEl) { if (!hintEl.id) hintEl.id = contourId("hint"); describedBy.push(hintEl.id); }
|
|
295
|
-
if (errEl) { if (!errEl.id) errEl.id = contourId("err"); describedBy.push(errEl.id); }
|
|
296
|
-
if (describedBy.length) input.setAttribute("aria-describedby", describedBy.join(" "));
|
|
297
|
-
// Reflect the native constraint state, not only ARIA: `checkValidity()`
|
|
298
|
-
// and the form's own validation must see `required`, and FormData must
|
|
299
|
-
// see `name`/`value`. ARIA alone never blocks submit.
|
|
300
|
-
if (this.hasAttribute("required")) { input.setAttribute("aria-required", "true"); input.setAttribute("required", ""); }
|
|
301
|
-
else { input.removeAttribute("aria-required"); input.removeAttribute("required"); }
|
|
302
|
-
if (this.hasAttribute("name")) input.setAttribute("name", this.getAttribute("name"));
|
|
303
|
-
if (this.hasAttribute("value")) input.value = this.getAttribute("value");
|
|
304
|
-
if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
|
|
305
|
-
else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
ContourField.prototype.enhance = function() {
|
|
309
|
-
if (this._wiredField) return;
|
|
310
|
-
this._wiredField = true;
|
|
311
|
-
const sync = () => {
|
|
312
|
-
const input = this.querySelector("input, textarea, select");
|
|
313
|
-
if (!input || !this._internals) return;
|
|
314
|
-
this._internals.setFormValue(input.value);
|
|
315
|
-
};
|
|
316
|
-
this.addEventListener("input", (e) => {
|
|
317
|
-
const input = this.querySelector("input, textarea, select");
|
|
318
|
-
if (!input || e.target !== input) return;
|
|
319
|
-
sync();
|
|
320
|
-
this._emitForm("contour:input");
|
|
321
|
-
});
|
|
322
|
-
this.addEventListener("change", (e) => {
|
|
323
|
-
const input = this.querySelector("input, textarea, select");
|
|
324
|
-
if (!input || e.target !== input) return;
|
|
325
|
-
sync();
|
|
326
|
-
this._emitForm("contour:change");
|
|
327
|
-
});
|
|
328
|
-
// Inline validation (BY2-U6): on blur, reflect validity on the input via
|
|
329
|
-
// aria-invalid and toggle the error/success state. The CSS already paints
|
|
330
|
-
// the invalid ring (components.css aria-invalid rules); this just drives it.
|
|
331
|
-
// `focusout` bubbles; `blur` does not, so a listener on the host would
|
|
332
|
-
// never see the input lose focus.
|
|
333
|
-
this.addEventListener("focusout", (e) => {
|
|
334
|
-
const input = this.querySelector("input, textarea, select");
|
|
335
|
-
if (!input || e.target !== input) return;
|
|
336
|
-
const valid = input.checkValidity();
|
|
337
|
-
if (valid) {
|
|
338
|
-
input.setAttribute("aria-invalid", "false");
|
|
339
|
-
this.classList.remove("is-invalid");
|
|
340
|
-
this.removeAttribute("data-invalid");
|
|
341
|
-
// Clear a transient validation error the blur handler surfaced, but
|
|
342
|
-
// never an error the author set explicitly.
|
|
343
|
-
if (!this.getAttribute("error")) {
|
|
344
|
-
const stale = this.querySelector(".c-field__error");
|
|
345
|
-
if (stale) {
|
|
346
|
-
const id = stale.id;
|
|
347
|
-
stale.remove();
|
|
348
|
-
if (id) input.setAttribute("aria-describedby", (input.getAttribute("aria-describedby") || "").split(" ").filter((x) => x && x !== id).join(" "));
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
} else {
|
|
352
|
-
input.setAttribute("aria-invalid", "true");
|
|
353
|
-
this.classList.add("is-invalid");
|
|
354
|
-
this.setAttribute("data-invalid", "");
|
|
355
|
-
// R22 WC4-26: emit a cancelable contour:invalid event. A listener
|
|
356
|
-
// can preventDefault() to suppress the invalid state (e.g. to show
|
|
357
|
-
// a custom message instead of the browser's).
|
|
358
|
-
const invalidEvent = new CustomEvent("contour:invalid", {
|
|
359
|
-
bubbles: true,
|
|
360
|
-
composed: true,
|
|
361
|
-
cancelable: true,
|
|
362
|
-
detail: { field: this, input, message: input.validationMessage || "Invalid value" },
|
|
363
|
-
});
|
|
364
|
-
const notCancelled = this.dispatchEvent(invalidEvent);
|
|
365
|
-
if (notCancelled) {
|
|
366
|
-
// Surface the browser's validation message when no explicit error attr.
|
|
367
|
-
if (!this.getAttribute("error") && !this.getAttribute("custom-error")) {
|
|
368
|
-
const msg = input.validationMessage || "Invalid value";
|
|
369
|
-
let errEl = this.querySelector(".c-field__error");
|
|
370
|
-
if (!errEl) {
|
|
371
|
-
errEl = document.createElement("span");
|
|
372
|
-
errEl.className = "c-field__error";
|
|
373
|
-
this.appendChild(errEl);
|
|
374
|
-
}
|
|
375
|
-
errEl.textContent = msg;
|
|
376
|
-
if (!errEl.id) errEl.id = contourId("err");
|
|
377
|
-
input.setAttribute("aria-describedby", (input.getAttribute("aria-describedby") || "").split(" ").filter((x) => x && x !== errEl.id).concat(errEl.id).join(" "));
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
sync();
|
|
382
|
-
}, true);
|
|
383
|
-
sync();
|
|
384
|
-
};
|
|
385
|
-
define("contour-field", ContourField);
|
|
386
|
-
|
|
387
|
-
/**
|
|
388
|
-
* Field-group: a grouped field with a shared label, optional hint and error
|
|
389
|
-
* text. Sets `role="group"` and `aria-required` when required; toggles
|
|
390
|
-
* `is-error` when an error is present. Child fields are labelled by the group.
|
|
391
|
-
*/
|
|
392
|
-
class ContourFieldGroup extends ContourBase {
|
|
393
|
-
static get observed() { return ["label", "hint", "error", "required"]; }
|
|
394
|
-
static get properties() { return { label: { attribute: "label" }, hint: { attribute: "hint" }, error: { attribute: "error" }, required: { attribute: "required", type: Boolean } }; }
|
|
395
|
-
render() {
|
|
396
|
-
this.classList.add("c-field-group");
|
|
397
|
-
this.setAttribute("role", "group");
|
|
398
|
-
const label = this.getAttribute("label");
|
|
399
|
-
if (label) {
|
|
400
|
-
const lbl = this.ensure(".c-field-group__label", () => { const el = document.createElement("div"); el.className = "c-field-group__label"; return el; });
|
|
401
|
-
lbl.textContent = label;
|
|
402
|
-
} else {
|
|
403
|
-
const lbl = this.querySelector(".c-field-group__label");
|
|
404
|
-
if (lbl) lbl.remove();
|
|
405
|
-
}
|
|
406
|
-
const hint = this.getAttribute("hint");
|
|
407
|
-
if (hint) {
|
|
408
|
-
const h = this.ensure(".c-field-group__hint", () => { const el = document.createElement("span"); el.className = "c-field-group__hint"; return el; });
|
|
409
|
-
h.textContent = hint;
|
|
410
|
-
} else {
|
|
411
|
-
const h = this.querySelector(".c-field-group__hint");
|
|
412
|
-
if (h) h.remove();
|
|
413
|
-
}
|
|
414
|
-
const error = this.getAttribute("error");
|
|
415
|
-
if (error) {
|
|
416
|
-
const e = this.ensure(".c-field-group__error", () => { const el = document.createElement("span"); el.className = "c-field-group__error"; return el; });
|
|
417
|
-
e.textContent = error;
|
|
418
|
-
} else {
|
|
419
|
-
const e = this.querySelector(".c-field-group__error");
|
|
420
|
-
if (e) e.remove();
|
|
421
|
-
}
|
|
422
|
-
if (error) this.classList.add("is-error"); else this.classList.remove("is-error");
|
|
423
|
-
if (this.hasAttribute("required")) this.setAttribute("aria-required", "true");
|
|
424
|
-
else this.removeAttribute("aria-required");
|
|
425
|
-
}
|
|
426
|
-
enhance() {
|
|
427
|
-
if (this._wiredFieldGroup) return;
|
|
428
|
-
this._wiredFieldGroup = true;
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
define("contour-field-group", ContourFieldGroup);
|
|
432
|
-
|
|
433
|
-
/**
|
|
434
|
-
* Form: a form wrapper with submission state and a validation summary. Adds
|
|
435
|
-
* `is-submitting` and disables the submit button while `submitting` is set.
|
|
436
|
-
* On invalid submit, prevents default and renders a `role="alert"` summary
|
|
437
|
-
* listing the invalid fields. Emits `contour:submit` on valid submit.
|
|
438
|
-
*/
|
|
439
|
-
class ContourForm extends ContourBase {
|
|
440
|
-
static get observed() { return ["submitting", "error", "summary", "title", "submit-label"]; }
|
|
441
|
-
static get properties() { return { submitting: { attribute: "submitting", type: Boolean }, error: { attribute: "error" }, summary: { attribute: "summary" }, title: { attribute: "title" }, submitLabel: { attribute: "submit-label" } }; }
|
|
442
|
-
render() {
|
|
443
|
-
this.classList.add("c-form");
|
|
444
|
-
if (this.hasAttribute("submitting")) this.classList.add("is-submitting"); else this.classList.remove("is-submitting");
|
|
445
|
-
const title = this.getAttribute("title");
|
|
446
|
-
let titleEl = this.querySelector(".c-form__title");
|
|
447
|
-
if (title) {
|
|
448
|
-
if (!titleEl) { titleEl = document.createElement("h2"); titleEl.className = "c-form__title"; this.prepend(titleEl); }
|
|
449
|
-
titleEl.textContent = title;
|
|
450
|
-
} else if (titleEl) {
|
|
451
|
-
titleEl.remove();
|
|
452
|
-
}
|
|
453
|
-
const summaryText = this.getAttribute("summary") || this.getAttribute("error");
|
|
454
|
-
let summary = this.querySelector(".c-form__summary");
|
|
455
|
-
if (summaryText) {
|
|
456
|
-
if (!summary) { summary = document.createElement("div"); summary.className = "c-form__summary"; summary.setAttribute("role", "alert"); this.prepend(summary); }
|
|
457
|
-
summary.textContent = summaryText;
|
|
458
|
-
summary.removeAttribute("hidden");
|
|
459
|
-
} else if (summary) {
|
|
460
|
-
summary.setAttribute("hidden", "");
|
|
461
|
-
}
|
|
462
|
-
// The component owns submission: it renders its own submit control when
|
|
463
|
-
// the author gives a `submit-label`, so an empty <contour-form> still
|
|
464
|
-
// shows a title and a button instead of rendering nothing.
|
|
465
|
-
const submitLabel = this.getAttribute("submit-label");
|
|
466
|
-
let submit = this.querySelector(".c-form__submit");
|
|
467
|
-
if (!submit) {
|
|
468
|
-
submit = document.createElement("button");
|
|
469
|
-
submit.type = "submit";
|
|
470
|
-
submit.className = "c-btn c-btn--primary c-form__submit";
|
|
471
|
-
this.appendChild(submit);
|
|
472
|
-
}
|
|
473
|
-
// `submit-label` is the authored override; `labels.submit` is the localised
|
|
474
|
-
// default. `applyLabel` re-applies the default on every render — so a
|
|
475
|
-
// `labels` change reaches a button an earlier render created — while an
|
|
476
|
-
// author's own button text still wins.
|
|
477
|
-
if (submitLabel) {
|
|
478
|
-
submit.textContent = submitLabel;
|
|
479
|
-
if (submit.dataset) delete submit.dataset.contourLabel;
|
|
480
|
-
} else {
|
|
481
|
-
applyLabel(submit, this, "submit", "Submit");
|
|
482
|
-
}
|
|
483
|
-
if (this.hasAttribute("submitting")) submit.setAttribute("disabled", "");
|
|
484
|
-
else submit.removeAttribute("disabled");
|
|
485
|
-
}
|
|
486
|
-
enhance() {
|
|
487
|
-
if (this._wiredForm) return;
|
|
488
|
-
this._wiredForm = true;
|
|
489
|
-
// A click on the component's own submit control is the submission path
|
|
490
|
-
// when there is no nested real <form>; prevent the default (there is no
|
|
491
|
-
// form to submit) and run the same validate-then-emit flow.
|
|
492
|
-
this.addEventListener("click", (e) => {
|
|
493
|
-
const btn = e.target && e.target.closest ? e.target.closest(".c-form__submit") : null;
|
|
494
|
-
if (!btn || !this.contains(btn)) return;
|
|
495
|
-
if (e.target.closest("form")) return; // a nested real form handles it
|
|
496
|
-
e.preventDefault();
|
|
497
|
-
this._submit();
|
|
498
|
-
});
|
|
499
|
-
this.addEventListener("submit", (e) => {
|
|
500
|
-
const form = e.target;
|
|
501
|
-
// The component claims ownership of submission: never let a nested
|
|
502
|
-
// real <form> navigate away.
|
|
503
|
-
e.preventDefault();
|
|
504
|
-
if (form && typeof form.checkValidity === "function" && !form.checkValidity()) {
|
|
505
|
-
const invalid = Array.from(form.querySelectorAll(":invalid"));
|
|
506
|
-
const names = invalid.map((el) => el.getAttribute("aria-label") || el.name || el.id || "field").join(", ");
|
|
507
|
-
let summary = this.querySelector(".c-form__summary");
|
|
508
|
-
if (!summary) { summary = document.createElement("div"); summary.className = "c-form__summary"; summary.setAttribute("role", "alert"); this.prepend(summary); }
|
|
509
|
-
summary.textContent = labelText(this, "validation-summary", "Please fix") + ": " + (names || labelText(this, "invalid-fields", "invalid fields"));
|
|
510
|
-
summary.removeAttribute("hidden");
|
|
511
|
-
return;
|
|
512
|
-
}
|
|
513
|
-
this._submit();
|
|
514
|
-
});
|
|
515
|
-
}
|
|
516
|
-
_submit() {
|
|
517
|
-
this.classList.add("is-submitting");
|
|
518
|
-
const submit = this.querySelector("[type='submit'], .c-form__submit");
|
|
519
|
-
if (submit) submit.setAttribute("disabled", "");
|
|
520
|
-
this.dispatchEvent(new CustomEvent("contour:submit", { bubbles: true, composed: true, detail: { submitting: true } }));
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
define("contour-form", ContourForm);
|
|
524
|
-
|
|
525
|
-
/**
|
|
526
|
-
* Range: a native `<input type=range>` wrapper with optional dual-handle range
|
|
527
|
-
* mode (`range`, `low`, `high`) and a sparkline canvas (`sparkline`). Form
|
|
528
|
-
* associated; emits `contour:input` / `contour:change` with the current value
|
|
529
|
-
* (or `{low, high}` in range mode). Renders a `--fill` custom property for the
|
|
530
|
-
* filled track.
|
|
531
|
-
*/
|
|
532
|
-
class ContourRange extends ContourBase {
|
|
533
|
-
static get observed() { return ["min", "max", "value", "low", "high", "range", "sparkline", "label", "disabled", "error", "help", "name", "step"]; }
|
|
534
|
-
static get formAssociated() { return true; }
|
|
535
|
-
static get properties() { return { min: { attribute: "min" }, max: { attribute: "max" }, value: { attribute: "value" }, label: { attribute: "label" }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" }, name: { attribute: "name" }, step: { attribute: "step" } }; }
|
|
536
|
-
render() {
|
|
537
|
-
this.classList.add("c-range");
|
|
538
|
-
const min = this.getAttribute("min") || "0";
|
|
539
|
-
const max = this.getAttribute("max") || "100";
|
|
540
|
-
const rangeMode = this.hasAttribute("range") || this.hasAttribute("low") || this.hasAttribute("high");
|
|
541
|
-
// sparkline canvas
|
|
542
|
-
const spark = this.getAttribute("sparkline");
|
|
543
|
-
if (spark) {
|
|
544
|
-
let canvas = this.querySelector(".c-range__sparkline");
|
|
545
|
-
if (!canvas) { canvas = document.createElement("canvas"); canvas.className = "c-range__sparkline"; canvas.setAttribute("part", "sparkline-canvas"); this.insertBefore(canvas, this.firstChild); }
|
|
546
|
-
} else {
|
|
547
|
-
const c = this.querySelector(".c-range__sparkline");
|
|
548
|
-
if (c) c.remove();
|
|
549
|
-
}
|
|
550
|
-
if (rangeMode) {
|
|
551
|
-
// remove single input if present
|
|
552
|
-
const single = this.querySelector("input.c-range:not(.c-range__low):not(.c-range__high)");
|
|
553
|
-
// keep generic input? We'll use two named inputs
|
|
554
|
-
let lowInput = this.querySelector("input.c-range__low");
|
|
555
|
-
if (!lowInput) { lowInput = document.createElement("input"); lowInput.type = "range"; lowInput.className = "c-range c-range__low"; lowInput.setAttribute("part", "input"); this.appendChild(lowInput); }
|
|
556
|
-
let highInput = this.querySelector("input.c-range__high");
|
|
557
|
-
if (!highInput) { highInput = document.createElement("input"); highInput.type = "range"; highInput.className = "c-range c-range__high"; highInput.setAttribute("part", "input"); this.appendChild(highInput); }
|
|
558
|
-
lowInput.min = min; lowInput.max = max;
|
|
559
|
-
highInput.min = min; highInput.max = max;
|
|
560
|
-
const step = this.getAttribute("step");
|
|
561
|
-
if (step) { lowInput.step = step; highInput.step = step; } else { lowInput.removeAttribute("step"); highInput.removeAttribute("step"); }
|
|
562
|
-
if (this.hasAttribute("disabled")) { lowInput.setAttribute("disabled", ""); highInput.setAttribute("disabled", ""); } else { lowInput.removeAttribute("disabled"); highInput.removeAttribute("disabled"); }
|
|
563
|
-
const lowVal = this.getAttribute("low") || min;
|
|
564
|
-
const highVal = this.getAttribute("high") || max;
|
|
565
|
-
if (this._rangeUserLow !== null && this._rangeAttrLowAtDirty === (this.getAttribute("low") || min)) lowInput.value = this._rangeUserLow;
|
|
566
|
-
else { lowInput.value = lowVal; this._rangeUserLow = null; this._rangeAttrLowAtDirty = null; }
|
|
567
|
-
if (this._rangeUserHigh !== null && this._rangeAttrHighAtDirty === (this.getAttribute("high") || max)) highInput.value = this._rangeUserHigh;
|
|
568
|
-
else { highInput.value = highVal; this._rangeUserHigh = null; this._rangeAttrHighAtDirty = null; }
|
|
569
|
-
const label = this.getAttribute("label");
|
|
570
|
-
if (label) { lowInput.setAttribute("aria-label", label + " low"); highInput.setAttribute("aria-label", label + " high"); }
|
|
571
|
-
// A dual range submits two entries under the host's name through
|
|
572
|
-
// the ElementInternals FormData form value (_syncFormValue below).
|
|
573
|
-
// The old hidden native mirrors submitted NOTHING: the base class's
|
|
574
|
-
// form="" detachment cannot tell a mirror from a double submission,
|
|
575
|
-
// so it detached them too — measured as zero entries by the R20
|
|
576
|
-
// form-participation arm. Remove any a previous render left behind.
|
|
577
|
-
Array.from(this.querySelectorAll('input[type="hidden"][data-range]')).forEach((n) => n.remove());
|
|
578
|
-
} else {
|
|
579
|
-
// remove dual inputs and any leftover mirrors from a dual render
|
|
580
|
-
Array.from(this.querySelectorAll("input.c-range__low, input.c-range__high, input[type='hidden'][data-range]")).forEach((n) => n.remove());
|
|
581
|
-
const input = this.ensure("input.c-range", () => { const el = document.createElement("input"); el.type = "range"; el.setAttribute("part", "input"); return el; });
|
|
582
|
-
// ensure class
|
|
583
|
-
input.className = "c-range";
|
|
584
|
-
input.type = "range";
|
|
585
|
-
input.min = min;
|
|
586
|
-
input.max = max;
|
|
587
|
-
const step = this.getAttribute("step");
|
|
588
|
-
if (step) input.step = step; else input.removeAttribute("step");
|
|
589
|
-
if (this.hasAttribute("disabled")) input.setAttribute("disabled", ""); else input.removeAttribute("disabled");
|
|
590
|
-
const attrVal = this.getAttribute("value") || "50";
|
|
591
|
-
if (this._rangeUserValue !== null && this._rangeAttrAtDirty === (this.getAttribute("value") || "50")) {
|
|
592
|
-
input.value = this._rangeUserValue;
|
|
593
|
-
} else {
|
|
594
|
-
input.value = attrVal;
|
|
595
|
-
this._rangeUserValue = null;
|
|
596
|
-
this._rangeAttrAtDirty = null;
|
|
597
|
-
}
|
|
598
|
-
const label = this.getAttribute("label");
|
|
599
|
-
if (label) input.setAttribute("aria-label", label);
|
|
600
|
-
else if (!input.hasAttribute("aria-label")) input.setAttribute("aria-label", "Range");
|
|
601
|
-
const updateFill = () => {
|
|
602
|
-
const mn = Number(input.min) || 0;
|
|
603
|
-
const mx = Number(input.max) || 100;
|
|
604
|
-
const val = Number(input.value) || 0;
|
|
605
|
-
const pct = mx > mn ? ((val - mn) / (mx - mn)) * 100 : 0;
|
|
606
|
-
input.style.setProperty("--fill", pct + "%");
|
|
607
|
-
};
|
|
608
|
-
updateFill();
|
|
609
|
-
if (!input._fillWired) {
|
|
610
|
-
input._fillWired = true;
|
|
611
|
-
input.addEventListener("input", updateFill);
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
// patch enhance onto ContourRange
|
|
617
|
-
const _origRangeRender = ContourRange.prototype.render;
|
|
618
|
-
ContourRange.prototype.attributeChangedCallback = function(name, oldValue, newValue) {
|
|
619
|
-
if (name === "value") { this._rangeUserValue = null; this._rangeAttrAtDirty = null; }
|
|
620
|
-
if (name === "low") { this._rangeUserLow = null; this._rangeAttrLowAtDirty = null; }
|
|
621
|
-
if (name === "high") { this._rangeUserHigh = null; this._rangeAttrHighAtDirty = null; }
|
|
622
|
-
return ContourBase.prototype.attributeChangedCallback.call(this, name, oldValue, newValue);
|
|
623
|
-
};
|
|
624
|
-
// Form value (R20 T-08): single submits the handle's value; dual submits
|
|
625
|
-
// TWO entries under the one host name via the FormData form value. The
|
|
626
|
-
// base generic would submit only the first handle, and the formdata
|
|
627
|
-
// re-sync calls THIS, so the override is what keeps the entry list right.
|
|
628
|
-
ContourRange.prototype._syncFormValue = function() {
|
|
629
|
-
if (!this._internals) return;
|
|
630
|
-
const low = this.querySelector("input.c-range__low");
|
|
631
|
-
const high = this.querySelector("input.c-range__high");
|
|
632
|
-
if (low && high) {
|
|
633
|
-
const name = this.getAttribute("name");
|
|
634
|
-
if (name) {
|
|
635
|
-
const fd = new FormData();
|
|
636
|
-
fd.append(name, low.value);
|
|
637
|
-
fd.append(name, high.value);
|
|
638
|
-
this._internals.setFormValue(fd);
|
|
639
|
-
} else {
|
|
640
|
-
this._internals.setFormValue(null);
|
|
641
|
-
}
|
|
642
|
-
} else {
|
|
643
|
-
const single = this.querySelector("input.c-range:not(.c-range__low):not(.c-range__high)");
|
|
644
|
-
if (single) this._internals.setFormValue(single.value);
|
|
645
|
-
}
|
|
646
|
-
};
|
|
647
|
-
ContourRange.prototype.formResetCallback = function() {
|
|
648
|
-
// The authored defaults are the value/low/high attributes; clear the
|
|
649
|
-
// user-drag tracking so the re-render reads them, under the resetting
|
|
650
|
-
// flag so the base restore cannot resurrect the dragged handles.
|
|
651
|
-
this._contourResetting = true;
|
|
652
|
-
try {
|
|
653
|
-
this._rangeUserValue = null; this._rangeAttrAtDirty = null;
|
|
654
|
-
this._rangeUserLow = null; this._rangeAttrLowAtDirty = null;
|
|
655
|
-
this._rangeUserHigh = null; this._rangeAttrHighAtDirty = null;
|
|
656
|
-
if (this.isConnected && this._contourAuthored) this.attributeChangedCallback("__rerender__", null, "");
|
|
657
|
-
this._syncFormValue();
|
|
658
|
-
} finally {
|
|
659
|
-
this._contourResetting = false;
|
|
660
|
-
}
|
|
661
|
-
};
|
|
662
|
-
ContourRange.prototype.formStateRestoreCallback = function(state) {
|
|
663
|
-
if (!this._internals || state === null || state === undefined) return;
|
|
664
|
-
const low = this.querySelector("input.c-range__low");
|
|
665
|
-
const high = this.querySelector("input.c-range__high");
|
|
666
|
-
if (low && high && state instanceof FormData) {
|
|
667
|
-
const vals = state.getAll(this.getAttribute("name"));
|
|
668
|
-
if (vals.length >= 2) { low.value = String(vals[0]); high.value = String(vals[1]); }
|
|
669
|
-
} else {
|
|
670
|
-
const single = this.querySelector("input.c-range:not(.c-range__low):not(.c-range__high)");
|
|
671
|
-
if (single) single.value = String(state);
|
|
672
|
-
}
|
|
673
|
-
this._syncFormValue();
|
|
674
|
-
};
|
|
675
|
-
ContourRange.prototype.enhance = function() {
|
|
676
|
-
if (this._wiredRange) return;
|
|
677
|
-
this._wiredRange = true;
|
|
678
|
-
const sync = () => { this._syncFormValue(); };
|
|
679
|
-
this.addEventListener("input", (e) => {
|
|
680
|
-
const low = this.querySelector("input.c-range__low");
|
|
681
|
-
const high = this.querySelector("input.c-range__high");
|
|
682
|
-
const single = this.querySelector("input.c-range:not(.c-range__low):not(.c-range__high)");
|
|
683
|
-
if (low && high && (e.target === low || e.target === high)) {
|
|
684
|
-
this._rangeUserLow = low.value;
|
|
685
|
-
this._rangeUserHigh = high.value;
|
|
686
|
-
this._rangeAttrLowAtDirty = this.getAttribute("low") || (this.getAttribute("min") || "0");
|
|
687
|
-
this._rangeAttrHighAtDirty = this.getAttribute("high") || (this.getAttribute("max") || "100");
|
|
688
|
-
sync();
|
|
689
|
-
this._emitForm("contour:input", { low: Number(low.value), high: Number(high.value) });
|
|
690
|
-
this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { low: Number(low.value), high: Number(high.value) } }));
|
|
691
|
-
} else if (single && e.target === single) {
|
|
692
|
-
this._rangeUserValue = single.value;
|
|
693
|
-
this._rangeAttrAtDirty = this.getAttribute("value") || "50";
|
|
694
|
-
sync();
|
|
695
|
-
this._emitForm("contour:input");
|
|
696
|
-
}
|
|
697
|
-
});
|
|
698
|
-
this.addEventListener("change", (e) => {
|
|
699
|
-
const low = this.querySelector("input.c-range__low");
|
|
700
|
-
const high = this.querySelector("input.c-range__high");
|
|
701
|
-
const single = this.querySelector("input.c-range:not(.c-range__low):not(.c-range__high)");
|
|
702
|
-
if (low && high && (e.target === low || e.target === high)) {
|
|
703
|
-
sync();
|
|
704
|
-
this._emitForm("contour:change", { low: Number(low.value), high: Number(high.value) });
|
|
705
|
-
this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { low: Number(low.value), high: Number(high.value) } }));
|
|
706
|
-
} else if (single && e.target === single) {
|
|
707
|
-
sync();
|
|
708
|
-
this._emitForm("contour:change");
|
|
709
|
-
}
|
|
710
|
-
});
|
|
711
|
-
sync();
|
|
712
|
-
};
|
|
713
|
-
define("contour-range", ContourRange);
|
|
714
|
-
/**
|
|
715
|
-
* Switch: a `role="switch"` checkbox control with label, required, disabled,
|
|
716
|
-
* error and help states. Form associated; emits `contour:change` on toggle.
|
|
717
|
-
* The input's ::after draws the track; there is no separate track element.
|
|
718
|
-
*/
|
|
719
|
-
class ContourSwitch extends ContourBase {
|
|
720
|
-
static get observed() { return ["label", "required", "checked", "disabled", "error", "help"]; }
|
|
721
|
-
static get properties() { return { label: { attribute: "label" }, required: { attribute: "required", type: Boolean }, checked: { attribute: "checked", type: Boolean }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" } }; }
|
|
722
|
-
static get formAssociated() { return true; }
|
|
723
|
-
render() {
|
|
724
|
-
this.classList.add("c-switch");
|
|
725
|
-
// Authored default captured before any toggle reflects into `checked`.
|
|
726
|
-
if (this._switchDefaultChecked === undefined) this._switchDefaultChecked = this.hasAttribute("checked");
|
|
727
|
-
const label = this.getAttribute("label");
|
|
728
|
-
// The guide's control is `label.c-switch` wrapping `input.c-switch__input`
|
|
729
|
-
// and a bare span of text; the sheet paints the track on the input itself.
|
|
730
|
-
const input = this.ensure("input.c-switch__input", () => { const el = document.createElement("input"); el.className = "c-switch__input"; el.type = "checkbox"; return el; });
|
|
731
|
-
input.checked = this.hasAttribute("checked");
|
|
732
|
-
input.setAttribute("role", "switch");
|
|
733
|
-
input.setAttribute("aria-checked", String(input.checked));
|
|
734
|
-
this._setCustomState("data-checked", input.checked);
|
|
735
|
-
if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
|
|
736
|
-
else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
|
|
737
|
-
const err = this.getAttribute("error");
|
|
738
|
-
const help = this.getAttribute("help");
|
|
739
|
-
let msg = this.querySelector(".c-switch__message");
|
|
740
|
-
if (err || help) {
|
|
741
|
-
if (!msg) { msg = document.createElement("div"); msg.className = "c-switch__message"; this.appendChild(msg); }
|
|
742
|
-
msg.textContent = err || help || "";
|
|
743
|
-
msg.classList.toggle("c-switch__message--error", !!err);
|
|
744
|
-
} else if (msg) { msg.remove(); }
|
|
745
|
-
if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
|
|
746
|
-
// The input's ::after draws the track; a separate .c-switch__track span
|
|
747
|
-
// would be a second, unstyled element the CSS never reaches (R18-41).
|
|
748
|
-
if (label) {
|
|
749
|
-
input.setAttribute("aria-label", label);
|
|
750
|
-
const txt = this.querySelector(":scope > span:not([class])") || (() => { const el = document.createElement("span"); this.appendChild(el); return el; })();
|
|
751
|
-
txt.textContent = label;
|
|
752
|
-
}
|
|
753
|
-
if (!input.hasAttribute("aria-label")) input.setAttribute("aria-label", "Switch");
|
|
754
|
-
}
|
|
755
|
-
enhance() {
|
|
756
|
-
const input = this.querySelector("input");
|
|
757
|
-
if (input && this._internals) {
|
|
758
|
-
input.setAttribute("aria-checked", String(input.checked));
|
|
759
|
-
this._setCustomState("data-checked", input.checked);
|
|
760
|
-
this._internals.setFormValue(input.checked ? (input.value || "on") : null);
|
|
761
|
-
this._syncValidity(this.hasAttribute("required") && !input.checked);
|
|
762
|
-
}
|
|
763
|
-
if (this._wiredSwitch) return;
|
|
764
|
-
this._wiredSwitch = true;
|
|
765
|
-
// Label activation: the host is not a native <label>, so a click on the
|
|
766
|
-
// text or track must toggle the input. The input's own click is left to
|
|
767
|
-
// the platform (early return) so it toggles exactly once.
|
|
768
|
-
this.addEventListener("click", (e) => {
|
|
769
|
-
if (e.target && e.target.closest && e.target.closest("input")) return;
|
|
770
|
-
const inp = this.querySelector("input");
|
|
771
|
-
if (!inp || inp.disabled) return;
|
|
772
|
-
e.preventDefault();
|
|
773
|
-
inp.click();
|
|
774
|
-
});
|
|
775
|
-
this.addEventListener("change", (e) => {
|
|
776
|
-
const inp = this.querySelector("input");
|
|
777
|
-
if (!inp || e.target !== inp || !this._internals) return;
|
|
778
|
-
inp.setAttribute("aria-checked", String(inp.checked));
|
|
779
|
-
this._setCustomState("data-checked", inp.checked);
|
|
780
|
-
this.toggleAttribute("checked", inp.checked);
|
|
781
|
-
this._internals.setFormValue(inp.checked ? (inp.value || "on") : null);
|
|
782
|
-
this._emitForm("contour:change");
|
|
783
|
-
this._syncValidity(this.hasAttribute("required") && !inp.checked);
|
|
784
|
-
});
|
|
785
|
-
}
|
|
786
|
-
formResetCallback() {
|
|
787
|
-
// `checked` is reflected on every toggle, so the authored default must
|
|
788
|
-
// come from the first-render capture — native defaultChecked semantics,
|
|
789
|
-
// not the last reflected state (R20 T-08).
|
|
790
|
-
this._contourResetting = true;
|
|
791
|
-
try {
|
|
792
|
-
this.toggleAttribute("checked", !!this._switchDefaultChecked);
|
|
793
|
-
const inp = this.querySelector("input");
|
|
794
|
-
if (inp) inp.checked = this.hasAttribute("checked");
|
|
795
|
-
this._syncFormValue();
|
|
796
|
-
} finally {
|
|
797
|
-
this._contourResetting = false;
|
|
798
|
-
}
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
define("contour-switch", ContourSwitch);
|
|
802
|
-
/**
|
|
803
|
-
* Check: a checkbox (or `type="radio"` when `type` is set) with label, name,
|
|
804
|
-
* value, required, checked, disabled, error and help states. The input's
|
|
805
|
-
* ::after draws the box; there is no separate box element. Form associated;
|
|
806
|
-
* emits `contour:change` on toggle.
|
|
807
|
-
*/
|
|
808
|
-
class ContourCheck extends ContourBase {
|
|
809
|
-
static get observed() { return ["label", "name", "value", "required", "type", "checked", "disabled", "error", "help"]; }
|
|
810
|
-
static get properties() { return { label: { attribute: "label" }, name: { attribute: "name" }, value: { attribute: "value" }, required: { attribute: "required", type: Boolean }, type: { attribute: "type" }, checked: { attribute: "checked", type: Boolean }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" } }; }
|
|
811
|
-
static get formAssociated() { return true; }
|
|
812
|
-
render() {
|
|
813
|
-
this.classList.add("c-check");
|
|
814
|
-
// Authored default captured before any toggle reflects into `checked`.
|
|
815
|
-
if (this._checkDefaultChecked === undefined) this._checkDefaultChecked = this.hasAttribute("checked");
|
|
816
|
-
const label = this.getAttribute("label");
|
|
817
|
-
const input = this.ensure("input.c-check__input", () => { const el = document.createElement("input"); el.className = "c-check__input"; el.type = this.getAttribute("type") === "radio" ? "radio" : "checkbox"; return el; });
|
|
818
|
-
input.checked = this.hasAttribute("checked");
|
|
819
|
-
// The input's ::after draws the box; a separate .c-check__box span would
|
|
820
|
-
// be a second, unstyled element the CSS never reaches (R18-41).
|
|
821
|
-
if (label) {
|
|
822
|
-
input.setAttribute("aria-label", label);
|
|
823
|
-
const txt = this.querySelector(":scope > span:not([class])") || (() => { const el = document.createElement("span"); this.appendChild(el); return el; })();
|
|
824
|
-
txt.textContent = label;
|
|
825
|
-
}
|
|
826
|
-
if (!input.hasAttribute("aria-label")) input.setAttribute("aria-label", "Checkbox");
|
|
827
|
-
if (this.hasAttribute("name")) input.name = this.getAttribute("name");
|
|
828
|
-
if (this.hasAttribute("value")) input.value = this.getAttribute("value");
|
|
829
|
-
if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
|
|
830
|
-
else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
|
|
831
|
-
const err = this.getAttribute("error");
|
|
832
|
-
const help = this.getAttribute("help");
|
|
833
|
-
let msg = this.querySelector(".c-check__message");
|
|
834
|
-
if (err || help) {
|
|
835
|
-
if (!msg) { msg = document.createElement("div"); msg.className = "c-check__message"; this.appendChild(msg); }
|
|
836
|
-
msg.textContent = err || help || "";
|
|
837
|
-
msg.classList.toggle("c-check__message--error", !!err);
|
|
838
|
-
} else if (msg) { msg.remove(); }
|
|
839
|
-
if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
|
|
840
|
-
}
|
|
841
|
-
enhance() {
|
|
842
|
-
const input = this.querySelector("input");
|
|
843
|
-
if (input && this._internals) {
|
|
844
|
-
this._setCustomState("data-checked", input.checked);
|
|
845
|
-
this._internals.setFormValue(input.checked ? (input.value || "on") : null);
|
|
846
|
-
this._syncValidity(this.hasAttribute("required") && !input.checked);
|
|
847
|
-
}
|
|
848
|
-
if (this._wiredCheck) return;
|
|
849
|
-
this._wiredCheck = true;
|
|
850
|
-
// Label activation: the host is not a native <label>, so a click on the
|
|
851
|
-
// text or box must toggle the input. The input's own click is left to
|
|
852
|
-
// the platform (early return) so it toggles exactly once.
|
|
853
|
-
this.addEventListener("click", (e) => {
|
|
854
|
-
if (e.target && e.target.closest && e.target.closest("input")) return;
|
|
855
|
-
const inp = this.querySelector("input");
|
|
856
|
-
if (!inp || inp.disabled) return;
|
|
857
|
-
e.preventDefault();
|
|
858
|
-
inp.click();
|
|
859
|
-
});
|
|
860
|
-
this.addEventListener("change", (e) => {
|
|
861
|
-
const inp = this.querySelector("input");
|
|
862
|
-
if (!inp || e.target !== inp || !this._internals) return;
|
|
863
|
-
this._setCustomState("data-checked", inp.checked);
|
|
864
|
-
this.toggleAttribute("checked", inp.checked);
|
|
865
|
-
this._internals.setFormValue(inp.checked ? (inp.value || "on") : null);
|
|
866
|
-
this._emitForm("contour:change");
|
|
867
|
-
this._syncValidity(this.hasAttribute("required") && !inp.checked);
|
|
868
|
-
});
|
|
869
|
-
}
|
|
870
|
-
formResetCallback() {
|
|
871
|
-
// Same default-capture contract as contour-switch (R20 T-08).
|
|
872
|
-
this._contourResetting = true;
|
|
873
|
-
try {
|
|
874
|
-
this.toggleAttribute("checked", !!this._checkDefaultChecked);
|
|
875
|
-
const inp = this.querySelector("input");
|
|
876
|
-
if (inp) inp.checked = this.hasAttribute("checked");
|
|
877
|
-
this._syncFormValue();
|
|
878
|
-
} finally {
|
|
879
|
-
this._contourResetting = false;
|
|
880
|
-
}
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
define("contour-check", ContourCheck);
|
|
884
|
-
/**
|
|
885
|
-
* Radio: a radio button with label, name, value, required, checked, disabled,
|
|
886
|
-
* error and help states. Form associated; unchecking clears the stale FormData
|
|
887
|
-
* entry. Emits `contour:change` on toggle.
|
|
888
|
-
*/
|
|
889
|
-
class ContourRadio extends ContourBase {
|
|
890
|
-
static get observed() { return ["label", "name", "value", "required", "checked", "disabled", "error", "help"]; }
|
|
891
|
-
static get properties() { return { label: { attribute: "label" }, name: { attribute: "name" }, value: { attribute: "value" }, required: { attribute: "required", type: Boolean }, checked: { attribute: "checked", type: Boolean }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" } }; }
|
|
892
|
-
static get formAssociated() { return true; }
|
|
893
|
-
render() {
|
|
894
|
-
this.classList.add("c-radio");
|
|
895
|
-
const label = this.getAttribute("label");
|
|
896
|
-
const input = this.ensure("input.c-radio__input", () => { const el = document.createElement("input"); el.className = "c-radio__input"; el.type = "radio"; return el; });
|
|
897
|
-
input.checked = this.hasAttribute("checked");
|
|
898
|
-
if (this.hasAttribute("name")) input.name = this.getAttribute("name");
|
|
899
|
-
if (this.hasAttribute("value")) input.value = this.getAttribute("value");
|
|
900
|
-
if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
|
|
901
|
-
else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
|
|
902
|
-
const err = this.getAttribute("error");
|
|
903
|
-
const help = this.getAttribute("help");
|
|
904
|
-
let msg = this.querySelector(".c-radio__message");
|
|
905
|
-
if (err || help) {
|
|
906
|
-
if (!msg) { msg = document.createElement("div"); msg.className = "c-radio__message"; this.appendChild(msg); }
|
|
907
|
-
msg.textContent = err || help || "";
|
|
908
|
-
msg.classList.toggle("c-radio__message--error", !!err);
|
|
909
|
-
} else if (msg) { msg.remove(); }
|
|
910
|
-
if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
|
|
911
|
-
if (label) {
|
|
912
|
-
input.setAttribute("aria-label", label);
|
|
913
|
-
const txt = this.querySelector(":scope > span:not([class])") || (() => { const el = document.createElement("span"); this.appendChild(el); return el; })();
|
|
914
|
-
txt.textContent = label;
|
|
915
|
-
}
|
|
916
|
-
if (!input.hasAttribute("aria-label")) input.setAttribute("aria-label", "Radio");
|
|
917
|
-
}
|
|
918
|
-
enhance() {
|
|
919
|
-
const input = this.querySelector("input");
|
|
920
|
-
if (input && this._internals) {
|
|
921
|
-
this._setCustomState("data-checked", input.checked);
|
|
922
|
-
this._internals.setFormValue(input.checked ? (input.value || "on") : null);
|
|
923
|
-
this._syncValidity(this.hasAttribute("required") && !input.checked);
|
|
924
|
-
}
|
|
925
|
-
if (this._wiredRadio) return;
|
|
926
|
-
this._wiredRadio = true;
|
|
927
|
-
// Label activation: the host is not a native <label>, so a click on the
|
|
928
|
-
// text must select the radio. The input's own click is left to the
|
|
929
|
-
// platform (early return) so it toggles exactly once.
|
|
930
|
-
this.addEventListener("click", (e) => {
|
|
931
|
-
if (e.target && e.target.closest && e.target.closest("input")) return;
|
|
932
|
-
const inp = this.querySelector("input");
|
|
933
|
-
if (!inp || inp.disabled) return;
|
|
934
|
-
e.preventDefault();
|
|
935
|
-
inp.click();
|
|
936
|
-
});
|
|
937
|
-
this.addEventListener("change", (e) => {
|
|
938
|
-
const inp = this.querySelector("input");
|
|
939
|
-
if (!inp || e.target !== inp || !this._internals) return;
|
|
940
|
-
// Unchecking (group movement) must clear the stale FormData entry,
|
|
941
|
-
// not leave it behind beside the new selection.
|
|
942
|
-
this._setCustomState("data-checked", inp.checked);
|
|
943
|
-
this._internals.setFormValue(inp.checked ? (inp.value || "on") : null);
|
|
944
|
-
this._emitForm("contour:change");
|
|
945
|
-
this._syncValidity(this.hasAttribute("required") && !inp.checked);
|
|
946
|
-
});
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
define("contour-radio", ContourRadio);
|
|
950
|
-
/**
|
|
951
|
-
* Select: a native `<select>` wrapper populated from a JSON `options` attribute
|
|
952
|
-
* (with optgroup support) or an authored `<select>`. Supports label, placeholder,
|
|
953
|
-
* required, disabled, error and help. Form associated; emits `contour:change`.
|
|
954
|
-
*/
|
|
955
|
-
class ContourSelect extends ContourBase {
|
|
956
|
-
static get observed() { return ["options", "required", "label", "placeholder", "disabled", "error", "help", "value", "name", "multiple", "autocomplete"]; }
|
|
957
|
-
static get properties() { return { options: { attribute: "options" }, required: { attribute: "required", type: Boolean }, label: { attribute: "label" }, placeholder: { attribute: "placeholder" }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" }, value: { attribute: "value" }, name: { attribute: "name" }, multiple: { attribute: "multiple", type: Boolean }, autocomplete: { attribute: "autocomplete" } }; }
|
|
958
|
-
static get formAssociated() { return true; }
|
|
959
|
-
render() {
|
|
960
|
-
this.classList.add("c-select");
|
|
961
|
-
// Authored default captured before any commit reflects into `value`.
|
|
962
|
-
if (this._selectDefault === undefined) this._selectDefault = this.getAttribute("value");
|
|
963
|
-
const options = this.getAttribute("options");
|
|
964
|
-
// Slot composition: an authored <select> wins over the JSON attribute.
|
|
965
|
-
const generated = new Set(this._contourGenerated || []);
|
|
966
|
-
const authored = Array.from(this.children).filter((n) => !generated.has(n));
|
|
967
|
-
if (options && !authored.length) {
|
|
968
|
-
try {
|
|
969
|
-
const parsed = JSON.parse(options);
|
|
970
|
-
const select = this.ensure("select.c-select", () => { const el = document.createElement("select"); el.className = "c-select"; return el; });
|
|
971
|
-
select.innerHTML = "";
|
|
972
|
-
const label = this.getAttribute("label");
|
|
973
|
-
if (label) {
|
|
974
|
-
select.setAttribute("aria-label", label);
|
|
975
|
-
}
|
|
976
|
-
const placeholder = this.getAttribute("placeholder");
|
|
977
|
-
if (placeholder) {
|
|
978
|
-
const ph = document.createElement("option");
|
|
979
|
-
ph.value = "";
|
|
980
|
-
ph.textContent = placeholder;
|
|
981
|
-
ph.disabled = true;
|
|
982
|
-
ph.selected = true;
|
|
983
|
-
select.appendChild(ph);
|
|
984
|
-
}
|
|
985
|
-
// Group support.
|
|
986
|
-
const groups = {};
|
|
987
|
-
parsed.forEach((opt) => {
|
|
988
|
-
const g = (typeof opt === "object" && opt !== null) ? opt.group : null;
|
|
989
|
-
if (g) {
|
|
990
|
-
if (!groups[g]) { groups[g] = document.createElement("optgroup"); groups[g].label = g; select.appendChild(groups[g]); }
|
|
991
|
-
const option = document.createElement("option");
|
|
992
|
-
option.value = typeof opt === "string" ? opt : opt.value;
|
|
993
|
-
option.textContent = typeof opt === "string" ? opt : opt.label;
|
|
994
|
-
groups[g].appendChild(option);
|
|
995
|
-
} else {
|
|
996
|
-
const option = document.createElement("option");
|
|
997
|
-
option.value = typeof opt === "string" ? opt : opt.value;
|
|
998
|
-
option.textContent = typeof opt === "string" ? opt : opt.label;
|
|
999
|
-
select.appendChild(option);
|
|
1000
|
-
}
|
|
1001
|
-
});
|
|
1002
|
-
if (select.parentNode !== this) this.appendChild(select);
|
|
1003
|
-
this.classList.remove("c-select");
|
|
1004
|
-
select.classList.add("c-select");
|
|
1005
|
-
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
1006
|
-
}
|
|
1007
|
-
// Ensure authored select gets c-select styling.
|
|
1008
|
-
const authoredSel = this.querySelector("select");
|
|
1009
|
-
if (authoredSel && !authoredSel.classList.contains("c-select")) {
|
|
1010
|
-
authoredSel.classList.add("c-select");
|
|
1011
|
-
this.classList.remove("c-select");
|
|
1012
|
-
}
|
|
1013
|
-
// Disabled / error / help contract (applies to authored or generated select).
|
|
1014
|
-
const sel = this.querySelector("select");
|
|
1015
|
-
if (sel) {
|
|
1016
|
-
if (this.hasAttribute("disabled")) { sel.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
|
|
1017
|
-
else { sel.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
|
|
1018
|
-
// Reflect the native attributes the platform reads: FormData needs
|
|
1019
|
-
// `name`, a multi-select needs `multiple`, and the value must be the
|
|
1020
|
-
// committed selection rather than whatever the first option happens to be.
|
|
1021
|
-
if (this.hasAttribute("name")) sel.setAttribute("name", this.getAttribute("name"));
|
|
1022
|
-
if (this.hasAttribute("multiple")) sel.setAttribute("multiple", ""); else sel.removeAttribute("multiple");
|
|
1023
|
-
if (this.hasAttribute("autocomplete")) sel.setAttribute("autocomplete", this.getAttribute("autocomplete"));
|
|
1024
|
-
if (this.hasAttribute("required")) sel.setAttribute("required", ""); else sel.removeAttribute("required");
|
|
1025
|
-
const val = this.getAttribute("value");
|
|
1026
|
-
if (val !== null) {
|
|
1027
|
-
if (sel.multiple) {
|
|
1028
|
-
const wanted = new Set(String(val).split(",").map((v) => v.trim()).filter(Boolean));
|
|
1029
|
-
Array.from(sel.options).forEach((o) => { o.selected = wanted.has(o.value); });
|
|
1030
|
-
} else {
|
|
1031
|
-
sel.value = val;
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
}
|
|
1035
|
-
// Label (applies to both JSON and authored options).
|
|
1036
|
-
const label = this.getAttribute("label");
|
|
1037
|
-
if (label) {
|
|
1038
|
-
let lbl = this.querySelector("label.c-select__label");
|
|
1039
|
-
if (!lbl) { lbl = document.createElement("label"); lbl.className = "c-select__label"; this.insertBefore(lbl, sel || this.firstChild); }
|
|
1040
|
-
lbl.textContent = label;
|
|
1041
|
-
if (sel) {
|
|
1042
|
-
if (!sel.id) sel.id = contourId("contour-select");
|
|
1043
|
-
lbl.setAttribute("for", sel.id);
|
|
1044
|
-
sel.setAttribute("aria-label", label);
|
|
1045
|
-
}
|
|
1046
|
-
}
|
|
1047
|
-
if (!this.querySelector("select")?.hasAttribute("aria-label")) {
|
|
1048
|
-
const sel = this.querySelector("select");
|
|
1049
|
-
if (sel) sel.setAttribute("aria-label", "Select");
|
|
1050
|
-
}
|
|
1051
|
-
const err = this.getAttribute("error");
|
|
1052
|
-
const help = this.getAttribute("help");
|
|
1053
|
-
let msg = this.querySelector(".c-select__message");
|
|
1054
|
-
if (err || help) {
|
|
1055
|
-
if (!msg) { msg = document.createElement("div"); msg.className = "c-select__message"; this.appendChild(msg); }
|
|
1056
|
-
msg.textContent = err || help || "";
|
|
1057
|
-
msg.classList.toggle("c-select__message--error", !!err);
|
|
1058
|
-
} else if (msg) { msg.remove(); }
|
|
1059
|
-
if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
|
|
1060
|
-
}
|
|
1061
|
-
enhance() {
|
|
1062
|
-
if (this._internals) this._syncFormValue();
|
|
1063
|
-
if (this._wiredSelect) return;
|
|
1064
|
-
this._wiredSelect = true;
|
|
1065
|
-
this.addEventListener("input", (e) => {
|
|
1066
|
-
const sel = this.querySelector("select");
|
|
1067
|
-
if (!sel || e.target !== sel) return;
|
|
1068
|
-
this._emitForm("contour:input");
|
|
1069
|
-
});
|
|
1070
|
-
this.addEventListener("change", (e) => {
|
|
1071
|
-
const sel = this.querySelector("select");
|
|
1072
|
-
if (!sel || e.target !== sel || !this._internals) return;
|
|
1073
|
-
// Reflect the WHOLE selection: for a multi-select sel.value is only
|
|
1074
|
-
// the first selected option, and the reflected attribute is what a
|
|
1075
|
-
// re-render rebuilds from (R20 T-06).
|
|
1076
|
-
const committed = sel.multiple ? Array.from(sel.selectedOptions).map((o) => o.value).join(",") : sel.value;
|
|
1077
|
-
this.setAttribute("value", committed);
|
|
1078
|
-
this._syncFormValue();
|
|
1079
|
-
this._emitForm("contour:change");
|
|
1080
|
-
});
|
|
1081
|
-
}
|
|
1082
|
-
// Multi-select submits every selected option as its own entry under the
|
|
1083
|
-
// host name — the FormData form value, not select.value (first option
|
|
1084
|
-
// only). The formdata re-sync in _wireFormData calls THIS, so the base
|
|
1085
|
-
// generic must not collapse the selection back to one entry.
|
|
1086
|
-
_syncFormValue() {
|
|
1087
|
-
if (!this._internals) return;
|
|
1088
|
-
const sel = this.querySelector("select");
|
|
1089
|
-
if (!sel) return;
|
|
1090
|
-
if (sel.multiple) {
|
|
1091
|
-
const chosen = Array.from(sel.selectedOptions).map((o) => o.value);
|
|
1092
|
-
const name = this.getAttribute("name");
|
|
1093
|
-
if (name && chosen.length) {
|
|
1094
|
-
const fd = new FormData();
|
|
1095
|
-
for (const v of chosen) fd.append(name, v);
|
|
1096
|
-
this._internals.setFormValue(fd);
|
|
1097
|
-
} else {
|
|
1098
|
-
this._internals.setFormValue(null);
|
|
1099
|
-
}
|
|
1100
|
-
this._syncValidity(this.hasAttribute("required") && !chosen.length);
|
|
1101
|
-
} else {
|
|
1102
|
-
this._internals.setFormValue(sel.value);
|
|
1103
|
-
this._syncValidity(this.hasAttribute("required") && !sel.value);
|
|
1104
|
-
}
|
|
1105
|
-
}
|
|
1106
|
-
formResetCallback() {
|
|
1107
|
-
// Restore the authored default, not the first option and not the last
|
|
1108
|
-
// reflected commit (R20 T-08). The attribute write re-renders the
|
|
1109
|
-
// selection; the resetting flag keeps the base restore out of it.
|
|
1110
|
-
this._contourResetting = true;
|
|
1111
|
-
try {
|
|
1112
|
-
const def = this._selectDefault ?? null;
|
|
1113
|
-
if (def === null) this.removeAttribute("value");
|
|
1114
|
-
else this.setAttribute("value", def);
|
|
1115
|
-
this._syncFormValue();
|
|
1116
|
-
} finally {
|
|
1117
|
-
this._contourResetting = false;
|
|
1118
|
-
}
|
|
1119
|
-
}
|
|
1120
|
-
formStateRestoreCallback(state) {
|
|
1121
|
-
const sel = this.querySelector("select");
|
|
1122
|
-
if (!sel || !this._internals) return;
|
|
1123
|
-
const values = state instanceof FormData
|
|
1124
|
-
? Array.from(state.getAll(this.getAttribute("name"))).map(String)
|
|
1125
|
-
: (state == null ? [] : String(state).split(",").map((v) => v.trim()).filter(Boolean));
|
|
1126
|
-
this._contourResetting = true;
|
|
1127
|
-
try {
|
|
1128
|
-
if (sel.multiple) {
|
|
1129
|
-
const wanted = new Set(values);
|
|
1130
|
-
for (const o of sel.options) o.selected = wanted.has(o.value);
|
|
1131
|
-
this.setAttribute("value", values.join(","));
|
|
1132
|
-
} else {
|
|
1133
|
-
sel.value = values[0] || "";
|
|
1134
|
-
this.setAttribute("value", sel.value);
|
|
1135
|
-
}
|
|
1136
|
-
this._syncFormValue();
|
|
1137
|
-
} finally {
|
|
1138
|
-
this._contourResetting = false;
|
|
1139
|
-
}
|
|
1140
|
-
}
|
|
1141
|
-
}
|
|
1142
|
-
define("contour-select", ContourSelect);
|
|
1143
|
-
/**
|
|
1144
|
-
* Version: a `<select>` of version options from a JSON `options` attribute,
|
|
1145
|
-
* with `selected` support per option. Form associated; emits `contour:change`.
|
|
1146
|
-
*/
|
|
1147
|
-
class ContourVersion extends ContourBase {
|
|
1148
|
-
static get observed() { return ["options", "value", "name"]; }
|
|
1149
|
-
static get formAssociated() { return true; }
|
|
1150
|
-
static get properties() { return { options: { attribute: "options" }, value: { attribute: "value" }, name: { attribute: "name" } }; }
|
|
1151
|
-
render() {
|
|
1152
|
-
this.classList.add("c-version");
|
|
1153
|
-
// Authored default captured before any commit reflects into `value`.
|
|
1154
|
-
if (this._versionDefault === undefined) this._versionDefault = this.getAttribute("value");
|
|
1155
|
-
const options = this.getAttribute("options");
|
|
1156
|
-
const generated = new Set(this._contourGenerated || []);
|
|
1157
|
-
const authored = Array.from(this.children).filter((n) => !generated.has(n));
|
|
1158
|
-
if (options && !authored.length) {
|
|
1159
|
-
try {
|
|
1160
|
-
const parsed = JSON.parse(options);
|
|
1161
|
-
const select = this.ensure("select.c-version", () => { const el = document.createElement("select"); el.className = "c-version"; return el; });
|
|
1162
|
-
select.innerHTML = "";
|
|
1163
|
-
if (!select.hasAttribute("aria-label")) select.setAttribute("aria-label", "Version");
|
|
1164
|
-
parsed.forEach((opt) => {
|
|
1165
|
-
const option = document.createElement("option");
|
|
1166
|
-
if (typeof opt === "string") { option.value = opt; option.textContent = opt; }
|
|
1167
|
-
else { option.value = opt.value || opt.label; option.textContent = opt.label || opt.value; if (opt.selected) option.selected = true; }
|
|
1168
|
-
select.appendChild(option);
|
|
1169
|
-
});
|
|
1170
|
-
if (select.parentNode !== this) this.appendChild(select);
|
|
1171
|
-
this.classList.remove("c-version");
|
|
1172
|
-
select.classList.add("c-version");
|
|
1173
|
-
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
1174
|
-
}
|
|
1175
|
-
// The committed value selects the option (R20 T-07): without this the
|
|
1176
|
-
// host always submitted the first option regardless of `value`.
|
|
1177
|
-
const sel = this.querySelector("select");
|
|
1178
|
-
if (sel) {
|
|
1179
|
-
if (this.hasAttribute("name")) sel.setAttribute("name", this.getAttribute("name"));
|
|
1180
|
-
const val = this.getAttribute("value");
|
|
1181
|
-
if (val !== null) sel.value = val;
|
|
1182
|
-
}
|
|
1183
|
-
}
|
|
1184
|
-
enhance() {
|
|
1185
|
-
const sync = () => {
|
|
1186
|
-
const select = this.querySelector("select");
|
|
1187
|
-
if (!select || !this._internals) return;
|
|
1188
|
-
this._internals.setFormValue(select.value);
|
|
1189
|
-
};
|
|
1190
|
-
sync();
|
|
1191
|
-
if (this._wiredVersion) return;
|
|
1192
|
-
this._wiredVersion = true;
|
|
1193
|
-
this.addEventListener("change", (e) => {
|
|
1194
|
-
const select = this.querySelector("select");
|
|
1195
|
-
if (!select || e.target !== select) return;
|
|
1196
|
-
// Reflect the committed selection so a consumer reading `value` sees
|
|
1197
|
-
// what the user picked, and a re-render rebuilds it.
|
|
1198
|
-
this.setAttribute("value", select.value);
|
|
1199
|
-
sync();
|
|
1200
|
-
this._emitForm("contour:change");
|
|
1201
|
-
});
|
|
1202
|
-
}
|
|
1203
|
-
formResetCallback() {
|
|
1204
|
-
// Restore the authored default, not the first option (R20 T-08).
|
|
1205
|
-
this._contourResetting = true;
|
|
1206
|
-
try {
|
|
1207
|
-
const def = this._versionDefault ?? null;
|
|
1208
|
-
if (def === null) this.removeAttribute("value");
|
|
1209
|
-
else this.setAttribute("value", def);
|
|
1210
|
-
this._syncFormValue();
|
|
1211
|
-
} finally {
|
|
1212
|
-
this._contourResetting = false;
|
|
1213
|
-
}
|
|
1214
|
-
}
|
|
1215
|
-
}
|
|
1216
|
-
define("contour-version", ContourVersion);
|
|
1217
|
-
/**
|
|
1218
|
-
* Textarea: a `<textarea>` wrapper with placeholder, required, disabled, error
|
|
1219
|
-
* and help states. Form associated; emits `contour:input` / `contour:change`.
|
|
1220
|
-
*/
|
|
1221
|
-
class ContourTextarea extends ContourBase {
|
|
1222
|
-
static get observed() { return ["placeholder", "required", "disabled", "error", "help", "value", "name", "label"]; }
|
|
1223
|
-
static get properties() { return { placeholder: { attribute: "placeholder" }, required: { attribute: "required", type: Boolean }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" }, value: { attribute: "value" }, name: { attribute: "name" }, label: { attribute: "label" } }; }
|
|
1224
|
-
static get formAssociated() { return true; }
|
|
1225
|
-
render() {
|
|
1226
|
-
const ta = this.ensure("textarea", () => { const el = document.createElement("textarea"); el.className = "c-textarea"; return el; });
|
|
1227
|
-
ta.className = "c-textarea";
|
|
1228
|
-
// value and name reach the generated control (R20 T-01): without them
|
|
1229
|
-
// the host submitted an empty entry under no name at all. Typed text
|
|
1230
|
-
// survives re-renders through the base class's user-dirty tracking.
|
|
1231
|
-
if (this.hasAttribute("name")) ta.name = this.getAttribute("name");
|
|
1232
|
-
else ta.removeAttribute("name");
|
|
1233
|
-
if (this.hasAttribute("value")) ta.value = this.getAttribute("value");
|
|
1234
|
-
if (this.hasAttribute("aria-label") && !ta.hasAttribute("aria-label")) ta.setAttribute("aria-label", this.getAttribute("aria-label"));
|
|
1235
|
-
if (this.hasAttribute("label") && !ta.hasAttribute("aria-label")) ta.setAttribute("aria-label", this.getAttribute("label"));
|
|
1236
|
-
if (!ta.hasAttribute("aria-label")) ta.setAttribute("aria-label", "Textarea");
|
|
1237
|
-
if (this.hasAttribute("placeholder")) ta.placeholder = this.getAttribute("placeholder");
|
|
1238
|
-
else ta.removeAttribute("placeholder");
|
|
1239
|
-
if (this.hasAttribute("required")) ta.setAttribute("required", "");
|
|
1240
|
-
else ta.removeAttribute("required");
|
|
1241
|
-
if (this.hasAttribute("disabled")) { ta.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
|
|
1242
|
-
else { ta.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
|
|
1243
|
-
const err = this.getAttribute("error");
|
|
1244
|
-
const help = this.getAttribute("help");
|
|
1245
|
-
let msg = this.querySelector(".c-textarea__message");
|
|
1246
|
-
if (err || help) {
|
|
1247
|
-
if (!msg) { msg = document.createElement("div"); msg.className = "c-textarea__message"; this.appendChild(msg); }
|
|
1248
|
-
msg.textContent = err || help || "";
|
|
1249
|
-
msg.classList.toggle("c-textarea__message--error", !!err);
|
|
1250
|
-
} else if (msg) { msg.remove(); }
|
|
1251
|
-
if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
|
|
1252
|
-
}
|
|
1253
|
-
enhance() {
|
|
1254
|
-
const ta = this.querySelector("textarea");
|
|
1255
|
-
if (ta && this._internals) {
|
|
1256
|
-
this._internals.setFormValue(ta.value);
|
|
1257
|
-
this._syncValidity(this.hasAttribute("required") && !ta.value.trim());
|
|
1258
|
-
}
|
|
1259
|
-
if (this._wiredTextarea) return;
|
|
1260
|
-
this._wiredTextarea = true;
|
|
1261
|
-
this.addEventListener("input", (e) => {
|
|
1262
|
-
const t = this.querySelector("textarea");
|
|
1263
|
-
if (!t || e.target !== t || !this._internals) return;
|
|
1264
|
-
this._internals.setFormValue(t.value);
|
|
1265
|
-
this._emitForm("contour:input");
|
|
1266
|
-
this._syncValidity(this.hasAttribute("required") && !t.value.trim());
|
|
1267
|
-
});
|
|
1268
|
-
this.addEventListener("change", (e) => {
|
|
1269
|
-
const t = this.querySelector("textarea");
|
|
1270
|
-
if (!t || e.target !== t || !this._internals) return;
|
|
1271
|
-
this._internals.setFormValue(t.value);
|
|
1272
|
-
this._emitForm("contour:change");
|
|
1273
|
-
this._syncValidity(this.hasAttribute("required") && !t.value.trim());
|
|
1274
|
-
});
|
|
1275
|
-
}
|
|
1276
|
-
}
|
|
1277
|
-
define("contour-textarea", ContourTextarea);
|
|
1278
|
-
/**
|
|
1279
|
-
* Input: an `<input>` wrapper with type, placeholder, required, value, disabled,
|
|
1280
|
-
* error and help states. Form associated; emits `contour:input` / `contour:change`.
|
|
1281
|
-
*/
|
|
1282
|
-
class ContourInputFull extends ContourBase {
|
|
1283
|
-
static get observed() { return ["type", "placeholder", "required", "value", "disabled", "error", "help", "label", "name"]; }
|
|
1284
|
-
static get properties() { return { type: { attribute: "type" }, placeholder: { attribute: "placeholder" }, required: { attribute: "required", type: Boolean }, value: { attribute: "value" }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" }, label: { attribute: "label" }, name: { attribute: "name" } }; }
|
|
1285
|
-
static get formAssociated() { return true; }
|
|
1286
|
-
render() {
|
|
1287
|
-
this.classList.add("c-input");
|
|
1288
|
-
const input = this.ensure("input", () => { const el = document.createElement("input"); el.className = "c-input"; return el; });
|
|
1289
|
-
input.className = "c-input";
|
|
1290
|
-
input.type = this.getAttribute("type") || "text";
|
|
1291
|
-
input.placeholder = this.getAttribute("placeholder") || "";
|
|
1292
|
-
// The name keys the base class's value/focus preservation and matches
|
|
1293
|
-
// the native control's own contract (R20 T-02/T-08).
|
|
1294
|
-
if (this.hasAttribute("name")) input.name = this.getAttribute("name");
|
|
1295
|
-
else input.removeAttribute("name");
|
|
1296
|
-
let label = this.getAttribute("label");
|
|
1297
|
-
if (!label) {
|
|
1298
|
-
const field = this.closest("contour-field");
|
|
1299
|
-
if (field) label = field.getAttribute("label");
|
|
1300
|
-
}
|
|
1301
|
-
if (label) input.setAttribute("aria-label", label);
|
|
1302
|
-
else if (!input.getAttribute("aria-label")) input.setAttribute("aria-label", "Input");
|
|
1303
|
-
if (this.hasAttribute("value")) input.value = this.getAttribute("value");
|
|
1304
|
-
if (this.hasAttribute("required")) input.setAttribute("required", "");
|
|
1305
|
-
else input.removeAttribute("required");
|
|
1306
|
-
if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
|
|
1307
|
-
else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
|
|
1308
|
-
// Error/help text
|
|
1309
|
-
const err = this.getAttribute("error");
|
|
1310
|
-
const help = this.getAttribute("help");
|
|
1311
|
-
let msg = this.querySelector(".c-input__message");
|
|
1312
|
-
if (err || help) {
|
|
1313
|
-
if (!msg) { msg = document.createElement("div"); msg.className = "c-input__message"; this.appendChild(msg); }
|
|
1314
|
-
msg.textContent = err || help || "";
|
|
1315
|
-
msg.classList.toggle("c-input__message--error", !!err);
|
|
1316
|
-
} else if (msg) { msg.remove(); }
|
|
1317
|
-
if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
|
|
1318
|
-
}
|
|
1319
|
-
enhance() {
|
|
1320
|
-
const input = this.querySelector("input");
|
|
1321
|
-
if (input && this._internals) {
|
|
1322
|
-
this._internals.setFormValue(input.value);
|
|
1323
|
-
this._syncValidity(this.hasAttribute("required") && !input.value.trim());
|
|
1324
|
-
}
|
|
1325
|
-
if (this._wiredInput) return;
|
|
1326
|
-
this._wiredInput = true;
|
|
1327
|
-
this.addEventListener("input", (e) => {
|
|
1328
|
-
const inp = this.querySelector("input");
|
|
1329
|
-
if (!inp || e.target !== inp || !this._internals) return;
|
|
1330
|
-
this._internals.setFormValue(inp.value);
|
|
1331
|
-
this._emitForm("contour:input");
|
|
1332
|
-
this._syncValidity(this.hasAttribute("required") && !inp.value.trim());
|
|
1333
|
-
});
|
|
1334
|
-
this.addEventListener("change", (e) => {
|
|
1335
|
-
const inp = this.querySelector("input");
|
|
1336
|
-
if (!inp || e.target !== inp || !this._internals) return;
|
|
1337
|
-
this._internals.setFormValue(inp.value);
|
|
1338
|
-
this._emitForm("contour:change");
|
|
1339
|
-
this._syncValidity(this.hasAttribute("required") && !inp.value.trim());
|
|
1340
|
-
});
|
|
1341
|
-
}
|
|
1342
|
-
}
|
|
1343
|
-
define("contour-input", ContourInputFull);
|
|
1344
|
-
/**
|
|
1345
|
-
* InputGroup: a text input with an optional search icon, a clear (×) affordance
|
|
1346
|
-
* and a submit (→) affordance. Attributes: `label`, `placeholder`, `clearable`,
|
|
1347
|
-
* `submit`, `value`, `name`, `required`, `disabled`. Form associated: the host
|
|
1348
|
-
* submits its value through ElementInternals. Emits `contour:input` /
|
|
1349
|
-
* `contour:change`, and `contour:change` (bubbles, composed) with `{ value: "" }`
|
|
1350
|
-
* on clear.
|
|
1351
|
-
*/
|
|
1352
|
-
class ContourInputGroup extends ContourBase {
|
|
1353
|
-
static get observed() { return ["label", "placeholder", "clearable", "submit", "value", "name", "required", "disabled"]; }
|
|
1354
|
-
static get properties() { return { label: { attribute: "label" }, placeholder: { attribute: "placeholder" }, clearable: { attribute: "clearable", type: Boolean }, submit: { attribute: "submit", type: Boolean }, value: { attribute: "value" }, name: { attribute: "name" }, required: { attribute: "required", type: Boolean }, disabled: { attribute: "disabled", type: Boolean } }; }
|
|
1355
|
-
static get formAssociated() { return true; }
|
|
1356
|
-
render() {
|
|
1357
|
-
this.classList.add("c-input-group");
|
|
1358
|
-
const icon = this.ensure("svg", () => { const el = document.createElementNS("http://www.w3.org/2000/svg", "svg"); el.setAttribute("aria-hidden", "true"); const use = document.createElementNS("http://www.w3.org/2000/svg", "use"); use.setAttribute("href", "#i-search"); el.appendChild(use); return el; });
|
|
1359
|
-
const input = this.ensure("input.c-input", () => { const el = document.createElement("input"); el.className = "c-input"; el.type = "text"; return el; });
|
|
1360
|
-
input.placeholder = this.getAttribute("placeholder") || this.getAttribute("label") || "";
|
|
1361
|
-
// Form participation (R20 T-05): the host submits through internals,
|
|
1362
|
-
// and the inner control carries the name/value the author wrote.
|
|
1363
|
-
if (this.hasAttribute("name")) input.name = this.getAttribute("name");
|
|
1364
|
-
else input.removeAttribute("name");
|
|
1365
|
-
if (this.hasAttribute("value")) input.value = this.getAttribute("value");
|
|
1366
|
-
if (this.hasAttribute("required")) input.setAttribute("required", "");
|
|
1367
|
-
else input.removeAttribute("required");
|
|
1368
|
-
if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
|
|
1369
|
-
else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
|
|
1370
|
-
const label = this.getAttribute("label");
|
|
1371
|
-
if (!input.hasAttribute("aria-label")) input.setAttribute("aria-label", label || "Search");
|
|
1372
|
-
// Clear affordance.
|
|
1373
|
-
const oldClear = this.querySelector(".c-input-group__clear");
|
|
1374
|
-
if (oldClear) oldClear.remove();
|
|
1375
|
-
if (this.hasAttribute("clearable")) {
|
|
1376
|
-
const btn = document.createElement("button");
|
|
1377
|
-
btn.className = "c-input-group__clear";
|
|
1378
|
-
btn.type = "button";
|
|
1379
|
-
btn.setAttribute("aria-label", "Clear");
|
|
1380
|
-
btn.textContent = "×";
|
|
1381
|
-
this.appendChild(btn);
|
|
1382
|
-
}
|
|
1383
|
-
// Submit affordance.
|
|
1384
|
-
const oldSubmit = this.querySelector(".c-input-group__submit");
|
|
1385
|
-
if (oldSubmit) oldSubmit.remove();
|
|
1386
|
-
if (this.hasAttribute("submit")) {
|
|
1387
|
-
const btn = document.createElement("button");
|
|
1388
|
-
btn.className = "c-input-group__submit";
|
|
1389
|
-
btn.type = "submit";
|
|
1390
|
-
btn.setAttribute("aria-label", "Submit");
|
|
1391
|
-
btn.textContent = "→";
|
|
1392
|
-
this.appendChild(btn);
|
|
1393
|
-
}
|
|
1394
|
-
}
|
|
1395
|
-
enhance() {
|
|
1396
|
-
const input = this.querySelector("input.c-input");
|
|
1397
|
-
if (input && this._internals) {
|
|
1398
|
-
this._internals.setFormValue(input.value);
|
|
1399
|
-
this._syncValidity(this.hasAttribute("required") && !input.value.trim());
|
|
1400
|
-
}
|
|
1401
|
-
if (this._wiredInputGroup) return;
|
|
1402
|
-
this._wiredInputGroup = true;
|
|
1403
|
-
this.addEventListener("input", (e) => {
|
|
1404
|
-
const inp = this.querySelector("input.c-input");
|
|
1405
|
-
if (!inp || e.target !== inp || !this._internals) return;
|
|
1406
|
-
this._internals.setFormValue(inp.value);
|
|
1407
|
-
this._emitForm("contour:input");
|
|
1408
|
-
this._syncValidity(this.hasAttribute("required") && !inp.value.trim());
|
|
1409
|
-
});
|
|
1410
|
-
this.addEventListener("change", (e) => {
|
|
1411
|
-
const inp = this.querySelector("input.c-input");
|
|
1412
|
-
if (!inp || e.target !== inp || !this._internals) return;
|
|
1413
|
-
this._internals.setFormValue(inp.value);
|
|
1414
|
-
this._emitForm("contour:change");
|
|
1415
|
-
this._syncValidity(this.hasAttribute("required") && !inp.value.trim());
|
|
1416
|
-
});
|
|
1417
|
-
this.addEventListener("click", (e) => {
|
|
1418
|
-
const clear = e.target && e.target.closest ? e.target.closest(".c-input-group__clear") : null;
|
|
1419
|
-
if (clear && this.contains(clear)) {
|
|
1420
|
-
e.preventDefault();
|
|
1421
|
-
const input = this.querySelector("input.c-input");
|
|
1422
|
-
if (input) { input.value = ""; input.focus(); }
|
|
1423
|
-
if (this._internals) {
|
|
1424
|
-
this._internals.setFormValue("");
|
|
1425
|
-
this._syncValidity(this.hasAttribute("required"));
|
|
1426
|
-
}
|
|
1427
|
-
this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: "" } }));
|
|
1428
|
-
}
|
|
1429
|
-
});
|
|
1430
|
-
}
|
|
1431
|
-
}
|
|
1432
|
-
define("contour-input-group", ContourInputGroup);
|
|
1433
|
-
/**
|
|
1434
|
-
* RadioList: a `role="radiogroup"` of radio options from a JSON `items`
|
|
1435
|
-
* attribute (or remote `src`). Supports roving tabindex, Home/End navigation,
|
|
1436
|
-
* RTL, empty/loading/error states, and `formResetCallback` that re-renders from
|
|
1437
|
-
* the authored `items` payload. Form associated; emits `contour:change`.
|
|
1438
|
-
*/
|
|
1439
|
-
class ContourRadioList extends ContourBase {
|
|
1440
|
-
static get observed() { return ["items", "name", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1441
|
-
static get properties() { return { items: { attribute: "items" }, name: { attribute: "name" }, src: { attribute: "src" } }; }
|
|
1442
|
-
static get formAssociated() { return true; }
|
|
1443
|
-
render() {
|
|
1444
|
-
this.classList.add("c-radio-list");
|
|
1445
|
-
this.setAttribute("role", "radiogroup");
|
|
1446
|
-
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", this.getAttribute("name") || "Options");
|
|
1447
|
-
wireStates(this);
|
|
1448
|
-
loadRemote(this, "items");
|
|
1449
|
-
if (renderStates(this, "radio-list")) return;
|
|
1450
|
-
const items = remoteData(this, "items");
|
|
1451
|
-
Array.from(this.querySelectorAll("label.c-radio")).forEach((l) => l.remove());
|
|
1452
|
-
if (items) {
|
|
1453
|
-
try {
|
|
1454
|
-
const parsed = JSON.parse(items);
|
|
1455
|
-
const groupName = this.getAttribute("name") || contourId("radio-list");
|
|
1456
|
-
parsed.forEach((it) => {
|
|
1457
|
-
const lbl = document.createElement("label");
|
|
1458
|
-
lbl.className = "c-radio";
|
|
1459
|
-
const input = document.createElement("input");
|
|
1460
|
-
input.type = "radio";
|
|
1461
|
-
input.className = "c-radio__input";
|
|
1462
|
-
input.name = groupName;
|
|
1463
|
-
input.tabIndex = -1;
|
|
1464
|
-
if (typeof it === "string") { input.value = it; lbl.appendChild(input); lbl.appendChild(document.createTextNode(" " + it)); }
|
|
1465
|
-
else { input.value = it.value || it.label; if (it.checked) input.checked = true; lbl.appendChild(input); const span = document.createElement("span"); span.textContent = it.label || it.value; lbl.appendChild(span); }
|
|
1466
|
-
this.appendChild(lbl);
|
|
1467
|
-
});
|
|
1468
|
-
// Roving tabindex: only the checked item (or the first) is in the tab
|
|
1469
|
-
// order, exactly like a native radiogroup.
|
|
1470
|
-
const radios = Array.from(this.querySelectorAll("input.c-radio__input"));
|
|
1471
|
-
const checked = radios.find((r) => r.checked) || radios[0];
|
|
1472
|
-
if (checked) checked.tabIndex = 0;
|
|
1473
|
-
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
1474
|
-
} else {
|
|
1475
|
-
renderEmpty(this, "radio-list");
|
|
1476
|
-
}
|
|
1477
|
-
}
|
|
1478
|
-
enhance() {
|
|
1479
|
-
const sync = () => {
|
|
1480
|
-
if (!this._internals) return;
|
|
1481
|
-
const checked = this.querySelector("input.c-radio__input:checked");
|
|
1482
|
-
this._internals.setFormValue(checked ? checked.value : null);
|
|
1483
|
-
};
|
|
1484
|
-
sync();
|
|
1485
|
-
if (this._wiredRadioList) return;
|
|
1486
|
-
this._wiredRadioList = true;
|
|
1487
|
-
// Form life + group semantics, delegated on the host (rule 12): the
|
|
1488
|
-
// inputs are rebuilt on every render, so node-bound listeners would die.
|
|
1489
|
-
this.addEventListener("change", (e) => {
|
|
1490
|
-
const input = e.target && e.target.closest ? e.target.closest("input.c-radio__input") : null;
|
|
1491
|
-
if (!input || !this.contains(input)) return;
|
|
1492
|
-
sync();
|
|
1493
|
-
this._emitForm("contour:change");
|
|
1494
|
-
});
|
|
1495
|
-
this.addEventListener("keydown", (e) => {
|
|
1496
|
-
const radios = Array.from(this.querySelectorAll("input.c-radio__input"));
|
|
1497
|
-
if (!radios.length) return;
|
|
1498
|
-
const idx = radios.indexOf(e.target);
|
|
1499
|
-
if (idx === -1) return;
|
|
1500
|
-
const rtl = (this.getAttribute("dir") || document.documentElement.getAttribute("dir") || "").toLowerCase() === "rtl";
|
|
1501
|
-
let next = -1;
|
|
1502
|
-
if (e.key === "ArrowDown") next = (idx + 1) % radios.length;
|
|
1503
|
-
else if (e.key === "ArrowUp") next = (idx - 1 + radios.length) % radios.length;
|
|
1504
|
-
else if (e.key === "ArrowRight") next = rtl ? (idx - 1 + radios.length) % radios.length : (idx + 1) % radios.length;
|
|
1505
|
-
else if (e.key === "ArrowLeft") next = rtl ? (idx + 1) % radios.length : (idx - 1 + radios.length) % radios.length;
|
|
1506
|
-
else if (e.key === "Home") next = 0;
|
|
1507
|
-
else if (e.key === "End") next = radios.length - 1;
|
|
1508
|
-
else return;
|
|
1509
|
-
e.preventDefault();
|
|
1510
|
-
const before = radios.find((r) => r.checked);
|
|
1511
|
-
for (const r of radios) r.tabIndex = -1;
|
|
1512
|
-
radios[next].tabIndex = 0;
|
|
1513
|
-
radios[next].checked = true;
|
|
1514
|
-
radios[next].focus();
|
|
1515
|
-
sync();
|
|
1516
|
-
// Native radio groups fire change when an arrow moves the selection;
|
|
1517
|
-
// wrap-around onto the same radio is not a change.
|
|
1518
|
-
if (before !== radios[next]) this._emitForm("contour:change");
|
|
1519
|
-
});
|
|
1520
|
-
}
|
|
1521
|
-
formResetCallback() {
|
|
1522
|
-
// The authored default lives in the `items` payload (`it.checked`), not
|
|
1523
|
-
// in checked attributes on generated radios, so re-render from the data
|
|
1524
|
-
// rather than blanking every selection like the generic base reset.
|
|
1525
|
-
// Synchronous and under the resetting flag: the base class's checked
|
|
1526
|
-
// restore would otherwise resurrect the user's selection over the
|
|
1527
|
-
// payload (measured by the R20 form-participation arm).
|
|
1528
|
-
this._contourResetting = true;
|
|
1529
|
-
try {
|
|
1530
|
-
if (this.isConnected && this._contourAuthored) this.attributeChangedCallback("__rerender__", null, "");
|
|
1531
|
-
this._syncFormValue();
|
|
1532
|
-
} finally {
|
|
1533
|
-
this._contourResetting = false;
|
|
1534
|
-
}
|
|
1535
|
-
}
|
|
1536
|
-
}
|
|
1537
|
-
define("contour-radio-list", ContourRadioList);
|
|
1538
|
-
|
|
1539
|
-
// Fieldset: a <fieldset> with a <legend>, for grouping related controls. The
|
|
1540
|
-
// platform already draws the group boundary; the component wraps it so a
|
|
1541
|
-
// consumer can drop <contour-fieldset legend="…"> and get the semantics.
|
|
1542
|
-
class ContourFieldset extends ContourBase {
|
|
1543
|
-
static get observed() { return ["legend", "disabled"]; }
|
|
1544
|
-
static get properties() { return { legend: { attribute: "legend" }, disabled: { attribute: "disabled", type: Boolean } }; }
|
|
1545
|
-
render() {
|
|
1546
|
-
const fs = this.ensure("fieldset", () => { const el = document.createElement("fieldset"); el.className = "c-fieldset"; return el; });
|
|
1547
|
-
if (this.hasAttribute("disabled")) fs.setAttribute("disabled", ""); else fs.removeAttribute("disabled");
|
|
1548
|
-
const legend = this.getAttribute("legend");
|
|
1549
|
-
let lg = fs.querySelector("legend");
|
|
1550
|
-
if (legend) {
|
|
1551
|
-
if (!lg) { lg = document.createElement("legend"); lg.className = "c-fieldset__legend"; fs.prepend(lg); }
|
|
1552
|
-
lg.textContent = legend;
|
|
1553
|
-
} else if (lg) lg.remove();
|
|
1554
|
-
// Move authored children into the fieldset (light DOM).
|
|
1555
|
-
const authored = Array.from(this.children).filter((c) => c !== fs);
|
|
1556
|
-
if (authored.length) { authored.forEach((c) => fs.appendChild(c)); }
|
|
1557
|
-
}
|
|
1558
|
-
}
|
|
1559
|
-
define("contour-fieldset", ContourFieldset);
|
|
1560
|
-
|
|
1561
|
-
// Checkbox group: a fieldset of checkboxes with a shared name. Form
|
|
1562
|
-
// associated (R20 T-03): the host owns the group value — each checked box
|
|
1563
|
-
// submits as its own entry under the host name (the FormData form value),
|
|
1564
|
-
// `value` reflects the comma-joined selection, reset restores the authored
|
|
1565
|
-
// default, and `required` reports group validity. Emits contour:change with
|
|
1566
|
-
// { value, values }.
|
|
1567
|
-
class ContourCheckboxGroup extends ContourBase {
|
|
1568
|
-
static get observed() { return ["legend", "name", "options", "value", "required", "disabled"]; }
|
|
1569
|
-
static get properties() { return { legend: { attribute: "legend" }, name: { attribute: "name" }, options: { attribute: "options" }, value: { attribute: "value" }, required: { attribute: "required", type: Boolean }, disabled: { attribute: "disabled", type: Boolean } }; }
|
|
1570
|
-
static get formAssociated() { return true; }
|
|
1571
|
-
render() {
|
|
1572
|
-
this.classList.add("c-checkbox-group");
|
|
1573
|
-
// Authored default captured before any toggle reflects into `value`.
|
|
1574
|
-
if (this._checkboxGroupDefault === undefined) this._checkboxGroupDefault = this.getAttribute("value");
|
|
1575
|
-
const fs = this.ensure("fieldset", () => { const el = document.createElement("fieldset"); el.className = "c-checkbox-group__fieldset"; return el; });
|
|
1576
|
-
if (this.hasAttribute("disabled")) fs.setAttribute("disabled", ""); else fs.removeAttribute("disabled");
|
|
1577
|
-
if (this.hasAttribute("required")) fs.setAttribute("aria-required", "true"); else fs.removeAttribute("aria-required");
|
|
1578
|
-
const legend = this.getAttribute("legend");
|
|
1579
|
-
let lg = fs.querySelector("legend");
|
|
1580
|
-
if (legend) {
|
|
1581
|
-
if (!lg) { lg = document.createElement("legend"); lg.className = "c-checkbox-group__legend"; fs.prepend(lg); }
|
|
1582
|
-
lg.textContent = legend;
|
|
1583
|
-
} else if (lg) lg.remove();
|
|
1584
|
-
const name = this.getAttribute("name") || "group";
|
|
1585
|
-
const options = this.getAttribute("options");
|
|
1586
|
-
const selected = (this.getAttribute("value") || "").split(",").map((s) => s.trim()).filter(Boolean);
|
|
1587
|
-
if (options) {
|
|
1588
|
-
try {
|
|
1589
|
-
const parsed = JSON.parse(options);
|
|
1590
|
-
Array.from(fs.querySelectorAll(".c-check")).forEach((n) => n.remove());
|
|
1591
|
-
parsed.forEach((opt) => {
|
|
1592
|
-
const label = typeof opt === "string" ? opt : (opt.label || opt.value || "");
|
|
1593
|
-
const value = typeof opt === "string" ? opt : (opt.value || opt.label || "");
|
|
1594
|
-
const wrap = document.createElement("label");
|
|
1595
|
-
wrap.className = "c-check";
|
|
1596
|
-
const input = document.createElement("input");
|
|
1597
|
-
input.type = "checkbox";
|
|
1598
|
-
input.className = "c-check__input";
|
|
1599
|
-
input.name = name;
|
|
1600
|
-
input.value = value;
|
|
1601
|
-
// Every box shares the group name, so name-based focus matching
|
|
1602
|
-
// would land on the FIRST box after the reflection re-render; the
|
|
1603
|
-
// per-option preserve key puts focus back on the box clicked.
|
|
1604
|
-
input.setAttribute("data-contour-preserve-key", value);
|
|
1605
|
-
if (selected.includes(value)) input.checked = true;
|
|
1606
|
-
const span = document.createElement("span");
|
|
1607
|
-
span.textContent = label;
|
|
1608
|
-
wrap.appendChild(input);
|
|
1609
|
-
wrap.appendChild(span);
|
|
1610
|
-
fs.appendChild(wrap);
|
|
1611
|
-
});
|
|
1612
|
-
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
1613
|
-
}
|
|
1614
|
-
}
|
|
1615
|
-
enhance() {
|
|
1616
|
-
if (this._internals) this._syncFormValue();
|
|
1617
|
-
if (this._wiredCheckboxGroup) return;
|
|
1618
|
-
this._wiredCheckboxGroup = true;
|
|
1619
|
-
this.addEventListener("change", (e) => {
|
|
1620
|
-
const t = e.target;
|
|
1621
|
-
if (t && t.matches && t.matches("input[type=checkbox]")) {
|
|
1622
|
-
const values = Array.from(this.querySelectorAll("input[type=checkbox]:checked")).map((i) => i.value);
|
|
1623
|
-
// Reflect the group value so `el.value` reads the live selection and
|
|
1624
|
-
// a re-render rebuilds it; the attribute write re-renders synchronously.
|
|
1625
|
-
this.setAttribute("value", values.join(","));
|
|
1626
|
-
this._syncFormValue();
|
|
1627
|
-
this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: values.join(","), values } }));
|
|
1628
|
-
}
|
|
1629
|
-
});
|
|
1630
|
-
}
|
|
1631
|
-
// Each checked box is its own entry under the host name — the FormData
|
|
1632
|
-
// form value, which keeps the native repeated-entry wire shape while the
|
|
1633
|
-
// host owns reset and validity. The formdata re-sync calls THIS.
|
|
1634
|
-
_syncFormValue() {
|
|
1635
|
-
if (!this._internals) return;
|
|
1636
|
-
const checked = Array.from(this.querySelectorAll("input[type=checkbox]:checked"));
|
|
1637
|
-
const name = this.getAttribute("name");
|
|
1638
|
-
if (name && checked.length) {
|
|
1639
|
-
const fd = new FormData();
|
|
1640
|
-
for (const c of checked) fd.append(name, c.value);
|
|
1641
|
-
this._internals.setFormValue(fd);
|
|
1642
|
-
} else {
|
|
1643
|
-
this._internals.setFormValue(null);
|
|
1644
|
-
}
|
|
1645
|
-
this._syncValidity(this.hasAttribute("required") && !checked.length);
|
|
1646
|
-
}
|
|
1647
|
-
formResetCallback() {
|
|
1648
|
-
// Restore the authored default, not the last reflected selection.
|
|
1649
|
-
this._contourResetting = true;
|
|
1650
|
-
try {
|
|
1651
|
-
const def = this._checkboxGroupDefault ?? null;
|
|
1652
|
-
if (def === null) this.removeAttribute("value");
|
|
1653
|
-
else this.setAttribute("value", def);
|
|
1654
|
-
this._syncFormValue();
|
|
1655
|
-
} finally {
|
|
1656
|
-
this._contourResetting = false;
|
|
1657
|
-
}
|
|
1658
|
-
}
|
|
1659
|
-
formStateRestoreCallback(state) {
|
|
1660
|
-
const values = state instanceof FormData
|
|
1661
|
-
? Array.from(state.getAll(this.getAttribute("name"))).map(String)
|
|
1662
|
-
: (state == null ? [] : String(state).split(",").map((v) => v.trim()).filter(Boolean));
|
|
1663
|
-
this._contourResetting = true;
|
|
1664
|
-
try {
|
|
1665
|
-
this.setAttribute("value", values.join(","));
|
|
1666
|
-
this._syncFormValue();
|
|
1667
|
-
} finally {
|
|
1668
|
-
this._contourResetting = false;
|
|
1669
|
-
}
|
|
1670
|
-
}
|
|
1671
|
-
}
|
|
1672
|
-
define("contour-checkbox-group", ContourCheckboxGroup);
|
|
1673
|
-
|
|
1674
|
-
// Search field: a text input with a search icon and a clear button. The
|
|
1675
|
-
// platform's type=search gives the clear affordance; the component adds the
|
|
1676
|
-
// icon and the accessible name. Form associated (R20 T-04): the host submits
|
|
1677
|
-
// its value through ElementInternals, with reset and required validity.
|
|
1678
|
-
class ContourSearchField extends ContourBase {
|
|
1679
|
-
static get observed() { return ["value", "placeholder", "label", "name", "required", "disabled"]; }
|
|
1680
|
-
static get properties() { return { value: { attribute: "value" }, placeholder: { attribute: "placeholder" }, label: { attribute: "label" }, name: { attribute: "name" }, required: { attribute: "required", type: Boolean }, disabled: { attribute: "disabled", type: Boolean } }; }
|
|
1681
|
-
static get formAssociated() { return true; }
|
|
1682
|
-
render() {
|
|
1683
|
-
this.classList.add("c-search-field");
|
|
1684
|
-
const input = this.ensure("input", () => { const el = document.createElement("input"); el.type = "search"; el.className = "c-search-field__input"; return el; });
|
|
1685
|
-
input.placeholder = this.getAttribute("placeholder") || "Search";
|
|
1686
|
-
if (this.getAttribute("value") !== null) input.value = this.getAttribute("value");
|
|
1687
|
-
if (this.hasAttribute("name")) input.name = this.getAttribute("name");
|
|
1688
|
-
if (this.hasAttribute("required")) input.setAttribute("required", "");
|
|
1689
|
-
else input.removeAttribute("required");
|
|
1690
|
-
if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
|
|
1691
|
-
else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
|
|
1692
|
-
const label = this.getAttribute("label");
|
|
1693
|
-
if (label) input.setAttribute("aria-label", label);
|
|
1694
|
-
else if (!input.hasAttribute("aria-label")) input.setAttribute("aria-label", "Search");
|
|
1695
|
-
}
|
|
1696
|
-
enhance() {
|
|
1697
|
-
const input = this.querySelector("input");
|
|
1698
|
-
if (input && this._internals) {
|
|
1699
|
-
this._internals.setFormValue(input.value);
|
|
1700
|
-
this._syncValidity(this.hasAttribute("required") && !input.value.trim());
|
|
1701
|
-
}
|
|
1702
|
-
if (this._wiredSearchField) return;
|
|
1703
|
-
this._wiredSearchField = true;
|
|
1704
|
-
this.addEventListener("input", (e) => {
|
|
1705
|
-
const t = e.target;
|
|
1706
|
-
if (t && t.matches && t.matches("input")) {
|
|
1707
|
-
if (this._internals) {
|
|
1708
|
-
this._internals.setFormValue(t.value);
|
|
1709
|
-
this._syncValidity(this.hasAttribute("required") && !t.value.trim());
|
|
1710
|
-
}
|
|
1711
|
-
this._emitForm("contour:input");
|
|
1712
|
-
}
|
|
1713
|
-
});
|
|
1714
|
-
this.addEventListener("change", (e) => {
|
|
1715
|
-
const t = e.target;
|
|
1716
|
-
if (!t || !t.matches || !t.matches("input") || !this._internals) return;
|
|
1717
|
-
this._internals.setFormValue(t.value);
|
|
1718
|
-
this._emitForm("contour:change");
|
|
1719
|
-
this._syncValidity(this.hasAttribute("required") && !t.value.trim());
|
|
1720
|
-
});
|
|
1721
|
-
}
|
|
1722
|
-
}
|
|
1723
|
-
define("contour-search-field", ContourSearchField);
|
|
1724
|
-
|
|
1725
|
-
// Density toggle: a two-state control (comfortable / compact) that sets a
|
|
1726
|
-
// data-density attribute on the host. The consumer's CSS reads it.
|
|
1727
|
-
class ContourDensityToggle extends ContourBase {
|
|
1728
|
-
static get observed() { return ["value", "label"]; }
|
|
1729
|
-
static get properties() { return { value: { attribute: "value" }, label: { attribute: "label" } }; }
|
|
1730
|
-
render() {
|
|
1731
|
-
this.classList.add("c-density-toggle");
|
|
1732
|
-
const value = this.getAttribute("value") || "comfortable";
|
|
1733
|
-
this.setAttribute("data-density", value);
|
|
1734
|
-
const btn = this.ensure("button", () => { const el = document.createElement("button"); el.className = "c-btn c-btn--sm c-density-toggle__btn"; el.type = "button"; return el; });
|
|
1735
|
-
const label = this.getAttribute("label") || (value === "compact" ? "Compact" : "Comfortable");
|
|
1736
|
-
btn.textContent = label;
|
|
1737
|
-
btn.setAttribute("aria-pressed", value === "compact" ? "true" : "false");
|
|
1738
|
-
}
|
|
1739
|
-
enhance() {
|
|
1740
|
-
if (this._wiredDensityToggle) return;
|
|
1741
|
-
this._wiredDensityToggle = true;
|
|
1742
|
-
this.addEventListener("click", () => {
|
|
1743
|
-
const next = this.getAttribute("data-density") === "compact" ? "comfortable" : "compact";
|
|
1744
|
-
this.setAttribute("value", next);
|
|
1745
|
-
this.setAttribute("data-density", next);
|
|
1746
|
-
const btn = this.querySelector(".c-density-toggle__btn");
|
|
1747
|
-
if (btn) { btn.textContent = next === "compact" ? "Compact" : "Comfortable"; btn.setAttribute("aria-pressed", next === "compact" ? "true" : "false"); }
|
|
1748
|
-
this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: next } }));
|
|
1749
|
-
});
|
|
1750
|
-
}
|
|
1751
|
-
}
|
|
1752
|
-
define("contour-density-toggle", ContourDensityToggle);
|
|
2
|
+
* Forms family barrel — the form-control web components, split into semantic
|
|
3
|
+
* fragments. Importing this module registers every form component (the
|
|
4
|
+
* fragments are side-effectful: each defines its own custom elements). The
|
|
5
|
+
* build concatenates the fragments for the IIFE/ESM bundles; this barrel keeps
|
|
6
|
+
* `contour-ds/wc/forms.mjs` working for consumers who import the family by name.
|
|
7
|
+
*/
|
|
8
|
+
import "./forms-field.mjs";
|
|
9
|
+
import "./forms-controls.mjs";
|
|
10
|
+
import "./forms-input.mjs";
|
|
11
|
+
import "./forms-groups.mjs";
|