contour-ds 1.7.2 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +244 -326
- package/dist/agent-cookbook.json +960 -0
- package/dist/agent-examples.json +65 -0
- package/dist/agent-map-wiring.json +152 -0
- package/dist/agent-rules.json +16 -0
- package/dist/build-manifest.json +344 -126
- package/dist/contour-wc-content.esm.js +1939 -0
- package/dist/contour-wc-content.esm.min.js +1 -0
- package/dist/contour-wc-core.esm.js +3724 -0
- package/dist/contour-wc-core.esm.min.js +1 -0
- package/dist/contour-wc-dashboard.esm.js +6986 -0
- package/dist/contour-wc-dashboard.esm.min.js +1 -0
- package/dist/contour-wc-data.esm.js +6572 -0
- package/dist/contour-wc-data.esm.min.js +1 -0
- package/dist/contour-wc-docs.esm.js +976 -0
- package/dist/contour-wc-docs.esm.min.js +1 -0
- package/dist/contour-wc-feedback.esm.js +1742 -0
- package/dist/contour-wc-feedback.esm.min.js +1 -0
- package/dist/contour-wc-forms.esm.js +2437 -0
- package/dist/contour-wc-forms.esm.min.js +1 -0
- package/dist/contour-wc-interaction.esm.js +1343 -0
- package/dist/contour-wc-interaction.esm.min.js +1 -0
- package/dist/contour-wc-layout.esm.js +845 -0
- package/dist/contour-wc-layout.esm.min.js +1 -0
- package/dist/contour-wc-map.esm.js +2411 -0
- package/dist/contour-wc-map.esm.min.js +1 -0
- package/dist/contour-wc-misc.esm.js +945 -0
- package/dist/contour-wc-misc.esm.min.js +1 -0
- package/dist/contour-wc-navigation.esm.js +2842 -0
- package/dist/contour-wc-navigation.esm.min.js +1 -0
- package/dist/contour-wc-ui.esm.js +6519 -0
- package/dist/contour-wc-ui.esm.min.js +1 -0
- package/dist/contour-wc.esm.js +14435 -5723
- package/dist/contour-wc.esm.min.js +1 -1
- package/dist/contour-wc.js +14436 -5725
- package/dist/contour-wc.min.js +1 -1
- package/dist/contour.a11y.json +402 -0
- package/dist/contour.code-snippets +4534 -0
- package/dist/contour.components.json +4870 -1222
- package/dist/contour.css +6672 -4711
- package/dist/contour.d.ts +753 -1085
- package/dist/contour.esm.js +440 -18
- package/dist/contour.esm.min.js +1 -1
- package/dist/contour.html-data.json +11343 -0
- package/dist/contour.js +440 -18
- package/dist/contour.min.css +1 -1
- package/dist/contour.min.js +1 -1
- package/dist/contour.react.d.ts +422 -0
- package/dist/contour.single.html +17 -0
- package/dist/contour.single.min.css +1 -0
- package/dist/contour.themes.json +56 -12
- package/dist/contour.tokens.json +1318 -1053
- package/dist/contour.vue.d.ts +420 -0
- package/dist/contour.web-types.json +11703 -0
- package/dist/custom-elements.json +36120 -0
- package/dist/docs/actions.md +16 -6
- package/dist/docs/affordances.md +21 -85
- package/dist/docs/apireference.md +9 -5
- package/dist/docs/colour.md +10 -4
- package/dist/docs/componentindex.md +9 -22
- package/dist/docs/data.md +39 -58
- package/dist/docs/docs.md +12 -7
- package/dist/docs/feedback.md +30 -12
- package/dist/docs/field.md +28 -13
- package/dist/docs/forms.md +35 -19
- package/dist/docs/index.json +70 -61
- package/dist/docs/install.md +12 -7
- package/dist/docs/landing.md +7 -4
- package/dist/docs/mapengine.md +30 -8
- package/dist/docs/motion.md +12 -6
- package/dist/docs/navigation.md +31 -7
- package/dist/docs/overlays.md +32 -25
- package/dist/docs/overview.md +3 -2
- package/dist/docs/patterns.md +20 -10
- package/dist/docs/playground.md +11 -4
- package/dist/docs/principles.md +8 -6
- package/dist/docs/recipes.md +117 -13
- package/dist/docs/space.md +10 -6
- package/dist/docs/status.md +13 -14
- package/dist/docs/surfaces.md +17 -22
- package/dist/docs/theming.md +18 -32
- package/dist/docs/type.md +12 -5
- package/dist/docs/webcomponents.md +75 -33
- package/dist/hljs.css +1 -20
- package/dist/map-chrome.mapbox.css +68 -92
- package/dist/map-chrome.maplibre.css +68 -92
- package/dist/registry/items/contour-core.json +2 -2
- package/dist/registry/items/contour-data.json +2 -2
- package/dist/registry/items/contour-docs.json +2 -2
- package/dist/registry/items/contour-landing.json +2 -2
- package/dist/registry/registry.json +8 -8
- package/dist/surfaces/contour-core.min.css +1 -1
- package/dist/surfaces/contour-data.min.css +1 -1
- package/dist/surfaces/contour-docs.min.css +1 -1
- package/dist/surfaces/contour-landing.min.css +1 -1
- package/dist/svg/icons.svg +367 -0
- package/dist/wc/behaviours.mjs +222 -192
- package/dist/wc/content.mjs +486 -142
- package/dist/wc/core.mjs +917 -395
- package/dist/wc/dashboard.mjs +252 -25
- package/dist/wc/data-chart.mjs +1333 -0
- package/dist/wc/data-export.mjs +391 -0
- package/dist/wc/data-gauge.mjs +779 -0
- package/dist/wc/data-geo.mjs +696 -0
- package/dist/wc/data-glyphs.mjs +133 -0
- package/dist/wc/data-legend.mjs +431 -0
- package/dist/wc/data-readout.mjs +227 -0
- package/dist/wc/data-series.mjs +1004 -0
- package/dist/wc/data-table.mjs +751 -0
- package/dist/wc/data.mjs +15 -3707
- package/dist/wc/docs.mjs +113 -19
- package/dist/wc/feedback.mjs +320 -116
- package/dist/wc/forms-controls.mjs +635 -0
- package/dist/wc/forms-field.mjs +547 -0
- package/dist/wc/forms-groups.mjs +347 -0
- package/dist/wc/forms-input.mjs +292 -0
- package/dist/wc/forms.mjs +10 -1122
- package/dist/wc/glyph.mjs +204 -0
- package/dist/wc/index.mjs +16 -7
- package/dist/wc/interaction.mjs +322 -75
- package/dist/wc/layout.mjs +100 -29
- package/dist/wc/map.mjs +888 -285
- package/dist/wc/misc.mjs +137 -26
- package/dist/wc/navigation-menu.mjs +735 -0
- package/dist/wc/navigation-shell.mjs +495 -0
- package/dist/wc/navigation-tree.mjs +995 -0
- package/dist/wc/navigation.mjs +9 -1636
- package/dist/wc/registration.mjs +1 -8
- package/dist/wc/shadow.mjs +285 -113
- package/dist/wc/states.mjs +75 -78
- package/dist/wc/svg.mjs +209 -34
- package/dist/wc/ui-atoms.mjs +608 -0
- package/dist/wc/ui-data.mjs +1404 -0
- package/dist/wc/ui-feedback.mjs +419 -0
- package/dist/wc/ui-inputs.mjs +1570 -0
- package/dist/wc/ui-menus.mjs +307 -0
- package/dist/wc/ui-overlays.mjs +1605 -0
- package/integrations/README.md +25 -5
- package/integrations/ai/CLAUDE.md +6 -3
- package/integrations/ai/COPILOT.md +14 -0
- package/integrations/ai/GEMINI.md +14 -0
- package/integrations/ai/WINDSURF.md +14 -0
- package/integrations/ai/v0-prompt.md +13 -1
- package/integrations/frameworks/README.md +235 -0
- package/integrations/native/README.md +0 -3
- package/integrations/native/style-dictionary.config.json +1 -1
- package/integrations/tailwind/contour-theme.css +71 -13
- package/integrations/validate-markup.mjs +172 -0
- package/package.json +103 -39
- package/dist/wc/ui.mjs +0 -3560
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
import { setHTML, ContourBase, define, onDispose, formatValue, contourId, navKey, isRtl, cssLength , safeColor, warnBadJson, labelText } from './core.mjs';
|
|
2
|
+
import { loadRemote, remoteData, renderStates, renderEmpty, wireStates, remoteInvalidate, watchViewport, parseArrayAttr, stateLabel } from './states.mjs';
|
|
3
|
+
import { donutSlices, barRects, smoothPath, polylinePoints, contourPaths } from './svg.mjs';
|
|
4
|
+
import { paintDonutGlyph, paintSparklineGlyph, paintPurityRing } from './glyph.mjs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Error Boundary: web component wrapper.
|
|
8
|
+
* Attributes: `fallback`, `error`.
|
|
9
|
+
*/
|
|
10
|
+
class ContourErrorBoundary extends ContourBase {
|
|
11
|
+
static get observed() { return ["fallback", "error"]; }
|
|
12
|
+
static get properties() { return { fallback: { attribute: "fallback" }, error: { attribute: "error" } }; }
|
|
13
|
+
render() {
|
|
14
|
+
this.classList.add("c-error-boundary");
|
|
15
|
+
// Author's role/live-region outranks boundary defaults; overwriting silently changed host semantics (F-RO18).
|
|
16
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "region");
|
|
17
|
+
if (!this.hasAttribute("aria-live")) this.setAttribute("aria-live", "polite");
|
|
18
|
+
const err = this.getAttribute("error");
|
|
19
|
+
if (err) {
|
|
20
|
+
this.dataset.state = "error";
|
|
21
|
+
// Hide authored children, show fallback. `display: none` restored from prior value, not `""` (UA default turns span/tr into block, F-RO17).
|
|
22
|
+
Array.from(this.children).forEach((c) => {
|
|
23
|
+
if (c.hasAttribute("data-fallback")) return;
|
|
24
|
+
if (c.dataset.contourDisplay === undefined) {
|
|
25
|
+
c.dataset.contourDisplay = c.style.display;
|
|
26
|
+
}
|
|
27
|
+
c.style.display = "none";
|
|
28
|
+
});
|
|
29
|
+
let fb = this.querySelector("[data-fallback]");
|
|
30
|
+
if (!fb) {
|
|
31
|
+
fb = document.createElement("div");
|
|
32
|
+
fb.className = "c-error-boundary__fallback";
|
|
33
|
+
fb.dataset.fallback = "";
|
|
34
|
+
fb.dataset.contourGenerated = "1";
|
|
35
|
+
fb.textContent = this.getAttribute("fallback") || "Something went wrong.";
|
|
36
|
+
this.appendChild(fb);
|
|
37
|
+
} else {
|
|
38
|
+
if (fb.style.display === "none") fb.style.display = "";
|
|
39
|
+
if (fb.dataset.contourGenerated === "1" || this.hasAttribute("fallback")) {
|
|
40
|
+
fb.textContent = this.getAttribute("fallback") || fb.textContent || "Something went wrong.";
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
this.dataset.state = "ready";
|
|
45
|
+
Array.from(this.children).forEach((c) => {
|
|
46
|
+
if (c.hasAttribute("data-fallback")) {
|
|
47
|
+
if (c.dataset.contourGenerated === "1") c.remove();
|
|
48
|
+
else c.style.display = "none";
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (c.dataset.contourDisplay !== undefined) {
|
|
52
|
+
c.style.display = c.dataset.contourDisplay;
|
|
53
|
+
delete c.dataset.contourDisplay;
|
|
54
|
+
} else if (c.style.display === "none") {
|
|
55
|
+
c.style.display = "";
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
enhance() {
|
|
61
|
+
if (this._wiredErrorBoundary) return;
|
|
62
|
+
this._wiredErrorBoundary = true;
|
|
63
|
+
// Catch errors thrown by descendants during render/event handling.
|
|
64
|
+
this.addEventListener("error", (e) => {
|
|
65
|
+
e.stopPropagation();
|
|
66
|
+
const msg = (e && e.error && e.error.message) ? e.error.message : (e && e.message) ? e.message : "Unknown error";
|
|
67
|
+
const src = e && e.target && (e.target.src || e.target.href) ? (e.target.src || e.target.href) : undefined;
|
|
68
|
+
this.setAttribute("error", msg);
|
|
69
|
+
this.dispatchEvent(new CustomEvent("contour:error", { bubbles: true, composed: true, detail: src ? { message: msg, src } : { message: msg } }));
|
|
70
|
+
}, true);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
define("contour-error-boundary", ContourErrorBoundary);
|
|
74
|
+
|
|
75
|
+
class ContourDataExport extends ContourBase {
|
|
76
|
+
static get observed() { return ["data", "format", "filename", "label"]; }
|
|
77
|
+
static get properties() { return { data: { attribute: "data" }, format: { attribute: "format" }, filename: { attribute: "filename" }, label: { attribute: "label" } }; }
|
|
78
|
+
render() {
|
|
79
|
+
this.classList.add("c-data-export");
|
|
80
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "group");
|
|
81
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "data-export", "Data export"));
|
|
82
|
+
const rawFmt = (this.getAttribute("format") || "json").toLowerCase();
|
|
83
|
+
const fmt = (rawFmt === "csv" || rawFmt === "json") ? rawFmt : "json";
|
|
84
|
+
const btn = this.ensure(".c-data-export__btn", () => {
|
|
85
|
+
const b = document.createElement("button");
|
|
86
|
+
// `c-btn` carries control contract (press language, focus ring, disabled) — hand-rolled rule couldn't keep in step (F-CSS21).
|
|
87
|
+
b.className = "c-btn c-data-export__btn";
|
|
88
|
+
b.type = "button";
|
|
89
|
+
return b;
|
|
90
|
+
});
|
|
91
|
+
// R31-145: a primary action keeps its text and gains an icon (icon+text).
|
|
92
|
+
setHTML(btn, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-download" /></svg>');
|
|
93
|
+
btn.appendChild(document.createTextNode(" " + (this.getAttribute("label") || (labelText(this, "export", "Export") + " " + fmt.toUpperCase()))));
|
|
94
|
+
if (btn.parentNode !== this) this.appendChild(btn);
|
|
95
|
+
}
|
|
96
|
+
enhance() {
|
|
97
|
+
if (this._wiredDataExport) return;
|
|
98
|
+
this._wiredDataExport = true;
|
|
99
|
+
const csvCell = (v) => {
|
|
100
|
+
let s = v == null ? "" : String(v);
|
|
101
|
+
// R31-49: neutralize spreadsheet formula injection (CSV injection). A
|
|
102
|
+
// cell beginning with = + - @ (or a leading tab/CR) is executed as a
|
|
103
|
+
// formula by Excel/Sheets; prefix a single quote so it stays text.
|
|
104
|
+
if (/^[=+\-@\t\r]/.test(s)) s = "'" + s;
|
|
105
|
+
return /[",\r\n]/.test(s) ? '"' + s.replace(/"/g, '""') + '"' : s;
|
|
106
|
+
};
|
|
107
|
+
this.addEventListener("click", (e) => {
|
|
108
|
+
const btn = e.target && e.target.closest ? e.target.closest(".c-data-export__btn") : null;
|
|
109
|
+
if (!btn || !this.contains(btn)) return;
|
|
110
|
+
const rawFmt = (this.getAttribute("format") || "json").toLowerCase();
|
|
111
|
+
const fmt = (rawFmt === "csv" || rawFmt === "json") ? rawFmt : (console.warn("[contour-data-export] unsupported format:", rawFmt), "json");
|
|
112
|
+
const raw = this.getAttribute("data") || "[]";
|
|
113
|
+
let text = raw;
|
|
114
|
+
if (fmt === "csv") {
|
|
115
|
+
try {
|
|
116
|
+
const arr = JSON.parse(raw);
|
|
117
|
+
if (Array.isArray(arr)) {
|
|
118
|
+
if (arr.length === 0) {
|
|
119
|
+
text = "";
|
|
120
|
+
} else {
|
|
121
|
+
const keys = Object.keys(arr[0]);
|
|
122
|
+
text = [keys.map(csvCell).join(",")].concat(arr.map((r) => keys.map((k) => csvCell(r[k])).join(","))).join("\r\n");
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
} catch (err) { warnBadJson(this, "data", err); }
|
|
126
|
+
}
|
|
127
|
+
// R31-49: prepend a UTF-8 BOM to CSV so Excel/Sheets read non-ASCII
|
|
128
|
+
// correctly; revoke the object URL asynchronously so the download has
|
|
129
|
+
// actually started before the blob is released (a sync revoke can cancel
|
|
130
|
+
// it in some engines).
|
|
131
|
+
const blob = new Blob([fmt === "csv" ? "\uFEFF" + text : text], { type: fmt === "csv" ? "text/csv" : "application/json" });
|
|
132
|
+
const url = URL.createObjectURL(blob);
|
|
133
|
+
const a = document.createElement("a");
|
|
134
|
+
a.href = url;
|
|
135
|
+
a.download = this.getAttribute("filename") || ("export." + fmt);
|
|
136
|
+
document.body.appendChild(a);
|
|
137
|
+
a.click();
|
|
138
|
+
a.remove();
|
|
139
|
+
setTimeout(() => URL.revokeObjectURL(url), 0);
|
|
140
|
+
this.dispatchEvent(new CustomEvent("contour:export", { bubbles: true, composed: true, detail: { format: fmt } }));
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
define("contour-data-export", ContourDataExport);
|
|
145
|
+
|
|
146
|
+
// Query builder: field/operator/value rows with AND/OR connectors, remove button per row, Add rule button; renders from `query` JSON, emits contour:change.
|
|
147
|
+
class ContourQueryBuilder extends ContourBase {
|
|
148
|
+
static get observed() { return ["query", "fields"]; }
|
|
149
|
+
static get properties() { return { query: { attribute: "query" }, fields: { attribute: "fields" } }; }
|
|
150
|
+
// Single reader for whole component: add/remove/move/group-edit all need same DOM→query projection; three copies had drifted (connector never read, AND/OR edits silently dropped).
|
|
151
|
+
readRules() {
|
|
152
|
+
const rows = [];
|
|
153
|
+
const nodes = Array.from(this.querySelectorAll(".c-query-builder__row"));
|
|
154
|
+
// One connector per gap (connector i-1 joins row i-1 to row i); siblings of rows/groups, lookup by position not parentage.
|
|
155
|
+
const conns = Array.from(this.querySelectorAll(".c-query-builder__connector__op"));
|
|
156
|
+
nodes.forEach((r, i) => {
|
|
157
|
+
const rule = {
|
|
158
|
+
field: r.querySelector(".c-query-builder__field")?.value || "",
|
|
159
|
+
op: r.querySelector(".c-query-builder__op")?.value || "=",
|
|
160
|
+
value: r.querySelector(".c-query-builder__value")?.value || "",
|
|
161
|
+
};
|
|
162
|
+
if (i > 0 && conns[i - 1]) rule.connector = conns[i - 1].value || "AND";
|
|
163
|
+
const g = r.closest(".c-query-builder__group");
|
|
164
|
+
if (g) rule.group = g._groupName || "";
|
|
165
|
+
rows.push(rule);
|
|
166
|
+
});
|
|
167
|
+
return rows;
|
|
168
|
+
}
|
|
169
|
+
// Connectors belong to GAP between rules, not to a rule. Structural edit changes which rule sits on each side of gap, so connector re-applied by position after: carrying on rule made AND/OR travel with moved rule, left stray on first row.
|
|
170
|
+
static reindexConnectors(rows, conns) {
|
|
171
|
+
rows.forEach((r, i) => {
|
|
172
|
+
if (i > 0 && conns && conns[i]) r.connector = conns[i];
|
|
173
|
+
else delete r.connector;
|
|
174
|
+
});
|
|
175
|
+
return rows;
|
|
176
|
+
}
|
|
177
|
+
// `query` write-back normally rebuilds rows; wrong during field edit: `change` fires on blur/select, rebuild destroys control (focus falls to body, WC5-76). Write allowed with re-render suppressed.
|
|
178
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
179
|
+
if (name === "query" && this._suppressQueryRender) return;
|
|
180
|
+
super.attributeChangedCallback(name, oldValue, newValue);
|
|
181
|
+
}
|
|
182
|
+
// Write the model back and say so.
|
|
183
|
+
commit(rows, rerender = true) {
|
|
184
|
+
if (rerender) {
|
|
185
|
+
this.setAttribute("query", JSON.stringify(rows));
|
|
186
|
+
} else {
|
|
187
|
+
this._suppressQueryRender = true;
|
|
188
|
+
try { this.setAttribute("query", JSON.stringify(rows)); }
|
|
189
|
+
finally { this._suppressQueryRender = false; }
|
|
190
|
+
}
|
|
191
|
+
this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { query: rows } }));
|
|
192
|
+
}
|
|
193
|
+
render() {
|
|
194
|
+
this.classList.add("c-query-builder");
|
|
195
|
+
const fields = this.getAttribute("fields");
|
|
196
|
+
let fieldList = [];
|
|
197
|
+
if (fields) { try { fieldList = JSON.parse(fields); } catch (e) { fieldList = []; } }
|
|
198
|
+
const query = this.getAttribute("query");
|
|
199
|
+
let rules = [];
|
|
200
|
+
if (query) { try { rules = JSON.parse(query); } catch (e) { rules = []; } }
|
|
201
|
+
const list = this.ensure(".c-query-builder__list", () => { const el = document.createElement("div"); el.className = "c-query-builder__list"; return el; });
|
|
202
|
+
Array.from(list.querySelectorAll(".c-query-builder__row, .c-query-builder__connector, .c-query-builder__group")).forEach((n) => n.remove());
|
|
203
|
+
let currentGroup = null;
|
|
204
|
+
rules.forEach((rule, i) => {
|
|
205
|
+
// Grouping: consecutive rules sharing a non-empty `group` label are
|
|
206
|
+
// wrapped in a .c-query-builder__group with a .c-query-builder__group-label.
|
|
207
|
+
const groupName = (rule && rule.group) ? String(rule.group) : "";
|
|
208
|
+
const sameGroup = !!(groupName && currentGroup && currentGroup._groupName === groupName);
|
|
209
|
+
let conn = null;
|
|
210
|
+
if (i > 0) {
|
|
211
|
+
conn = document.createElement("div");
|
|
212
|
+
conn.className = "c-query-builder__connector";
|
|
213
|
+
const sel = document.createElement("select");
|
|
214
|
+
sel.className = "c-input c-query-builder__connector__op";
|
|
215
|
+
sel.setAttribute("aria-label", labelText(this, "connector", "Connector") + " " + i);
|
|
216
|
+
["AND", "OR"].forEach((c) => {
|
|
217
|
+
const opt = document.createElement("option");
|
|
218
|
+
opt.value = c; opt.textContent = c;
|
|
219
|
+
if (c === (rule.connector || "AND")) opt.selected = true;
|
|
220
|
+
sel.appendChild(opt);
|
|
221
|
+
});
|
|
222
|
+
conn.appendChild(sel);
|
|
223
|
+
}
|
|
224
|
+
if (groupName) {
|
|
225
|
+
if (!sameGroup) {
|
|
226
|
+
if (conn) list.appendChild(conn);
|
|
227
|
+
currentGroup = document.createElement("div");
|
|
228
|
+
currentGroup.className = "c-query-builder__group";
|
|
229
|
+
currentGroup._groupName = groupName;
|
|
230
|
+
const head = document.createElement("div");
|
|
231
|
+
head.className = "c-query-builder__group-head";
|
|
232
|
+
const lbl = document.createElement("div");
|
|
233
|
+
lbl.className = "c-query-builder__group-label";
|
|
234
|
+
lbl.textContent = groupName;
|
|
235
|
+
// Groups are part of the model, so they have to be editable from the
|
|
236
|
+
// page rather than only from the JSON attribute (WC5-33).
|
|
237
|
+
const rm = document.createElement("button");
|
|
238
|
+
rm.type = "button";
|
|
239
|
+
rm.className = "c-btn c-btn--sm c-btn--ghost c-query-builder__group-remove";
|
|
240
|
+
rm.setAttribute("aria-label", labelText(this, "remove-group", "Remove group") + " " + groupName);
|
|
241
|
+
rm.setAttribute("data-group", groupName);
|
|
242
|
+
rm.textContent = "\u00d7";
|
|
243
|
+
head.appendChild(lbl);
|
|
244
|
+
head.appendChild(rm);
|
|
245
|
+
currentGroup.appendChild(head);
|
|
246
|
+
list.appendChild(currentGroup);
|
|
247
|
+
} else if (conn) {
|
|
248
|
+
currentGroup.appendChild(conn);
|
|
249
|
+
}
|
|
250
|
+
} else {
|
|
251
|
+
if (conn) list.appendChild(conn);
|
|
252
|
+
currentGroup = null;
|
|
253
|
+
}
|
|
254
|
+
const row = document.createElement("div");
|
|
255
|
+
row.className = "c-query-builder__row";
|
|
256
|
+
const field = document.createElement("select");
|
|
257
|
+
field.className = "c-input c-query-builder__field";
|
|
258
|
+
field.setAttribute("aria-label", labelText(this, "field", "Field") + " " + (i + 1));
|
|
259
|
+
fieldList.forEach((f) => {
|
|
260
|
+
const opt = document.createElement("option");
|
|
261
|
+
opt.value = typeof f === "string" ? f : (f.value || f.label || "");
|
|
262
|
+
opt.textContent = typeof f === "string" ? f : (f.label || f.value || "");
|
|
263
|
+
if (opt.value === rule.field) opt.selected = true;
|
|
264
|
+
field.appendChild(opt);
|
|
265
|
+
});
|
|
266
|
+
const op = document.createElement("select");
|
|
267
|
+
op.className = "c-input c-query-builder__op";
|
|
268
|
+
op.setAttribute("aria-label", labelText(this, "operator", "Operator") + " " + (i + 1));
|
|
269
|
+
["=", "!=", ">", "<", "contains"].forEach((o) => {
|
|
270
|
+
const opt = document.createElement("option");
|
|
271
|
+
opt.value = o; opt.textContent = o;
|
|
272
|
+
if (o === rule.op) opt.selected = true;
|
|
273
|
+
op.appendChild(opt);
|
|
274
|
+
});
|
|
275
|
+
const val = document.createElement("input");
|
|
276
|
+
val.className = "c-input c-query-builder__value";
|
|
277
|
+
val.type = "text";
|
|
278
|
+
// Value attr is identity for base class restore; without it, control matched by index which shifts after structural edits (DW-4).
|
|
279
|
+
val.setAttribute("value", rule.value || "");
|
|
280
|
+
val.value = rule.value || "";
|
|
281
|
+
val.setAttribute("aria-label", labelText(this, "value", "Value") + " " + (i + 1));
|
|
282
|
+
// Reordering (WC5-75): buttons not drag handles (pointer-only), so keyboard can reach same operation.
|
|
283
|
+
const up = document.createElement("button");
|
|
284
|
+
up.type = "button";
|
|
285
|
+
up.className = "c-btn c-btn--sm c-btn--ghost c-query-builder__move c-query-builder__move--up";
|
|
286
|
+
up.setAttribute("aria-label", labelText(this, "move-rule", "Move rule") + " " + (i + 1) + " " + labelText(this, "up", "up"));
|
|
287
|
+
up.textContent = "\u2191";
|
|
288
|
+
if (i === 0) up.disabled = true;
|
|
289
|
+
const down = document.createElement("button");
|
|
290
|
+
down.type = "button";
|
|
291
|
+
down.className = "c-btn c-btn--sm c-btn--ghost c-query-builder__move c-query-builder__move--down";
|
|
292
|
+
down.setAttribute("aria-label", labelText(this, "move-rule", "Move rule") + " " + (i + 1) + " " + labelText(this, "down", "down"));
|
|
293
|
+
down.textContent = "\u2193";
|
|
294
|
+
if (i === rules.length - 1) down.disabled = true;
|
|
295
|
+
const remove = document.createElement("button");
|
|
296
|
+
remove.type = "button";
|
|
297
|
+
remove.className = "c-btn c-btn--sm c-btn--ghost c-query-builder__remove";
|
|
298
|
+
remove.setAttribute("aria-label", labelText(this, "remove-rule", "Remove rule") + " " + (i + 1));
|
|
299
|
+
remove.textContent = "\u00d7";
|
|
300
|
+
row.appendChild(field); row.appendChild(op); row.appendChild(val);
|
|
301
|
+
row.appendChild(up); row.appendChild(down); row.appendChild(remove);
|
|
302
|
+
if (currentGroup) currentGroup.appendChild(row); else list.appendChild(row);
|
|
303
|
+
});
|
|
304
|
+
const add = this.ensure(".c-query-builder__add", () => { const b = document.createElement("button"); b.type = "button"; b.className = "c-btn c-btn--sm c-query-builder__add"; return b; });
|
|
305
|
+
// R31-145: primary add actions are icon+text.
|
|
306
|
+
setHTML(add, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-plus" /></svg>');
|
|
307
|
+
add.appendChild(document.createTextNode(" " + labelText(this, "add-rule", "Add rule")));
|
|
308
|
+
if (add.parentNode !== this) this.appendChild(add);
|
|
309
|
+
const addGroup = this.ensure(".c-query-builder__add-group", () => { const b = document.createElement("button"); b.type = "button"; b.className = "c-btn c-btn--sm c-btn--ghost c-query-builder__add-group"; return b; });
|
|
310
|
+
setHTML(addGroup, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-plus" /></svg>');
|
|
311
|
+
addGroup.appendChild(document.createTextNode(" " + labelText(this, "add-group", "Add group")));
|
|
312
|
+
if (addGroup.parentNode !== this) this.appendChild(addGroup);
|
|
313
|
+
}
|
|
314
|
+
enhance() {
|
|
315
|
+
if (this._wiredQueryBuilder) return;
|
|
316
|
+
this._wiredQueryBuilder = true;
|
|
317
|
+
// Field/op/value/connector edits reach consumer; connector <select> keyboard is platform's (WC5-76); changing it was a no-op.
|
|
318
|
+
this.addEventListener("change", (e) => {
|
|
319
|
+
const t = e.target;
|
|
320
|
+
if (!(t instanceof Element)) return;
|
|
321
|
+
if (!t.matches(".c-query-builder__field, .c-query-builder__op, .c-query-builder__value, .c-query-builder__connector__op")) return;
|
|
322
|
+
this.commit(this.readRules(), false);
|
|
323
|
+
});
|
|
324
|
+
this.addEventListener("click", (e) => {
|
|
325
|
+
const t = e.target;
|
|
326
|
+
if (!(t instanceof Element)) return;
|
|
327
|
+
if (t.closest(".c-query-builder__add")) {
|
|
328
|
+
const conns = this.readRules().map((r) => r.connector);
|
|
329
|
+
const rows = this.readRules();
|
|
330
|
+
rows.push({ field: "", op: "=", value: "" });
|
|
331
|
+
this.commit(ContourQueryBuilder.reindexConnectors(rows, conns));
|
|
332
|
+
const all = this.querySelectorAll(".c-query-builder__row");
|
|
333
|
+
const added = all[all.length - 1];
|
|
334
|
+
const f = added && added.querySelector(".c-query-builder__field");
|
|
335
|
+
if (f) try { f.focus(); } catch (err) {}
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
if (t.closest(".c-query-builder__add-group")) {
|
|
339
|
+
const conns = this.readRules().map((r) => r.connector);
|
|
340
|
+
const rows = this.readRules();
|
|
341
|
+
const used = new Set(rows.map((r) => r.group).filter(Boolean));
|
|
342
|
+
let n = 1;
|
|
343
|
+
while (used.has("Group " + n)) n++;
|
|
344
|
+
rows.push({ field: "", op: "=", value: "", group: "Group " + n });
|
|
345
|
+
this.commit(ContourQueryBuilder.reindexConnectors(rows, conns));
|
|
346
|
+
const all = this.querySelectorAll(".c-query-builder__row");
|
|
347
|
+
const added = all[all.length - 1];
|
|
348
|
+
const f = added && added.querySelector(".c-query-builder__field");
|
|
349
|
+
if (f) try { f.focus(); } catch (err) {}
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
const groupBtn = t.closest(".c-query-builder__group-remove");
|
|
353
|
+
if (groupBtn) {
|
|
354
|
+
const name = groupBtn.getAttribute("data-group") || "";
|
|
355
|
+
const conns = this.readRules().map((r) => r.connector);
|
|
356
|
+
const rows = this.readRules().filter((r) => (r.group || "") !== name);
|
|
357
|
+
this.commit(ContourQueryBuilder.reindexConnectors(rows, conns));
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
const moveBtn = t.closest(".c-query-builder__move");
|
|
361
|
+
if (moveBtn) {
|
|
362
|
+
const row = moveBtn.closest(".c-query-builder__row");
|
|
363
|
+
if (!row) return;
|
|
364
|
+
const isUp = moveBtn.classList.contains("c-query-builder__move--up");
|
|
365
|
+
const conns = this.readRules().map((r) => r.connector);
|
|
366
|
+
const rows = this.readRules();
|
|
367
|
+
const nodes = Array.from(this.querySelectorAll(".c-query-builder__row"));
|
|
368
|
+
const idx = nodes.indexOf(row);
|
|
369
|
+
if (idx < 0) return;
|
|
370
|
+
const to = isUp ? idx - 1 : idx + 1;
|
|
371
|
+
if (to < 0 || to >= rows.length) return;
|
|
372
|
+
const tmp = rows[to]; rows[to] = rows[idx]; rows[idx] = tmp;
|
|
373
|
+
this.commit(ContourQueryBuilder.reindexConnectors(rows, conns));
|
|
374
|
+
const movedRow = this.querySelectorAll(".c-query-builder__row")[to];
|
|
375
|
+
const focusBtn = movedRow && movedRow.querySelector(isUp ? ".c-query-builder__move--up" : ".c-query-builder__move--down");
|
|
376
|
+
if (focusBtn && !focusBtn.disabled) try { focusBtn.focus(); } catch (err) {}
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
if (t.closest(".c-query-builder__remove")) {
|
|
380
|
+
const row = t.closest(".c-query-builder__row");
|
|
381
|
+
if (!row) return;
|
|
382
|
+
const conns = this.readRules().map((r) => r.connector);
|
|
383
|
+
const rows = this.readRules();
|
|
384
|
+
const idx = Array.from(this.querySelectorAll(".c-query-builder__row")).indexOf(row);
|
|
385
|
+
if (idx >= 0) rows.splice(idx, 1);
|
|
386
|
+
this.commit(ContourQueryBuilder.reindexConnectors(rows, conns));
|
|
387
|
+
}
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
define("contour-query-builder", ContourQueryBuilder);
|