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,995 @@
|
|
|
1
|
+
import { setHTML, ContourBase, define, onDispose, supportsUntilFound, contourId, headingTag, navKey, safeHref, cssLength , warnBadJson, labelText, applyLabel, wcEmitOverlay } from './core.mjs';
|
|
2
|
+
import { loadRemote, remoteData, renderStates, renderEmpty, wireStates } from './states.mjs';
|
|
3
|
+
import { wireMenu, wirePagination, wireTabs, wireTree, wireRemovable } from './behaviours.mjs';
|
|
4
|
+
|
|
5
|
+
class ContourTree extends ContourBase {
|
|
6
|
+
static get updateMode() { return "keyed"; }
|
|
7
|
+
static get observed() { return ["items", "virtual", "item-height", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "persist", "selectable", "cache-key", "no-cache", "density"]; }
|
|
8
|
+
static get properties() { return { items: { attribute: "items" }, src: { attribute: "src" }, "item-height": { attribute: "item-height" } }; }
|
|
9
|
+
_itemHeight() {
|
|
10
|
+
const h = Number(this.getAttribute("item-height"));
|
|
11
|
+
if (Number.isFinite(h) && h > 0) return h;
|
|
12
|
+
return cssLength("--virtual-list-item-height", 28);
|
|
13
|
+
}
|
|
14
|
+
_labelToPaths(nodes, pathPrefix, map) {
|
|
15
|
+
(nodes || []).forEach((node, i) => {
|
|
16
|
+
const p = pathPrefix + "." + i;
|
|
17
|
+
const label = String(node.label || node).trim().slice(0, 120);
|
|
18
|
+
if (!map.has(label)) map.set(label, []);
|
|
19
|
+
map.get(label).push(p);
|
|
20
|
+
if (Array.isArray(node.children)) this._labelToPaths(node.children, p, map);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
_restoreExpanded() {
|
|
24
|
+
const persist = this.getAttribute("persist");
|
|
25
|
+
if (!persist || !this._treeData) return;
|
|
26
|
+
let labels = null;
|
|
27
|
+
try {
|
|
28
|
+
if (persist === "storage" && this.id) {
|
|
29
|
+
const saved = localStorage.getItem("contour-tree:" + this.id);
|
|
30
|
+
if (saved !== null) labels = JSON.parse(saved);
|
|
31
|
+
} else if (persist === "url") {
|
|
32
|
+
const v = new URLSearchParams(window.location.search).get("c-tree");
|
|
33
|
+
if (v !== null) labels = JSON.parse(v);
|
|
34
|
+
}
|
|
35
|
+
} catch (e) { labels = null; }
|
|
36
|
+
if (!Array.isArray(labels)) return;
|
|
37
|
+
const want = new Set(labels.map((l) => String(l)));
|
|
38
|
+
const map = new Map();
|
|
39
|
+
this._labelToPaths(this._treeData, "", map);
|
|
40
|
+
const expanded = this._expanded || (this._expanded = new Set());
|
|
41
|
+
for (const lbl of want) {
|
|
42
|
+
const paths = map.get(lbl);
|
|
43
|
+
if (paths) paths.forEach((p) => expanded.add(p));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
_persistExpanded() {
|
|
47
|
+
const persist = this.getAttribute("persist");
|
|
48
|
+
if (!persist || !this._expanded) return;
|
|
49
|
+
// Map expanded paths back to labels.
|
|
50
|
+
const pathToNode = new Map();
|
|
51
|
+
const walk = (nodes, pathPrefix) => {
|
|
52
|
+
(nodes || []).forEach((node, i) => {
|
|
53
|
+
const p = pathPrefix + "." + i;
|
|
54
|
+
pathToNode.set(p, node);
|
|
55
|
+
if (Array.isArray(node.children)) walk(node.children, p);
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
walk(this._treeData, "");
|
|
59
|
+
const open = [];
|
|
60
|
+
for (const p of this._expanded) {
|
|
61
|
+
const node = pathToNode.get(p);
|
|
62
|
+
if (node) open.push(String(node.label || node).trim().slice(0, 120));
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
if (persist === "storage" && this.id) {
|
|
66
|
+
localStorage.setItem("contour-tree:" + this.id, JSON.stringify(open));
|
|
67
|
+
} else if (persist === "url") {
|
|
68
|
+
const url = new URL(window.location.href);
|
|
69
|
+
url.searchParams.set("c-tree", JSON.stringify(open));
|
|
70
|
+
window.history.replaceState(null, "", url.toString());
|
|
71
|
+
}
|
|
72
|
+
} catch (e) {}
|
|
73
|
+
}
|
|
74
|
+
_flatten(nodes, pathPrefix, depth, expanded, out) {
|
|
75
|
+
(nodes || []).forEach((node, i) => {
|
|
76
|
+
const p = pathPrefix + "." + i;
|
|
77
|
+
const hasChildren = Array.isArray(node.children) && node.children.length > 0;
|
|
78
|
+
const isExpanded = expanded.has(p);
|
|
79
|
+
out.push({ node, path: p, depth, hasChildren, expanded: isExpanded });
|
|
80
|
+
if (hasChildren && isExpanded) {
|
|
81
|
+
this._flatten(node.children, p, depth + 1, expanded, out);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
_renderNodeFlat(rootUl, f, setsize, posinset) {
|
|
86
|
+
const node = f.node;
|
|
87
|
+
const depth = f.depth;
|
|
88
|
+
const li = document.createElement("div");
|
|
89
|
+
li.className = "c-tree__node";
|
|
90
|
+
li.setAttribute("role", "treeitem");
|
|
91
|
+
li.setAttribute("aria-level", String(depth));
|
|
92
|
+
li.setAttribute("aria-setsize", String(setsize));
|
|
93
|
+
li.setAttribute("aria-posinset", String(posinset));
|
|
94
|
+
li.dataset.path = f.path;
|
|
95
|
+
if (f.hasChildren) {
|
|
96
|
+
li.setAttribute("aria-expanded", String(f.expanded));
|
|
97
|
+
const row = document.createElement("div");
|
|
98
|
+
row.className = "c-tree__row" + (node.active ? " c-tree__row--active" : "") + (node.dir ? " c-tree__row--dir" : "");
|
|
99
|
+
// Density-aware indent matching plain tree's indent token, not hardcoded rem ignoring scoped density.
|
|
100
|
+
row.style.paddingInlineStart = `calc(${depth - 1} * 1rem * var(--density, 1))`;
|
|
101
|
+
const toggle = document.createElement("button");
|
|
102
|
+
toggle.className = "c-tree__toggle";
|
|
103
|
+
toggle.setAttribute("type", "button");
|
|
104
|
+
toggle.setAttribute("aria-expanded", String(f.expanded));
|
|
105
|
+
toggle.setAttribute("aria-label", labelText(this, "toggle", "Toggle"));
|
|
106
|
+
setHTML(toggle, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-chevron-right" /></svg>');
|
|
107
|
+
row.appendChild(toggle);
|
|
108
|
+
const span = document.createElement("span");
|
|
109
|
+
span.textContent = node.label;
|
|
110
|
+
row.appendChild(span);
|
|
111
|
+
li.appendChild(row);
|
|
112
|
+
} else {
|
|
113
|
+
const leaf = document.createElement("div");
|
|
114
|
+
leaf.className = "c-tree__leaf" + (node.active ? " c-tree__row--active" : "") + (node.dir ? " c-tree__row--dir" : "");
|
|
115
|
+
leaf.style.paddingInlineStart = `calc(${depth} * 1rem * var(--density, 1))`;
|
|
116
|
+
if (this.hasAttribute("selectable")) {
|
|
117
|
+
const cb = document.createElement("input");
|
|
118
|
+
cb.type = "checkbox";
|
|
119
|
+
cb.className = "c-tree__select";
|
|
120
|
+
cb.setAttribute("aria-label", labelText(this, "select", "Select") + " " + (node.label || node));
|
|
121
|
+
// Key selection by path, not label, so duplicate labels (e.g. two "Dups") don't collide.
|
|
122
|
+
if (this._selectedTree && this._selectedTree.has(f.path)) cb.checked = true;
|
|
123
|
+
leaf.insertBefore(cb, leaf.firstChild);
|
|
124
|
+
}
|
|
125
|
+
leaf.appendChild(document.createTextNode(node.label || node));
|
|
126
|
+
li.appendChild(leaf);
|
|
127
|
+
}
|
|
128
|
+
return li;
|
|
129
|
+
}
|
|
130
|
+
_renderWindow(rootUl, scrollTop) {
|
|
131
|
+
if (!this._treeData) return;
|
|
132
|
+
const ih = this._itemHeight();
|
|
133
|
+
const expanded = this._expanded || (this._expanded = new Set());
|
|
134
|
+
const flat = [];
|
|
135
|
+
this._flatten(this._treeData, "", 1, expanded, flat);
|
|
136
|
+
const total = flat.length;
|
|
137
|
+
const viewportSize = rootUl.clientHeight || 320;
|
|
138
|
+
const visibleCount = Math.ceil(viewportSize / ih) + 6;
|
|
139
|
+
let start = Math.floor((scrollTop || 0) / ih);
|
|
140
|
+
if (start < 0) start = 0;
|
|
141
|
+
if (start > Math.max(0, total - visibleCount)) start = Math.max(0, total - visibleCount);
|
|
142
|
+
const end = Math.min(total, start + visibleCount);
|
|
143
|
+
const topSize = start * ih;
|
|
144
|
+
const bottomSize = Math.max(0, (total - end) * ih);
|
|
145
|
+
setHTML(rootUl, "");
|
|
146
|
+
const top = document.createElement("div");
|
|
147
|
+
top.className = "c-tree__spacer c-tree__spacer--top";
|
|
148
|
+
top.style.height = topSize + "px";
|
|
149
|
+
rootUl.appendChild(top);
|
|
150
|
+
// Sibling sets for aria-setsize/aria-posinset (group by parent path).
|
|
151
|
+
const byParent = new Map();
|
|
152
|
+
flat.forEach((f, k) => {
|
|
153
|
+
const pp = f.path.includes(".") ? f.path.slice(0, f.path.lastIndexOf(".")) : "";
|
|
154
|
+
let s = byParent.get(pp);
|
|
155
|
+
if (!s) { s = []; byParent.set(pp, s); }
|
|
156
|
+
s.push(k);
|
|
157
|
+
});
|
|
158
|
+
for (let i = start; i < end; i++) {
|
|
159
|
+
const f = flat[i];
|
|
160
|
+
const pp = f.path.includes(".") ? f.path.slice(0, f.path.lastIndexOf(".")) : "";
|
|
161
|
+
const sibs = byParent.get(pp);
|
|
162
|
+
rootUl.appendChild(this._renderNodeFlat(rootUl, f, sibs.length, sibs.indexOf(i) + 1));
|
|
163
|
+
}
|
|
164
|
+
const bottom = document.createElement("div");
|
|
165
|
+
bottom.className = "c-tree__spacer c-tree__spacer--bottom";
|
|
166
|
+
bottom.style.height = bottomSize + "px";
|
|
167
|
+
rootUl.appendChild(bottom);
|
|
168
|
+
}
|
|
169
|
+
render() {
|
|
170
|
+
this.classList.add("c-tree");
|
|
171
|
+
// Slot composition wins over JSON attribute (same as ContourMenu): authored tree preserved across re-renders instead of rebuilt from items.
|
|
172
|
+
const authored = Array.from(this.children).filter((n) => !n.classList || !n.classList.contains("c-tree"));
|
|
173
|
+
wireStates(this);
|
|
174
|
+
loadRemote(this, "items");
|
|
175
|
+
if (renderStates(this, "tree")) return;
|
|
176
|
+
const items = remoteData(this, "items");
|
|
177
|
+
if (items && !authored.length) {
|
|
178
|
+
try {
|
|
179
|
+
const parsed = JSON.parse(items);
|
|
180
|
+
const rootUl = this.ensure("div.c-tree", () => { const el = document.createElement("div"); el.className = "c-tree"; el.setAttribute("role", "tree"); return el; });
|
|
181
|
+
setHTML(rootUl, "");
|
|
182
|
+
rootUl.className = "c-tree";
|
|
183
|
+
rootUl.setAttribute("role", "tree");
|
|
184
|
+
const virtual = this.hasAttribute("virtual");
|
|
185
|
+
if (virtual) {
|
|
186
|
+
this._treeData = parsed;
|
|
187
|
+
this._expanded = this._expanded || new Set();
|
|
188
|
+
this._treeRoot = rootUl;
|
|
189
|
+
this._restoreExpanded();
|
|
190
|
+
rootUl.style.maxHeight = rootUl.style.maxHeight || "24rem";
|
|
191
|
+
rootUl.style.overflow = "auto";
|
|
192
|
+
const scrollTop = this._treeScrollTop || 0;
|
|
193
|
+
this._renderWindow(rootUl, scrollTop);
|
|
194
|
+
try { rootUl.scrollTop = scrollTop; } catch (e) {}
|
|
195
|
+
} else {
|
|
196
|
+
this._treeData = null;
|
|
197
|
+
const render = (nodes, parent, depth, pathPrefix) => {
|
|
198
|
+
const ul = parent ? document.createElement("div") : rootUl;
|
|
199
|
+
if (parent) {
|
|
200
|
+
ul.className = "c-tree__children";
|
|
201
|
+
ul.setAttribute("role", "group");
|
|
202
|
+
if (supportsUntilFound()) ul.setAttribute("hidden", "until-found"); else ul.setAttribute("hidden", "");
|
|
203
|
+
}
|
|
204
|
+
nodes.forEach((node, i) => {
|
|
205
|
+
const p = (pathPrefix || "") + "." + i;
|
|
206
|
+
const li = document.createElement("div");
|
|
207
|
+
li.className = "c-tree__node";
|
|
208
|
+
li.setAttribute("role", "treeitem");
|
|
209
|
+
li.setAttribute("aria-level", String(depth));
|
|
210
|
+
li.setAttribute("aria-setsize", String(nodes.length));
|
|
211
|
+
li.setAttribute("aria-posinset", String(i + 1));
|
|
212
|
+
li.dataset.path = p;
|
|
213
|
+
if (node.children) {
|
|
214
|
+
li.setAttribute("aria-expanded", "false");
|
|
215
|
+
const row = document.createElement("div");
|
|
216
|
+
row.className = "c-tree__row" + (node.active ? " c-tree__row--active" : "") + (node.dir ? " c-tree__row--dir" : "");
|
|
217
|
+
if (node.indent) {
|
|
218
|
+
const ind = document.createElement("span");
|
|
219
|
+
ind.className = "c-tree__indent";
|
|
220
|
+
ind.style.inlineSize = (node.indent * 1) + "rem";
|
|
221
|
+
row.appendChild(ind);
|
|
222
|
+
}
|
|
223
|
+
const toggle = document.createElement("button");
|
|
224
|
+
toggle.className = "c-tree__toggle";
|
|
225
|
+
toggle.setAttribute("type", "button");
|
|
226
|
+
toggle.setAttribute("aria-expanded", "false");
|
|
227
|
+
toggle.setAttribute("aria-label", labelText(this, "toggle", "Toggle"));
|
|
228
|
+
setHTML(toggle, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-chevron-right" /></svg>');
|
|
229
|
+
row.appendChild(toggle);
|
|
230
|
+
const span = document.createElement("span");
|
|
231
|
+
span.textContent = node.label;
|
|
232
|
+
row.appendChild(span);
|
|
233
|
+
li.appendChild(row);
|
|
234
|
+
render(node.children, li, depth + 1, p);
|
|
235
|
+
} else {
|
|
236
|
+
const leaf = document.createElement("div");
|
|
237
|
+
leaf.className = "c-tree__leaf" + (node.active ? " c-tree__row--active" : "") + (node.dir ? " c-tree__row--dir" : "");
|
|
238
|
+
if (node.indent) {
|
|
239
|
+
const ind = document.createElement("span");
|
|
240
|
+
ind.className = "c-tree__indent";
|
|
241
|
+
ind.style.inlineSize = (node.indent * 1) + "rem";
|
|
242
|
+
leaf.appendChild(ind);
|
|
243
|
+
}
|
|
244
|
+
if (this.hasAttribute("selectable")) {
|
|
245
|
+
const cb = document.createElement("input");
|
|
246
|
+
cb.type = "checkbox";
|
|
247
|
+
cb.className = "c-tree__select";
|
|
248
|
+
cb.setAttribute("aria-label", labelText(this, "select", "Select") + " " + (node.label || node));
|
|
249
|
+
if (this._selectedTree && this._selectedTree.has(p)) cb.checked = true;
|
|
250
|
+
leaf.insertBefore(cb, leaf.firstChild);
|
|
251
|
+
}
|
|
252
|
+
leaf.appendChild(document.createTextNode(node.label || node));
|
|
253
|
+
li.appendChild(leaf);
|
|
254
|
+
}
|
|
255
|
+
ul.appendChild(li);
|
|
256
|
+
});
|
|
257
|
+
if (parent) parent.appendChild(ul);
|
|
258
|
+
};
|
|
259
|
+
render(parsed, null, 1, "");
|
|
260
|
+
}
|
|
261
|
+
this.classList.remove("c-tree");
|
|
262
|
+
rootUl.classList.add("c-tree");
|
|
263
|
+
if (rootUl.parentNode !== this) this.appendChild(rootUl);
|
|
264
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
265
|
+
} else if (!items && !authored.length) {
|
|
266
|
+
renderEmpty(this, "tree");
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
enhance() {
|
|
270
|
+
// Toggle handling for virtual trees only. Non-virtual handled by wireTree in behaviours.mjs. Both firing on same click canceled each other: ContourTree set aria-expanded to !expanded, then wireTree read new value and set it back.
|
|
271
|
+
if (!this._wiredTreeToggle) {
|
|
272
|
+
this._wiredTreeToggle = true;
|
|
273
|
+
this.addEventListener("click", (e) => {
|
|
274
|
+
if (!this.hasAttribute("virtual")) return;
|
|
275
|
+
let toggle = e.target && e.target.closest ? e.target.closest(".c-tree__toggle") : null;
|
|
276
|
+
if (!toggle) {
|
|
277
|
+
const row = e.target && e.target.closest ? e.target.closest(".c-tree__row") : null;
|
|
278
|
+
if (row) toggle = row.querySelector(":scope > .c-tree__toggle");
|
|
279
|
+
}
|
|
280
|
+
if (!toggle || !this.contains(toggle)) return;
|
|
281
|
+
e.stopPropagation();
|
|
282
|
+
const nodeEl = toggle.closest(".c-tree__node");
|
|
283
|
+
const path = nodeEl && nodeEl.dataset ? nodeEl.dataset.path : null;
|
|
284
|
+
const expanded = toggle.getAttribute("aria-expanded") === "true";
|
|
285
|
+
if (path && this._expanded) {
|
|
286
|
+
if (expanded) this._expanded.delete(path); else this._expanded.add(path);
|
|
287
|
+
}
|
|
288
|
+
toggle.setAttribute("aria-expanded", String(!expanded));
|
|
289
|
+
const row = toggle.closest(".c-tree__row");
|
|
290
|
+
if (row) row.setAttribute("aria-expanded", String(!expanded));
|
|
291
|
+
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { path, expanded: !expanded } }));
|
|
292
|
+
if (this.hasAttribute("virtual") && this._treeRoot) {
|
|
293
|
+
const s = this._treeRoot;
|
|
294
|
+
this._treeScrollTop = s.scrollTop || 0;
|
|
295
|
+
this._renderWindow(s, this._treeScrollTop);
|
|
296
|
+
try { s.scrollTop = this._treeScrollTop; } catch (err) {}
|
|
297
|
+
this._persistExpanded();
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
// Scroll-driven windowing for virtual trees.
|
|
302
|
+
if (this.hasAttribute("virtual") && !this._wiredTreeScroll) {
|
|
303
|
+
this._wiredTreeScroll = true;
|
|
304
|
+
const attach = () => {
|
|
305
|
+
const s = this.querySelector(".c-tree");
|
|
306
|
+
if (!s || s._treeScrollWired) return;
|
|
307
|
+
s._treeScrollWired = true;
|
|
308
|
+
let raf = 0;
|
|
309
|
+
const onScroll = () => {
|
|
310
|
+
if (raf) return;
|
|
311
|
+
raf = requestAnimationFrame(() => {
|
|
312
|
+
raf = 0;
|
|
313
|
+
this._treeScrollTop = s.scrollTop || 0;
|
|
314
|
+
this._renderWindow(s, this._treeScrollTop);
|
|
315
|
+
try { s.scrollTop = this._treeScrollTop; } catch (err) {}
|
|
316
|
+
});
|
|
317
|
+
};
|
|
318
|
+
s.addEventListener("scroll", onScroll, { passive: true });
|
|
319
|
+
onDispose(this, () => { s.removeEventListener("scroll", onScroll); if (raf) cancelAnimationFrame(raf); });
|
|
320
|
+
};
|
|
321
|
+
attach();
|
|
322
|
+
// retry if root not ready
|
|
323
|
+
if (!this.querySelector(".c-tree")) {
|
|
324
|
+
const mo = new MutationObserver(() => { if (this.querySelector(".c-tree")) { attach(); mo.disconnect(); } });
|
|
325
|
+
mo.observe(this, { childList: true, subtree: true });
|
|
326
|
+
onDispose(this, () => mo.disconnect());
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
// Auto-scroll during drag for virtual trees (so off-screen targets
|
|
330
|
+
// become reachable). Delegated on the host; only active in virtual mode.
|
|
331
|
+
if (this.hasAttribute("virtual") && !this._wiredTreeDragScroll) {
|
|
332
|
+
this._wiredTreeDragScroll = true;
|
|
333
|
+
let dragScrollRaf = 0;
|
|
334
|
+
let dragScrollDir = 0;
|
|
335
|
+
const tick = () => {
|
|
336
|
+
if (!dragScrollDir) { dragScrollRaf = 0; return; }
|
|
337
|
+
const s = this._treeRoot;
|
|
338
|
+
if (s) {
|
|
339
|
+
s.scrollTop += dragScrollDir * 8;
|
|
340
|
+
this._treeScrollTop = s.scrollTop;
|
|
341
|
+
this._renderWindow(s, this._treeScrollTop);
|
|
342
|
+
}
|
|
343
|
+
dragScrollRaf = requestAnimationFrame(tick);
|
|
344
|
+
};
|
|
345
|
+
this.addEventListener("dragover", (e) => {
|
|
346
|
+
const s = this._treeRoot;
|
|
347
|
+
if (!s) return;
|
|
348
|
+
const rect = s.getBoundingClientRect();
|
|
349
|
+
const edge = 40;
|
|
350
|
+
if (e.clientY < rect.top + edge) dragScrollDir = -1;
|
|
351
|
+
else if (e.clientY > rect.bottom - edge) dragScrollDir = 1;
|
|
352
|
+
else dragScrollDir = 0;
|
|
353
|
+
if (dragScrollDir && !dragScrollRaf) dragScrollRaf = requestAnimationFrame(tick);
|
|
354
|
+
});
|
|
355
|
+
const stop = () => {
|
|
356
|
+
dragScrollDir = 0;
|
|
357
|
+
if (dragScrollRaf) { cancelAnimationFrame(dragScrollRaf); dragScrollRaf = 0; }
|
|
358
|
+
};
|
|
359
|
+
this.addEventListener("dragend", stop);
|
|
360
|
+
this.addEventListener("drop", stop);
|
|
361
|
+
}
|
|
362
|
+
// Interaction lives in behaviours.mjs (shared with shadow wrappers). One implementation prevents drift: shadow copy queried root for slotted nodes, found none, wired nothing.
|
|
363
|
+
wireTree(this);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
define("contour-tree", ContourTree);
|
|
367
|
+
class ContourFilterBar extends ContourBase {
|
|
368
|
+
static get observed() { return ["label", "divider", "items", "input", "placeholder", "mode", "modes", "scope", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "count", "clearable", "cache-key", "no-cache"]; }
|
|
369
|
+
static get properties() { return { label: { attribute: "label" }, divider: { attribute: "divider" }, items: { attribute: "items" }, src: { attribute: "src" }, count: { attribute: "count" }, clearable: { attribute: "clearable" }, scope: { attribute: "scope" } }; }
|
|
370
|
+
render() {
|
|
371
|
+
this.classList.add("c-filter-bar");
|
|
372
|
+
wireStates(this);
|
|
373
|
+
loadRemote(this, "items");
|
|
374
|
+
if (renderStates(this, "filter-bar")) return;
|
|
375
|
+
const label = this.getAttribute("label");
|
|
376
|
+
if (label) {
|
|
377
|
+
const l = this.ensure(".c-filter-bar__label", () => { const el = document.createElement("span"); el.className = "c-filter-bar__label"; return el; });
|
|
378
|
+
l.textContent = label;
|
|
379
|
+
} else {
|
|
380
|
+
const l = this.querySelector(".c-filter-bar__label");
|
|
381
|
+
if (l) l.remove();
|
|
382
|
+
}
|
|
383
|
+
if (this.hasAttribute("divider")) {
|
|
384
|
+
this.ensure(".c-filter-bar__divider", () => { const el = document.createElement("span"); el.className = "c-filter-bar__divider"; return el; });
|
|
385
|
+
} else {
|
|
386
|
+
const d = this.querySelector(".c-filter-bar__divider");
|
|
387
|
+
if (d) d.remove();
|
|
388
|
+
}
|
|
389
|
+
// Text input support
|
|
390
|
+
if (this.hasAttribute("input") || this.hasAttribute("placeholder")) {
|
|
391
|
+
let inp = this.querySelector(".c-filter-bar__input");
|
|
392
|
+
if (!inp) { inp = document.createElement("input"); inp.type = "search"; inp.className = "c-filter-bar__input"; this.appendChild(inp); }
|
|
393
|
+
const ph = this.getAttribute("placeholder");
|
|
394
|
+
if (ph) inp.setAttribute("placeholder", ph);
|
|
395
|
+
} else {
|
|
396
|
+
const inp = this.querySelector(".c-filter-bar__input");
|
|
397
|
+
if (inp) inp.remove();
|
|
398
|
+
}
|
|
399
|
+
// Mode toolbar
|
|
400
|
+
const modesAttr = this.getAttribute("modes");
|
|
401
|
+
let modes = null;
|
|
402
|
+
if (modesAttr) { try { modes = JSON.parse(modesAttr); } catch (e) { modes = modesAttr.split(",").map((s) => s.trim()); } }
|
|
403
|
+
if (modes || this.hasAttribute("mode")) {
|
|
404
|
+
let bar = this.querySelector(".c-filter-bar__modes");
|
|
405
|
+
if (!bar) { bar = document.createElement("div"); bar.className = "c-filter-bar__modes"; bar.setAttribute("role", "toolbar"); bar.setAttribute("aria-label", label || "Filter modes"); this.appendChild(bar); }
|
|
406
|
+
setHTML(bar, "");
|
|
407
|
+
const current = this.getAttribute("mode");
|
|
408
|
+
const list = Array.isArray(modes) ? modes : ["draw", "erase", "select"];
|
|
409
|
+
list.forEach((m) => {
|
|
410
|
+
const name = typeof m === "string" ? m : (m.label || m.value || m);
|
|
411
|
+
const val = typeof m === "string" ? m : (m.value || m.label || m);
|
|
412
|
+
const btn = document.createElement("button");
|
|
413
|
+
btn.type = "button";
|
|
414
|
+
btn.className = "c-filter-bar__mode";
|
|
415
|
+
btn.textContent = name;
|
|
416
|
+
btn.dataset.mode = val;
|
|
417
|
+
if (current && current === val) btn.setAttribute("aria-pressed", "true");
|
|
418
|
+
bar.appendChild(btn);
|
|
419
|
+
});
|
|
420
|
+
} else {
|
|
421
|
+
const bar = this.querySelector(".c-filter-bar__modes");
|
|
422
|
+
if (bar) bar.remove();
|
|
423
|
+
}
|
|
424
|
+
// Scope toggle (viewport / global) — CARTO-inspired.
|
|
425
|
+
const scope = this.getAttribute("scope");
|
|
426
|
+
if (scope === "viewport" || scope === "global") {
|
|
427
|
+
Array.from(this.querySelectorAll(".c-filter-bar__scope")).forEach((n) => n.remove());
|
|
428
|
+
const bar = document.createElement("div");
|
|
429
|
+
bar.className = "c-filter-bar__modes c-filter-bar__scope";
|
|
430
|
+
bar.setAttribute("role", "toolbar");
|
|
431
|
+
bar.setAttribute("aria-label", labelText(this, "data-scope", "Data scope"));
|
|
432
|
+
["viewport", "global"].forEach((s) => {
|
|
433
|
+
const btn = document.createElement("button");
|
|
434
|
+
btn.type = "button";
|
|
435
|
+
btn.className = "c-filter-bar__mode c-filter-bar__scope-btn";
|
|
436
|
+
btn.textContent = s === "viewport" ? "Viewport" : "Global";
|
|
437
|
+
btn.dataset.scope = s;
|
|
438
|
+
if (scope === s) btn.setAttribute("aria-pressed", "true");
|
|
439
|
+
bar.appendChild(btn);
|
|
440
|
+
});
|
|
441
|
+
this.appendChild(bar);
|
|
442
|
+
} else {
|
|
443
|
+
const bar = this.querySelector(".c-filter-bar__scope");
|
|
444
|
+
if (bar) bar.remove();
|
|
445
|
+
}
|
|
446
|
+
// Render filter pills from items.
|
|
447
|
+
Array.from(this.querySelectorAll(".c-filter-pill")).forEach((n) => n.remove());
|
|
448
|
+
const items = remoteData(this, "items");
|
|
449
|
+
// Slotted content: authored .c-filter-pill children take precedence.
|
|
450
|
+
const authoredPills = Array.from(this.querySelectorAll(":scope > .c-filter-pill"));
|
|
451
|
+
let parsed = null;
|
|
452
|
+
if (authoredPills.length) {
|
|
453
|
+
parsed = authoredPills.map((p) => p.textContent.trim());
|
|
454
|
+
authoredPills.forEach((p) => p.remove());
|
|
455
|
+
} else if (items) { try { parsed = JSON.parse(items); } catch (e) { parsed = null; } }
|
|
456
|
+
if (Array.isArray(parsed)) {
|
|
457
|
+
parsed.forEach((it) => {
|
|
458
|
+
const pill = document.createElement("span");
|
|
459
|
+
pill.className = "c-filter-pill";
|
|
460
|
+
const isObj = typeof it === "object" && it !== null;
|
|
461
|
+
const txt = typeof it === "string" ? it : (it.label || it.value || "");
|
|
462
|
+
// Carry identity on pill so contour:remove reports key/value.
|
|
463
|
+
const key = isObj ? it.key : null;
|
|
464
|
+
const value = isObj ? it.value : it;
|
|
465
|
+
if (key != null && key !== "") pill.setAttribute("key", String(key));
|
|
466
|
+
if (value != null && value !== "") pill.setAttribute("value", String(value));
|
|
467
|
+
pill.textContent = txt;
|
|
468
|
+
// R24-40: a string pill is removable too. Only an object that sets
|
|
469
|
+
// removable:false suppresses the remove button.
|
|
470
|
+
if (!isObj || it.removable !== false) {
|
|
471
|
+
const btn = document.createElement("button");
|
|
472
|
+
btn.className = "c-filter-pill__remove";
|
|
473
|
+
btn.type = "button";
|
|
474
|
+
btn.setAttribute("aria-label", labelText(this, "remove", "Remove") + " " + txt);
|
|
475
|
+
btn.textContent = "×";
|
|
476
|
+
pill.appendChild(btn);
|
|
477
|
+
}
|
|
478
|
+
this.appendChild(pill);
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
// Clear-all affordance (CARTO-inspired): panel-level clear with active count.
|
|
482
|
+
Array.from(this.querySelectorAll(".c-filter-bar__clear-all")).forEach((n) => n.remove());
|
|
483
|
+
if (this.hasAttribute("clearable")) {
|
|
484
|
+
const btn = document.createElement("button");
|
|
485
|
+
btn.type = "button";
|
|
486
|
+
btn.className = "c-btn c-btn--ghost c-btn--sm c-filter-bar__clear-all";
|
|
487
|
+
const count = this.getAttribute("count");
|
|
488
|
+
// R31-145: clear-all is icon+text (never icon-only destructive).
|
|
489
|
+
setHTML(btn, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#i-x" /></svg>');
|
|
490
|
+
btn.appendChild(document.createTextNode(" " + (count ? (labelText(this, "clear-all", "Clear all") + " (" + count + ")") : labelText(this, "clear-all", "Clear all"))));
|
|
491
|
+
this.appendChild(btn);
|
|
492
|
+
}
|
|
493
|
+
if (!parsed && !label) renderEmpty(this, "filter-bar");
|
|
494
|
+
}
|
|
495
|
+
enhance() {
|
|
496
|
+
wireRemovable(this);
|
|
497
|
+
if (this._wiredFilterBar) return;
|
|
498
|
+
this._wiredFilterBar = true;
|
|
499
|
+
this.addEventListener("click", (e) => {
|
|
500
|
+
const btn = e.target && e.target.closest ? e.target.closest(".c-filter-bar__mode") : null;
|
|
501
|
+
if (!btn || !this.contains(btn)) return;
|
|
502
|
+
// Mode and scope buttons are independent pressed pools.
|
|
503
|
+
if (btn.classList.contains("c-filter-bar__scope-btn")) {
|
|
504
|
+
const scope = btn.dataset.scope || null;
|
|
505
|
+
Array.from(this.querySelectorAll(".c-filter-bar__scope-btn")).forEach((b) => b.setAttribute("aria-pressed", String(b === btn)));
|
|
506
|
+
if (scope) this.setAttribute("scope", scope);
|
|
507
|
+
this.dispatchEvent(new CustomEvent("contour:scope-change", { bubbles: true, composed: true, detail: { scope } }));
|
|
508
|
+
} else {
|
|
509
|
+
const mode = btn.dataset.mode || btn.textContent.trim();
|
|
510
|
+
Array.from(this.querySelectorAll(".c-filter-bar__mode:not(.c-filter-bar__scope-btn)")).forEach((b) => b.setAttribute("aria-pressed", String(b === btn)));
|
|
511
|
+
this.dispatchEvent(new CustomEvent("contour:mode-change", { bubbles: true, composed: true, detail: { mode } }));
|
|
512
|
+
}
|
|
513
|
+
});
|
|
514
|
+
this.addEventListener("keydown", (e) => {
|
|
515
|
+
const modes = Array.from(this.querySelectorAll(".c-filter-bar__mode"));
|
|
516
|
+
navKey(e, modes, { wrap: false, onKey: () => { document.activeElement.click(); } });
|
|
517
|
+
});
|
|
518
|
+
// text input
|
|
519
|
+
const inp = this.querySelector(".c-filter-bar__input");
|
|
520
|
+
if (inp && !inp._wiredFilterInput) {
|
|
521
|
+
inp._wiredFilterInput = true;
|
|
522
|
+
inp.addEventListener("input", () => {
|
|
523
|
+
this.dispatchEvent(new CustomEvent("contour:input", { bubbles: true, composed: true, detail: { value: inp.value } }));
|
|
524
|
+
});
|
|
525
|
+
inp.addEventListener("change", () => {
|
|
526
|
+
this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: inp.value } }));
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
// Clear-all (CARTO-inspired): delegated on host.
|
|
530
|
+
if (!this._wiredClearAll) {
|
|
531
|
+
this._wiredClearAll = true;
|
|
532
|
+
this.addEventListener("click", (e) => {
|
|
533
|
+
const btn = e.target && e.target.closest ? e.target.closest(".c-filter-bar__clear-all") : null;
|
|
534
|
+
if (!btn || !this.contains(btn)) return;
|
|
535
|
+
e.preventDefault();
|
|
536
|
+
this.dispatchEvent(new CustomEvent("contour:clear-all", { bubbles: true, composed: true, detail: {} }));
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
define("contour-filter-bar", ContourFilterBar);
|
|
542
|
+
class ContourCommand extends ContourBase {
|
|
543
|
+
static get observed() { return ["placeholder", "items", "recent", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "cache-key", "no-cache", "anchor"]; }
|
|
544
|
+
static get properties() { return { placeholder: { attribute: "placeholder" }, items: { attribute: "items" }, recent: { attribute: "recent" }, empty: { attribute: "empty" }, src: { attribute: "src" } }; }
|
|
545
|
+
render() {
|
|
546
|
+
this.classList.add("c-command");
|
|
547
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "dialog");
|
|
548
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "command-palette", "Command palette"));
|
|
549
|
+
if (!this.hasAttribute("popover")) this.setAttribute("popover", "auto");
|
|
550
|
+
wireStates(this);
|
|
551
|
+
loadRemote(this, "items");
|
|
552
|
+
if (renderStates(this, "command")) return;
|
|
553
|
+
const placeholder = this.getAttribute("placeholder") || "Search…";
|
|
554
|
+
// Mirror palette structure so CSS applies instead of UA input border.
|
|
555
|
+
const inputWrap = this.ensure(".c-command__input", () => { const el = document.createElement("div"); el.className = "c-command__input"; return el; });
|
|
556
|
+
const input = this.ensure(".c-command__field", () => { const el = document.createElement("input"); el.className = "c-command__field"; el.type = "text"; return el; });
|
|
557
|
+
if (!inputWrap.contains(input)) inputWrap.appendChild(input);
|
|
558
|
+
input.type = "text";
|
|
559
|
+
input.placeholder = placeholder;
|
|
560
|
+
input.setAttribute("aria-label", labelText(this, "command", "Command"));
|
|
561
|
+
input.setAttribute("role", "combobox");
|
|
562
|
+
input.setAttribute("aria-autocomplete", "list");
|
|
563
|
+
input.setAttribute("aria-expanded", "true");
|
|
564
|
+
const list = this.querySelector(".c-command__list");
|
|
565
|
+
if (list && !list.id) list.id = contourId("c-command-list");
|
|
566
|
+
if (list && list.id) input.setAttribute("aria-controls", list.id);
|
|
567
|
+
// R24-38: anchor wiring — position-anchor on the host, anchor-name on the
|
|
568
|
+
// trigger element, like map-popup / ContourPopover.
|
|
569
|
+
this._applyCommandAnchor();
|
|
570
|
+
const items = remoteData(this, "items");
|
|
571
|
+
const list2 = this.querySelector(".c-command__list");
|
|
572
|
+
const authored = list2 ? Array.from(list2.children).filter((n) => n.classList && n.classList.contains("c-command__item") || n.classList && n.classList.contains("c-command__group")) : [];
|
|
573
|
+
if (items && !authored.length) {
|
|
574
|
+
try {
|
|
575
|
+
const parsed = JSON.parse(items);
|
|
576
|
+
const l = this.ensure(".c-command__list", () => { const el = document.createElement("div"); el.className = "c-command__list"; el.setAttribute("role", "listbox"); el.id = contourId("c-command-list"); return el; });
|
|
577
|
+
l.setAttribute("role", "listbox");
|
|
578
|
+
setHTML(l, "");
|
|
579
|
+
const recentRaw = this.getAttribute("recent");
|
|
580
|
+
if (recentRaw) {
|
|
581
|
+
try {
|
|
582
|
+
const recentParsed = JSON.parse(recentRaw);
|
|
583
|
+
const group = document.createElement("div");
|
|
584
|
+
group.className = "c-command__group";
|
|
585
|
+
const gt = document.createElement("div");
|
|
586
|
+
gt.className = "c-command__group-title";
|
|
587
|
+
gt.textContent = labelText(this, "recent", "Recent");
|
|
588
|
+
group.appendChild(gt);
|
|
589
|
+
recentParsed.forEach((it) => {
|
|
590
|
+
const item = document.createElement("div");
|
|
591
|
+
item.className = "c-command__item";
|
|
592
|
+
item.setAttribute("role", "option");
|
|
593
|
+
const body = document.createElement("div");
|
|
594
|
+
body.className = "c-command__item-body";
|
|
595
|
+
const t = document.createElement("div");
|
|
596
|
+
t.className = "c-command__item-title";
|
|
597
|
+
t.textContent = typeof it === "string" ? it : (it.title || it.label || "");
|
|
598
|
+
body.appendChild(t);
|
|
599
|
+
item.appendChild(body);
|
|
600
|
+
group.appendChild(item);
|
|
601
|
+
});
|
|
602
|
+
l.appendChild(group);
|
|
603
|
+
} catch (e) { /* skip */ }
|
|
604
|
+
}
|
|
605
|
+
parsed.forEach((it) => {
|
|
606
|
+
if (it.group) {
|
|
607
|
+
const group = document.createElement("div");
|
|
608
|
+
group.className = "c-command__group";
|
|
609
|
+
const gt = document.createElement("div");
|
|
610
|
+
gt.className = "c-command__group-title";
|
|
611
|
+
gt.textContent = it.group;
|
|
612
|
+
group.appendChild(gt);
|
|
613
|
+
const item = document.createElement("div");
|
|
614
|
+
item.className = "c-command__item";
|
|
615
|
+
item.setAttribute("role", "option");
|
|
616
|
+
if (it.icon) {
|
|
617
|
+
const ic = document.createElement("span");
|
|
618
|
+
ic.className = "c-command__item-icon";
|
|
619
|
+
ic.textContent = it.icon;
|
|
620
|
+
item.appendChild(ic);
|
|
621
|
+
}
|
|
622
|
+
const body = document.createElement("div");
|
|
623
|
+
body.className = "c-command__item-body";
|
|
624
|
+
if (it.title || it.label) {
|
|
625
|
+
const t = document.createElement("div");
|
|
626
|
+
t.className = "c-command__item-title";
|
|
627
|
+
t.textContent = it.title || it.label;
|
|
628
|
+
body.appendChild(t);
|
|
629
|
+
}
|
|
630
|
+
if (it.hint) {
|
|
631
|
+
const h = document.createElement("span");
|
|
632
|
+
h.className = "c-command__item-hint";
|
|
633
|
+
h.textContent = it.hint;
|
|
634
|
+
body.appendChild(h);
|
|
635
|
+
}
|
|
636
|
+
if (it.shortcut) {
|
|
637
|
+
const sc = document.createElement("kbd");
|
|
638
|
+
sc.className = "c-command__item-shortcut";
|
|
639
|
+
sc.textContent = it.shortcut;
|
|
640
|
+
item.appendChild(sc);
|
|
641
|
+
}
|
|
642
|
+
item.appendChild(body);
|
|
643
|
+
group.appendChild(item);
|
|
644
|
+
l.appendChild(group);
|
|
645
|
+
} else {
|
|
646
|
+
const item = document.createElement("div");
|
|
647
|
+
item.className = "c-command__item";
|
|
648
|
+
item.setAttribute("role", "option");
|
|
649
|
+
if (it.icon) {
|
|
650
|
+
const ic = document.createElement("span");
|
|
651
|
+
ic.className = "c-command__item-icon";
|
|
652
|
+
ic.textContent = it.icon;
|
|
653
|
+
item.appendChild(ic);
|
|
654
|
+
}
|
|
655
|
+
const body = document.createElement("div");
|
|
656
|
+
body.className = "c-command__item-body";
|
|
657
|
+
if (it.title || it.label) {
|
|
658
|
+
const t = document.createElement("div");
|
|
659
|
+
t.className = "c-command__item-title";
|
|
660
|
+
t.textContent = it.title || it.label;
|
|
661
|
+
body.appendChild(t);
|
|
662
|
+
}
|
|
663
|
+
if (it.hint) {
|
|
664
|
+
const h = document.createElement("span");
|
|
665
|
+
h.className = "c-command__item-hint";
|
|
666
|
+
h.textContent = it.hint;
|
|
667
|
+
body.appendChild(h);
|
|
668
|
+
}
|
|
669
|
+
if (it.shortcut) {
|
|
670
|
+
const sc = document.createElement("kbd");
|
|
671
|
+
sc.className = "c-command__item-shortcut";
|
|
672
|
+
sc.textContent = it.shortcut;
|
|
673
|
+
item.appendChild(sc);
|
|
674
|
+
}
|
|
675
|
+
item.appendChild(body);
|
|
676
|
+
l.appendChild(item);
|
|
677
|
+
}
|
|
678
|
+
});
|
|
679
|
+
} catch (e) { warnBadJson(this, "attribute", e); }
|
|
680
|
+
} else if (!items && list) {
|
|
681
|
+
list.remove();
|
|
682
|
+
}
|
|
683
|
+
const empty = this.getAttribute("empty");
|
|
684
|
+
if (empty) {
|
|
685
|
+
const e = this.ensure(".c-command__empty", () => { const el = document.createElement("div"); el.className = "c-command__empty"; return el; });
|
|
686
|
+
e.textContent = empty;
|
|
687
|
+
// Empty message shown only when query yields nothing.
|
|
688
|
+
e.hidden = this.querySelectorAll(".c-command__item").length > 0;
|
|
689
|
+
} else {
|
|
690
|
+
const e = this.querySelector(".c-command__empty");
|
|
691
|
+
if (e) e.remove();
|
|
692
|
+
}
|
|
693
|
+
// Live filter region exists empty at mount; filled only when typing.
|
|
694
|
+
const status = this.ensure(".c-command__status", () => { const el = document.createElement("div"); el.className = "c-command__status"; el.setAttribute("role", "status"); return el; });
|
|
695
|
+
status.textContent = "";
|
|
696
|
+
if (!items && !list) {
|
|
697
|
+
renderEmpty(this, "command");
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
// R24-38: anchor wiring — position-anchor on the host, anchor-name on the
|
|
701
|
+
// trigger element, like map-popup / ContourPopover.
|
|
702
|
+
_applyCommandAnchor() {
|
|
703
|
+
const anchorSel = this.getAttribute("anchor");
|
|
704
|
+
const anchorEl = anchorSel ? (anchorSel.startsWith("#") ? document.getElementById(anchorSel.slice(1)) : document.querySelector(anchorSel)) : null;
|
|
705
|
+
if (this._commandAnchorEl && this._commandAnchorEl !== anchorEl) {
|
|
706
|
+
this._commandAnchorEl.style.removeProperty("anchor-name");
|
|
707
|
+
this._commandAnchorEl.removeAttribute("aria-controls");
|
|
708
|
+
this._commandAnchorEl.removeAttribute("aria-expanded");
|
|
709
|
+
}
|
|
710
|
+
this._commandAnchorEl = anchorEl || null;
|
|
711
|
+
if (anchorEl) {
|
|
712
|
+
const anchorName = "--command-" + this.id;
|
|
713
|
+
anchorEl.style.setProperty("anchor-name", anchorName);
|
|
714
|
+
this.style.setProperty("position-anchor", anchorName);
|
|
715
|
+
anchorEl.setAttribute("aria-controls", this.id);
|
|
716
|
+
if (!this._commandAnchorDispose) {
|
|
717
|
+
this._commandAnchorDispose = true;
|
|
718
|
+
onDispose(this, () => {
|
|
719
|
+
if (this._commandAnchorEl) { this._commandAnchorEl.style.removeProperty("anchor-name"); this._commandAnchorEl.removeAttribute("aria-controls"); this._commandAnchorEl.removeAttribute("aria-expanded"); }
|
|
720
|
+
this._commandAnchorDispose = false;
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
} else {
|
|
724
|
+
this.style.removeProperty("position-anchor");
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
// R24-38: show/hide/toggle with aria-expanded sync, mirroring
|
|
728
|
+
// ContourCommandPalette (ui.mjs) and ContourPopover.
|
|
729
|
+
show() {
|
|
730
|
+
if (this.matches(":popover-open")) { if (!this.hasAttribute("open")) this.setAttribute("open", ""); return; }
|
|
731
|
+
if (typeof this.showPopover === "function") { try { this.showPopover(); } catch (e) {} }
|
|
732
|
+
this.classList.add("is-open");
|
|
733
|
+
const inp = this.querySelector(".c-command__field");
|
|
734
|
+
if (inp) inp.setAttribute("aria-expanded", "true");
|
|
735
|
+
if (!this.hasAttribute("open")) this.setAttribute("open", "");
|
|
736
|
+
this._setCommandTriggerExpanded(true);
|
|
737
|
+
}
|
|
738
|
+
hide() {
|
|
739
|
+
const isOpen = this.matches(":popover-open");
|
|
740
|
+
if (!isOpen) { if (this.hasAttribute("open")) this.removeAttribute("open"); return; }
|
|
741
|
+
if (typeof this.hidePopover === "function") { try { this.hidePopover(); } catch (e) {} }
|
|
742
|
+
this.classList.remove("is-open");
|
|
743
|
+
const inp = this.querySelector(".c-command__field");
|
|
744
|
+
if (inp) inp.setAttribute("aria-expanded", "false");
|
|
745
|
+
if (this.hasAttribute("open")) this.removeAttribute("open");
|
|
746
|
+
this._setCommandTriggerExpanded(false);
|
|
747
|
+
}
|
|
748
|
+
toggle() { if (this.matches(":popover-open")) this.hide(); else this.show(); }
|
|
749
|
+
_setCommandTriggerExpanded(open) {
|
|
750
|
+
const trg = this._commandAnchorEl;
|
|
751
|
+
if (!trg) return;
|
|
752
|
+
trg.setAttribute("aria-controls", this.id);
|
|
753
|
+
trg.setAttribute("aria-expanded", String(!!open));
|
|
754
|
+
}
|
|
755
|
+
enhance() {
|
|
756
|
+
if (this._wiredCommand) return;
|
|
757
|
+
this._wiredCommand = true;
|
|
758
|
+
// Emit contour:open/close (canonical) plus deprecated aliases; sync aria-expanded.
|
|
759
|
+
this.addEventListener("beforetoggle", (e) => {
|
|
760
|
+
if (e.newState === "open") {
|
|
761
|
+
this.classList.add("is-open");
|
|
762
|
+
wcEmitOverlay(this, "contour:open", {});
|
|
763
|
+
const inp = this.querySelector(".c-command__field");
|
|
764
|
+
if (inp) { inp.setAttribute("aria-expanded", "true"); try { inp.focus(); } catch (e) {} }
|
|
765
|
+
this._setCommandTriggerExpanded(true);
|
|
766
|
+
} else {
|
|
767
|
+
this.classList.remove("is-open");
|
|
768
|
+
wcEmitOverlay(this, "contour:close", {});
|
|
769
|
+
this._setCommandTriggerExpanded(false);
|
|
770
|
+
}
|
|
771
|
+
});
|
|
772
|
+
// Re-apply anchor on open (like map-popup).
|
|
773
|
+
this.addEventListener("toggle", (e) => {
|
|
774
|
+
if (e.newState === "open") { requestAnimationFrame(() => { this._applyCommandAnchor(); }); }
|
|
775
|
+
});
|
|
776
|
+
const input = () => this.querySelector(".c-command__field");
|
|
777
|
+
const items = () => Array.from(this.querySelectorAll(".c-command__item"));
|
|
778
|
+
// R31-100: the cursor walks only items the reader can see. A hidden option
|
|
779
|
+
// (filtered out by typing) is not a stop; arrowing onto it moved the active
|
|
780
|
+
// descendant to an invisible row.
|
|
781
|
+
const visibleItems = () => items().filter((el) => !el.hidden && !el.closest("[hidden]"));
|
|
782
|
+
let cursor = -1;
|
|
783
|
+
const mark = () => {
|
|
784
|
+
visibleItems().forEach((it, i) => {
|
|
785
|
+
it.classList.toggle("c-command__item--active", i === cursor);
|
|
786
|
+
it.setAttribute("aria-selected", String(i === cursor));
|
|
787
|
+
if (i === cursor) {
|
|
788
|
+
if (!it.id) it.id = contourId("contour-command-option");
|
|
789
|
+
const inp = input();
|
|
790
|
+
if (inp) inp.setAttribute("aria-activedescendant", it.id);
|
|
791
|
+
}
|
|
792
|
+
});
|
|
793
|
+
if (cursor < 0) {
|
|
794
|
+
const inp = input();
|
|
795
|
+
if (inp) inp.removeAttribute("aria-activedescendant");
|
|
796
|
+
}
|
|
797
|
+
};
|
|
798
|
+
this.addEventListener("keydown", (e) => {
|
|
799
|
+
const inp = input();
|
|
800
|
+
if (!inp || e.target !== inp) return;
|
|
801
|
+
const its = visibleItems();
|
|
802
|
+
if (!its.length) return;
|
|
803
|
+
if (e.key === "ArrowDown") { e.preventDefault(); cursor = Math.min(cursor + 1, its.length - 1); mark(); }
|
|
804
|
+
else if (e.key === "ArrowUp") { e.preventDefault(); cursor = Math.max(cursor - 1, 0); mark(); }
|
|
805
|
+
else if (e.key === "Home") { e.preventDefault(); cursor = 0; mark(); }
|
|
806
|
+
else if (e.key === "End") { e.preventDefault(); cursor = its.length - 1; mark(); }
|
|
807
|
+
else if (e.key === "Enter") {
|
|
808
|
+
e.preventDefault();
|
|
809
|
+
if (cursor >= 0 && its[cursor]) {
|
|
810
|
+
const item = its[cursor];
|
|
811
|
+
const idx = items().indexOf(item);
|
|
812
|
+
this.dispatchEvent(new CustomEvent("contour:select", { detail: { index: idx, label: item.textContent.trim() }, bubbles: true, composed: true }));
|
|
813
|
+
this.hide();
|
|
814
|
+
}
|
|
815
|
+
} else if (e.key === "Escape") {
|
|
816
|
+
this.hide();
|
|
817
|
+
}
|
|
818
|
+
});
|
|
819
|
+
this.addEventListener("click", (e) => {
|
|
820
|
+
const item = e.target && e.target.closest ? e.target.closest(".c-command__item") : null;
|
|
821
|
+
if (item && this.contains(item)) {
|
|
822
|
+
const idx = items().indexOf(item);
|
|
823
|
+
this.dispatchEvent(new CustomEvent("contour:select", { detail: { index: idx, label: item.textContent.trim() }, bubbles: true, composed: true }));
|
|
824
|
+
this.hide();
|
|
825
|
+
}
|
|
826
|
+
});
|
|
827
|
+
// Typing narrows option set; hidden items excluded from cursor walk.
|
|
828
|
+
this.addEventListener("input", (e) => {
|
|
829
|
+
const inp = input();
|
|
830
|
+
if (!inp || e.target !== inp) return;
|
|
831
|
+
const q = inp.value.trim().toLowerCase();
|
|
832
|
+
const all = items();
|
|
833
|
+
let visible = 0;
|
|
834
|
+
all.forEach((it) => {
|
|
835
|
+
const match = !q || (it.textContent || "").toLowerCase().includes(q);
|
|
836
|
+
it.hidden = !match;
|
|
837
|
+
if (match) visible += 1;
|
|
838
|
+
});
|
|
839
|
+
this.querySelectorAll(".c-command__group").forEach((g) => {
|
|
840
|
+
const hasVisible = Array.from(g.querySelectorAll(".c-command__item")).some((it) => !it.hidden);
|
|
841
|
+
g.hidden = !hasVisible;
|
|
842
|
+
});
|
|
843
|
+
// Highlight first visible result; reveal empty message only on no match.
|
|
844
|
+
const firstVisible = all.findIndex((it) => !it.hidden);
|
|
845
|
+
// mark() numbers the visible set, not the full item list.
|
|
846
|
+
cursor = firstVisible >= 0 ? 0 : -1;
|
|
847
|
+
mark();
|
|
848
|
+
const emptyEl = this.querySelector(".c-command__empty");
|
|
849
|
+
if (emptyEl) emptyEl.hidden = visible !== 0;
|
|
850
|
+
const status = this.querySelector(".c-command__status");
|
|
851
|
+
if (status) status.textContent = q ? `${visible} of ${all.length}` : "";
|
|
852
|
+
});
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
define("contour-command", ContourCommand);
|
|
856
|
+
|
|
857
|
+
/**
|
|
858
|
+
* Spatial filter (CARTO-inspired): draw-on-map affordance. Engine-agnostic:
|
|
859
|
+
* Contour renders the mode toolbar and emits `contour:draw-start` (with the
|
|
860
|
+
* `mode`) and `contour:spatial-filter` to signal intent; it does NOT own the
|
|
861
|
+
* drawn geometry. The engine that owns the canvas emits its own draw-end with
|
|
862
|
+
* the geometry payload (R31-94: engine ownership is explicit, so a consumer
|
|
863
|
+
* never waits for a `contour:draw-end` the seam does not send). The consumer
|
|
864
|
+
* runs the spatial query against its map engine.
|
|
865
|
+
* Attributes: `modes`, `mode`, `active`, `bounds`, `operator`, `loading`,
|
|
866
|
+
* `error`, `retry`, `skeleton`, `src`, `cache-key`.
|
|
867
|
+
*/
|
|
868
|
+
class ContourSpatialFilter extends ContourBase {
|
|
869
|
+
// Pure UI component; unused loader attrs dropped from observed.
|
|
870
|
+
static get observed() { return ["modes", "mode", "active", "bounds", "operator", "loading", "error", "retry", "cache-key", "skeleton", "src"]; }
|
|
871
|
+
static get properties() { return { modes: { attribute: "modes" }, mode: { attribute: "mode" }, active: { attribute: "active" }, bounds: { attribute: "bounds" }, operator: { attribute: "operator" } }; }
|
|
872
|
+
render() {
|
|
873
|
+
this.classList.add("c-spatial-filter");
|
|
874
|
+
// The host is a labelled group; the mode bar is a labelled toolbar, so a
|
|
875
|
+
// screen reader announces both the filter and its control set (NAV-19).
|
|
876
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "group");
|
|
877
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", labelText(this, "spatial-filter", "Spatial filter"));
|
|
878
|
+
wireStates(this);
|
|
879
|
+
// No remote src; loader call and attrs removed.
|
|
880
|
+
if (renderStates(this, "spatial-filter")) return;
|
|
881
|
+
const modesAttr = this.getAttribute("modes");
|
|
882
|
+
let modes = null;
|
|
883
|
+
if (modesAttr) { try { modes = JSON.parse(modesAttr); } catch (e) { modes = modesAttr.split(",").map((s) => s.trim()); } }
|
|
884
|
+
const list = Array.isArray(modes) ? modes : ["rect", "circle", "polygon", "clear"];
|
|
885
|
+
let bar = this.querySelector(".c-spatial-filter__modes");
|
|
886
|
+
if (!bar) { bar = document.createElement("div"); bar.className = "c-spatial-filter__modes"; bar.setAttribute("role", "toolbar"); bar.setAttribute("aria-label", labelText(this, "spatial-filter-modes", "Spatial filter modes")); this.appendChild(bar); }
|
|
887
|
+
setHTML(bar, "");
|
|
888
|
+
// Clicked mode persists across re-renders via private field.
|
|
889
|
+
const attrMode = this.getAttribute("mode");
|
|
890
|
+
if (attrMode !== this._spatialSeenMode) { this._spatialMode = null; this._spatialSeenMode = attrMode; }
|
|
891
|
+
const current = this._spatialMode != null ? this._spatialMode : attrMode;
|
|
892
|
+
list.forEach((m) => {
|
|
893
|
+
const name = typeof m === "string" ? m : (m.label || m.value || m);
|
|
894
|
+
const val = typeof m === "string" ? m : (m.value || m.label || m);
|
|
895
|
+
const btn = document.createElement("button");
|
|
896
|
+
btn.type = "button";
|
|
897
|
+
btn.className = "c-spatial-filter__mode c-btn c-btn--ghost c-btn--sm";
|
|
898
|
+
// R31-155: each mode carries a shape glyph (icon+text); the name stays.
|
|
899
|
+
const MODE_GLYPH = { rect: "i-square", circle: "i-circle", polygon: "i-triangle", lasso: "i-lasso", clear: "i-x" };
|
|
900
|
+
const glyph = MODE_GLYPH[val];
|
|
901
|
+
if (glyph) setHTML(btn, '<svg aria-hidden="true" viewBox="0 0 24 24"><use href="#' + glyph + '" /></svg>');
|
|
902
|
+
btn.appendChild(document.createTextNode((glyph ? " " : "") + name));
|
|
903
|
+
btn.dataset.mode = val;
|
|
904
|
+
if (current && current === val) btn.setAttribute("aria-pressed", "true");
|
|
905
|
+
bar.appendChild(btn);
|
|
906
|
+
});
|
|
907
|
+
// Operator selection
|
|
908
|
+
let operator = this.querySelector(".c-spatial-filter__operator");
|
|
909
|
+
if (!operator) { operator = document.createElement("div"); operator.className = "c-spatial-filter__operator"; this.appendChild(operator); }
|
|
910
|
+
const ops = ["intersects", "contains", "within", "disjoint"];
|
|
911
|
+
const currentOp = this.getAttribute("operator") || "intersects";
|
|
912
|
+
setHTML(operator, "");
|
|
913
|
+
const opLabel = document.createElement("span");
|
|
914
|
+
opLabel.textContent = labelText(this, "operator", "Operator") + ":";
|
|
915
|
+
operator.appendChild(opLabel);
|
|
916
|
+
const opSelect = document.createElement("select");
|
|
917
|
+
opSelect.className = "c-spatial-filter__operator-select";
|
|
918
|
+
opSelect.setAttribute("aria-label", labelText(this, "operator", "Operator"));
|
|
919
|
+
opSelect.setAttribute("data-contour-label", "true");
|
|
920
|
+
ops.forEach((op) => {
|
|
921
|
+
const o = document.createElement("option");
|
|
922
|
+
o.value = op;
|
|
923
|
+
o.textContent = op;
|
|
924
|
+
if (op === currentOp) o.setAttribute("selected", "");
|
|
925
|
+
opSelect.appendChild(o);
|
|
926
|
+
});
|
|
927
|
+
operator.appendChild(opSelect);
|
|
928
|
+
// Bounds readout
|
|
929
|
+
let readout = this.querySelector(".c-spatial-filter__readout");
|
|
930
|
+
if (!readout) { readout = document.createElement("div"); readout.className = "c-spatial-filter__readout"; this.appendChild(readout); }
|
|
931
|
+
const bounds = this.getAttribute("bounds");
|
|
932
|
+
readout.textContent = bounds || "—";
|
|
933
|
+
// Clear all
|
|
934
|
+
let clearAll = this.querySelector(".c-spatial-filter__clear-all");
|
|
935
|
+
if (!clearAll) { clearAll = document.createElement("button"); clearAll.type = "button"; clearAll.className = "c-spatial-filter__clear-all"; this.appendChild(clearAll); }
|
|
936
|
+
applyLabel(clearAll, this, "clear-all", "Clear all");
|
|
937
|
+
// R24-43: same field-over-attribute persistence as `mode` above.
|
|
938
|
+
const attrActive = this.hasAttribute("active");
|
|
939
|
+
if (attrActive !== this._spatialSeenActive) { this._spatialActive = null; this._spatialSeenActive = attrActive; }
|
|
940
|
+
if (this._spatialActive != null ? this._spatialActive : attrActive) {
|
|
941
|
+
this.classList.add("c-spatial-filter--active");
|
|
942
|
+
} else {
|
|
943
|
+
this.classList.remove("c-spatial-filter--active");
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
enhance() {
|
|
947
|
+
if (this._wiredSpatialFilter) return;
|
|
948
|
+
this._wiredSpatialFilter = true;
|
|
949
|
+
this.addEventListener("click", (e) => {
|
|
950
|
+
const btn = e.target && e.target.closest ? e.target.closest("button") : null;
|
|
951
|
+
if (!btn || !this.contains(btn)) return;
|
|
952
|
+
if (btn.classList.contains("c-spatial-filter__clear-all")) {
|
|
953
|
+
this.classList.remove("c-spatial-filter--active");
|
|
954
|
+
Array.from(this.querySelectorAll(".c-spatial-filter__mode")).forEach((b) => b.setAttribute("aria-pressed", "false"));
|
|
955
|
+
// R24-43: clear the persisted mode + active fields so a re-render
|
|
956
|
+
// cannot restore the old selection.
|
|
957
|
+
this._spatialActive = false;
|
|
958
|
+
this._spatialMode = null;
|
|
959
|
+
this.dispatchEvent(new CustomEvent("contour:clear", { bubbles: true, composed: true, detail: {} }));
|
|
960
|
+
this.dispatchEvent(new CustomEvent("contour:spatial-filter", { bubbles: true, composed: true, detail: { action: "clear-all" } }));
|
|
961
|
+
return;
|
|
962
|
+
}
|
|
963
|
+
const modeBtn = btn.closest(".c-spatial-filter__mode");
|
|
964
|
+
if (!modeBtn) return;
|
|
965
|
+
const mode = modeBtn.dataset.mode || modeBtn.textContent.trim();
|
|
966
|
+
if (mode === "clear") {
|
|
967
|
+
this.classList.remove("c-spatial-filter--active");
|
|
968
|
+
Array.from(this.querySelectorAll(".c-spatial-filter__mode")).forEach((b) => b.setAttribute("aria-pressed", "false"));
|
|
969
|
+
this._spatialActive = false;
|
|
970
|
+
this._spatialMode = null;
|
|
971
|
+
this.dispatchEvent(new CustomEvent("contour:clear", { bubbles: true, composed: true, detail: {} }));
|
|
972
|
+
return;
|
|
973
|
+
}
|
|
974
|
+
this.classList.add("c-spatial-filter--active");
|
|
975
|
+
Array.from(this.querySelectorAll(".c-spatial-filter__mode")).forEach((b) => b.setAttribute("aria-pressed", String(b === modeBtn)));
|
|
976
|
+
// Persist mode/active in private fields to survive re-render.
|
|
977
|
+
this._spatialActive = true;
|
|
978
|
+
this._spatialMode = mode;
|
|
979
|
+
this.dispatchEvent(new CustomEvent("contour:draw-start", { bubbles: true, composed: true, detail: { mode } }));
|
|
980
|
+
this.dispatchEvent(new CustomEvent("contour:spatial-filter", { bubbles: true, composed: true, detail: { action: "draw-start", mode } }));
|
|
981
|
+
});
|
|
982
|
+
this.addEventListener("change", (e) => {
|
|
983
|
+
const select = e.target;
|
|
984
|
+
if (select && select.classList.contains("c-spatial-filter__operator-select")) {
|
|
985
|
+
this.setAttribute("operator", select.value);
|
|
986
|
+
this.dispatchEvent(new CustomEvent("contour:spatial-filter", { bubbles: true, composed: true, detail: { action: "operator", operator: select.value } }));
|
|
987
|
+
}
|
|
988
|
+
});
|
|
989
|
+
this.addEventListener("keydown", (e) => {
|
|
990
|
+
const modes = Array.from(this.querySelectorAll(".c-spatial-filter__mode"));
|
|
991
|
+
navKey(e, modes, { wrap: false, onKey: () => { document.activeElement.click(); } });
|
|
992
|
+
});
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
define("contour-spatial-filter", ContourSpatialFilter);
|