contour-ds 1.7.2 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -11
- package/dist/agent-rules.json +16 -0
- package/dist/build-manifest.json +181 -104
- package/dist/contour-wc-content.esm.js +5125 -0
- package/dist/contour-wc-content.esm.min.js +1 -0
- package/dist/contour-wc-dashboard.esm.js +8654 -0
- package/dist/contour-wc-dashboard.esm.min.js +1 -0
- package/dist/contour-wc-data.esm.js +8260 -0
- package/dist/contour-wc-data.esm.min.js +1 -0
- package/dist/contour-wc-docs.esm.js +4305 -0
- package/dist/contour-wc-docs.esm.min.js +1 -0
- package/dist/contour-wc-feedback.esm.js +4917 -0
- package/dist/contour-wc-feedback.esm.min.js +1 -0
- package/dist/contour-wc-forms.esm.js +5688 -0
- package/dist/contour-wc-forms.esm.min.js +1 -0
- package/dist/contour-wc-interaction.esm.js +4580 -0
- package/dist/contour-wc-interaction.esm.min.js +1 -0
- package/dist/contour-wc-layout.esm.js +4174 -0
- package/dist/contour-wc-layout.esm.min.js +1 -0
- package/dist/contour-wc-map.esm.js +5205 -0
- package/dist/contour-wc-map.esm.min.js +1 -0
- package/dist/contour-wc-misc.esm.js +4264 -0
- package/dist/contour-wc-misc.esm.min.js +1 -0
- package/dist/contour-wc-navigation.esm.js +5844 -0
- package/dist/contour-wc-navigation.esm.min.js +1 -0
- package/dist/contour-wc-ui.esm.js +9009 -0
- package/dist/contour-wc-ui.esm.min.js +1 -0
- package/dist/contour-wc.esm.js +6109 -1641
- package/dist/contour-wc.esm.min.js +1 -1
- package/dist/contour-wc.js +6108 -1641
- package/dist/contour-wc.min.js +1 -1
- package/dist/contour.code-snippets +4512 -0
- package/dist/contour.components.json +2597 -799
- package/dist/contour.css +5275 -4050
- package/dist/contour.d.ts +560 -1085
- package/dist/contour.esm.js +7 -0
- package/dist/contour.esm.min.js +1 -1
- package/dist/contour.html-data.json +10311 -0
- package/dist/contour.js +7 -0
- package/dist/contour.min.css +1 -1
- package/dist/contour.min.js +1 -1
- package/dist/contour.react.d.ts +420 -0
- package/dist/contour.single.html +17 -0
- package/dist/contour.single.min.css +1 -0
- package/dist/contour.tokens.json +940 -902
- package/dist/contour.vue.d.ts +418 -0
- package/dist/contour.web-types.json +10703 -0
- package/dist/custom-elements.json +30708 -0
- package/dist/docs/actions.md +3 -2
- package/dist/docs/affordances.md +23 -9
- package/dist/docs/apireference.md +1 -1
- package/dist/docs/colour.md +1 -1
- package/dist/docs/componentindex.md +6 -2
- package/dist/docs/data.md +7 -2
- package/dist/docs/docs.md +9 -2
- package/dist/docs/feedback.md +1 -1
- package/dist/docs/field.md +1 -1
- package/dist/docs/forms.md +1 -1
- package/dist/docs/index.json +22 -20
- package/dist/docs/install.md +1 -1
- package/dist/docs/landing.md +1 -1
- package/dist/docs/mapengine.md +19 -2
- package/dist/docs/motion.md +1 -1
- package/dist/docs/navigation.md +1 -1
- package/dist/docs/overlays.md +1 -1
- package/dist/docs/overview.md +1 -1
- package/dist/docs/patterns.md +2 -2
- package/dist/docs/playground.md +22 -2
- package/dist/docs/principles.md +1 -1
- package/dist/docs/recipes.md +13 -8
- package/dist/docs/space.md +1 -1
- package/dist/docs/status.md +14 -2
- package/dist/docs/surfaces.md +1 -1
- package/dist/docs/theming.md +1 -1
- package/dist/docs/type.md +1 -1
- package/dist/docs/webcomponents.md +17 -3
- 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/wc/behaviours.mjs +45 -57
- package/dist/wc/content.mjs +263 -63
- package/dist/wc/core.mjs +390 -71
- package/dist/wc/dashboard.mjs +220 -13
- package/dist/wc/data.mjs +1075 -460
- package/dist/wc/docs.mjs +105 -12
- package/dist/wc/feedback.mjs +63 -14
- package/dist/wc/forms.mjs +733 -104
- package/dist/wc/index.mjs +9 -2
- package/dist/wc/interaction.mjs +182 -28
- package/dist/wc/layout.mjs +95 -25
- package/dist/wc/map.mjs +185 -118
- package/dist/wc/misc.mjs +124 -24
- package/dist/wc/navigation.mjs +384 -115
- package/dist/wc/shadow.mjs +94 -18
- package/dist/wc/states.mjs +21 -3
- package/dist/wc/svg.mjs +104 -0
- package/dist/wc/ui.mjs +1988 -476
- package/integrations/README.md +2 -0
- package/integrations/ai/CLAUDE.md +3 -3
- package/integrations/frameworks/README.md +235 -0
- package/integrations/native/style-dictionary.config.json +1 -1
- package/integrations/tailwind/contour-theme.css +5 -6
- package/package.json +53 -24
package/dist/wc/core.mjs
CHANGED
|
@@ -102,28 +102,32 @@
|
|
|
102
102
|
// {index, label} and {value} across its sites, so all three are listed.
|
|
103
103
|
/** Frozen event vocabulary with the public detail keys for each event. */
|
|
104
104
|
export const CONTOUR_EVENTS = Object.freeze({
|
|
105
|
-
"contour:activate": { payload: ["row"], composed: true },
|
|
105
|
+
"contour:activate": { payload: ["files", "label", "row", "value"], composed: true },
|
|
106
106
|
"contour:add": { payload: ["value"], composed: true },
|
|
107
|
+
"contour:activity-clear": { payload: [], composed: true },
|
|
108
|
+
"contour:activity-filter": { payload: ["unread"], composed: true },
|
|
107
109
|
"contour:activity-select": { payload: ["index", "text"], composed: true },
|
|
108
110
|
"contour:break-change": { payload: ["layer", "value"], composed: true },
|
|
109
|
-
"contour:style-resolved": { payload: ["applied", "items", "layer", "property", "value"], composed: true },
|
|
111
|
+
"contour:style-resolved": { payload: ["applied", "classification", "colors", "items", "layer", "n", "palette", "property", "value"], composed: true },
|
|
110
112
|
"contour:advanced-toggle": { payload: ["title"], composed: true },
|
|
111
113
|
"contour:affordance-activate": { payload: ["name"], composed: true },
|
|
112
114
|
"contour:aggregate": { payload: ["aggregate"], composed: true },
|
|
113
115
|
"contour:bearing": { payload: ["direction", "degrees"], composed: true },
|
|
114
116
|
"contour:btn-group-change": { payload: ["index", "label"], composed: true },
|
|
115
|
-
"contour:brush-start": { payload: ["end", "start", "value"], composed: true },
|
|
116
|
-
"contour:brush-end": { payload: ["end", "start", "value"], composed: true },
|
|
117
|
-
"contour:brush": { payload: ["end", "start", "value"], composed: true },
|
|
118
|
-
"contour:change": { payload: ["checked", "color", "direction", "end", "files", "high", "index", "low", "month", "name", "speed", "start", "unit", "value", "year"], composed: true },
|
|
117
|
+
"contour:brush-start": { payload: ["end", "range", "start", "value"], composed: true },
|
|
118
|
+
"contour:brush-end": { payload: ["end", "range", "start", "value"], composed: true },
|
|
119
|
+
"contour:brush": { payload: ["end", "range", "start", "value"], composed: true },
|
|
120
|
+
"contour:change": { payload: ["checked", "color", "direction", "end", "files", "high", "index", "low", "month", "name", "paused", "query", "speed", "start", "unit", "value", "values", "year"], composed: true },
|
|
119
121
|
"contour:collapse": { payload: ["collapsed"], composed: true },
|
|
120
122
|
"contour:cluster-toggle": { payload: ["count", "expanded"], composed: true },
|
|
121
123
|
"contour:clear": { payload: [], composed: true },
|
|
122
124
|
"contour:clear-all": { payload: [], composed: true },
|
|
123
|
-
"contour:close": { payload: ["index", "label"], composed: true },
|
|
125
|
+
"contour:close": { payload: ["count", "index", "label", "message", "open", "value"], composed: true },
|
|
124
126
|
"contour:copy": { payload: ["text"], composed: true },
|
|
127
|
+
"contour:apply": { payload: ["name"], composed: true },
|
|
125
128
|
"contour:dash-action": { payload: ["label"], composed: true },
|
|
126
129
|
"contour:diff-activate": { payload: ["kind", "text"], composed: true },
|
|
130
|
+
"contour:dismiss": { payload: ["label"], composed: true },
|
|
127
131
|
"contour:draw-start": { payload: ["mode"], composed: true },
|
|
128
132
|
"contour:drag": { payload: ["delta", "key", "value"], composed: true },
|
|
129
133
|
"contour:do-dont-activate": { payload: ["kind", "text"], composed: true },
|
|
@@ -133,43 +137,52 @@
|
|
|
133
137
|
"contour:drop": { payload: ["value", "label"], composed: true },
|
|
134
138
|
"contour:empty-action": { payload: ["state"], composed: true },
|
|
135
139
|
"contour:filter": { payload: ["query"], composed: true },
|
|
140
|
+
"contour:filter-change": { payload: ["source", "filter"], composed: true },
|
|
136
141
|
"contour:error": { payload: ["src", "message", "name", "status"], composed: true },
|
|
137
142
|
"contour:export": { payload: ["format"], composed: true },
|
|
138
143
|
"contour:refresh": { payload: [], composed: true },
|
|
139
144
|
"contour:hide": { payload: [], composed: true },
|
|
140
145
|
"contour:hover": { payload: ["row"], composed: true },
|
|
141
146
|
"contour:input": { payload: ["name", "value", "checked"], composed: true },
|
|
147
|
+
"contour:invalid": { payload: ["field", "input", "message"], composed: true, cancelable: true },
|
|
148
|
+
"contour:inspect-action": { payload: ["label"], composed: true },
|
|
142
149
|
"contour:layer-opacity": { payload: ["name", "opacity"], composed: true },
|
|
143
150
|
"contour:layer-rename": { payload: ["name", "newName"], composed: true },
|
|
144
151
|
"contour:layer-duplicate": { payload: ["name"], composed: true },
|
|
145
152
|
"contour:layer-zoom": { payload: ["name"], composed: true },
|
|
153
|
+
"contour:zoom": { payload: ["data", "index", "row"], composed: true },
|
|
146
154
|
"contour:layer-projection": { payload: ["name", "projection"], composed: true },
|
|
147
155
|
"contour:layer-remove": { payload: ["name"], composed: true },
|
|
148
156
|
"contour:layer-reorder": { payload: ["layerIds"], composed: true },
|
|
149
157
|
"contour:layer-toggle": { payload: ["name", "visible"], composed: true },
|
|
150
158
|
"contour:layer-visibility": { payload: ["name", "visible"], composed: true },
|
|
151
|
-
"contour:legend-toggle": { payload: ["key", "label", "pressed"], composed: true },
|
|
159
|
+
"contour:legend-toggle": { payload: ["index", "key", "label", "pressed"], composed: true },
|
|
152
160
|
"contour:leave": { payload: [], composed: true },
|
|
153
161
|
"contour:load": { payload: ["src", "count"], composed: true },
|
|
154
162
|
"contour:map-control": { payload: ["control"], composed: true },
|
|
155
163
|
"contour:map-attach": { payload: [], composed: true },
|
|
156
164
|
"contour:map-detach": { payload: [], composed: true },
|
|
165
|
+
"contour:map-popup-reposition": { payload: ["anchor", "flippedX", "flippedY", "left", "top"], composed: true },
|
|
157
166
|
"contour:mode-change": { payload: ["mode"], composed: true },
|
|
167
|
+
"contour:scope-change": { payload: ["scope"], composed: true },
|
|
158
168
|
"contour:move": { payload: ["direction", "from", "to"], composed: true },
|
|
159
169
|
"contour:open": { payload: [], composed: true },
|
|
160
170
|
"contour:page": { payload: ["page"], composed: true },
|
|
161
171
|
"contour:ready": { payload: ["version", "count"], composed: true },
|
|
162
|
-
"contour:
|
|
172
|
+
"contour:read": { payload: ["label"], composed: true },
|
|
173
|
+
"contour:remove": { payload: ["key", "label", "name", "value"], composed: true },
|
|
163
174
|
"contour:reorder": { payload: ["from", "to"], composed: true },
|
|
164
175
|
"contour:range-change": { payload: ["value"], composed: true },
|
|
165
|
-
"contour:resize": { payload: ["height", "width"], composed: true },
|
|
176
|
+
"contour:resize": { payload: ["delta", "height", "value", "width"], composed: true },
|
|
166
177
|
"contour:retry": { payload: ["src"], composed: true },
|
|
167
178
|
"contour:loop-change": { payload: ["loop"], composed: true },
|
|
168
179
|
"contour:pause": { payload: [], composed: true },
|
|
169
180
|
"contour:play": { payload: [], composed: true },
|
|
170
181
|
"contour:seek": { payload: ["progress", "value"], composed: true },
|
|
171
|
-
"contour:select": { payload: ["area", "col", "index", "key", "label", "labels", "path", "row", "rows", "series", "value"], composed: true },
|
|
182
|
+
"contour:select": { payload: ["area", "col", "expanded", "href", "index", "key", "label", "labels", "path", "range", "result", "row", "rows", "series", "value"], composed: true },
|
|
172
183
|
"contour:search": { payload: ["query"], composed: true },
|
|
184
|
+
"contour:spatial-filter": { payload: ["action", "mode", "operator"], composed: true },
|
|
185
|
+
"contour:split-change": { payload: ["value", "width", "height"], composed: true },
|
|
173
186
|
"contour:speed-change": { payload: ["speed"], composed: true },
|
|
174
187
|
"contour:showcase-activate": { payload: ["title"], composed: true },
|
|
175
188
|
"contour:step-activate": { payload: ["index", "title"], composed: true },
|
|
@@ -183,7 +196,7 @@
|
|
|
183
196
|
"contour:tick": { payload: ["frame"], composed: true },
|
|
184
197
|
"contour:time-change": { payload: ["progress", "value"], composed: true },
|
|
185
198
|
"contour:time-range-change": { payload: ["value"], composed: true },
|
|
186
|
-
"contour:toggle": { payload: ["expanded", "label", "open", "path", "playing"], composed: true },
|
|
199
|
+
"contour:toggle": { payload: ["collapsed", "expanded", "label", "open", "path", "playing"], composed: true },
|
|
187
200
|
"contour:view-enter": { payload: [], composed: true },
|
|
188
201
|
"contour:view-leave": { payload: [], composed: true },
|
|
189
202
|
});
|
|
@@ -224,24 +237,119 @@
|
|
|
224
237
|
walk(doc.body);
|
|
225
238
|
return doc.body.innerHTML;
|
|
226
239
|
}
|
|
240
|
+
/**
|
|
241
|
+
* Validate a CSS colour for use in an inline style.
|
|
242
|
+
*
|
|
243
|
+
* Returns the trimmed value when it is a plain colour (named, hex, or a
|
|
244
|
+
* known colour function) and an empty string otherwise. Anything that could
|
|
245
|
+
* break out of the declaration, load a resource, or run script is rejected,
|
|
246
|
+
* so a consumer-supplied `color` attribute cannot become an injection sink.
|
|
247
|
+
*
|
|
248
|
+
* @param {unknown} value candidate colour
|
|
249
|
+
* @returns {string} the safe colour, or "" when rejected
|
|
250
|
+
*/
|
|
251
|
+
export function safeColor(value) {
|
|
252
|
+
const raw = String(value == null ? "" : value).trim();
|
|
253
|
+
if (!raw) return "";
|
|
254
|
+
if (/[;{}<>"'`\\]/.test(raw)) return "";
|
|
255
|
+
if (/url\s*\(/i.test(raw) || /expression\s*\(/i.test(raw)) return "";
|
|
256
|
+
if (/^#[0-9a-f]{3,8}$/i.test(raw)) return raw;
|
|
257
|
+
if (/^(rgb|rgba|hsl|hsla|hwb|lab|lch|oklab|oklch|color)\(/i.test(raw)) return raw;
|
|
258
|
+
if (/^[a-z]+$/i.test(raw)) return raw;
|
|
259
|
+
return "";
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Resolve an href candidate to a value that is safe to assign to a sink.
|
|
263
|
+
*
|
|
264
|
+
* Fragments, relative paths and the schemes we can vouch for pass through
|
|
265
|
+
* unchanged; `javascript:`, `data:` and any other scheme collapse to "#".
|
|
266
|
+
* This closes the attribute-to-property path that `sanitizeHtml` does not
|
|
267
|
+
* cover, because assigning `a.href = "javascript:…"` executes on click.
|
|
268
|
+
*
|
|
269
|
+
* @param {unknown} value candidate href
|
|
270
|
+
* @returns {string} the safe href, or "#"
|
|
271
|
+
*/
|
|
272
|
+
export function safeHref(value) {
|
|
273
|
+
const raw = String(value == null ? "" : value).trim();
|
|
274
|
+
if (!raw) return "#";
|
|
275
|
+
if (raw.startsWith("#") || raw.startsWith("/") || raw.startsWith("./") || raw.startsWith("../") || raw.startsWith("?")) return raw;
|
|
276
|
+
if (typeof document === "undefined" || !document.baseURI) return "#";
|
|
277
|
+
try {
|
|
278
|
+
const url = new URL(raw, document.baseURI);
|
|
279
|
+
return ["http:", "https:", "mailto:", "tel:"].includes(url.protocol) ? raw : "#";
|
|
280
|
+
} catch (e) {
|
|
281
|
+
return "#";
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Read a length token from the document root, in pixels.
|
|
286
|
+
*
|
|
287
|
+
* Virtualized components used to hard-code 36/32/28 px row heights, which
|
|
288
|
+
* disagreed with the rendered row and ignored density. The height is now a
|
|
289
|
+
* token (`--data-grid-row-height`, …) and this reads its computed value.
|
|
290
|
+
*
|
|
291
|
+
* @param {string} name custom-property name
|
|
292
|
+
* @param {number} fallback pixels to use when the token is absent or invalid
|
|
293
|
+
* @returns {number} the resolved length in pixels
|
|
294
|
+
*/
|
|
295
|
+
export function cssLength(name, fallback) {
|
|
296
|
+
if (typeof getComputedStyle === "undefined" || typeof document === "undefined") return fallback;
|
|
297
|
+
const v = parseFloat(getComputedStyle(document.documentElement).getPropertyValue(name));
|
|
298
|
+
return Number.isFinite(v) && v > 0 ? v : fallback;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Surface a malformed JSON attribute instead of swallowing it.
|
|
302
|
+
*
|
|
303
|
+
* A bare `catch (e) { /* keep existing *\/ }` turns a typo in a component
|
|
304
|
+
* attribute into a silent no-op: the render keeps whatever was there before
|
|
305
|
+
* and the defect is invisible. This warns once, with the component name and
|
|
306
|
+
* the parser message, so the author can find it.
|
|
307
|
+
*
|
|
308
|
+
* @param {Element|null} host the component that owns the attribute
|
|
309
|
+
* @param {string} label the attribute (or a short description)
|
|
310
|
+
* @param {unknown} error the thrown parse error
|
|
311
|
+
*/
|
|
312
|
+
export function warnBadJson(host, label, error) {
|
|
313
|
+
if (typeof console === "undefined" || !console.warn) return;
|
|
314
|
+
const name = host && host.tagName ? host.tagName.toLowerCase() : "component";
|
|
315
|
+
const msg = (error && error.message) || String(error);
|
|
316
|
+
console.warn(`[contour] ${name}: malformed ${label || "attribute"} — ${msg}`);
|
|
317
|
+
}
|
|
227
318
|
// contract: an attribute that is not here cannot ask an element to re-render,
|
|
228
319
|
// and an attribute a component WRITES to itself must never be here, because
|
|
229
320
|
// that write would fire the callback that performs the render.
|
|
230
321
|
//
|
|
231
322
|
// Excluded because the render bodies below set them on the host:
|
|
232
323
|
// role, open, aria-label, aria-valuenow, aria-valuemin, aria-valuemax, tabindex
|
|
324
|
+
// speed — the time-slider writes its committed speed back (R20 T-30);
|
|
325
|
+
// both readers (time-slider, animation-controls) observe it per-class.
|
|
326
|
+
// x, y — the annotation writes its dragged position back (R20 T-11);
|
|
327
|
+
// its only reader observes them per-class.
|
|
328
|
+
// progress — animation-controls writes its playhead back (R20 T-10);
|
|
329
|
+
// both readers (animation-controls, file-upload) observe it per-class.
|
|
330
|
+
// colors — palette-editor writes the edited palette back (R20 T-15);
|
|
331
|
+
// all readers (palette-editor, style-panel, bivariate, bivariate-legend)
|
|
332
|
+
// observe it per-class.
|
|
233
333
|
// Adding one of those back to this list makes that component recurse.
|
|
234
334
|
/** Shared attribute vocabulary used by components that opt into defaults. */
|
|
235
335
|
export const OBSERVED = [
|
|
236
|
-
"accept", "action", "actions", "active", "after", "allow-duplicate", "allow-remove", "allow-rename", "allow-zoom", "alpha", "anchor", "answer", "area", "article", "attribution", "attribution-mark", "audit", "autoplay", "axis", "axis-x", "axis-y", "brownout", "brownout-level", "before", "body", "brand", "breakpoint", "breaks", "brush", "brush-end", "brush-max", "brush-min", "brush-start", "cache-key", "canvas", "center", "clearable", "cols", "columns", "color", "command",
|
|
237
|
-
"cells", "checked", "chrome", "debounce", "closable", "collapsed", "collapsible", "classification", "
|
|
238
|
-
"empty", "exclusive", "fallback", "filename", "format", "heading", "help", "hint", "href", "icon", "illustration", "instrument", "interval", "items", "key", "layers", "level", "range-end", "range-start",
|
|
239
|
-
"label", "lazy", "lede", "legend", "line", "limit", "link", "links", "live", "loading", "locale", "loop", "max", "media", "message", "method", "menu", "min", "multiple", "name", "needle", "next", "no", "no-cache", "no-data-message", "nodes", "note", "norm", "normalize",
|
|
240
|
-
"options", "orientation", "page-size", "pages", "pause", "paused", "pausable", "persist", "placeholder", "playing", "point", "points", "prev", "presets", "
|
|
241
|
-
"quote", "ramp", "refresh", "removable", "resolution", "reverse", "rings", "retry", "results", "rows", "scale", "selectable", "segments", "show-header", "sparkline", "threshold", "thresholds", "selected", "separator", "series", "shortcut", "side", "size", "skeleton", "sort", "sort-dir", "
|
|
242
|
-
"state", "steps", "style", "subtitle", "summary", "src", "table", "tabs", "tag", "text", "ticks",
|
|
243
|
-
"variant", "values", "viewport", "
|
|
244
|
-
"caption", "current-time", "is-playing", "loop-label",
|
|
336
|
+
"accept", "action", "actions", "active", "after", "allow-duplicate", "allow-remove", "allow-rename", "allow-zoom", "alpha", "anchor", "answer", "area", "article", "attribution", "attribution-mark", "audit", "autoplay", "axis", "axis-x", "axis-y", "brownout", "brownout-level", "before", "body", "brand", "bounds", "breakpoint", "breaks", "brush", "brush-end", "brush-max", "brush-min", "brush-start", "cache-key", "canvas", "center", "clearable", "cols", "columns", "color", "command",
|
|
337
|
+
"cells", "checked", "chrome", "confidence", "coverage", "debounce", "closable", "collapsed", "collapsible", "classification", "continuous", "content", "controls", "copyable", "count", "data", "data-table", "date", "delta", "description", "glyphs", "graduated", "demo", "density", "desc", "dir", "direction", "disabled", "distance", "dismissible", "divider", "do", "dont", "dot", "ends", "high", "input", "layer", "low", "mode", "modes", "n", "opacity", "palette", "polarity", "precision", "range", "single",
|
|
338
|
+
"empty", "exclusive", "fallback", "filename", "format", "heading", "help", "hint", "href", "icon", "illustration", "instrument", "interval", "items", "key", "layers", "level", "markers", "range-end", "range-start",
|
|
339
|
+
"label", "labels", "lazy", "lede", "legend", "left-label", "right-label", "line", "limit", "link", "links", "live", "loading", "locale", "loop", "max", "media", "message", "method", "methodology", "menu", "min", "multiple", "name", "needle", "next", "no", "no-cache", "no-data-message", "nodes", "note", "norm", "normalize",
|
|
340
|
+
"options", "orientation", "page-size", "pages", "pause", "paused", "pausable", "persist", "placeholder", "playing", "point", "points", "prev", "presets", "prompt", "question", "recent", "required",
|
|
341
|
+
"quote", "ramp", "refresh", "removable", "resolution", "reverse", "rings", "retry", "results", "rows", "scale", "selectable", "segments", "show-header", "sparkline", "threshold", "thresholds", "selected", "separator", "series", "shortcut", "side", "size", "skeleton", "sort", "sort-dir", "status", "step", "submit", "submitting", "timeout", "trigger", "virtual", "sticky", "cluster-count", "cluster-expanded", "time", "resizable",
|
|
342
|
+
"state", "steps", "style", "subtitle", "summary", "src", "source", "table", "tabs", "tag", "text", "ticks", "title", "type", "unread-only", "unit", "updated", "cluster-items", "row-height",
|
|
343
|
+
"variant", "values", "viewport", "warning", "yes", "zoomable",
|
|
344
|
+
"caption", "current-time", "is-playing", "loop-label", "no-data-color", "no-data-label", "property", "show-loop", "show-thumb", "show-thumb-caption", "speeds", "item-height", "pause-label", "play-label", "speed-label", "time-label", "shimmer",
|
|
345
|
+
"search",
|
|
346
|
+
"numbered",
|
|
347
|
+
"bucket-count", "limit-values",
|
|
348
|
+
"autocomplete", "levels", "submit-label",
|
|
349
|
+
"fields", "gap",
|
|
350
|
+
"controls",
|
|
351
|
+
"flush", "head", "preview", "tags", "url",
|
|
352
|
+
"custom-error",
|
|
245
353
|
];
|
|
246
354
|
|
|
247
355
|
/** Resolve an authored heading level while keeping the fallback valid. */
|
|
@@ -250,6 +358,48 @@
|
|
|
250
358
|
return /^h[1-6]$/.test(v || "") ? v : fallback;
|
|
251
359
|
}
|
|
252
360
|
|
|
361
|
+
/**
|
|
362
|
+
* Resolve a localised label for a host (R18-63). A consumer supplies a
|
|
363
|
+
* `labels` JSON attribute (e.g. `labels='{"clear":"Effacer"}'`); it is merged
|
|
364
|
+
* over the English `fallback`, so a partial object localises only the keys it
|
|
365
|
+
* names. A malformed attribute is ignored rather than thrown — a bad label
|
|
366
|
+
* must not take the widget down. Returns `fallback` when no override exists.
|
|
367
|
+
*/
|
|
368
|
+
export function labelText(host, key, fallback) {
|
|
369
|
+
const def = fallback !== undefined ? fallback : key;
|
|
370
|
+
const raw = host && host.getAttribute ? host.getAttribute("labels") : null;
|
|
371
|
+
if (!raw) return def;
|
|
372
|
+
try {
|
|
373
|
+
const parsed = JSON.parse(raw);
|
|
374
|
+
if (parsed && typeof parsed === "object" && typeof parsed[key] === "string" && parsed[key]) return parsed[key];
|
|
375
|
+
} catch (e) { /* a malformed labels attribute is ignored, not fatal */ }
|
|
376
|
+
return def;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Write localised copy onto a node without stealing an author's words (R18-63).
|
|
381
|
+
*
|
|
382
|
+
* `labelText()` resolves the string; this decides whether the node may take it.
|
|
383
|
+
* A node the component generated on an earlier render carries
|
|
384
|
+
* `data-contour-label`, so a `labels` change reaches it. A node the AUTHOR
|
|
385
|
+
* wrote — a `.c-saved-view__apply` button with its own text, a
|
|
386
|
+
* `.c-spatial-filter__clear-all` — has no such mark and keeps its words,
|
|
387
|
+
* because a default must never overwrite copy a consumer chose.
|
|
388
|
+
*
|
|
389
|
+
* This exists because the rule is not obvious and the failure is silent: an
|
|
390
|
+
* unconditional `node.textContent = labelText(...)` looks like the fix and is a
|
|
391
|
+
* regression for every consumer who supplied their own button.
|
|
392
|
+
*/
|
|
393
|
+
export function applyLabel(node, host, key, fallback) {
|
|
394
|
+
if (!node) return;
|
|
395
|
+
if (node.dataset && node.dataset.contourLabel === "true") {
|
|
396
|
+
node.textContent = labelText(host, key, fallback);
|
|
397
|
+
} else if (!node.textContent) {
|
|
398
|
+
node.textContent = labelText(host, key, fallback);
|
|
399
|
+
if (node.dataset) node.dataset.contourLabel = "true";
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
253
403
|
/**
|
|
254
404
|
* Base class for all Contour web components.
|
|
255
405
|
*
|
|
@@ -293,9 +443,20 @@
|
|
|
293
443
|
static get observed() {
|
|
294
444
|
return OBSERVED;
|
|
295
445
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
446
|
+
/**
|
|
447
|
+
* The attribute list the platform is told about.
|
|
448
|
+
*
|
|
449
|
+
* `labels` is appended here rather than left to each subclass's `observed`,
|
|
450
|
+
* because the reader is a SHARED helper: `labelText()` below resolves copy for
|
|
451
|
+
* whichever component asks, so a per-class list has to remember it once per
|
|
452
|
+
* class or a `labels` change silently does nothing on every host that forgot.
|
|
453
|
+
* That is exactly how it stood — one component listed it and eleven did not.
|
|
454
|
+
* A component that writes `labels` to itself would recurse, and none does.
|
|
455
|
+
*/
|
|
456
|
+
static get observedAttributes() {
|
|
457
|
+
const list = this.observed;
|
|
458
|
+
return list.includes("labels") ? list : [...list, "labels"];
|
|
459
|
+
}
|
|
299
460
|
|
|
300
461
|
// Subclasses override to declare reflected properties:
|
|
301
462
|
// static get properties() { return { value: { attribute: "value", type: String } }; }
|
|
@@ -346,8 +507,10 @@
|
|
|
346
507
|
if (ctor._propsInstalled) return;
|
|
347
508
|
ctor._propsInstalled = true;
|
|
348
509
|
const props = ctor.properties || {};
|
|
510
|
+
const declared = new Set();
|
|
349
511
|
for (const [name, spec] of Object.entries(props)) {
|
|
350
512
|
const attr = (spec && spec.attribute) || name;
|
|
513
|
+
declared.add(attr);
|
|
351
514
|
const type = (spec && spec.type) || String;
|
|
352
515
|
Object.defineProperty(ctor.prototype, name, {
|
|
353
516
|
get() {
|
|
@@ -365,6 +528,36 @@
|
|
|
365
528
|
configurable: true,
|
|
366
529
|
});
|
|
367
530
|
}
|
|
531
|
+
// Default reflection (R18-54): every observed attribute a component reads
|
|
532
|
+
// but does not declare in properties() still gets an accessor, so
|
|
533
|
+
// `el.allowDuplicate = true` writes `allow-duplicate=""` instead of being
|
|
534
|
+
// a silent no-op. The property name is the camelCase form of the
|
|
535
|
+
// attribute (kebab -> camel); a kebab attribute with no valid identifier
|
|
536
|
+
// form is skipped rather than guessed. Declared properties win.
|
|
537
|
+
//
|
|
538
|
+
// The list is `observedAttributes`, not `observed`, so the reflection
|
|
539
|
+
// surface and the platform's stay the same set — `labels` included.
|
|
540
|
+
const observed = ctor.observedAttributes;
|
|
541
|
+
for (const attr of observed) {
|
|
542
|
+
if (declared.has(attr)) continue;
|
|
543
|
+
const prop = attr.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
544
|
+
if (!/^[a-zA-Z_$][\w$]*$/.test(prop)) continue;
|
|
545
|
+
if (prop in ctor.prototype) continue; // an inherited accessor already exists
|
|
546
|
+
const isBool = attr === "disabled" || attr === "checked" || attr === "required" || attr === "readonly" || attr === "multiple" || attr === "selected" || attr === "open" || attr === "hidden";
|
|
547
|
+
Object.defineProperty(ctor.prototype, prop, {
|
|
548
|
+
get() {
|
|
549
|
+
const raw = this.getAttribute(attr);
|
|
550
|
+
if (isBool) return raw !== null;
|
|
551
|
+
return raw;
|
|
552
|
+
},
|
|
553
|
+
set(v) {
|
|
554
|
+
if (v === null || v === undefined || v === false) this.removeAttribute(attr);
|
|
555
|
+
else if (isBool) { if (v) this.setAttribute(attr, ""); else this.removeAttribute(attr); }
|
|
556
|
+
else this.setAttribute(attr, String(v));
|
|
557
|
+
},
|
|
558
|
+
configurable: true,
|
|
559
|
+
});
|
|
560
|
+
}
|
|
368
561
|
}
|
|
369
562
|
|
|
370
563
|
connectedCallback() {
|
|
@@ -380,13 +573,14 @@
|
|
|
380
573
|
this._ensureCacheGen = this._contourRenderGen;
|
|
381
574
|
this._countRender();
|
|
382
575
|
try { this.render(); }
|
|
383
|
-
catch (e) { console.error("Contour render error:", e); this.textContent = "Component failed to render."; }
|
|
576
|
+
catch (e) { console.error("Contour render error:", e); this.textContent = labelText(this, "render-error", "Component failed to render."); }
|
|
384
577
|
this._contourGenerated = Array.from(this.childNodes).filter((n) => !before.includes(n));
|
|
385
578
|
this._applyParts(this);
|
|
386
579
|
this._applyDensity();
|
|
387
580
|
this.enhance();
|
|
388
581
|
this._detachInnerFormControls();
|
|
389
582
|
this._wireFormData();
|
|
583
|
+
this._wireValueTracking();
|
|
390
584
|
}
|
|
391
585
|
|
|
392
586
|
attributeChangedCallback(name, oldValue, newValue) {
|
|
@@ -425,21 +619,37 @@
|
|
|
425
619
|
// dropped and rebuilt, so without this a host attribute change wipes
|
|
426
620
|
// whatever the user typed.
|
|
427
621
|
const savedControls = Array.from(this.querySelectorAll("input, textarea, select"));
|
|
428
|
-
const savedValues = savedControls.map((el) => ({
|
|
622
|
+
const savedValues = savedControls.map((el) => ({
|
|
623
|
+
key: el.name || el.id || null,
|
|
624
|
+
preserveKey: el.getAttribute("data-contour-preserve-key") || null,
|
|
625
|
+
value: el.value,
|
|
626
|
+
checked: el.checked,
|
|
627
|
+
type: el.type,
|
|
628
|
+
// User-dirty tracking (R20 T-02): a control the user edited keeps
|
|
629
|
+
// its value until the host's `value` attribute changes. A
|
|
630
|
+
// multi-select saves its whole selection, not just select.value
|
|
631
|
+
// (which is only the first selected option).
|
|
632
|
+
dirty: !!el._contourUserDirty,
|
|
633
|
+
attrAtDirty: el._contourAttrAtDirty,
|
|
634
|
+
selected: el.tagName === "SELECT" && el.multiple ? Array.from(el.selectedOptions).map((o) => o.value) : null,
|
|
635
|
+
}));
|
|
429
636
|
// Preserve focus, scroll position and <details> open state across the
|
|
430
637
|
// rebuild, so a host attribute change does not yank focus to <body>
|
|
431
638
|
// or collapse an open disclosure.
|
|
432
639
|
const hadFocus = this.contains(document.activeElement) ? document.activeElement : null;
|
|
433
640
|
// Capture a recovery key for unkeyed active elements: an id is the
|
|
434
|
-
// strongest key, then a `
|
|
435
|
-
// focusable controls inside the host.
|
|
436
|
-
// update that rebuilds an unkeyed input
|
|
641
|
+
// strongest key, then a `data-contour-preserve-key`, then a `name`,
|
|
642
|
+
// then the relative index among all focusable controls inside the host.
|
|
643
|
+
// Without these, an attribute update that rebuilds an unkeyed input
|
|
644
|
+
// drops focus to <body>.
|
|
437
645
|
const _focusableSelector = "button, [href], input, select, textarea, [tabindex]:not([tabindex='-1'])";
|
|
438
646
|
const _focusablesBefore = Array.from(this.querySelectorAll(_focusableSelector));
|
|
439
647
|
const hadFocusIndex = hadFocus ? _focusablesBefore.indexOf(hadFocus) : -1;
|
|
648
|
+
const hadFocusKey = hadFocus ? (hadFocus.id || null) : null;
|
|
649
|
+
const hadFocusPreserveKey = hadFocus ? (hadFocus.getAttribute("data-contour-preserve-key") || null) : null;
|
|
440
650
|
const hadFocusName = hadFocus ? (hadFocus.getAttribute("name") || null) : null;
|
|
441
|
-
const savedScrolls = Array.from(this.querySelectorAll("*")).filter((el) => el.scrollHeight > el.clientHeight || el.scrollWidth > el.clientWidth).map((el) => ({ el, top: el.scrollTop, left: el.scrollLeft }));
|
|
442
|
-
const savedDetails = Array.from(this.querySelectorAll("details")).map((d) => ({ id: d.id || null, open: d.open }));
|
|
651
|
+
const savedScrolls = Array.from(this.querySelectorAll("*")).filter((el) => el.scrollHeight > el.clientHeight || el.scrollWidth > el.clientWidth).map((el) => ({ el, id: el.id || null, preserveKey: el.getAttribute("data-contour-preserve-key") || null, top: el.scrollTop, left: el.scrollLeft }));
|
|
652
|
+
const savedDetails = Array.from(this.querySelectorAll("details")).map((d) => ({ id: d.id || null, preserveKey: d.getAttribute("data-contour-preserve-key") || null, open: d.open }));
|
|
443
653
|
// Unwrap authored content from generated wrappers before dropping them,
|
|
444
654
|
// so an attribute re-render cannot destroy authored light-DOM children
|
|
445
655
|
// that render() moved into a body/pre wrapper (B3-05).
|
|
@@ -471,7 +681,7 @@
|
|
|
471
681
|
this._ensureCacheGen = this._contourRenderGen;
|
|
472
682
|
this._countRender();
|
|
473
683
|
try { this.render(); }
|
|
474
|
-
catch (e) { console.error("Contour render error:", e); this.textContent = "Component failed to render."; }
|
|
684
|
+
catch (e) { console.error("Contour render error:", e); this.textContent = labelText(this, "render-error", "Component failed to render."); }
|
|
475
685
|
this._contourGenerated = Array.from(this.childNodes).filter((n) => !before.includes(n));
|
|
476
686
|
this._applyParts(this);
|
|
477
687
|
this._applyDensity();
|
|
@@ -483,34 +693,44 @@
|
|
|
483
693
|
// the two lists, so a field removed at the end does not shift values
|
|
484
694
|
// onto the wrong input.
|
|
485
695
|
const newControls = Array.from(this.querySelectorAll("input, textarea, select"));
|
|
486
|
-
const keyed = savedValues.filter((sv) => sv.key);
|
|
487
|
-
const unkeyed = savedValues.filter((sv) => !sv.key);
|
|
696
|
+
const keyed = savedValues.filter((sv) => sv.key || sv.preserveKey);
|
|
697
|
+
const unkeyed = savedValues.filter((sv) => !sv.key && !sv.preserveKey);
|
|
488
698
|
const used = new Set();
|
|
489
699
|
for (const el of newControls) {
|
|
490
|
-
const key = el.name || el.id || null;
|
|
700
|
+
const key = el.name || el.id || el.getAttribute("data-contour-preserve-key") || null;
|
|
491
701
|
if (!key) continue;
|
|
492
|
-
const match = keyed.find((sv) => sv.key === key && !used.has(sv));
|
|
702
|
+
const match = keyed.find((sv) => (sv.key === key || sv.preserveKey === key) && !used.has(sv));
|
|
493
703
|
if (!match) continue;
|
|
494
704
|
used.add(match);
|
|
495
|
-
if (
|
|
496
|
-
|
|
497
|
-
}
|
|
498
|
-
if ((el.type === "checkbox" || el.type === "radio") && typeof match.checked === "boolean" && !this._checkedAttrChanged) {
|
|
705
|
+
if (!this._contourResetting) this._restoreControlValue(el, match);
|
|
706
|
+
if ((el.type === "checkbox" || el.type === "radio") && typeof match.checked === "boolean" && !this._checkedAttrChanged && !this._contourResetting) {
|
|
499
707
|
el.checked = match.checked;
|
|
500
708
|
}
|
|
501
709
|
}
|
|
502
|
-
|
|
710
|
+
// Restore unkeyed controls by type-aware index matching: group saved
|
|
711
|
+
// unkeyed controls by type, then match new unkeyed controls by type and
|
|
712
|
+
// index within that type group. This prevents misalignment when elements
|
|
713
|
+
// are inserted or removed between renders (F-R4). A textarea removed
|
|
714
|
+
// from the middle no longer shifts its value onto a following input.
|
|
715
|
+
const savedByType = new Map();
|
|
716
|
+
for (const sv of unkeyed) {
|
|
717
|
+
const group = savedByType.get(sv.type) || [];
|
|
718
|
+
group.push(sv);
|
|
719
|
+
savedByType.set(sv.type, group);
|
|
720
|
+
}
|
|
721
|
+
const usedByType = new Map();
|
|
503
722
|
for (const el of newControls) {
|
|
504
723
|
if (el.name || el.id) continue;
|
|
505
|
-
const
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
if (
|
|
509
|
-
|
|
724
|
+
const type = el.type;
|
|
725
|
+
const group = savedByType.get(type) || [];
|
|
726
|
+
const used = usedByType.get(type) || 0;
|
|
727
|
+
if (used >= group.length) continue;
|
|
728
|
+
const saved = group[used];
|
|
729
|
+
usedByType.set(type, used + 1);
|
|
730
|
+
if (!this._contourResetting) this._restoreControlValue(el, saved);
|
|
731
|
+
if ((el.type === "checkbox" || el.type === "radio") && typeof saved.checked === "boolean" && !this._checkedAttrChanged && !this._contourResetting) {
|
|
732
|
+
el.checked = saved.checked;
|
|
510
733
|
}
|
|
511
|
-
if ((el.type === "checkbox" || el.type === "radio") && typeof saved.checked === "boolean" && !this._checkedAttrChanged) {
|
|
512
|
-
el.checked = saved.checked;
|
|
513
|
-
}
|
|
514
734
|
}
|
|
515
735
|
// Restore <details> open state. A disclosure carries an `id` when it is
|
|
516
736
|
// stable across renders (a faq item, a doc section); match those by id
|
|
@@ -519,14 +739,15 @@
|
|
|
519
739
|
// the shorter list, which is the behaviour the length guard existed
|
|
520
740
|
// to protect and still protects for the tail of either list.
|
|
521
741
|
const newDetails = Array.from(this.querySelectorAll("details"));
|
|
522
|
-
const keyedDetails = savedDetails.filter((sd) => sd.id);
|
|
742
|
+
const keyedDetails = savedDetails.filter((sd) => sd.id || sd.preserveKey);
|
|
523
743
|
const usedIds = new Set();
|
|
524
744
|
for (const d of newDetails) {
|
|
525
745
|
const id = d.id || null;
|
|
526
|
-
|
|
527
|
-
|
|
746
|
+
const preserveKey = d.getAttribute("data-contour-preserve-key") || null;
|
|
747
|
+
if (!id && !preserveKey) continue;
|
|
748
|
+
const match = keyedDetails.find((sd) => (sd.id === id || sd.preserveKey === preserveKey) && !usedIds.has(sd.id || sd.preserveKey));
|
|
528
749
|
if (!match) continue;
|
|
529
|
-
usedIds.add(match.id);
|
|
750
|
+
usedIds.add(match.id || match.preserveKey);
|
|
530
751
|
d.open = match.open;
|
|
531
752
|
}
|
|
532
753
|
let di = 0;
|
|
@@ -543,19 +764,20 @@
|
|
|
543
764
|
// the wrong container; the rest fall back to index matching up to the
|
|
544
765
|
// shorter list, which is what the old length guard protected.
|
|
545
766
|
const newScrolls = Array.from(this.querySelectorAll("*")).filter((el) => el.scrollHeight > el.clientHeight || el.scrollWidth > el.clientWidth);
|
|
546
|
-
const keyedScrolls = savedScrolls.filter((s) => s.
|
|
767
|
+
const keyedScrolls = savedScrolls.filter((s) => s.id || s.preserveKey);
|
|
547
768
|
const usedScrolls = new Set();
|
|
548
769
|
for (const el of newScrolls) {
|
|
549
770
|
const id = el.id || null;
|
|
550
|
-
|
|
551
|
-
|
|
771
|
+
const preserveKey = el.getAttribute("data-contour-preserve-key") || null;
|
|
772
|
+
if (!id && !preserveKey) continue;
|
|
773
|
+
const match = keyedScrolls.find((s) => (s.id === id || s.preserveKey === preserveKey) && !usedScrolls.has(s.el));
|
|
552
774
|
if (!match) continue;
|
|
553
775
|
usedScrolls.add(match.el);
|
|
554
776
|
el.scrollTop = match.top;
|
|
555
777
|
el.scrollLeft = match.left;
|
|
556
778
|
}
|
|
557
779
|
let si = 0;
|
|
558
|
-
const plainScrolls = savedScrolls.filter((s) => !s.
|
|
780
|
+
const plainScrolls = savedScrolls.filter((s) => !s.id && !s.preserveKey);
|
|
559
781
|
for (const el of newScrolls) {
|
|
560
782
|
if (el.id) continue;
|
|
561
783
|
const s = plainScrolls[si];
|
|
@@ -569,19 +791,22 @@
|
|
|
569
791
|
// their relative index among focusable controls, so an attribute update
|
|
570
792
|
// that rebuilds an unkeyed input no longer drops focus to <body>.
|
|
571
793
|
if (hadFocus) {
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
794
|
+
let target = null;
|
|
795
|
+
if (hadFocusKey) {
|
|
796
|
+
try { target = this.querySelector("#" + CSS.escape(hadFocusKey)); } catch (e) { target = null; }
|
|
797
|
+
}
|
|
798
|
+
if (!target && hadFocusPreserveKey) {
|
|
799
|
+
try { target = this.querySelector('[data-contour-preserve-key="' + CSS.escape(hadFocusPreserveKey) + '"]'); } catch (e) { target = null; }
|
|
800
|
+
}
|
|
801
|
+
if (!target && hadFocusName) {
|
|
802
|
+
try { target = this.querySelector('[name="' + CSS.escape(hadFocusName) + '"]'); } catch (e) { target = null; }
|
|
803
|
+
}
|
|
804
|
+
if (!target && hadFocusIndex >= 0) {
|
|
805
|
+
const after = Array.from(this.querySelectorAll(_focusableSelector));
|
|
806
|
+
if (after.length) {
|
|
807
|
+
target = after[Math.min(hadFocusIndex, after.length - 1)];
|
|
808
|
+
}
|
|
809
|
+
}
|
|
585
810
|
if (target && typeof target.focus === "function") {
|
|
586
811
|
try { target.focus(); } catch (e) {}
|
|
587
812
|
} else if (document.contains(hadFocus)) {
|
|
@@ -595,6 +820,7 @@
|
|
|
595
820
|
this.enhance();
|
|
596
821
|
this._detachInnerFormControls();
|
|
597
822
|
this._checkedAttrChanged = false;
|
|
823
|
+
this._contourResetting = false;
|
|
598
824
|
} finally {
|
|
599
825
|
this._contourRendering = false;
|
|
600
826
|
}
|
|
@@ -705,8 +931,11 @@
|
|
|
705
931
|
// Reset synchronously: re-rendering would restore the base class's
|
|
706
932
|
// *preserved* typed value, not the authored default. The authored
|
|
707
933
|
// default is the host's own value/checked attributes, so restore the
|
|
708
|
-
// inner control from them, then re-sync internals.
|
|
934
|
+
// inner control from them, then re-sync internals. The user-dirty marks
|
|
935
|
+
// go with the reset: a later re-render must not resurrect the typed
|
|
936
|
+
// value the form just discarded.
|
|
709
937
|
for (const ctl of this.querySelectorAll("input, textarea, select")) {
|
|
938
|
+
ctl._contourUserDirty = false;
|
|
710
939
|
if (ctl.type === "checkbox" || ctl.type === "radio") {
|
|
711
940
|
ctl.checked = this.hasAttribute("checked");
|
|
712
941
|
} else if (ctl.tagName === "SELECT") {
|
|
@@ -777,6 +1006,53 @@
|
|
|
777
1006
|
});
|
|
778
1007
|
}
|
|
779
1008
|
|
|
1009
|
+
// User-dirty value tracking (R20 T-02). The restore path only fills
|
|
1010
|
+
// controls a render left empty, so a host with an authored `value`
|
|
1011
|
+
// attribute overwrote whatever the user typed on every unrelated
|
|
1012
|
+
// attribute change. A control the user actually edited — an `input` or
|
|
1013
|
+
// `change` event, which programmatic `.value` writes do not fire — is
|
|
1014
|
+
// marked dirty together with the host's `value` attribute at that moment;
|
|
1015
|
+
// `_restoreControlValue` keeps the typed value until the author changes
|
|
1016
|
+
// that attribute. Scoped to form-associated hosts: their controls carry
|
|
1017
|
+
// the submission contract, and a non-form widget that clears its own
|
|
1018
|
+
// field on re-render keeps that behaviour. Delegated on the host (rule
|
|
1019
|
+
// 12): the controls are rebuilt on every render.
|
|
1020
|
+
_wireValueTracking() {
|
|
1021
|
+
if (!this._internals || this._wiredValueTracking) return;
|
|
1022
|
+
this._wiredValueTracking = true;
|
|
1023
|
+
const mark = (e) => {
|
|
1024
|
+
const t = e.target;
|
|
1025
|
+
if (!t || !t.matches || !t.matches("input, textarea, select")) return;
|
|
1026
|
+
if (this._ownerBetween(t, this)) return;
|
|
1027
|
+
t._contourUserDirty = true;
|
|
1028
|
+
t._contourAttrAtDirty = this.getAttribute("value");
|
|
1029
|
+
};
|
|
1030
|
+
this.addEventListener("input", mark);
|
|
1031
|
+
this.addEventListener("change", mark);
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
// Restore one control's value from its snapshot (R20 T-02/T-06). A
|
|
1035
|
+
// user-dirty control keeps its typed value — a multi-select its whole
|
|
1036
|
+
// selection, not just the first selected option — until the host's
|
|
1037
|
+
// `value` attribute changes. Otherwise the original rule stands: only a
|
|
1038
|
+
// control the render left empty, with no value attribute of its own,
|
|
1039
|
+
// takes the saved value. The dirty mark is re-applied to the rebuilt
|
|
1040
|
+
// control so the NEXT re-render preserves it too.
|
|
1041
|
+
_restoreControlValue(el, saved) {
|
|
1042
|
+
if (saved.dirty && saved.attrAtDirty === this.getAttribute("value")) {
|
|
1043
|
+
if (saved.selected && el.tagName === "SELECT" && el.multiple) {
|
|
1044
|
+
const wanted = new Set(saved.selected);
|
|
1045
|
+
for (const o of el.options) o.selected = wanted.has(o.value);
|
|
1046
|
+
} else {
|
|
1047
|
+
el.value = saved.value;
|
|
1048
|
+
}
|
|
1049
|
+
el._contourUserDirty = true;
|
|
1050
|
+
el._contourAttrAtDirty = saved.attrAtDirty;
|
|
1051
|
+
return;
|
|
1052
|
+
}
|
|
1053
|
+
if (el.value === "" && el.getAttribute("value") === null) el.value = saved.value;
|
|
1054
|
+
}
|
|
1055
|
+
|
|
780
1056
|
// The inner native control(s) are scaffolding; the host reports through
|
|
781
1057
|
// ElementInternals. A same-name native control inside a <form> would submit
|
|
782
1058
|
// a second entry with the same name — double submission, measured as
|
|
@@ -1024,6 +1300,49 @@
|
|
|
1024
1300
|
catch (e) { return value; }
|
|
1025
1301
|
}
|
|
1026
1302
|
|
|
1303
|
+
// Shared keyboard navigation for roving-tabindex patterns.
|
|
1304
|
+
// `items`: array of focusable elements, `e`: KeyboardEvent.
|
|
1305
|
+
// Options: `{ wrap (default true), enter (default true), homeEnd (false),
|
|
1306
|
+
// onKey(key, idx, item) }` — return truthy to preventDefault.
|
|
1307
|
+
// `onNavigate(newIdx)` — called after focus moves with new index.
|
|
1308
|
+
// `rtl` — if true, ArrowRight/Left swap direction; defaults to dir attribute.
|
|
1309
|
+
/** Navigate a roving-tabindex group with arrow keys, Home/End, Enter/Space. */
|
|
1310
|
+
export function navKey(e, items, { wrap = true, enter = true, homeEnd = false, onKey, onNavigate, rtl } = {}) {
|
|
1311
|
+
const idx = items.indexOf(document.activeElement);
|
|
1312
|
+
if (idx < 0) return;
|
|
1313
|
+
let next = -1;
|
|
1314
|
+
// Determine direction: ArrowRight/Down always advance forward in LTR.
|
|
1315
|
+
// With RTL, ArrowRight goes back and ArrowLeft goes forward.
|
|
1316
|
+
const fwdKey = rtl ? "ArrowLeft" : "ArrowRight";
|
|
1317
|
+
const revKey = rtl ? "ArrowRight" : "ArrowLeft";
|
|
1318
|
+
if (e.key === fwdKey || e.key === "ArrowDown") next = wrap ? (idx + 1) % items.length : Math.min(idx + 1, items.length - 1);
|
|
1319
|
+
else if (e.key === revKey || e.key === "ArrowUp") next = wrap ? (idx - 1 + items.length) % items.length : Math.max(0, idx - 1);
|
|
1320
|
+
else if ((homeEnd || wrap) && e.key === "Home") next = 0;
|
|
1321
|
+
else if ((homeEnd || wrap) && e.key === "End") next = items.length - 1;
|
|
1322
|
+
if (next >= 0 && next !== idx) {
|
|
1323
|
+
e.preventDefault();
|
|
1324
|
+
try { items[next].focus(); } catch (_) {}
|
|
1325
|
+
if (onNavigate) onNavigate(next);
|
|
1326
|
+
if (onKey) onKey(e.key, idx, items[idx]);
|
|
1327
|
+
} else if ((enter || wrap) && (e.key === "Enter" || e.key === " ")) {
|
|
1328
|
+
e.preventDefault();
|
|
1329
|
+
if (onKey) onKey(e.key, idx, items[idx]);
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
// Resolve RTL direction from element or document. Returns true for RTL layout.
|
|
1334
|
+
/** Check whether the given element uses right-to-left text direction. */
|
|
1335
|
+
export function isRtl(el) {
|
|
1336
|
+
let node = el;
|
|
1337
|
+
while (node && node.nodeType === 1) {
|
|
1338
|
+
const d = node.getAttribute && node.getAttribute("dir");
|
|
1339
|
+
if (d) return d.toLowerCase() === "rtl";
|
|
1340
|
+
node = node.parentElement;
|
|
1341
|
+
}
|
|
1342
|
+
try { return (typeof document !== "undefined" && (document.documentElement.getAttribute("dir") || "").toLowerCase() === "rtl"); }
|
|
1343
|
+
catch (e) { return false; }
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1027
1346
|
// Spatial maths (BY-23): pure functions on the host's own attributes.
|
|
1028
1347
|
// Haversine distance in meters between two lat/lon points.
|
|
1029
1348
|
/** Return the great-circle distance between two latitude/longitude points. */
|