contour-ds 1.7.2 → 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 +244 -326
- package/dist/agent-cookbook.json +960 -0
- package/dist/agent-examples.json +65 -0
- package/dist/agent-map-wiring.json +152 -0
- package/dist/agent-rules.json +16 -0
- package/dist/build-manifest.json +344 -126
- package/dist/contour-wc-content.esm.js +1939 -0
- package/dist/contour-wc-content.esm.min.js +1 -0
- 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 +6986 -0
- package/dist/contour-wc-dashboard.esm.min.js +1 -0
- package/dist/contour-wc-data.esm.js +6572 -0
- package/dist/contour-wc-data.esm.min.js +1 -0
- package/dist/contour-wc-docs.esm.js +976 -0
- package/dist/contour-wc-docs.esm.min.js +1 -0
- package/dist/contour-wc-feedback.esm.js +1742 -0
- package/dist/contour-wc-feedback.esm.min.js +1 -0
- package/dist/contour-wc-forms.esm.js +2437 -0
- package/dist/contour-wc-forms.esm.min.js +1 -0
- package/dist/contour-wc-interaction.esm.js +1343 -0
- package/dist/contour-wc-interaction.esm.min.js +1 -0
- package/dist/contour-wc-layout.esm.js +845 -0
- package/dist/contour-wc-layout.esm.min.js +1 -0
- package/dist/contour-wc-map.esm.js +2411 -0
- package/dist/contour-wc-map.esm.min.js +1 -0
- package/dist/contour-wc-misc.esm.js +945 -0
- package/dist/contour-wc-misc.esm.min.js +1 -0
- package/dist/contour-wc-navigation.esm.js +2842 -0
- package/dist/contour-wc-navigation.esm.min.js +1 -0
- package/dist/contour-wc-ui.esm.js +6519 -0
- package/dist/contour-wc-ui.esm.min.js +1 -0
- package/dist/contour-wc.esm.js +14435 -5723
- package/dist/contour-wc.esm.min.js +1 -1
- package/dist/contour-wc.js +14436 -5725
- package/dist/contour-wc.min.js +1 -1
- package/dist/contour.a11y.json +402 -0
- package/dist/contour.code-snippets +4534 -0
- package/dist/contour.components.json +4870 -1222
- package/dist/contour.css +6672 -4711
- package/dist/contour.d.ts +753 -1085
- package/dist/contour.esm.js +440 -18
- package/dist/contour.esm.min.js +1 -1
- package/dist/contour.html-data.json +11343 -0
- package/dist/contour.js +440 -18
- package/dist/contour.min.css +1 -1
- package/dist/contour.min.js +1 -1
- package/dist/contour.react.d.ts +422 -0
- package/dist/contour.single.html +17 -0
- package/dist/contour.single.min.css +1 -0
- package/dist/contour.themes.json +56 -12
- package/dist/contour.tokens.json +1318 -1053
- package/dist/contour.vue.d.ts +420 -0
- package/dist/contour.web-types.json +11703 -0
- package/dist/custom-elements.json +36120 -0
- package/dist/docs/actions.md +16 -6
- package/dist/docs/affordances.md +21 -85
- package/dist/docs/apireference.md +9 -5
- package/dist/docs/colour.md +10 -4
- package/dist/docs/componentindex.md +9 -22
- package/dist/docs/data.md +39 -58
- package/dist/docs/docs.md +12 -7
- 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 +70 -61
- package/dist/docs/install.md +12 -7
- package/dist/docs/landing.md +7 -4
- package/dist/docs/mapengine.md +30 -8
- 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 +20 -10
- package/dist/docs/playground.md +11 -4
- package/dist/docs/principles.md +8 -6
- package/dist/docs/recipes.md +117 -13
- package/dist/docs/space.md +10 -6
- package/dist/docs/status.md +13 -14
- 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 +75 -33
- 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 +222 -192
- package/dist/wc/content.mjs +486 -142
- package/dist/wc/core.mjs +917 -395
- package/dist/wc/dashboard.mjs +252 -25
- 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 -3707
- package/dist/wc/docs.mjs +113 -19
- package/dist/wc/feedback.mjs +320 -116
- 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 -1122
- package/dist/wc/glyph.mjs +204 -0
- package/dist/wc/index.mjs +16 -7
- package/dist/wc/interaction.mjs +322 -75
- package/dist/wc/layout.mjs +100 -29
- package/dist/wc/map.mjs +888 -285
- package/dist/wc/misc.mjs +137 -26
- 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 -1636
- package/dist/wc/registration.mjs +1 -8
- package/dist/wc/shadow.mjs +285 -113
- package/dist/wc/states.mjs +75 -78
- package/dist/wc/svg.mjs +209 -34
- 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 +25 -5
- package/integrations/ai/CLAUDE.md +6 -3
- 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/frameworks/README.md +235 -0
- package/integrations/native/README.md +0 -3
- package/integrations/native/style-dictionary.config.json +1 -1
- package/integrations/tailwind/contour-theme.css +71 -13
- package/integrations/validate-markup.mjs +172 -0
- package/package.json +103 -39
- package/dist/wc/ui.mjs +0 -3560
package/dist/wc/behaviours.mjs
CHANGED
|
@@ -31,17 +31,31 @@
|
|
|
31
31
|
========================================================================= */
|
|
32
32
|
|
|
33
33
|
// `contourId` is the shared counter: a generated node that needs an id (a
|
|
34
|
-
|
|
35
|
-
// calling Math.random(), which can hand two instances the same id and then point
|
|
36
|
-
// one control at another's list.
|
|
37
|
-
import { contourId, supportsUntilFound, onDispose } from './core.mjs';
|
|
34
|
+
import { contourId, supportsUntilFound, onDispose, navKey, isRtl, labelText } from './core.mjs';
|
|
38
35
|
|
|
39
36
|
// A host is wired once per behaviour. Re-entering is normal — the base class
|
|
40
|
-
// calls enhance() after every render — so the guard lives in a WeakMap keyed on
|
|
41
|
-
// the node, where a re-render cannot drop it.
|
|
42
37
|
const WIRED_HOSTS = new WeakMap();
|
|
38
|
+
// R28-09 (CD-06): the listeners a behaviour attaches for a host. wcReset (the
|
|
39
|
+
const WIRED_LISTENERS = new WeakMap();
|
|
40
|
+
const wcTrack = (host, target, type, fn, options) => {
|
|
41
|
+
let arr = WIRED_LISTENERS.get(host);
|
|
42
|
+
if (!arr) { arr = []; WIRED_LISTENERS.set(host, arr); }
|
|
43
|
+
arr.push({ target, type, fn, options });
|
|
44
|
+
// Mark the listener as behaviour-managed so the light base class's host
|
|
45
|
+
try { fn._contourBehaviour = true; } catch (e) { /* frozen fn */ }
|
|
46
|
+
target.addEventListener(type, fn, options);
|
|
47
|
+
};
|
|
43
48
|
/** Reset the wired-host claim for a host, allowing re-wiring after disconnect. */
|
|
44
|
-
export const wcReset = (host) => {
|
|
49
|
+
export const wcReset = (host) => {
|
|
50
|
+
WIRED_HOSTS.delete(host);
|
|
51
|
+
const arr = WIRED_LISTENERS.get(host);
|
|
52
|
+
if (arr) {
|
|
53
|
+
for (const { target, type, fn, options } of arr) {
|
|
54
|
+
try { target.removeEventListener(type, fn, options); } catch (e) { /* already gone */ }
|
|
55
|
+
}
|
|
56
|
+
WIRED_LISTENERS.delete(host);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
45
59
|
const wcClaim = (host, name) => {
|
|
46
60
|
let set = WIRED_HOSTS.get(host);
|
|
47
61
|
if (!set) { set = new Set(); WIRED_HOSTS.set(host, set); }
|
|
@@ -62,18 +76,12 @@ const wcAll = (host, sel) => {
|
|
|
62
76
|
};
|
|
63
77
|
const wcOne = (host, sel) => wcAll(host, sel)[0] || null;
|
|
64
78
|
// A custom element carries its own block class, and `querySelectorAll` never
|
|
65
|
-
// returns the node it was called on, so a group element that IS the host has to
|
|
66
|
-
// be added explicitly or the light wrappers find no group at all.
|
|
67
79
|
const wcSelfOrAll = (host, sel) => {
|
|
68
80
|
const found = typeof host.matches === "function" && host.matches(sel) ? [host] : [];
|
|
69
81
|
for (const el of wcAll(host, sel)) if (!found.includes(el)) found.push(el);
|
|
70
82
|
return found;
|
|
71
83
|
};
|
|
72
84
|
// The flat tree is not the node tree. A group element inside a shadow root and
|
|
73
|
-
// the nodes slotted into it are in different trees, so `group.contains(node)` is
|
|
74
|
-
// false for exactly the authored content the group exists to hold. A group's
|
|
75
|
-
// nodes are therefore its own subtree plus, when the group is template-owned,
|
|
76
|
-
// the host's light DOM — which is what a reader actually slotted into it.
|
|
77
85
|
const wcShadowOf = (node) => {
|
|
78
86
|
const root = node && node.getRootNode ? node.getRootNode() : null;
|
|
79
87
|
return root && root.host ? root : null;
|
|
@@ -86,15 +94,6 @@ const wcGroup = (host, group, sel) => {
|
|
|
86
94
|
return found;
|
|
87
95
|
};
|
|
88
96
|
// Both scopes are listened to because retargeting is the asymmetry that decides
|
|
89
|
-
// where a node is visible from: a listener on the host sees the author's slotted
|
|
90
|
-
// nodes with their real target, but an event that started inside a shadow tree
|
|
91
|
-
// arrives there retargeted to the host, so `closest` finds nothing. The root
|
|
92
|
-
// listener sees those inner nodes unretargeted.
|
|
93
|
-
//
|
|
94
|
-
// A composed event is therefore heard twice on its way out, so each handler runs
|
|
95
|
-
// once per event — but keyed on the handler too. A set of events alone would let
|
|
96
|
-
// one component swallow the click of a component nested inside it, and each host
|
|
97
|
-
// owns its own interaction.
|
|
98
97
|
const HEARD = new WeakMap();
|
|
99
98
|
const wcListen = (host, type, handler) => {
|
|
100
99
|
const scoped = (e) => {
|
|
@@ -104,7 +103,7 @@ const wcListen = (host, type, handler) => {
|
|
|
104
103
|
seen.add(scoped);
|
|
105
104
|
handler(e);
|
|
106
105
|
};
|
|
107
|
-
for (const scope of wcScopes(host)) scope
|
|
106
|
+
for (const scope of wcScopes(host)) wcTrack(host, scope, type, scoped);
|
|
108
107
|
};
|
|
109
108
|
const wcOwned = (host, node) =>
|
|
110
109
|
!!node && wcScopes(host).some((scope) => scope.contains(node));
|
|
@@ -113,11 +112,6 @@ const wcOwned = (host, node) =>
|
|
|
113
112
|
const wcClosest = (host, target, sel) =>
|
|
114
113
|
(typeof target?.closest === "function" && wcOwned(host, target)) ? target.closest(sel) : null;
|
|
115
114
|
// Dispatched on the HOST, so a listener outside this layer hears it whatever the flag
|
|
116
|
-
// says — which is why an event reaching the document proves nothing about `composed`.
|
|
117
|
-
// The flag is for a boundary this layer does not own: A/B on a wrapper mounted inside a
|
|
118
|
-
// foreign component's shadow root, the option pressed in both runs, and the document
|
|
119
|
-
// heard the event in one of them — `composed: false` arrived 0 times, `composed: true`
|
|
120
|
-
// once. Consumers that wrap contour inside their own shadow tree are who it serves.
|
|
121
115
|
const wcEmit = (host, name, detail) => {
|
|
122
116
|
host.dispatchEvent(new CustomEvent(name, { detail, bubbles: true, composed: true }));
|
|
123
117
|
};
|
|
@@ -127,21 +121,6 @@ const wcEmit = (host, name, detail) => {
|
|
|
127
121
|
* The active tab is `[aria-selected="true"]`, which is the rule the sheet
|
|
128
122
|
* paints, so no state class is ever written — and none is invented either.
|
|
129
123
|
*/
|
|
130
|
-
// RTL awareness (BY2-A7): a horizontal control reverses its arrow keys in a
|
|
131
|
-
// right-to-left context, so ArrowRight moves to the previous item and
|
|
132
|
-
// ArrowLeft to the next. The direction is read from the host, then its
|
|
133
|
-
// nearest ancestor, then the document — the same cascade the platform uses.
|
|
134
|
-
function isRtl(host) {
|
|
135
|
-
let el = host;
|
|
136
|
-
while (el && el.nodeType === 1) {
|
|
137
|
-
const d = el.getAttribute && el.getAttribute("dir");
|
|
138
|
-
if (d) return d.toLowerCase() === "rtl";
|
|
139
|
-
el = el.parentElement;
|
|
140
|
-
}
|
|
141
|
-
try { return (document.documentElement.getAttribute("dir") || "").toLowerCase() === "rtl"; }
|
|
142
|
-
catch (e) { return false; }
|
|
143
|
-
}
|
|
144
|
-
|
|
145
124
|
/** Wire tab keyboard navigation and selection for a host. */
|
|
146
125
|
export function wireTabs(host) {
|
|
147
126
|
if (!wcClaim(host, "tabs")) return;
|
|
@@ -149,11 +128,10 @@ export function wireTabs(host) {
|
|
|
149
128
|
const isCode = list.classList.contains("c-code-tabs__list");
|
|
150
129
|
const panelSel = isCode ? ".c-code-tabs__panel" : ".c-tabs__panel";
|
|
151
130
|
// `list.contains(tab)` is the test that fails on a shadow wrapper: the list
|
|
152
|
-
// is in the root and the tabs the author wrote are slotted light DOM, so the
|
|
153
|
-
// node tree says they are unrelated even though the flat tree does not.
|
|
154
131
|
const tabsOf = () => wcGroup(host, list, "[role='tab']");
|
|
155
132
|
const activate = (tab, focus) => {
|
|
156
133
|
const tabs = tabsOf();
|
|
134
|
+
if (!tab.id) tab.id = contourId("c-tab");
|
|
157
135
|
tabs.forEach((t) => {
|
|
158
136
|
const selected = t === tab;
|
|
159
137
|
t.setAttribute("aria-selected", String(selected));
|
|
@@ -161,7 +139,12 @@ export function wireTabs(host) {
|
|
|
161
139
|
const ctrl = t.getAttribute("aria-controls");
|
|
162
140
|
if (!ctrl) return;
|
|
163
141
|
const panel = wcOne(host, "#" + CSS.escape(ctrl)) || document.getElementById(ctrl);
|
|
164
|
-
if (panel)
|
|
142
|
+
if (panel) {
|
|
143
|
+
panel.hidden = !selected;
|
|
144
|
+
// A tabpanel is named by its tab: without this a screen reader
|
|
145
|
+
// announces the panel with no name.
|
|
146
|
+
if (selected) panel.setAttribute("aria-labelledby", t.id);
|
|
147
|
+
}
|
|
165
148
|
});
|
|
166
149
|
const panels = wcAll(host, panelSel);
|
|
167
150
|
if (panels.length) {
|
|
@@ -169,34 +152,35 @@ export function wireTabs(host) {
|
|
|
169
152
|
panels.forEach((p, i) => { p.hidden = i !== index; });
|
|
170
153
|
}
|
|
171
154
|
if (focus) try { tab.focus(); } catch (e) { /* detached mid-key */ }
|
|
172
|
-
// Emit activation so consumers can observe tab changes (B3-10).
|
|
173
|
-
const name = tab.getAttribute("aria-controls") ||
|
|
155
|
+
// Emit activation so consumers can observe tab changes (B3-10). The label
|
|
156
|
+
const name = tab.textContent.trim() || tab.getAttribute("aria-controls") || "";
|
|
174
157
|
host.dispatchEvent(new CustomEvent("contour:tab-change", { bubbles: true, composed: true, detail: { index: tabs.indexOf(tab), label: name } }));
|
|
175
158
|
};
|
|
176
|
-
// Same-document View Transitions (BY-24). A
|
|
177
|
-
// `data-view-transition` / `--view-transition-name` gets a cross-fade on a
|
|
178
|
-
// tab swap; the morph must run inside startViewTransition so the browser
|
|
179
|
-
// has an old and a new state to interpolate. The initial mount activation
|
|
180
|
-
// below stays direct — a transition on load is a page fade nobody asked
|
|
181
|
-
// for — and the plain swap is the entire fallback, because the CSS harness
|
|
182
|
-
// (components.css) is enhancement-only too.
|
|
159
|
+
// Same-document View Transitions (BY-24). A tab swap runs inside
|
|
183
160
|
const runActivation = (tab, focus) => {
|
|
184
161
|
// Keyboard activation must update aria-selected synchronously so assistive
|
|
185
|
-
// tech and keyboard users see the new state immediately; view transitions
|
|
186
|
-
// are a visual enhancement and must not defer the state change (a deferred
|
|
187
|
-
// activation leaves the previous tab marked selected until the transition
|
|
188
|
-
// callback runs, which breaks keyboard roving and any synchronous test).
|
|
189
162
|
const can = !focus && typeof document.startViewTransition === "function"
|
|
190
163
|
&& !(typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches);
|
|
191
164
|
if (can) {
|
|
192
|
-
try {
|
|
165
|
+
try {
|
|
166
|
+
const vt = document.startViewTransition(() => activate(tab, focus));
|
|
167
|
+
if (vt && vt.ready) vt.ready.catch(() => {});
|
|
168
|
+
if (vt && vt.finished) vt.finished.catch(() => {});
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
193
171
|
catch (e) { /* an in-flight transition or a private context: plain swap */ }
|
|
194
172
|
}
|
|
195
173
|
activate(tab, focus);
|
|
196
174
|
};
|
|
197
175
|
wcListen(host, "click", (e) => {
|
|
198
176
|
const tab = wcClosest(host, e.target, "[role='tab']");
|
|
199
|
-
if (tab && tabsOf().includes(tab))
|
|
177
|
+
if (tab && tabsOf().includes(tab)) {
|
|
178
|
+
// A button nested inside a tab (a close control, say) is its own
|
|
179
|
+
// target: activating the tab underneath it would be a surprise.
|
|
180
|
+
const inner = e.target && e.target.closest ? e.target.closest("button") : null;
|
|
181
|
+
if (inner && inner !== tab && tab.contains(inner)) return;
|
|
182
|
+
runActivation(tab, false);
|
|
183
|
+
}
|
|
200
184
|
});
|
|
201
185
|
wcListen(host, "keydown", (e) => {
|
|
202
186
|
let tab = wcClosest(host, e.target, "[role='tab']");
|
|
@@ -219,10 +203,6 @@ export function wireTabs(host) {
|
|
|
219
203
|
if (next) runActivation(next, true);
|
|
220
204
|
});
|
|
221
205
|
// Respect an author-marked selected tab; fall back to the first. With
|
|
222
|
-
// `persist="storage"` (BY-49) the last user choice wins over both, so a
|
|
223
|
-
// reload lands on the tab the reader left. The key is the host id (a
|
|
224
|
-
// stable identity the author provides); without one persistence is a
|
|
225
|
-
// no-op rather than a collision across every unnamed tabs instance.
|
|
226
206
|
const tabs = tabsOf();
|
|
227
207
|
const persist = host.getAttribute("persist");
|
|
228
208
|
let restored = null;
|
|
@@ -244,11 +224,11 @@ export function wireTabs(host) {
|
|
|
244
224
|
if (first) activate(first, false);
|
|
245
225
|
// Persist on every subsequent activation.
|
|
246
226
|
if (persist === "storage" && host.id) {
|
|
247
|
-
host
|
|
227
|
+
wcTrack(host, host, "contour:tab-change", (e) => {
|
|
248
228
|
try { localStorage.setItem("contour-tabs:" + host.id, String(e.detail && e.detail.index)); } catch (err) { /* quota/private mode */ }
|
|
249
229
|
});
|
|
250
230
|
} else if (persist === "url") {
|
|
251
|
-
host
|
|
231
|
+
wcTrack(host, host, "contour:tab-change", (e) => {
|
|
252
232
|
try {
|
|
253
233
|
const url = new URL(window.location.href);
|
|
254
234
|
url.searchParams.set("c-tabs", String(e.detail && e.detail.index));
|
|
@@ -268,20 +248,8 @@ export function wireTabs(host) {
|
|
|
268
248
|
export function wireSegmented(host) {
|
|
269
249
|
const groups = wcSelfOrAll(host, ".c-segmented");
|
|
270
250
|
// The block's contract is the option class, a group role and an explicit
|
|
271
|
-
// pressed state — that is what the sheet styles (`.c-segmented__option
|
|
272
|
-
// [aria-pressed="true"]`) and what the guide's raw specimens write by hand. A
|
|
273
|
-
// wrapper that only classes the host leaves the author's buttons unstyled:
|
|
274
|
-
// measured in §23, three buttons with no class and no `aria-pressed` at all.
|
|
275
|
-
// Normalised here, on every pass, so both layers and slotted markup agree.
|
|
276
251
|
const normalize = () => {
|
|
277
252
|
// Who owns the pressed state. The author's `value` wins when it CHANGES — an
|
|
278
|
-
// attribute the author writes again is a new instruction — and the reader's own
|
|
279
|
-
// click wins in between, because the pressed attribute on the option is that
|
|
280
|
-
// choice and these buttons are the author's nodes, which survive a re-render.
|
|
281
|
-
// The one remembered value is what makes both halves hold: without it a click
|
|
282
|
-
// would move the state and the next re-render would move it back to `value`;
|
|
283
|
-
// with a bare "reader has picked" flag, an author writing `value` later would
|
|
284
|
-
// be ignored forever.
|
|
285
253
|
const authored = host.getAttribute("value");
|
|
286
254
|
const chosen = authored !== host._segAuthorValue ? authored : null;
|
|
287
255
|
if (chosen !== null) host._segAuthorValue = authored;
|
|
@@ -304,13 +272,6 @@ export function wireSegmented(host) {
|
|
|
304
272
|
return seen;
|
|
305
273
|
};
|
|
306
274
|
// A classic `<script src="dist/contour-wc.js">` in `<head>` upgrades the host
|
|
307
|
-
// while the parser is still inside it, so the author's buttons do not exist yet
|
|
308
|
-
// and this pass normalises nothing — measured across three arms: head gave 0
|
|
309
|
-
// option classes, 0 pressed states and 2 tab stops, where the same bundle with
|
|
310
|
-
// `defer` and the ESM entry (deferred by spec) both gave 2, 2, 1. The listeners
|
|
311
|
-
// below are unaffected because they delegate on the host, which outlives the
|
|
312
|
-
// parse. One retry on a later task is all the missing children need; a group
|
|
313
|
-
// that is genuinely empty just re-runs an idempotent pass once.
|
|
314
275
|
if (!normalize()) {
|
|
315
276
|
if (!host._segRetryScheduled) {
|
|
316
277
|
host._segRetryScheduled = true;
|
|
@@ -322,9 +283,6 @@ export function wireSegmented(host) {
|
|
|
322
283
|
const seg = groups.find((g) => wcGroup(host, g, "button").includes(btn));
|
|
323
284
|
if (!seg) return;
|
|
324
285
|
// `value` is deliberately not written back to the host here: it sits in the
|
|
325
|
-
// shared OBSERVED list, so writing it would spend a full re-render on every
|
|
326
|
-
// click. The pressed attribute on the option is the state, and it survives a
|
|
327
|
-
// re-render because these buttons are the author's nodes, not generated ones.
|
|
328
286
|
wcGroup(host, seg, "button").forEach((o) => {
|
|
329
287
|
const on = o === btn;
|
|
330
288
|
o.setAttribute("aria-pressed", String(on));
|
|
@@ -343,15 +301,7 @@ export function wireSegmented(host) {
|
|
|
343
301
|
const seg = groups.find((g) => wcGroup(host, g, "button").includes(btn));
|
|
344
302
|
if (!seg) return;
|
|
345
303
|
const opts = wcGroup(host, seg, "button");
|
|
346
|
-
|
|
347
|
-
let next = -1;
|
|
348
|
-
const rtl = isRtl(host);
|
|
349
|
-
if (e.key === "ArrowRight" || e.key === "ArrowDown") next = rtl ? Math.max(idx - 1, 0) : Math.min(idx + 1, opts.length - 1);
|
|
350
|
-
else if (e.key === "ArrowLeft" || e.key === "ArrowUp") next = rtl ? Math.min(idx + 1, opts.length - 1) : Math.max(idx - 1, 0);
|
|
351
|
-
else if (e.key === "Home") next = 0;
|
|
352
|
-
else if (e.key === "End") next = opts.length - 1;
|
|
353
|
-
else if (e.key === "Enter" || e.key === " ") { e.preventDefault(); activate(btn); return; }
|
|
354
|
-
if (next >= 0 && next !== idx) { e.preventDefault(); opts[next].focus(); }
|
|
304
|
+
navKey(e, opts, { wrap: false, homeEnd: true, rtl: isRtl(host), onNavigate: (i) => activate(opts[i]), onKey: (key) => { if (key === "Enter" || key === " ") activate(btn); } });
|
|
355
305
|
});
|
|
356
306
|
}
|
|
357
307
|
|
|
@@ -369,10 +319,6 @@ export function wireCombobox(host) {
|
|
|
369
319
|
const optionList = () => wcAll(host, ".c-combobox__option");
|
|
370
320
|
|
|
371
321
|
// Roles are re-applied on every pass, not claimed once. A re-render drops the
|
|
372
|
-
// generated input and list and rebuilds them, so an attribute set on the first
|
|
373
|
-
// pass is simply gone; the roles also belong to the markup, which the shared
|
|
374
|
-
// implementation is what both layers have in common. Idempotent, so re-running
|
|
375
|
-
// it cannot stack anything.
|
|
376
322
|
if (!list.id) list.id = contourId("c-combobox-list");
|
|
377
323
|
list.setAttribute("role", "listbox");
|
|
378
324
|
input.setAttribute("role", "combobox");
|
|
@@ -387,22 +333,20 @@ export function wireCombobox(host) {
|
|
|
387
333
|
});
|
|
388
334
|
|
|
389
335
|
// Listeners are claimed once, and they are delegated on the HOST for the same
|
|
390
|
-
// reason the other behaviours are: a listener bound to the generated input died
|
|
391
|
-
// with it on the next render while the per-host claim was already spent, so a
|
|
392
|
-
// combobox that changed any attribute stopped opening and stopped answering the
|
|
393
|
-
// arrow keys. Measured: fresh -> openedOnFocus true, activeOptionCount 1; after
|
|
394
|
-
// a placeholder change -> false and 0. The host outlives every rebuild, so the
|
|
395
|
-
// nodes are looked up again per event instead of captured.
|
|
396
336
|
if (!wcClaim(host, "combobox")) return;
|
|
397
337
|
const liveInput = () => wcOne(host, ".c-combobox__input");
|
|
398
338
|
const liveList = () => wcOne(host, ".c-combobox__list");
|
|
399
339
|
let cursor = -1;
|
|
400
340
|
const mark = (visible) => {
|
|
401
341
|
const field = liveInput();
|
|
342
|
+
// R31-05: in a multi-select the cursor is tracked by aria-activedescendant
|
|
343
|
+
// and the --active class; aria-selected is the SELECTION and must survive
|
|
344
|
+
// arrowing and Escape. Only a single-select listbox conflates the two.
|
|
345
|
+
const multiple = host.hasAttribute("multiple");
|
|
402
346
|
visible.forEach((o, i) => {
|
|
403
347
|
const on = i === cursor;
|
|
404
348
|
o.classList.toggle("c-combobox__option--active", on);
|
|
405
|
-
o.setAttribute("aria-selected", String(on));
|
|
349
|
+
if (!multiple) o.setAttribute("aria-selected", String(on));
|
|
406
350
|
});
|
|
407
351
|
if (field) {
|
|
408
352
|
const active = cursor >= 0 ? visible[cursor] : null;
|
|
@@ -419,12 +363,46 @@ export function wireCombobox(host) {
|
|
|
419
363
|
}
|
|
420
364
|
optionList().forEach((o) => { o.hidden = !!(q && !o.textContent.toLowerCase().includes(q)); });
|
|
421
365
|
cursor = -1;
|
|
366
|
+
// R31-24: an authored list that matches nothing used to render as an empty
|
|
367
|
+
// box — indistinguishable from a list that has not loaded. The virtual
|
|
368
|
+
// renderer already says "No matches"; this is the same row for the
|
|
369
|
+
// authored path.
|
|
370
|
+
const list = liveList();
|
|
371
|
+
if (!list) return;
|
|
372
|
+
const total = optionList().length;
|
|
373
|
+
const visible = optionList().filter((o) => !o.hidden).length;
|
|
374
|
+
const empty = list.querySelector(".c-combobox__empty");
|
|
375
|
+
if (total > 0 && visible === 0) {
|
|
376
|
+
if (!empty) {
|
|
377
|
+
const row = document.createElement(list.tagName === "UL" || list.tagName === "OL" ? "li" : "div");
|
|
378
|
+
row.className = "c-combobox__empty";
|
|
379
|
+
// A listbox may only contain `option`, so the row is a disabled option
|
|
380
|
+
// rather than a live region: `role="status"` here is an axe violation
|
|
381
|
+
// (aria-required-children) and an option that cannot be chosen says the
|
|
382
|
+
// same thing to a screen reader walking the list.
|
|
383
|
+
row.setAttribute("role", "option");
|
|
384
|
+
row.setAttribute("aria-disabled", "true");
|
|
385
|
+
row.setAttribute("aria-selected", "false");
|
|
386
|
+
row.textContent = labelText(host, "no-matches", "No matches");
|
|
387
|
+
list.appendChild(row);
|
|
388
|
+
}
|
|
389
|
+
} else if (empty) empty.remove();
|
|
422
390
|
};
|
|
423
391
|
const open = () => {
|
|
424
392
|
const l = liveList();
|
|
425
393
|
if (!l) return;
|
|
426
|
-
l.removeAttribute("hidden");
|
|
427
394
|
const field = liveInput();
|
|
395
|
+
// Fixed positioning from the input rect: the list escapes any ancestor
|
|
396
|
+
// overflow:hidden that would clip an absolutely-positioned list.
|
|
397
|
+
if (field) {
|
|
398
|
+
const r = field.getBoundingClientRect();
|
|
399
|
+
l.style.position = "fixed";
|
|
400
|
+
l.style.insetBlockStart = `${Math.round(r.bottom + 4)}px`;
|
|
401
|
+
l.style.insetInlineStart = `${Math.round(r.left)}px`;
|
|
402
|
+
l.style.insetInlineEnd = "auto";
|
|
403
|
+
l.style.inlineSize = `${Math.round(r.width)}px`;
|
|
404
|
+
}
|
|
405
|
+
l.removeAttribute("hidden");
|
|
428
406
|
if (field) field.setAttribute("aria-expanded", "true");
|
|
429
407
|
};
|
|
430
408
|
const close = () => {
|
|
@@ -436,12 +414,12 @@ export function wireCombobox(host) {
|
|
|
436
414
|
field.removeAttribute("aria-activedescendant");
|
|
437
415
|
}
|
|
438
416
|
cursor = -1;
|
|
439
|
-
//
|
|
440
|
-
//
|
|
441
|
-
|
|
417
|
+
// R31-05: clear the cursor highlight, but keep the multi-select selection —
|
|
418
|
+
// Escape/close must not wipe the aria-selected the consumer picked.
|
|
419
|
+
const multiple = host.hasAttribute("multiple");
|
|
442
420
|
optionList().forEach((o) => {
|
|
443
421
|
o.classList.remove("c-combobox__option--active");
|
|
444
|
-
o.setAttribute("aria-selected", "false");
|
|
422
|
+
if (!multiple) o.setAttribute("aria-selected", "false");
|
|
445
423
|
});
|
|
446
424
|
};
|
|
447
425
|
if (host._comboboxVirtual && list && !list._contourVirtualScroll) {
|
|
@@ -460,7 +438,7 @@ export function wireCombobox(host) {
|
|
|
460
438
|
const selected = (host.getAttribute("value") || "").split(",").map((v) => v.trim()).filter(Boolean);
|
|
461
439
|
const value = host._comboboxVirtual && host._comboboxFiltered
|
|
462
440
|
? host._comboboxFiltered.find((item) => item.index === Number(opt.dataset.optionIndex))?.value
|
|
463
|
-
: opt.textContent.trim();
|
|
441
|
+
: (opt.dataset.optionValue != null ? opt.dataset.optionValue : opt.textContent.trim());
|
|
464
442
|
const position = selected.indexOf(String(value));
|
|
465
443
|
if (now && position >= 0) selected.splice(position, 1);
|
|
466
444
|
if (!now && position < 0) selected.push(String(value));
|
|
@@ -470,15 +448,18 @@ export function wireCombobox(host) {
|
|
|
470
448
|
field.focus();
|
|
471
449
|
return;
|
|
472
450
|
}
|
|
451
|
+
// Commit the option's value, not its label: the field shows the label, the
|
|
452
|
+
// form submits the value, and `contour:select` carries the value.
|
|
453
|
+
const value = opt.dataset.optionValue != null ? opt.dataset.optionValue : opt.textContent.trim();
|
|
473
454
|
field.value = opt.textContent;
|
|
474
|
-
|
|
455
|
+
host.setAttribute("value", value);
|
|
456
|
+
if (typeof host._syncFormValue === "function") host._syncFormValue();
|
|
457
|
+
wcEmit(host, "contour:select", { value });
|
|
475
458
|
close();
|
|
476
459
|
field.focus();
|
|
477
460
|
};
|
|
478
461
|
|
|
479
462
|
// `input` and `focus` do not both bubble out of a shadow root in the same way,
|
|
480
|
-
// so `focusin` is what the focus-driven open listens to, and every handler
|
|
481
|
-
// checks the event actually came from this host's field.
|
|
482
463
|
const isField = (target) => wcClosest(host, target, ".c-combobox__input") !== null;
|
|
483
464
|
wcListen(host, "input", (e) => {
|
|
484
465
|
if (!isField(e.target)) return;
|
|
@@ -512,8 +493,6 @@ export function wireCombobox(host) {
|
|
|
512
493
|
}
|
|
513
494
|
|
|
514
495
|
// Outside-click dismissal for comboboxes. A single document listener is cheaper and
|
|
515
|
-
// leak-free compared to one per instance; it closes every open list whose host
|
|
516
|
-
// does not contain the click target.
|
|
517
496
|
let _comboboxDocWired = false;
|
|
518
497
|
function wireComboboxDocDismiss() {
|
|
519
498
|
if (_comboboxDocWired) return;
|
|
@@ -542,12 +521,6 @@ const visibleStops = (host) => wcAll(host, ".c-tree__toggle, .c-tree__leaf").fil
|
|
|
542
521
|
/** Wire tree toggle and keyboard navigation for a host. */
|
|
543
522
|
export function wireTree(host) {
|
|
544
523
|
// The ARIA shape and the tab stop are re-applied on every pass, before the
|
|
545
|
-
// claim. Two reasons, both measured on the shipped guide: the generated items
|
|
546
|
-
// carried `role="tree"` on the list and NO `role="treeitem"` anywhere, so the
|
|
547
|
-
// structure announced nothing to a screen reader; and every toggle and leaf was
|
|
548
|
-
// stamped `tabindex="-1"` with nothing ever set to 0, so the tree had no tab
|
|
549
|
-
// stop and a keyboard reader could not reach it at all. Roles cannot be guarded
|
|
550
|
-
// by a one-shot claim, because a re-render rebuilds the nodes that carry them.
|
|
551
524
|
const nodes = () => wcAll(host, ".c-tree__node");
|
|
552
525
|
const rootList = wcSelfOrAll(host, "ul.c-tree")[0];
|
|
553
526
|
if (rootList && !rootList.hasAttribute("role")) rootList.setAttribute("role", "tree");
|
|
@@ -567,12 +540,6 @@ export function wireTree(host) {
|
|
|
567
540
|
else if (node.hasAttribute("aria-expanded")) node.removeAttribute("aria-expanded");
|
|
568
541
|
});
|
|
569
542
|
// Exactly one tab stop. The author's own `tabindex="0"` is the choice, then the
|
|
570
|
-
// element that already holds focus, then the first item — in that order, so the
|
|
571
|
-
// invariant (one stop, never none, never N) holds without overriding intent.
|
|
572
|
-
// Only the VISIBLE items count: a collapsed branch is `hidden`, and a stop on a
|
|
573
|
-
// node the browser will not focus is a stop the reader never reaches. Measured
|
|
574
|
-
// when this was missed — ArrowDown left focus on item 0 and moved the stop onto
|
|
575
|
-
// a hidden child, so the tree reported one tab stop that nothing could hold.
|
|
576
543
|
const stops = visibleStops(host);
|
|
577
544
|
const authored = stops.find((el) => el.getAttribute("tabindex") === "0");
|
|
578
545
|
const active = authored || stops.find((el) => el === document.activeElement) || stops[0];
|
|
@@ -587,37 +554,53 @@ export function wireTree(host) {
|
|
|
587
554
|
// Checkbox selection (F-08): track checked nodes and emit contour:select.
|
|
588
555
|
host._selectedTree = host._selectedTree || new Set();
|
|
589
556
|
let lastTreeIndex = -1;
|
|
557
|
+
let treeModShift = false;
|
|
558
|
+
let treeModCtrl = false;
|
|
559
|
+
wcListen(host, "pointerdown", (e) => {
|
|
560
|
+
treeModShift = Boolean(e.shiftKey);
|
|
561
|
+
treeModCtrl = Boolean(e.ctrlKey || e.metaKey);
|
|
562
|
+
});
|
|
563
|
+
wcListen(host, "keydown", (e) => {
|
|
564
|
+
treeModShift = Boolean(e.shiftKey);
|
|
565
|
+
treeModCtrl = Boolean(e.ctrlKey || e.metaKey);
|
|
566
|
+
});
|
|
590
567
|
wcListen(host, "change", (e) => {
|
|
591
568
|
const cb = e.target && e.target.closest ? e.target.closest(".c-tree__select") : null;
|
|
592
569
|
if (!cb || !host.contains(cb)) return;
|
|
593
570
|
const cbs = Array.from(host.querySelectorAll(".c-tree__select"));
|
|
594
571
|
const idx = cbs.indexOf(cb);
|
|
595
|
-
const
|
|
596
|
-
|
|
572
|
+
const nodeOf = (el) => el && el.closest ? el.closest(".c-tree__node") : null;
|
|
573
|
+
const pathOf = (el) => { const n = nodeOf(el); return n && n.dataset ? n.dataset.path : null; };
|
|
574
|
+
const path = pathOf(cb);
|
|
575
|
+
const shift = Boolean(e.shiftKey || treeModShift);
|
|
576
|
+
const mod = Boolean(e.ctrlKey || e.metaKey || treeModCtrl);
|
|
577
|
+
treeModShift = false;
|
|
578
|
+
treeModCtrl = false;
|
|
579
|
+
if (shift && lastTreeIndex >= 0) {
|
|
597
580
|
const from = Math.min(lastTreeIndex, idx);
|
|
598
581
|
const to = Math.max(lastTreeIndex, idx);
|
|
599
582
|
for (let i = from; i <= to; i++) {
|
|
600
583
|
cbs[i].checked = cb.checked;
|
|
601
|
-
const
|
|
602
|
-
if (cb.checked) host._selectedTree.add(
|
|
584
|
+
const p = pathOf(cbs[i]);
|
|
585
|
+
if (p) { if (cb.checked) host._selectedTree.add(p); else host._selectedTree.delete(p); }
|
|
603
586
|
}
|
|
604
|
-
} else if (!
|
|
587
|
+
} else if (!mod) {
|
|
605
588
|
// single select: clear others unless ctrl
|
|
606
589
|
if (cb.checked) {
|
|
607
590
|
cbs.forEach((c, i) => {
|
|
608
591
|
if (i !== idx && c.checked) {
|
|
609
592
|
c.checked = false;
|
|
610
|
-
const
|
|
611
|
-
host._selectedTree.delete(
|
|
593
|
+
const p = pathOf(c);
|
|
594
|
+
if (p) host._selectedTree.delete(p);
|
|
612
595
|
}
|
|
613
596
|
});
|
|
614
597
|
}
|
|
615
|
-
if (cb.checked) host._selectedTree.add(
|
|
598
|
+
if (path) { if (cb.checked) host._selectedTree.add(path); else host._selectedTree.delete(path); }
|
|
616
599
|
} else {
|
|
617
|
-
if (cb.checked) host._selectedTree.add(
|
|
600
|
+
if (path) { if (cb.checked) host._selectedTree.add(path); else host._selectedTree.delete(path); }
|
|
618
601
|
}
|
|
619
602
|
lastTreeIndex = idx;
|
|
620
|
-
wcEmit(host, "contour:select", {
|
|
603
|
+
wcEmit(host, "contour:select", { paths: Array.from(host._selectedTree) });
|
|
621
604
|
});
|
|
622
605
|
// Drag-and-drop (F-08): nodes are draggable; drop emits contour:move.
|
|
623
606
|
wcAll(host, ".c-tree__node, .c-tree__leaf").forEach((n) => { if (!n.hasAttribute("draggable")) n.setAttribute("draggable", "true"); });
|
|
@@ -645,11 +628,6 @@ export function wireTree(host) {
|
|
|
645
628
|
dragLabel = null;
|
|
646
629
|
});
|
|
647
630
|
// Expanded-state persistence (BY-49), one path per component like tabs:
|
|
648
|
-
// restore runs once at connect, the write fires from the same handler that
|
|
649
|
-
// emits contour:toggle. Identity is the emitted label — the row's text
|
|
650
|
-
// trimmed and sliced to 120 chars — because the generated DOM stamps no node
|
|
651
|
-
// ids (route table tmp/persist-route-table.md). Storage requires a host id;
|
|
652
|
-
// url mode is the single `c-tree` search param, never a hash write.
|
|
653
631
|
const persist = host.getAttribute("persist");
|
|
654
632
|
if (persist === "storage" && host.id) {
|
|
655
633
|
try {
|
|
@@ -744,7 +722,24 @@ export function wireTree(host) {
|
|
|
744
722
|
const rove = (keep) => {
|
|
745
723
|
wcAll(host, ".c-tree__toggle, .c-tree__leaf").forEach((el) => el.setAttribute("tabindex", el === keep ? "0" : "-1"));
|
|
746
724
|
};
|
|
725
|
+
// R24-17: virtual trees render from host._expanded (a Set of paths), so a
|
|
726
|
+
const virtualToggle = (toggle, open) => {
|
|
727
|
+
const nodeEl = toggle.closest(".c-tree__node");
|
|
728
|
+
const path = nodeEl && nodeEl.dataset ? nodeEl.dataset.path : null;
|
|
729
|
+
if (path && host._expanded) { if (open) host._expanded.add(path); else host._expanded.delete(path); }
|
|
730
|
+
const s = host._treeRoot;
|
|
731
|
+
if (s) {
|
|
732
|
+
host._treeScrollTop = s.scrollTop || 0;
|
|
733
|
+
host._renderWindow(s, host._treeScrollTop);
|
|
734
|
+
try { s.scrollTop = host._treeScrollTop; } catch (err) {}
|
|
735
|
+
const again = path ? s.querySelector('.c-tree__node[data-path="' + path + '"] > .c-tree__row > .c-tree__toggle') : null;
|
|
736
|
+
if (again) { again.focus(); rove(again); }
|
|
737
|
+
}
|
|
738
|
+
if (host._persistExpanded) host._persistExpanded();
|
|
739
|
+
};
|
|
747
740
|
wcListen(host, "click", (e) => {
|
|
741
|
+
// Virtual trees are handled by ContourTree's own click handler in
|
|
742
|
+
if (host.hasAttribute("virtual")) return;
|
|
748
743
|
let toggle = wcClosest(host, e.target, ".c-tree__toggle");
|
|
749
744
|
if (!toggle) {
|
|
750
745
|
const row = wcClosest(host, e.target, ".c-tree__row");
|
|
@@ -766,7 +761,27 @@ export function wireTree(host) {
|
|
|
766
761
|
const items = stopsOf();
|
|
767
762
|
const idx = items.indexOf(toggle);
|
|
768
763
|
if (e.key === "Enter" || e.key === " ") {
|
|
769
|
-
|
|
764
|
+
const branch = branchOf(toggle);
|
|
765
|
+
if (branch) {
|
|
766
|
+
e.preventDefault();
|
|
767
|
+
if (host.hasAttribute("virtual")) {
|
|
768
|
+
// Virtual trees own their model + re-render; drive it directly.
|
|
769
|
+
virtualToggle(branch, branch.getAttribute("aria-expanded") !== "true");
|
|
770
|
+
} else {
|
|
771
|
+
toggleNode(branch);
|
|
772
|
+
}
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
// R24-73: keyboard selection of a leaf matches clicking its checkbox, so
|
|
776
|
+
// click and keyboard behave consistently.
|
|
777
|
+
if (host.hasAttribute("selectable")) {
|
|
778
|
+
const leaf = toggle.classList.contains("c-tree__leaf") ? toggle : toggle.closest(".c-tree__leaf");
|
|
779
|
+
const cb = leaf ? leaf.querySelector(".c-tree__select") : null;
|
|
780
|
+
if (cb) {
|
|
781
|
+
e.preventDefault();
|
|
782
|
+
cb.click();
|
|
783
|
+
}
|
|
784
|
+
}
|
|
770
785
|
return;
|
|
771
786
|
}
|
|
772
787
|
// Right opens a branch, Left closes it — the pair a tree reader expects, and
|
|
@@ -775,7 +790,14 @@ export function wireTree(host) {
|
|
|
775
790
|
const branch = branchOf(toggle);
|
|
776
791
|
const closed = branch && branch.getAttribute("aria-expanded") === "false";
|
|
777
792
|
e.preventDefault();
|
|
778
|
-
if (closed) {
|
|
793
|
+
if (closed) {
|
|
794
|
+
if (host.hasAttribute("virtual")) {
|
|
795
|
+
virtualToggle(branch, true);
|
|
796
|
+
} else {
|
|
797
|
+
toggleNode(branch);
|
|
798
|
+
rove(toggle);
|
|
799
|
+
}
|
|
800
|
+
}
|
|
779
801
|
else { const next = items[idx + 1]; if (next) { next.focus(); rove(next); } }
|
|
780
802
|
return;
|
|
781
803
|
}
|
|
@@ -783,8 +805,12 @@ export function wireTree(host) {
|
|
|
783
805
|
const branch = branchOf(toggle);
|
|
784
806
|
if (branch && branch.getAttribute("aria-expanded") === "true") {
|
|
785
807
|
e.preventDefault();
|
|
786
|
-
|
|
787
|
-
|
|
808
|
+
if (host.hasAttribute("virtual")) {
|
|
809
|
+
virtualToggle(branch, false);
|
|
810
|
+
} else {
|
|
811
|
+
toggleNode(branch);
|
|
812
|
+
rove(toggle);
|
|
813
|
+
}
|
|
788
814
|
} else {
|
|
789
815
|
const parent = toggle.closest(".c-tree__children");
|
|
790
816
|
const owner = parent ? parent.closest(".c-tree__node") : null;
|
|
@@ -793,24 +819,17 @@ export function wireTree(host) {
|
|
|
793
819
|
}
|
|
794
820
|
return;
|
|
795
821
|
}
|
|
796
|
-
|
|
797
|
-
if (e.key === "ArrowDown") next = Math.min(idx + 1, items.length - 1);
|
|
798
|
-
else if (e.key === "ArrowUp") next = Math.max(idx - 1, 0);
|
|
799
|
-
else if (e.key === "Home") next = 0;
|
|
800
|
-
else if (e.key === "End") next = items.length - 1;
|
|
801
|
-
if (next >= 0 && next !== idx) {
|
|
802
|
-
e.preventDefault();
|
|
803
|
-
items[next].focus();
|
|
804
|
-
rove(items[next]);
|
|
805
|
-
}
|
|
822
|
+
navKey(e, items, { wrap: false, homeEnd: true, onNavigate: (i) => rove(items[i]) });
|
|
806
823
|
});
|
|
807
824
|
}
|
|
808
825
|
|
|
809
826
|
/** Menu: roving focus over items, `contour:select` from key or pointer. */
|
|
810
827
|
/** Wire menu keyboard navigation and selection for a host. */
|
|
811
828
|
export function wireMenu(host) {
|
|
812
|
-
|
|
813
|
-
const
|
|
829
|
+
// R24-37: include menuitemcheckbox and menuitemradio in the selector.
|
|
830
|
+
const SEL = "[role='menuitem'], [role='menuitemcheckbox'], [role='menuitemradio']";
|
|
831
|
+
wcAll(host, SEL).forEach((it) => { if (!it.hasAttribute("tabindex")) it.setAttribute("tabindex", it.getAttribute("aria-disabled") === "true" ? "-1" : "-1"); });
|
|
832
|
+
const all = () => wcAll(host, SEL);
|
|
814
833
|
if (!all().some((it) => it.getAttribute("tabindex") === "0") && all().length) {
|
|
815
834
|
const first = all().find((it) => it.getAttribute("aria-disabled") !== "true");
|
|
816
835
|
if (first) first.setAttribute("tabindex", "0");
|
|
@@ -865,17 +884,7 @@ export function wireMenu(host) {
|
|
|
865
884
|
}
|
|
866
885
|
}
|
|
867
886
|
|
|
868
|
-
|
|
869
|
-
if (e.key === "ArrowDown") next = index < 0 ? 0 : Math.min(index + 1, its.length - 1);
|
|
870
|
-
else if (e.key === "ArrowUp") next = index < 0 ? its.length - 1 : Math.max(index - 1, 0);
|
|
871
|
-
else if (e.key === "Home") next = 0;
|
|
872
|
-
else if (e.key === "End") next = its.length - 1;
|
|
873
|
-
if (next >= 0) { e.preventDefault(); its[next].focus(); return; }
|
|
874
|
-
if ((e.key === "Enter" || e.key === " ") && index >= 0 && !(target && target.getAttribute("aria-haspopup") === "menu")) {
|
|
875
|
-
e.preventDefault();
|
|
876
|
-
wcEmit(host, "contour:select", { index, label: its[index].textContent.trim() });
|
|
877
|
-
closeAllSubmenus();
|
|
878
|
-
}
|
|
887
|
+
navKey(e, its, { wrap: true, homeEnd: true, onKey: () => { if (e.key === "Enter" || e.key === " ") { const idx = its.indexOf(document.activeElement); if (idx >= 0 && !(target && target.getAttribute("aria-haspopup") === "menu")) { const role = its[idx].getAttribute("role"); if (role === "menuitemcheckbox" || role === "menuitemradio") { const checked = its[idx].getAttribute("aria-checked") === "true"; if (role === "menuitemradio") its.forEach((x) => { if (x !== its[idx] && x.getAttribute("role") === "menuitemradio") x.setAttribute("aria-checked", "false"); }); its[idx].setAttribute("aria-checked", String(!checked)); wcEmit(host, "contour:select", { index: idx, label: its[idx].textContent.trim(), checked: !checked }); } else { wcEmit(host, "contour:select", { index: idx, label: its[idx].textContent.trim() }); } closeAllSubmenus(); } } } });
|
|
879
888
|
// Typeahead (F-21): printable char jumps to the first item whose label
|
|
880
889
|
// starts with the typed character.
|
|
881
890
|
if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
|
@@ -885,9 +894,20 @@ export function wireMenu(host) {
|
|
|
885
894
|
}
|
|
886
895
|
});
|
|
887
896
|
wcListen(host, "click", (e) => {
|
|
888
|
-
const item = wcClosest(host, e.target,
|
|
897
|
+
const item = wcClosest(host, e.target, SEL);
|
|
889
898
|
if (!item) return;
|
|
890
899
|
if (item.getAttribute("aria-disabled") === "true") return;
|
|
900
|
+
// R24-37: toggle aria-checked on checkbox/radio items.
|
|
901
|
+
const role = item.getAttribute("role");
|
|
902
|
+
if (role === "menuitemcheckbox" || role === "menuitemradio") {
|
|
903
|
+
const checked = item.getAttribute("aria-checked") === "true";
|
|
904
|
+
if (role === "menuitemradio") {
|
|
905
|
+
all().forEach((x) => { if (x !== item && x.getAttribute("role") === "menuitemradio") x.setAttribute("aria-checked", "false"); });
|
|
906
|
+
}
|
|
907
|
+
item.setAttribute("aria-checked", String(!checked));
|
|
908
|
+
wcEmit(host, "contour:select", { index: all().indexOf(item), label: item.textContent.trim(), checked: !checked });
|
|
909
|
+
return;
|
|
910
|
+
}
|
|
891
911
|
// Toggle submenu on click for haspopup items.
|
|
892
912
|
if (item.getAttribute("aria-haspopup") === "menu") {
|
|
893
913
|
const sub = submenusOf(item);
|
|
@@ -972,11 +992,16 @@ export function wireCopy(host) {
|
|
|
972
992
|
if (!btn) return;
|
|
973
993
|
const owner = wcClosest(host, btn, ".c-code") || wcClosest(host, btn, ".c-install") || host;
|
|
974
994
|
const src = owner.querySelector("code, .c-install__command");
|
|
975
|
-
|
|
995
|
+
// A numbered block carries its gutter as elements inside the <code>, so
|
|
996
|
+
const readSource = (el) => {
|
|
997
|
+
const lines = el && el.querySelectorAll ? el.querySelectorAll(".c-code__line") : null;
|
|
998
|
+
if (!lines || !lines.length) return el ? el.textContent || "" : "";
|
|
999
|
+
return Array.from(lines).map((l) => Array.from(l.childNodes)
|
|
1000
|
+
.filter((n) => !(n.classList && n.classList.contains("c-code__line-number")))
|
|
1001
|
+
.map((n) => n.textContent).join("")).join("\n");
|
|
1002
|
+
};
|
|
1003
|
+
const text = readSource(src) || (src ? "" : owner.textContent) || "";
|
|
976
1004
|
// The confirmation is the one the system script paints for the guide's own
|
|
977
|
-
// copy buttons: a label swap, `data-copied` (which the shipped CSS styles)
|
|
978
|
-
// and an icon check on the trigger, reverted after the same beat. The
|
|
979
|
-
// trigger keeps focus, so the label change is what a screen reader hears.
|
|
980
1005
|
const confirm = (ok) => {
|
|
981
1006
|
const icon = btn.querySelector("use");
|
|
982
1007
|
const originalHref = icon && icon.getAttribute("href");
|
|
@@ -989,8 +1014,10 @@ export function wireCopy(host) {
|
|
|
989
1014
|
if (icon && originalHref) icon.setAttribute("href", originalHref);
|
|
990
1015
|
btn.setAttribute("aria-label", originalLabel);
|
|
991
1016
|
delete btn.dataset.copied;
|
|
1017
|
+
btn._copyTimer = null;
|
|
992
1018
|
}, 1600);
|
|
993
|
-
|
|
1019
|
+
if (btn._copyTimer) clearTimeout(btn._copyTimer);
|
|
1020
|
+
btn._copyTimer = timer;
|
|
994
1021
|
};
|
|
995
1022
|
const doCopy = async () => {
|
|
996
1023
|
try {
|
|
@@ -1069,13 +1096,6 @@ export function wireRemovable(host) {
|
|
|
1069
1096
|
}
|
|
1070
1097
|
|
|
1071
1098
|
// Modal containment for the light dialog family (BY-46). A native <dialog> in
|
|
1072
|
-
// showModal() modalises the page for free — top layer, backdrop, background
|
|
1073
|
-
// inert — but the light contour-dialog/drawer/sheet have no platform modal, so
|
|
1074
|
-
// opening one must lock the document scroll and inert the background or the
|
|
1075
|
-
// page behind it stays reachable. Stacked: two open surfaces must not unlock
|
|
1076
|
-
// the page on the first close. The guide's own modalise() is the pattern; this
|
|
1077
|
-
// is the system's copy, since a rule that only works inside the guide does not
|
|
1078
|
-
// ship.
|
|
1079
1099
|
const modalDepth = { n: 0 };
|
|
1080
1100
|
let modalSavedOverflow = null;
|
|
1081
1101
|
let modalSavedX = 0;
|
|
@@ -1083,6 +1103,8 @@ let modalSavedY = 0;
|
|
|
1083
1103
|
const modalInerted = new Set();
|
|
1084
1104
|
const modalStack = [];
|
|
1085
1105
|
let modalTrapWired = false;
|
|
1106
|
+
// R24-15: per-host inert tracking. When modal B opens on top of modal A,
|
|
1107
|
+
const modalInertedBy = new Map(); // host -> Set of inerted siblings
|
|
1086
1108
|
|
|
1087
1109
|
function modalFocusables(host) {
|
|
1088
1110
|
return Array.from(host.querySelectorAll("button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])"))
|
|
@@ -1110,8 +1132,6 @@ export function modalContain(host, open) {
|
|
|
1110
1132
|
if (open) {
|
|
1111
1133
|
if (modalDepth.n === 0) {
|
|
1112
1134
|
// The lock itself clamps the scroll (overflow:hidden on the scroller),
|
|
1113
|
-
// so the position must be captured BEFORE it is applied or the restore
|
|
1114
|
-
// puts a clamped 0 back (measured: open-after-scrollTo read scrollY 0).
|
|
1115
1135
|
modalSavedX = window.scrollX;
|
|
1116
1136
|
modalSavedY = window.scrollY;
|
|
1117
1137
|
modalSavedOverflow = document.documentElement.style.overflow;
|
|
@@ -1124,19 +1144,29 @@ export function modalContain(host, open) {
|
|
|
1124
1144
|
document.addEventListener("keydown", modalTrapHandler);
|
|
1125
1145
|
}
|
|
1126
1146
|
// An ancestor cannot be inert (it would inert the whole subtree); the
|
|
1127
|
-
|
|
1147
|
+
const inerted = new Set();
|
|
1128
1148
|
for (let el = host; el && el !== document.body; el = el.parentElement) {
|
|
1129
1149
|
for (const sib of el.parentElement.children) {
|
|
1130
|
-
if (sib === el || sib.inert
|
|
1150
|
+
if (sib === el || sib.inert) continue;
|
|
1131
1151
|
sib.inert = true;
|
|
1132
|
-
|
|
1152
|
+
inerted.add(sib);
|
|
1133
1153
|
}
|
|
1134
1154
|
}
|
|
1155
|
+
modalInertedBy.set(host, inerted);
|
|
1135
1156
|
} else {
|
|
1136
1157
|
const idx = modalStack.lastIndexOf(host);
|
|
1137
1158
|
if (idx >= 0) modalStack.splice(idx, 1);
|
|
1138
1159
|
modalDepth.n = Math.max(0, modalDepth.n - 1);
|
|
1160
|
+
// Release only the siblings THIS host inerted (R24-15). A lower modal's
|
|
1161
|
+
// siblings stay inert while it is still open.
|
|
1162
|
+
const inerted = modalInertedBy.get(host);
|
|
1163
|
+
if (inerted) {
|
|
1164
|
+
for (const el of inerted) { el.inert = false; modalInerted.delete(el); }
|
|
1165
|
+
modalInertedBy.delete(host);
|
|
1166
|
+
}
|
|
1139
1167
|
if (modalDepth.n === 0) {
|
|
1168
|
+
// Final cleanup: release anything still inerted (should be empty, but
|
|
1169
|
+
// guards against a host removed without a close).
|
|
1140
1170
|
for (const el of modalInerted) el.inert = false;
|
|
1141
1171
|
modalInerted.clear();
|
|
1142
1172
|
document.documentElement.style.overflow = modalSavedOverflow || "";
|