contour-ds 1.11.0 → 1.13.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/dist/build-manifest.json +90 -90
- package/dist/contour-wc-content.esm.js +8 -1
- package/dist/contour-wc-content.esm.min.js +1 -1
- package/dist/contour-wc-core.esm.js +15 -8
- package/dist/contour-wc-core.esm.min.js +1 -1
- package/dist/contour-wc-dashboard.esm.js +360 -29
- package/dist/contour-wc-dashboard.esm.min.js +1 -1
- package/dist/contour-wc-data.esm.js +360 -29
- package/dist/contour-wc-data.esm.min.js +1 -1
- package/dist/contour-wc-docs.esm.js +4 -0
- package/dist/contour-wc-feedback.esm.js +59 -7
- package/dist/contour-wc-feedback.esm.min.js +1 -1
- package/dist/contour-wc-forms.esm.js +20 -2
- package/dist/contour-wc-forms.esm.min.js +1 -1
- package/dist/contour-wc-interaction.esm.js +4 -0
- package/dist/contour-wc-layout.esm.js +4 -0
- package/dist/contour-wc-map.esm.js +42 -5
- package/dist/contour-wc-map.esm.min.js +1 -1
- package/dist/contour-wc-misc.esm.js +4 -0
- package/dist/contour-wc-navigation.esm.js +24 -14
- package/dist/contour-wc-navigation.esm.min.js +1 -1
- package/dist/contour-wc-ui.esm.js +290 -13
- package/dist/contour-wc-ui.esm.min.js +1 -1
- package/dist/contour-wc.esm.js +794 -79
- package/dist/contour-wc.esm.min.js +1 -1
- package/dist/contour-wc.js +794 -79
- package/dist/contour-wc.min.js +1 -1
- package/dist/contour.code-snippets +1 -1
- package/dist/contour.components.json +260 -29
- package/dist/contour.css +208 -1
- package/dist/contour.d.ts +8 -6
- package/dist/contour.html-data.json +82 -4
- package/dist/contour.min.css +1 -1
- package/dist/contour.react.d.ts +2 -2
- package/dist/contour.single.html +1 -1
- package/dist/contour.single.min.css +1 -1
- package/dist/contour.vue.d.ts +2 -2
- package/dist/contour.web-types.json +82 -5
- package/dist/custom-elements.json +319 -2
- package/dist/docs/actions.md +1 -1
- package/dist/docs/affordances.md +1 -1
- package/dist/docs/apireference.md +1 -1
- package/dist/docs/colour.md +1 -1
- package/dist/docs/componentindex.md +1 -1
- package/dist/docs/data.md +1 -1
- package/dist/docs/docs.md +1 -1
- 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 +2 -2
- package/dist/docs/install.md +1 -1
- package/dist/docs/landing.md +1 -1
- package/dist/docs/mapengine.md +1 -1
- 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 +1 -1
- package/dist/docs/playground.md +1 -1
- package/dist/docs/principles.md +1 -1
- package/dist/docs/recipes.md +1 -1
- package/dist/docs/space.md +1 -1
- package/dist/docs/status.md +1 -1
- 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 +1 -1
- package/dist/register.js +15 -0
- 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 +13 -7
- package/dist/wc/content.mjs +4 -1
- package/dist/wc/core.mjs +1 -0
- package/dist/wc/data-chart.mjs +228 -21
- package/dist/wc/data-export.mjs +43 -5
- package/dist/wc/data-series.mjs +74 -0
- package/dist/wc/data-table.mjs +13 -5
- package/dist/wc/feedback.mjs +55 -7
- package/dist/wc/forms-input.mjs +16 -2
- package/dist/wc/index.mjs +1 -1
- package/dist/wc/map.mjs +38 -5
- package/dist/wc/navigation-menu.mjs +20 -14
- package/dist/wc/shadow.mjs +4 -0
- package/dist/wc/ui-atoms.mjs +134 -3
- package/dist/wc/ui-data.mjs +67 -0
- package/dist/wc/ui-feedback.mjs +8 -1
- package/dist/wc/ui-overlays.mjs +77 -9
- package/integrations/libreship/contract.json +13 -3
- package/package.json +2 -1
|
@@ -438,6 +438,10 @@ import { CLASS_ONLY, CONTOUR_EVENTS, ContourBase, MERCATOR_MAX_LAT, MODS, OBSERV
|
|
|
438
438
|
// Shadow tabs are a styling shell: panels are authored by the consumer
|
|
439
439
|
shadow("contour-shadow-tabs", `<div class="c-tabs" part="tabs"><div class="c-tabs__list" part="list" role="tablist"><slot name="tabs"></slot></div><div class="c-tabs__panels" role="presentation"><slot></slot></div></div>`);
|
|
440
440
|
shadow("contour-shadow-breadcrumb", `<nav class="c-breadcrumb" part="breadcrumb" aria-label="Breadcrumb"><ol><slot></slot></ol></nav>`);
|
|
441
|
+
// U-17: contour-shadow-menu is a shadow-styled shell with role="menu"; the
|
|
442
|
+
// consumer slots `role="menuitem"` children. It has no open/focus state of its
|
|
443
|
+
// own — pair it with contour-context-menu (which owns open/Escape/focus
|
|
444
|
+
// return) or drive focus with the standard menu keyboard contract.
|
|
441
445
|
shadow("contour-shadow-menu", `<div class="c-menu" part="menu" role="menu"><slot></slot></div>`);
|
|
442
446
|
shadow("contour-shadow-combobox", `<div class="c-combobox" part="combobox"><input class="c-combobox__input" part="input" type="text" /><ul class="c-combobox__list" part="list" hidden><slot></slot></ul></div>`);
|
|
443
447
|
shadow("contour-shadow-chart", `<div class="c-chart" part="chart"><div class="c-chart__plot" part="plot"><slot></slot></div></div>`);
|
|
@@ -1609,6 +1613,11 @@ class ContourDataTable extends ContourTable {
|
|
|
1609
1613
|
class ContourColumnPicker extends ContourBase {
|
|
1610
1614
|
static get observed() { return ["columns", "label"]; }
|
|
1611
1615
|
static get properties() { return { columns: { attribute: "columns" }, label: { attribute: "label" } }; }
|
|
1616
|
+
// Contract (U-13): `columns` is a JSON array. Each item is either a string
|
|
1617
|
+
// (the column key) or an object `{ key?, value?, name?, label?, checked? }`.
|
|
1618
|
+
// The checkbox `data-column` (and the `contour:column-toggle` detail) always
|
|
1619
|
+
// carries a STRING key — `key ?? value ?? name ?? label` — never the object
|
|
1620
|
+
// stringified to "[object Object]". `checked`/`visible` default to true.
|
|
1612
1621
|
render() {
|
|
1613
1622
|
this.classList.add("c-column-picker");
|
|
1614
1623
|
const btn = this.ensure(".c-column-picker__trigger", () => { const b = document.createElement("button"); b.type = "button"; b.className = "c-btn c-btn--sm c-column-picker__trigger"; return b; });
|
|
@@ -1619,16 +1628,19 @@ class ContourColumnPicker extends ContourBase {
|
|
|
1619
1628
|
try { const p = JSON.parse(this.getAttribute("columns") || "[]"); if (Array.isArray(p)) cols = p; } catch (e) { /* empty */ }
|
|
1620
1629
|
panel.innerHTML = "";
|
|
1621
1630
|
cols.forEach((c) => {
|
|
1622
|
-
const
|
|
1623
|
-
const
|
|
1631
|
+
const isStr = typeof c === "string";
|
|
1632
|
+
const name = isStr ? c : (c.label || c.name || c.key || c.value || "");
|
|
1633
|
+
// U-13: a string key, never "[object Object]".
|
|
1634
|
+
let key = isStr ? c : (c.key != null ? c.key : (c.value != null ? c.value : (c.name != null ? c.name : name)));
|
|
1635
|
+
key = String(key);
|
|
1624
1636
|
const item = document.createElement("label");
|
|
1625
1637
|
item.className = "c-column-picker__item";
|
|
1626
1638
|
const cb = document.createElement("input");
|
|
1627
1639
|
cb.type = "checkbox";
|
|
1628
|
-
cb.checked = true;
|
|
1629
|
-
cb.dataset.column =
|
|
1640
|
+
cb.checked = isStr ? true : (c.checked != null ? !!c.checked : (c.visible != null ? !!c.visible : true));
|
|
1641
|
+
cb.dataset.column = key;
|
|
1630
1642
|
item.appendChild(cb);
|
|
1631
|
-
item.appendChild(document.createTextNode(" " + name));
|
|
1643
|
+
item.appendChild(document.createTextNode(" " + (name || key)));
|
|
1632
1644
|
panel.appendChild(item);
|
|
1633
1645
|
});
|
|
1634
1646
|
}
|
|
@@ -1706,6 +1718,10 @@ const normalizeChartBin = (bin) => {
|
|
|
1706
1718
|
const out = { x0, x1, count };
|
|
1707
1719
|
const normalized = Number(bin.normalized);
|
|
1708
1720
|
if (Number.isFinite(normalized)) out.normalized = normalized;
|
|
1721
|
+
// U-1: a bin may carry its own colour (a value-range ramp). safeColor guards
|
|
1722
|
+
// injection; an invalid colour is dropped rather than rendered as a raw string.
|
|
1723
|
+
const color = safeColor(bin.color);
|
|
1724
|
+
if (color) out.color = color;
|
|
1709
1725
|
return out;
|
|
1710
1726
|
};
|
|
1711
1727
|
|
|
@@ -1726,8 +1742,15 @@ const normalizeChartBin = (bin) => {
|
|
|
1726
1742
|
*/
|
|
1727
1743
|
class ContourChart extends ContourBase {
|
|
1728
1744
|
static get updateMode() { return "keyed"; }
|
|
1729
|
-
static get observed() { return ["series", "axis", "color", "label", "legend", "brownout", "brownout-level", "empty", "loading", "error", "retry", "skeleton", "zoomable", "data-table", "brush", "brush-min", "brush-max", "brush-start", "brush-end", "note", "bucket-count", "limit-values", "title", "cache-key", "dir", "src"]; }
|
|
1730
|
-
static get properties() { return { series: { attribute: "series" }, axis: { attribute: "axis" }, color: { attribute: "color" }, label: { attribute: "label" }, legend: { attribute: "legend" }, zoomable: { attribute: "zoomable", type: Boolean }, brush: { attribute: "brush", type: Boolean }, note: { attribute: "note" }, "bucket-count": { attribute: "bucket-count" }, "limit-values": { attribute: "limit-values" } }; }
|
|
1745
|
+
static get observed() { return ["series", "axis", "color", "colors", "label", "legend", "brownout", "brownout-level", "empty", "loading", "error", "retry", "skeleton", "zoomable", "data-table", "brush", "brush-min", "brush-max", "brush-start", "brush-end", "note", "annotations", "mean-marker", "median-marker", "bucket-count", "limit-values", "title", "cache-key", "dir", "src"]; }
|
|
1746
|
+
static get properties() { return { series: { attribute: "series" }, axis: { attribute: "axis" }, color: { attribute: "color" }, colors: { attribute: "colors" }, label: { attribute: "label" }, legend: { attribute: "legend" }, zoomable: { attribute: "zoomable", type: Boolean }, brush: { attribute: "brush", type: Boolean }, note: { attribute: "note" }, annotations: { attribute: "annotations" }, "mean-marker": { attribute: "mean-marker", type: Boolean }, "median-marker": { attribute: "median-marker", type: Boolean }, "bucket-count": { attribute: "bucket-count" }, "limit-values": { attribute: "limit-values" } }; }
|
|
1747
|
+
// U-4: JS formatters. The `axis` attribute is JSON, so a consumer cannot pass a
|
|
1748
|
+
// function through it. These properties accept a function directly: `format`
|
|
1749
|
+
// formats a value-axis tick, `tooltipFormat` builds a mark's tooltip text.
|
|
1750
|
+
set format(fn) { this._jsFormat = typeof fn === "function" ? fn : null; this.requestRender(); }
|
|
1751
|
+
get format() { return this._jsFormat || null; }
|
|
1752
|
+
set tooltipFormat(fn) { this._jsTooltipFormat = typeof fn === "function" ? fn : null; this.requestRender(); }
|
|
1753
|
+
get tooltipFormat() { return this._jsTooltipFormat || null; }
|
|
1731
1754
|
// Bindable histogram contract (R18-68): consumer drives via bins/backgroundData/range (JS props, not attrs); push re-renders, read returns drawn bins.
|
|
1732
1755
|
get bins() {
|
|
1733
1756
|
const pushed = this._pushedBins;
|
|
@@ -1862,6 +1885,31 @@ class ContourChart extends ContourBase {
|
|
|
1862
1885
|
return Number.isFinite(min) && Number.isFinite(max) ? [min, max] : null;
|
|
1863
1886
|
} catch (e) { return null; }
|
|
1864
1887
|
}
|
|
1888
|
+
// U-2/U-3: paint mean/median reference markers and value annotations as
|
|
1889
|
+
// absolutely-positioned overlays on the plot. `frac` is the 0..1 position
|
|
1890
|
+
// across the plot's x-domain. The marks are decorative (aria-hidden): the
|
|
1891
|
+
// authoritative values live in the chart's data table.
|
|
1892
|
+
_renderChartMarkers(markers) {
|
|
1893
|
+
const plot = this._plot || this.querySelector(".c-chart__plot");
|
|
1894
|
+
if (!plot) return;
|
|
1895
|
+
Array.from(plot.querySelectorAll(".c-chart__marker, .c-chart__annotation")).forEach((n) => n.remove());
|
|
1896
|
+
if (!Array.isArray(markers) || !markers.length) return;
|
|
1897
|
+
markers.forEach((m) => {
|
|
1898
|
+
if (!m || !Number.isFinite(m.frac)) return;
|
|
1899
|
+
const el = document.createElement("div");
|
|
1900
|
+
el.className = m.kind === "annotation" ? "c-chart__annotation" : "c-chart__marker";
|
|
1901
|
+
el.style.left = (Math.max(0, Math.min(1, m.frac)) * 100).toFixed(3) + "%";
|
|
1902
|
+
if (m.kind && m.kind !== "annotation") el.dataset.kind = m.kind;
|
|
1903
|
+
if (m.label) {
|
|
1904
|
+
const lab = document.createElement("span");
|
|
1905
|
+
lab.className = "c-chart__marker-label";
|
|
1906
|
+
lab.textContent = m.label;
|
|
1907
|
+
el.appendChild(lab);
|
|
1908
|
+
}
|
|
1909
|
+
el.setAttribute("aria-hidden", "true");
|
|
1910
|
+
plot.appendChild(el);
|
|
1911
|
+
});
|
|
1912
|
+
}
|
|
1865
1913
|
_renderValueAxis() {
|
|
1866
1914
|
const ax = this.querySelector(".c-chart__axis");
|
|
1867
1915
|
if (!ax) return;
|
|
@@ -1879,7 +1927,7 @@ class ContourChart extends ContourBase {
|
|
|
1879
1927
|
this.classList.add("c-chart--value-axis");
|
|
1880
1928
|
ax.className = "c-chart__axis c-chart__axis--y";
|
|
1881
1929
|
const ticks = (y && y.ticks) || niceTicks(domain[0], domain[1], 5);
|
|
1882
|
-
|
|
1930
|
+
const format = this._jsFormat || (y && y.format) || ((v) => String(v));
|
|
1883
1931
|
ax.textContent = "";
|
|
1884
1932
|
// Per-axis titles: y.label titles value axis; category label (top-level
|
|
1885
1933
|
// or x.label) rides its own row under the plot.
|
|
@@ -2035,12 +2083,23 @@ class ContourChart extends ContourBase {
|
|
|
2035
2083
|
series = JSON.stringify([{ type: "histogram", bins: this._pushedBins }]);
|
|
2036
2084
|
}
|
|
2037
2085
|
if (series) {
|
|
2038
|
-
|
|
2039
|
-
|
|
2086
|
+
// U-6: parse the LOCAL `series` (attribute or the bins-alone fallback
|
|
2087
|
+
// built above), not the attribute again — re-reading the attribute made
|
|
2088
|
+
// a pushed-bins histogram inert because there is no `series` attribute.
|
|
2089
|
+
let parsed;
|
|
2090
|
+
try { parsed = JSON.parse(series); } catch (e) { warnBadJson(this, "series", e); parsed = []; }
|
|
2091
|
+
if (!Array.isArray(parsed)) parsed = [];
|
|
2092
|
+
if (parsed.length === 0) { renderEmpty(this, "chart"); return; }
|
|
2093
|
+
// U-4: keep the drawn series so a JS tooltipFormat can read a mark's datum.
|
|
2094
|
+
this._chartSeries = parsed;
|
|
2040
2095
|
const plot = this.ensure(".c-chart__plot", () => { const el = document.createElement("div"); el.className = "c-chart__plot"; return el; });
|
|
2041
2096
|
// R24-88: keep the plot alive across renders so patchChildren can reuse its marks instead of the base dropping and rebuilding them.
|
|
2042
2097
|
this.keepNode(plot);
|
|
2043
|
-
|
|
2098
|
+
const frag = document.createDocumentFragment();
|
|
2099
|
+
// U-2/U-3: mean/median reference markers and value annotations are
|
|
2100
|
+
// collected while the histogram renders, then painted over the plot
|
|
2101
|
+
// after patchChildren (which only manages the SVG marks in `frag`).
|
|
2102
|
+
const pendingMarkers = [];
|
|
2044
2103
|
// Structured series: an item may carry `values` plus a `type` ("donut" | "histogram" | "line") instead of a pre-computed `d` path, or carry pre-binned `bins` instead of raw `values`. The helpers in svg.mjs turn those into geometry so a consumer does not have to hand-compute arc or bar math.
|
|
2045
2104
|
const hasStructured = parsed.some((s) => s && (Array.isArray(s.values) || Array.isArray(s.bins)));
|
|
2046
2105
|
if (hasStructured) {
|
|
@@ -2124,6 +2183,14 @@ svg.setAttribute("role", "group");
|
|
|
2124
2183
|
bins = buckets.map((count, bi) => ({ x0: min + bi * width, x1: min + (bi + 1) * width, count }));
|
|
2125
2184
|
}
|
|
2126
2185
|
if (bins) plotVals = bins.map((b) => b.count);
|
|
2186
|
+
// U-1: a histogram may colour by value range. A `colors` array
|
|
2187
|
+
// (chart-level, or per-series `s.colors`) aligns to bins; a bin's
|
|
2188
|
+
// own `color` wins over the array. Each entry is safeColor-guarded.
|
|
2189
|
+
let binColorList = null;
|
|
2190
|
+
const colorsAttr = this.getAttribute("colors");
|
|
2191
|
+
const rawColors = colorsAttr ? (() => { try { return JSON.parse(colorsAttr); } catch (e) { return null; } })()
|
|
2192
|
+
: (Array.isArray(s.colors) ? s.colors : null);
|
|
2193
|
+
if (Array.isArray(rawColors)) binColorList = rawColors.map((c) => safeColor(c)).filter(Boolean);
|
|
2127
2194
|
// Raw values with no bucket count have no boundaries to publish: those bars are counts at index positions, not a distribution over a domain, so `bins` stays empty and the consumer is told there is nothing to map a range onto.
|
|
2128
2195
|
this._renderedBins = bins ? bins.slice() : [];
|
|
2129
2196
|
const pushedBackground = this._pushedBackground && this._pushedBackground.length ? this._pushedBackground : null;
|
|
@@ -2159,7 +2226,10 @@ svg.setAttribute("role", "group");
|
|
|
2159
2226
|
const rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
|
|
2160
2227
|
rect.setAttribute("class", "c-chart__bar");
|
|
2161
2228
|
rect.setAttribute("data-series", String(i + 1));
|
|
2162
|
-
|
|
2229
|
+
// U-1: per-bin colour — bin.color, then the aligned colors
|
|
2230
|
+
// array, then the series colour.
|
|
2231
|
+
const binColor = (bins && bins[ri] && bins[ri].color) || (binColorList && binColorList[ri]) || color;
|
|
2232
|
+
rect.style.setProperty("--c", binColor);
|
|
2163
2233
|
rect.setAttribute("x", r.x);
|
|
2164
2234
|
rect.setAttribute("y", r.y);
|
|
2165
2235
|
rect.setAttribute("width", r.width);
|
|
@@ -2173,7 +2243,40 @@ svg.setAttribute("role", "group");
|
|
|
2173
2243
|
svg.appendChild(rect);
|
|
2174
2244
|
});
|
|
2175
2245
|
frag.appendChild(svg);
|
|
2176
|
-
|
|
2246
|
+
// U-2/U-3: position mean/median markers and annotations on the
|
|
2247
|
+
// histogram's own x-domain (bins[0].x0 .. bins[last].x1), which
|
|
2248
|
+
// is the same domain the bars are laid out over.
|
|
2249
|
+
if (bins && bins.length) {
|
|
2250
|
+
const dMin = Number(bins[0].x0);
|
|
2251
|
+
const dMax = Number(bins[bins.length - 1].x1);
|
|
2252
|
+
const dSpan = (dMax - dMin) || 1;
|
|
2253
|
+
const toFrac = (v) => (v - dMin) / dSpan;
|
|
2254
|
+
const totalCount = bins.reduce((a, b) => a + (Number(b.count) || 0), 0);
|
|
2255
|
+
if (flagOn(this, "mean-marker") && totalCount > 0) {
|
|
2256
|
+
let sum = 0;
|
|
2257
|
+
bins.forEach((b) => { const mid = (Number(b.x0) + Number(b.x1)) / 2; sum += mid * (Number(b.count) || 0); });
|
|
2258
|
+
const mean = sum / totalCount;
|
|
2259
|
+
pendingMarkers.push({ frac: toFrac(mean), label: labelText(this, "mean", "mean") + " " + formatValue(mean), kind: "mean" });
|
|
2260
|
+
}
|
|
2261
|
+
if (flagOn(this, "median-marker") && totalCount > 0) {
|
|
2262
|
+
let acc = 0, median = dMin;
|
|
2263
|
+
const half = totalCount / 2;
|
|
2264
|
+
for (const b of bins) { acc += (Number(b.count) || 0); if (acc >= half) { median = (Number(b.x0) + Number(b.x1)) / 2; break; } }
|
|
2265
|
+
pendingMarkers.push({ frac: toFrac(median), label: labelText(this, "median", "median") + " " + formatValue(median), kind: "median" });
|
|
2266
|
+
}
|
|
2267
|
+
let anns = Array.isArray(s.annotations) ? s.annotations : null;
|
|
2268
|
+
const annAttr = this.getAttribute("annotations");
|
|
2269
|
+
if (!anns && annAttr) { try { const p = JSON.parse(annAttr); if (Array.isArray(p)) anns = p; } catch (e) {} }
|
|
2270
|
+
if (Array.isArray(anns)) {
|
|
2271
|
+
anns.forEach((a) => {
|
|
2272
|
+
const v = Number(a && a.value != null ? a.value : a);
|
|
2273
|
+
if (!Number.isFinite(v)) return;
|
|
2274
|
+
const label = a && typeof a === "object" ? (a.label != null ? String(a.label) : formatValue(v)) : formatValue(v);
|
|
2275
|
+
pendingMarkers.push({ frac: toFrac(v), label, kind: "annotation" });
|
|
2276
|
+
});
|
|
2277
|
+
}
|
|
2278
|
+
}
|
|
2279
|
+
} else if (s.type === "scatter") {
|
|
2177
2280
|
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
2178
2281
|
svg.setAttribute("viewBox", "0 0 300 120");
|
|
2179
2282
|
svg.setAttribute("preserveAspectRatio", "none");
|
|
@@ -2286,6 +2389,8 @@ svg.setAttribute("role", "group");
|
|
|
2286
2389
|
frag.appendChild(svg);
|
|
2287
2390
|
}
|
|
2288
2391
|
patchChildren(plot, frag);
|
|
2392
|
+
// U-2/U-3: paint mean/median markers and annotations over the plot.
|
|
2393
|
+
this._renderChartMarkers(pendingMarkers);
|
|
2289
2394
|
// Styled tooltip element (positioned via --chart-tip-*). R25-03: shed at level ≥2. The hover/focus handlers re-query the tip per event and no-op when absent, so removing it is safe.
|
|
2290
2395
|
if (this.shed("tooltip", 2)) {
|
|
2291
2396
|
const oldTip = this.querySelector(".c-chart__tooltip");
|
|
@@ -2301,7 +2406,12 @@ svg.setAttribute("role", "group");
|
|
|
2301
2406
|
const dataTableRaw = (this.getAttribute("data-table") || "").trim().toLowerCase();
|
|
2302
2407
|
const dataTableOff = dataTableRaw === "none" || dataTableRaw === "off" || dataTableRaw === "false" || dataTableRaw === "0";
|
|
2303
2408
|
const hasTabularValues = parsed.some((s) => Array.isArray(s && s.values) && s.values.length);
|
|
2304
|
-
|
|
2409
|
+
// U-5: a bins-driven histogram has no series `values`, but its drawn
|
|
2410
|
+
// distribution is still tabular data — render it as a range/count table
|
|
2411
|
+
// so the accessible fallback exists for a pushed-bins chart too.
|
|
2412
|
+
const drawnBins = this._renderedBins || [];
|
|
2413
|
+
const hasBinsTable = !hasTabularValues && drawnBins.length > 0;
|
|
2414
|
+
if (!dataTableOff && (hasTabularValues || hasBinsTable)) {
|
|
2305
2415
|
let table = this.querySelector(".c-chart__data-table");
|
|
2306
2416
|
if (!table) {
|
|
2307
2417
|
table = document.createElement("table");
|
|
@@ -2314,6 +2424,33 @@ svg.setAttribute("role", "group");
|
|
|
2314
2424
|
const cap = document.createElement("caption");
|
|
2315
2425
|
cap.textContent = title;
|
|
2316
2426
|
table.appendChild(cap);
|
|
2427
|
+
if (hasBinsTable) {
|
|
2428
|
+
const bThead = document.createElement("thead");
|
|
2429
|
+
const bhr = document.createElement("tr");
|
|
2430
|
+
const bh1 = document.createElement("th");
|
|
2431
|
+
bh1.setAttribute("scope", "col");
|
|
2432
|
+
bh1.textContent = labelText(this, "range", "Range");
|
|
2433
|
+
bhr.appendChild(bh1);
|
|
2434
|
+
const bh2 = document.createElement("th");
|
|
2435
|
+
bh2.setAttribute("scope", "col");
|
|
2436
|
+
bh2.textContent = labelText(this, "count", "Count");
|
|
2437
|
+
bhr.appendChild(bh2);
|
|
2438
|
+
bThead.appendChild(bhr);
|
|
2439
|
+
table.appendChild(bThead);
|
|
2440
|
+
const bBody = document.createElement("tbody");
|
|
2441
|
+
drawnBins.forEach((b) => {
|
|
2442
|
+
const tr = document.createElement("tr");
|
|
2443
|
+
const td0 = document.createElement("th");
|
|
2444
|
+
td0.setAttribute("scope", "row");
|
|
2445
|
+
td0.textContent = formatValue(b.x0) + "–" + formatValue(b.x1);
|
|
2446
|
+
tr.appendChild(td0);
|
|
2447
|
+
const td1 = document.createElement("td");
|
|
2448
|
+
td1.textContent = isMissing(b.count) ? "" : String(b.count);
|
|
2449
|
+
tr.appendChild(td1);
|
|
2450
|
+
bBody.appendChild(tr);
|
|
2451
|
+
});
|
|
2452
|
+
table.appendChild(bBody);
|
|
2453
|
+
} else {
|
|
2317
2454
|
const thead = document.createElement("thead");
|
|
2318
2455
|
const hr = document.createElement("tr");
|
|
2319
2456
|
const h = document.createElement("th");
|
|
@@ -2346,6 +2483,7 @@ svg.setAttribute("role", "group");
|
|
|
2346
2483
|
tbody.appendChild(tr);
|
|
2347
2484
|
});
|
|
2348
2485
|
table.appendChild(tbody);
|
|
2486
|
+
}
|
|
2349
2487
|
} else {
|
|
2350
2488
|
const old = this.querySelector(".c-chart__data-table");
|
|
2351
2489
|
if (old) old.remove();
|
|
@@ -2564,7 +2702,16 @@ svg.setAttribute("role", "group");
|
|
|
2564
2702
|
const mark = e.target && e.target.closest ? e.target.closest(".c-chart__bar, .c-chart__point, .c-chart__line, .c-donut__slice") : null;
|
|
2565
2703
|
if (!mark || !plot.contains(mark)) { tip.setAttribute("hidden", ""); return; }
|
|
2566
2704
|
const title = mark.getAttribute("data-title") || mark.getAttribute("title");
|
|
2567
|
-
|
|
2705
|
+
// U-4: a JS `tooltipFormat` builds the tip text from the mark's datum.
|
|
2706
|
+
if (this._jsTooltipFormat) {
|
|
2707
|
+
try {
|
|
2708
|
+
const idx = mark.getAttribute("data-index");
|
|
2709
|
+
const seriesObj = this._chartSeries ? this._chartSeries[(Number(mark.getAttribute("data-series")) || 1) - 1] : null;
|
|
2710
|
+
const value = seriesObj && Array.isArray(seriesObj.values) && idx !== null && idx !== undefined ? seriesObj.values[Number(idx)] : title;
|
|
2711
|
+
const out = this._jsTooltipFormat({ series: mark.getAttribute("data-series"), index: idx != null ? Number(idx) : null, value, title });
|
|
2712
|
+
if (title || out != null) tip.textContent = out == null ? title : String(out);
|
|
2713
|
+
} catch (e) { if (title) tip.textContent = title; }
|
|
2714
|
+
} else if (title) tip.textContent = title;
|
|
2568
2715
|
if (!plotRectCache) {
|
|
2569
2716
|
plotRectCache = plot.getBoundingClientRect();
|
|
2570
2717
|
if (!plotRectObserver && typeof ResizeObserver === "function") {
|
|
@@ -3107,18 +3254,24 @@ class ContourReferenceRule extends ContourBase {
|
|
|
3107
3254
|
|
|
3108
3255
|
/**
|
|
3109
3256
|
* Small Multiples (R33-45): a grid of charts that share axes. Attributes:
|
|
3110
|
-
* `columns` (grid column count) and `
|
|
3111
|
-
* responsive grid; the group is the shared-axis frame, the
|
|
3112
|
-
* individual multiples.
|
|
3257
|
+
* `columns` (grid column count), `label` and `multiples`. Slotted charts are
|
|
3258
|
+
* laid out in a responsive grid; the group is the shared-axis frame, the
|
|
3259
|
+
* children are the individual multiples.
|
|
3113
3260
|
*
|
|
3114
|
-
*
|
|
3115
|
-
* `
|
|
3116
|
-
*
|
|
3117
|
-
*
|
|
3261
|
+
* Data contract (U4): `multiples` is a JSON array of
|
|
3262
|
+
* `{ label, points, key?, value? }`. When it is present the frame renders one
|
|
3263
|
+
* cell per entry — a caption and an inline sparkline — so a consumer can drive
|
|
3264
|
+
* the grid from data without hand-authoring a child per multiple. Each cell is
|
|
3265
|
+
* a focusable `role="button"` that emits `contour:select` with
|
|
3266
|
+
* `{ index, key, label, value }`, where `value` defaults to the entry's last
|
|
3267
|
+
* finite point. When `multiples` is absent the frame is layout-only and slotted
|
|
3268
|
+
* children supply the marks, so the two forms are alternatives: a child that
|
|
3269
|
+
* selects bubbles its own `contour:select` through the frame, and a page still
|
|
3270
|
+
* listens once.
|
|
3118
3271
|
*/
|
|
3119
3272
|
class ContourSmallMultiples extends ContourBase {
|
|
3120
|
-
static get observed() { return ["columns", "label"]; }
|
|
3121
|
-
static get properties() { return { columns: { attribute: "columns", type: Number }, label: { attribute: "label" } }; }
|
|
3273
|
+
static get observed() { return ["columns", "label", "multiples"]; }
|
|
3274
|
+
static get properties() { return { columns: { attribute: "columns", type: Number }, label: { attribute: "label" }, multiples: { attribute: "multiples" } }; }
|
|
3122
3275
|
render() {
|
|
3123
3276
|
this.classList.add("c-small-multiples");
|
|
3124
3277
|
if (!this.hasAttribute("role")) this.setAttribute("role", "group");
|
|
@@ -3126,6 +3279,72 @@ class ContourSmallMultiples extends ContourBase {
|
|
|
3126
3279
|
if (label) this.setAttribute("aria-label", label); else this.removeAttribute("aria-label");
|
|
3127
3280
|
const cols = this.getAttribute("columns");
|
|
3128
3281
|
if (cols) this.style.setProperty("--sm-cols", cols); else this.style.removeProperty("--sm-cols");
|
|
3282
|
+
this._smEntries = null;
|
|
3283
|
+
const raw = this.getAttribute("multiples");
|
|
3284
|
+
if (!raw) return;
|
|
3285
|
+
let parsed;
|
|
3286
|
+
try { parsed = JSON.parse(raw); } catch (e) { return; } // malformed JSON leaves the frame layout-only
|
|
3287
|
+
if (!Array.isArray(parsed)) return;
|
|
3288
|
+
this._smEntries = parsed;
|
|
3289
|
+
parsed.forEach((entry, i) => this._renderCell(entry, i));
|
|
3290
|
+
}
|
|
3291
|
+
_renderCell(entry, index) {
|
|
3292
|
+
const item = entry && typeof entry === "object" ? entry : {};
|
|
3293
|
+
const points = Array.isArray(item.points) ? item.points.filter(Number.isFinite) : [];
|
|
3294
|
+
const name = item.label != null ? String(item.label) : `Multiple ${index + 1}`;
|
|
3295
|
+
const cell = document.createElement("figure");
|
|
3296
|
+
cell.className = "c-small-multiples__cell";
|
|
3297
|
+
cell.setAttribute("data-sm-index", String(index));
|
|
3298
|
+
cell.setAttribute("role", "button");
|
|
3299
|
+
cell.setAttribute("tabindex", "0");
|
|
3300
|
+
cell.setAttribute("aria-label", name);
|
|
3301
|
+
const cap = document.createElement("figcaption");
|
|
3302
|
+
cap.className = "c-small-multiples__label";
|
|
3303
|
+
cap.textContent = name;
|
|
3304
|
+
cell.appendChild(cap);
|
|
3305
|
+
const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
|
|
3306
|
+
svg.setAttribute("class", "c-small-multiples__mark");
|
|
3307
|
+
svg.setAttribute("viewBox", "0 0 100 30");
|
|
3308
|
+
svg.setAttribute("preserveAspectRatio", "none");
|
|
3309
|
+
svg.setAttribute("aria-hidden", "true");
|
|
3310
|
+
if (points.length >= 2) {
|
|
3311
|
+
const min = Math.min(...points);
|
|
3312
|
+
const range = (Math.max(...points) - min) || 1;
|
|
3313
|
+
const n = points.length;
|
|
3314
|
+
const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
3315
|
+
path.setAttribute("d", points.map((p, i) => (i === 0 ? "M" : "L") + " " + (i * 100 / (n - 1)) + " " + (30 - ((p - min) / range) * 30)).join(" "));
|
|
3316
|
+
svg.appendChild(path);
|
|
3317
|
+
}
|
|
3318
|
+
cell.appendChild(svg);
|
|
3319
|
+
this.appendChild(cell);
|
|
3320
|
+
}
|
|
3321
|
+
enhance() {
|
|
3322
|
+
if (this._wiredSmallMultiples) return;
|
|
3323
|
+
this._wiredSmallMultiples = true;
|
|
3324
|
+
// Delegated on the host (rule 12): render() rebuilds the cells on every
|
|
3325
|
+
// attribute change, so a listener bound to a cell would be lost.
|
|
3326
|
+
const select = (e) => {
|
|
3327
|
+
const cell = e.target && e.target.closest ? e.target.closest(".c-small-multiples__cell[data-sm-index]") : null;
|
|
3328
|
+
if (!cell || !this.contains(cell)) return;
|
|
3329
|
+
const index = Number(cell.getAttribute("data-sm-index"));
|
|
3330
|
+
const entry = (this._smEntries || [])[index] || {};
|
|
3331
|
+
const points = Array.isArray(entry.points) ? entry.points.filter(Number.isFinite) : [];
|
|
3332
|
+
const value = entry.value != null ? entry.value : (points.length ? points[points.length - 1] : null);
|
|
3333
|
+
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: {
|
|
3334
|
+
index,
|
|
3335
|
+
key: entry.key != null ? entry.key : null,
|
|
3336
|
+
label: entry.label != null ? String(entry.label) : "",
|
|
3337
|
+
value,
|
|
3338
|
+
} }));
|
|
3339
|
+
};
|
|
3340
|
+
this.addEventListener("click", select);
|
|
3341
|
+
this.addEventListener("keydown", (e) => {
|
|
3342
|
+
if (e.key !== "Enter" && e.key !== " ") return;
|
|
3343
|
+
const cell = e.target && e.target.closest ? e.target.closest(".c-small-multiples__cell[data-sm-index]") : null;
|
|
3344
|
+
if (!cell || !this.contains(cell)) return;
|
|
3345
|
+
e.preventDefault();
|
|
3346
|
+
select(e);
|
|
3347
|
+
});
|
|
3129
3348
|
}
|
|
3130
3349
|
}
|
|
3131
3350
|
define("contour-small-multiples", ContourSmallMultiples);
|
|
@@ -4328,8 +4547,63 @@ class ContourPivot extends ContourBase {
|
|
|
4328
4547
|
if (n === "max") return (vals) => vals.length ? Math.max(...vals) : 0;
|
|
4329
4548
|
return (vals) => vals.reduce((a,b)=>a+b,0);
|
|
4330
4549
|
}
|
|
4550
|
+
// U-10: focus snapshot/restore. The pivot rebuilds its whole table (and
|
|
4551
|
+
// toolbar) on every render, which drops focus to <body>; capture the focused
|
|
4552
|
+
// cell (or the filter input) and restore it to the same place afterwards.
|
|
4553
|
+
_pivotCaptureFocus() {
|
|
4554
|
+
// The base drops the focused node before render() runs; use the last cell
|
|
4555
|
+
// (or the filter input) the user focused, recorded by focusin in enhance().
|
|
4556
|
+
if (this._pivotFocus) return this._pivotFocus;
|
|
4557
|
+
const el = document.activeElement;
|
|
4558
|
+
if (!el || !this.contains(el)) return null;
|
|
4559
|
+
if (el.classList && el.classList.contains("c-pivot__filter")) return { kind: "filter" };
|
|
4560
|
+
const cell = el.closest ? el.closest("th, td") : null;
|
|
4561
|
+
if (!cell || !this.contains(cell)) return null;
|
|
4562
|
+
const tr = cell.parentElement;
|
|
4563
|
+
if (!tr) return null;
|
|
4564
|
+
const rowHeader = tr.querySelector ? tr.querySelector("th[role='rowheader']") : null;
|
|
4565
|
+
return {
|
|
4566
|
+
kind: "cell",
|
|
4567
|
+
row: rowHeader ? rowHeader.textContent : (tr.dataset ? tr.dataset.row : undefined),
|
|
4568
|
+
col: Array.from(tr.children).indexOf(cell),
|
|
4569
|
+
isHeader: !!(cell.closest && cell.closest("thead")),
|
|
4570
|
+
};
|
|
4571
|
+
}
|
|
4572
|
+
_pivotRestoreFocus(snap) {
|
|
4573
|
+
if (!snap) return;
|
|
4574
|
+
// Deferred so it runs after the base class's generic focus preservation
|
|
4575
|
+
// (U-10): the pivot rebuilds its whole table, so the base would otherwise
|
|
4576
|
+
// land focus on whatever focusable sits at the old index.
|
|
4577
|
+
queueMicrotask(() => {
|
|
4578
|
+
if (!this.isConnected) return;
|
|
4579
|
+
const active = document.activeElement;
|
|
4580
|
+
if (active && active !== this && active !== document.body && !this.contains(active)) return;
|
|
4581
|
+
if (snap.kind === "filter") {
|
|
4582
|
+
const f = this.querySelector(".c-pivot__filter");
|
|
4583
|
+
if (f) { try { f.focus(); } catch (e) {} }
|
|
4584
|
+
return;
|
|
4585
|
+
}
|
|
4586
|
+
const table = this.querySelector("table");
|
|
4587
|
+
if (!table) return;
|
|
4588
|
+
let cell = null;
|
|
4589
|
+
if (snap.isHeader) {
|
|
4590
|
+
const hr = table.querySelector("thead tr");
|
|
4591
|
+
if (hr) cell = hr.children[snap.col] || null;
|
|
4592
|
+
} else {
|
|
4593
|
+
const rowHeader = snap.row != null ? Array.from(table.querySelectorAll("th[role='rowheader']")).find((th) => th.textContent === snap.row) : null;
|
|
4594
|
+
const tr = rowHeader ? rowHeader.parentElement : null;
|
|
4595
|
+
if (tr && tr.children[snap.col]) cell = tr.children[snap.col];
|
|
4596
|
+
}
|
|
4597
|
+
if (cell) {
|
|
4598
|
+
table.querySelectorAll('[tabindex="0"]').forEach((c) => c.setAttribute("tabindex", "-1"));
|
|
4599
|
+
cell.setAttribute("tabindex", "0");
|
|
4600
|
+
try { cell.focus(); } catch (e) {}
|
|
4601
|
+
}
|
|
4602
|
+
});
|
|
4603
|
+
}
|
|
4331
4604
|
render() {
|
|
4332
4605
|
this.classList.add("c-pivot");
|
|
4606
|
+
const focusSnap = this._pivotCaptureFocus();
|
|
4333
4607
|
wireStates(this);
|
|
4334
4608
|
loadRemote(this, ["data"]);
|
|
4335
4609
|
if (renderStates(this, "pivot")) return;
|
|
@@ -4451,10 +4725,29 @@ class ContourPivot extends ContourBase {
|
|
|
4451
4725
|
table.appendChild(tbody);
|
|
4452
4726
|
wrap.appendChild(table);
|
|
4453
4727
|
this.appendChild(wrap);
|
|
4728
|
+
// U-10: restore focus to the same cell (or the filter input) after rebuild.
|
|
4729
|
+
this._pivotRestoreFocus(focusSnap);
|
|
4454
4730
|
}
|
|
4455
4731
|
enhance() {
|
|
4456
4732
|
if (this._wiredPivot) return;
|
|
4457
4733
|
this._wiredPivot = true;
|
|
4734
|
+
// U-10: remember the last focused cell / filter input across a re-render.
|
|
4735
|
+
this.addEventListener("focusin", (e) => {
|
|
4736
|
+
const t = e.target;
|
|
4737
|
+
if (!t || !this.contains(t)) return;
|
|
4738
|
+
if (t.classList && t.classList.contains("c-pivot__filter")) { this._pivotFocus = { kind: "filter" }; return; }
|
|
4739
|
+
const cell = t.closest ? t.closest("th, td") : null;
|
|
4740
|
+
if (!cell || !this.contains(cell)) return;
|
|
4741
|
+
const tr = cell.parentElement;
|
|
4742
|
+
if (!tr) return;
|
|
4743
|
+
const rowHeader = tr.querySelector ? tr.querySelector("th[role='rowheader']") : null;
|
|
4744
|
+
this._pivotFocus = {
|
|
4745
|
+
kind: "cell",
|
|
4746
|
+
row: rowHeader ? rowHeader.textContent : (tr.dataset ? tr.dataset.row : undefined),
|
|
4747
|
+
col: Array.from(tr.children).indexOf(cell),
|
|
4748
|
+
isHeader: !!(cell.closest && cell.closest("thead")),
|
|
4749
|
+
};
|
|
4750
|
+
});
|
|
4458
4751
|
this.addEventListener("click", (e) => {
|
|
4459
4752
|
const th = e.target && e.target.closest ? e.target.closest("th") : null;
|
|
4460
4753
|
const td = e.target && e.target.closest ? e.target.closest("td") : null;
|
|
@@ -6361,6 +6654,26 @@ function readRuleValue(row) {
|
|
|
6361
6654
|
if (nullBox) return nullBox.checked ? "null" : "";
|
|
6362
6655
|
return row.querySelector(".c-query-builder__value")?.value || "";
|
|
6363
6656
|
}
|
|
6657
|
+
/**
|
|
6658
|
+
* Query builder: a controlled rule editor. Emits `contour:change` with
|
|
6659
|
+
* `{ query, draft }`.
|
|
6660
|
+
*
|
|
6661
|
+
* Contract (U-13) — all three inputs are JSON **attribute strings**:
|
|
6662
|
+
* - `fields`: an array of column definitions. Each item is a string, or an
|
|
6663
|
+
* object `{ value?, key?, label?, name?, type?, options? }`. `type` is one of
|
|
6664
|
+
* `text | number | date | enum | null | range` and selects the value editor;
|
|
6665
|
+
* `enum` requires `options` (array of strings or `{ value, label }`). A map
|
|
6666
|
+
* object (`{ "<key>": <meta> }`) is also accepted and normalised to the array
|
|
6667
|
+
* form. A non-array, non-map value degrades to an empty field list rather than
|
|
6668
|
+
* throwing (which used to surface as "Component failed to render").
|
|
6669
|
+
* - `query`: an array of rule objects `{ id?, field, op, value, connector?,
|
|
6670
|
+
* group?, not? }` (`op` ∈ `= != > < contains`; `connector` ∈ `AND OR` on every
|
|
6671
|
+
* rule after the first; `group` groups consecutive rules; `not` negates). An
|
|
6672
|
+
* object with a `rules` array is also accepted.
|
|
6673
|
+
* - `draft`: boolean. While present, edits are held locally and announced with
|
|
6674
|
+
* `draft:true`; removing it (or `commitDraft()`) finalises the draft into
|
|
6675
|
+
* `query` and announces `draft:false`.
|
|
6676
|
+
*/
|
|
6364
6677
|
class ContourQueryBuilder extends ContourBase {
|
|
6365
6678
|
static get observed() { return ["query", "fields", "draft"]; }
|
|
6366
6679
|
static get properties() { return { query: { attribute: "query" }, fields: { attribute: "fields" }, draft: { attribute: "draft", type: Boolean } }; }
|
|
@@ -6434,16 +6747,34 @@ class ContourQueryBuilder extends ContourBase {
|
|
|
6434
6747
|
render() {
|
|
6435
6748
|
this.classList.add("c-query-builder");
|
|
6436
6749
|
const fields = this.getAttribute("fields");
|
|
6750
|
+
// U-13: accept an array of strings/objects OR a `{ key: meta }` map; never
|
|
6751
|
+
// throw on an unexpected shape (that surfaced as "Component failed to
|
|
6752
|
+
// render"). A field item's key is `value ?? key ?? label ?? name`.
|
|
6753
|
+
const fieldKey = (f) => (typeof f === "string" ? f : (f.value ?? f.key ?? f.label ?? f.name ?? ""));
|
|
6754
|
+
const fieldLabel = (f) => (typeof f === "string" ? f : (f.label ?? f.name ?? f.value ?? f.key ?? ""));
|
|
6437
6755
|
let fieldList = [];
|
|
6438
|
-
if (fields) {
|
|
6756
|
+
if (fields) {
|
|
6757
|
+
try {
|
|
6758
|
+
const p = JSON.parse(fields);
|
|
6759
|
+
if (Array.isArray(p)) fieldList = p;
|
|
6760
|
+
else if (p && typeof p === "object") fieldList = Object.keys(p).map((k) => (p[k] && typeof p[k] === "object" ? { value: k, ...p[k] } : k));
|
|
6761
|
+
} catch (e) { fieldList = []; }
|
|
6762
|
+
}
|
|
6439
6763
|
const query = this.getAttribute("query");
|
|
6440
6764
|
let rules = [];
|
|
6441
6765
|
// R34-165: in draft mode the rows come from the held draft, not the attr.
|
|
6442
6766
|
if (this.hasAttribute("draft") && this._draftRows) {
|
|
6443
6767
|
rules = this._draftRows;
|
|
6444
|
-
} else if (query) {
|
|
6768
|
+
} else if (query) {
|
|
6769
|
+
try {
|
|
6770
|
+
const p = JSON.parse(query);
|
|
6771
|
+
// U-13: an array of rules, or an object carrying a `rules` array.
|
|
6772
|
+
if (Array.isArray(p)) rules = p;
|
|
6773
|
+
else if (p && Array.isArray(p.rules)) rules = p.rules;
|
|
6774
|
+
} catch (e) { rules = []; }
|
|
6775
|
+
}
|
|
6445
6776
|
// Field metadata (type/options) drives the value editor (R34-165).
|
|
6446
|
-
const fieldMeta = (name) => fieldList.find((f) => (
|
|
6777
|
+
const fieldMeta = (name) => fieldList.find((f) => fieldKey(f) === name) || {};
|
|
6447
6778
|
const list = this.ensure(".c-query-builder__list", () => { const el = document.createElement("div"); el.className = "c-query-builder__list"; return el; });
|
|
6448
6779
|
Array.from(list.querySelectorAll(".c-query-builder__row, .c-query-builder__connector, .c-query-builder__group")).forEach((n) => n.remove());
|
|
6449
6780
|
let currentGroup = null;
|
|
@@ -6505,8 +6836,8 @@ class ContourQueryBuilder extends ContourBase {
|
|
|
6505
6836
|
field.setAttribute("aria-label", labelText(this, "field", "Field") + " " + (i + 1));
|
|
6506
6837
|
fieldList.forEach((f) => {
|
|
6507
6838
|
const opt = document.createElement("option");
|
|
6508
|
-
opt.value =
|
|
6509
|
-
opt.textContent =
|
|
6839
|
+
opt.value = fieldKey(f);
|
|
6840
|
+
opt.textContent = fieldLabel(f);
|
|
6510
6841
|
if (opt.value === rule.field) opt.selected = true;
|
|
6511
6842
|
field.appendChild(opt);
|
|
6512
6843
|
});
|