contour-ds 1.1.2 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -2
- package/dist/agent-rules.json +5 -1
- package/dist/build-manifest.json +94 -93
- package/dist/contour-wc.esm.js +4443 -534
- package/dist/contour-wc.esm.min.js +1 -1
- package/dist/contour-wc.js +4441 -528
- package/dist/contour-wc.min.js +1 -1
- package/dist/contour.components.json +4054 -171
- package/dist/contour.css +1325 -565
- package/dist/contour.d.ts +119 -62
- package/dist/contour.esm.js +23 -0
- package/dist/contour.esm.min.js +1 -1
- package/dist/contour.js +23 -0
- package/dist/contour.min.css +1 -1
- package/dist/contour.min.js +1 -1
- package/dist/contour.tokens.json +47 -2
- package/dist/docs/actions.md +6 -2
- package/dist/docs/affordances.md +19 -3
- package/dist/docs/apireference.md +30 -0
- package/dist/docs/colour.md +2 -2
- package/dist/docs/componentindex.md +39 -0
- package/dist/docs/data.md +38 -3
- package/dist/docs/docs.md +6 -2
- package/dist/docs/feedback.md +13 -3
- package/dist/docs/field.md +7 -2
- package/dist/docs/forms.md +35 -3
- package/dist/docs/index.json +44 -75
- package/dist/docs/install.md +4 -2
- package/dist/docs/landing.md +3 -2
- package/dist/docs/mapengine.md +9 -3
- package/dist/docs/motion.md +5 -2
- package/dist/docs/navigation.md +10 -3
- package/dist/docs/overlays.md +26 -3
- package/dist/docs/overview.md +2 -2
- package/dist/docs/patterns.md +38 -3
- package/dist/docs/playground.md +5 -2
- package/dist/docs/principles.md +2 -2
- package/dist/docs/recipes.md +7 -3
- package/dist/docs/space.md +2 -2
- package/dist/docs/status.md +19 -3
- package/dist/docs/surfaces.md +7 -3
- package/dist/docs/theming.md +5 -2
- package/dist/docs/type.md +2 -2
- package/dist/docs/webcomponents.md +26 -7
- package/dist/map-chrome.mapbox.css +4 -4
- package/dist/map-chrome.maplibre.css +4 -4
- package/dist/registry/items/contour-core.json +2 -2
- package/dist/registry/items/contour-data.json +2 -2
- package/dist/registry/items/contour-docs.json +2 -2
- package/dist/registry/items/contour-landing.json +2 -2
- package/dist/registry/registry.json +8 -8
- package/dist/surfaces/contour-core.min.css +1 -1
- package/dist/surfaces/contour-data.min.css +1 -1
- package/dist/surfaces/contour-docs.min.css +1 -1
- package/dist/surfaces/contour-landing.min.css +1 -1
- package/dist/wc/behaviours.mjs +69 -11
- package/dist/wc/content.mjs +163 -8
- package/dist/wc/core.mjs +177 -36
- package/dist/wc/dashboard.mjs +69 -4
- package/dist/wc/data.mjs +933 -128
- package/dist/wc/docs.mjs +118 -0
- package/dist/wc/feedback.mjs +75 -13
- package/dist/wc/forms.mjs +371 -34
- package/dist/wc/index.mjs +31 -3
- package/dist/wc/interaction.mjs +11 -6
- package/dist/wc/map.mjs +142 -38
- package/dist/wc/misc.mjs +29 -1
- package/dist/wc/navigation.mjs +424 -75
- package/dist/wc/registration.mjs +8 -4
- package/dist/wc/shadow.mjs +29 -12
- package/dist/wc/states.mjs +15 -0
- package/dist/wc/svg.mjs +10 -0
- package/dist/wc/ui.mjs +1767 -129
- package/package.json +39 -6
package/dist/wc/navigation.mjs
CHANGED
|
@@ -346,8 +346,154 @@ class ContourHeader extends ContourBase {
|
|
|
346
346
|
}
|
|
347
347
|
define("contour-header", ContourHeader);
|
|
348
348
|
class ContourTree extends ContourBase {
|
|
349
|
-
static get
|
|
350
|
-
static get
|
|
349
|
+
static get updateMode() { return "keyed"; }
|
|
350
|
+
static get observed() { return ["items", "virtual", "item-height", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "persist", "selectable"]; }
|
|
351
|
+
static get properties() { return { items: { attribute: "items" }, src: { attribute: "src" }, "item-height": { attribute: "item-height" } }; }
|
|
352
|
+
_itemHeight() {
|
|
353
|
+
const h = Number(this.getAttribute("item-height"));
|
|
354
|
+
return Number.isFinite(h) && h > 0 ? h : 28;
|
|
355
|
+
}
|
|
356
|
+
_labelToPaths(nodes, pathPrefix, map) {
|
|
357
|
+
(nodes || []).forEach((node, i) => {
|
|
358
|
+
const p = pathPrefix + "." + i;
|
|
359
|
+
const label = String(node.label || node).trim().slice(0, 120);
|
|
360
|
+
if (!map.has(label)) map.set(label, []);
|
|
361
|
+
map.get(label).push(p);
|
|
362
|
+
if (Array.isArray(node.children)) this._labelToPaths(node.children, p, map);
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
_restoreExpanded() {
|
|
366
|
+
const persist = this.getAttribute("persist");
|
|
367
|
+
if (!persist || !this._treeData) return;
|
|
368
|
+
let labels = null;
|
|
369
|
+
try {
|
|
370
|
+
if (persist === "storage" && this.id) {
|
|
371
|
+
const saved = localStorage.getItem("contour-tree:" + this.id);
|
|
372
|
+
if (saved !== null) labels = JSON.parse(saved);
|
|
373
|
+
} else if (persist === "url") {
|
|
374
|
+
const v = new URLSearchParams(window.location.search).get("c-tree");
|
|
375
|
+
if (v !== null) labels = JSON.parse(v);
|
|
376
|
+
}
|
|
377
|
+
} catch (e) { labels = null; }
|
|
378
|
+
if (!Array.isArray(labels)) return;
|
|
379
|
+
const want = new Set(labels.map((l) => String(l)));
|
|
380
|
+
const map = new Map();
|
|
381
|
+
this._labelToPaths(this._treeData, "", map);
|
|
382
|
+
const expanded = this._expanded || (this._expanded = new Set());
|
|
383
|
+
for (const lbl of want) {
|
|
384
|
+
const paths = map.get(lbl);
|
|
385
|
+
if (paths) paths.forEach((p) => expanded.add(p));
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
_persistExpanded() {
|
|
389
|
+
const persist = this.getAttribute("persist");
|
|
390
|
+
if (!persist || !this._expanded) return;
|
|
391
|
+
// Map expanded paths back to labels.
|
|
392
|
+
const pathToNode = new Map();
|
|
393
|
+
const walk = (nodes, pathPrefix) => {
|
|
394
|
+
(nodes || []).forEach((node, i) => {
|
|
395
|
+
const p = pathPrefix + "." + i;
|
|
396
|
+
pathToNode.set(p, node);
|
|
397
|
+
if (Array.isArray(node.children)) walk(node.children, p);
|
|
398
|
+
});
|
|
399
|
+
};
|
|
400
|
+
walk(this._treeData, "");
|
|
401
|
+
const open = [];
|
|
402
|
+
for (const p of this._expanded) {
|
|
403
|
+
const node = pathToNode.get(p);
|
|
404
|
+
if (node) open.push(String(node.label || node).trim().slice(0, 120));
|
|
405
|
+
}
|
|
406
|
+
try {
|
|
407
|
+
if (persist === "storage" && this.id) {
|
|
408
|
+
localStorage.setItem("contour-tree:" + this.id, JSON.stringify(open));
|
|
409
|
+
} else if (persist === "url") {
|
|
410
|
+
const url = new URL(window.location.href);
|
|
411
|
+
url.searchParams.set("c-tree", JSON.stringify(open));
|
|
412
|
+
window.history.replaceState(null, "", url.toString());
|
|
413
|
+
}
|
|
414
|
+
} catch (e) {}
|
|
415
|
+
}
|
|
416
|
+
_flatten(nodes, pathPrefix, depth, expanded, out) {
|
|
417
|
+
(nodes || []).forEach((node, i) => {
|
|
418
|
+
const p = pathPrefix + "." + i;
|
|
419
|
+
const hasChildren = Array.isArray(node.children) && node.children.length > 0;
|
|
420
|
+
const isExpanded = expanded.has(p);
|
|
421
|
+
out.push({ node, path: p, depth, hasChildren, expanded: isExpanded });
|
|
422
|
+
if (hasChildren && isExpanded) {
|
|
423
|
+
this._flatten(node.children, p, depth + 1, expanded, out);
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
_renderNodeFlat(rootUl, f) {
|
|
428
|
+
const node = f.node;
|
|
429
|
+
const depth = f.depth;
|
|
430
|
+
const li = document.createElement("div");
|
|
431
|
+
li.className = "c-tree__node";
|
|
432
|
+
li.setAttribute("role", "treeitem");
|
|
433
|
+
li.setAttribute("aria-level", String(depth));
|
|
434
|
+
li.dataset.path = f.path;
|
|
435
|
+
if (f.hasChildren) {
|
|
436
|
+
li.setAttribute("aria-expanded", String(f.expanded));
|
|
437
|
+
const row = document.createElement("div");
|
|
438
|
+
row.className = "c-tree__row" + (node.active ? " c-tree__row--active" : "") + (node.dir ? " c-tree__row--dir" : "");
|
|
439
|
+
row.style.paddingInlineStart = ((depth - 1) * 1) + "rem";
|
|
440
|
+
const toggle = document.createElement("button");
|
|
441
|
+
toggle.className = "c-tree__toggle";
|
|
442
|
+
toggle.setAttribute("type", "button");
|
|
443
|
+
toggle.setAttribute("aria-expanded", String(f.expanded));
|
|
444
|
+
toggle.setAttribute("aria-label", "Toggle");
|
|
445
|
+
toggle.innerHTML = '<svg aria-hidden="true"><use href="#i-chevron-right" /></svg>';
|
|
446
|
+
row.appendChild(toggle);
|
|
447
|
+
const span = document.createElement("span");
|
|
448
|
+
span.textContent = node.label;
|
|
449
|
+
row.appendChild(span);
|
|
450
|
+
li.appendChild(row);
|
|
451
|
+
} else {
|
|
452
|
+
const leaf = document.createElement("div");
|
|
453
|
+
leaf.className = "c-tree__leaf" + (node.active ? " c-tree__row--active" : "") + (node.dir ? " c-tree__row--dir" : "");
|
|
454
|
+
leaf.style.paddingInlineStart = (depth * 1) + "rem";
|
|
455
|
+
if (this.hasAttribute("selectable")) {
|
|
456
|
+
const cb = document.createElement("input");
|
|
457
|
+
cb.type = "checkbox";
|
|
458
|
+
cb.className = "c-tree__select";
|
|
459
|
+
cb.setAttribute("aria-label", "Select " + (node.label || node));
|
|
460
|
+
const label = String(node.label || node).trim().slice(0, 120);
|
|
461
|
+
if (this._selectedTree && this._selectedTree.has(label)) cb.checked = true;
|
|
462
|
+
leaf.insertBefore(cb, leaf.firstChild);
|
|
463
|
+
}
|
|
464
|
+
leaf.appendChild(document.createTextNode(node.label || node));
|
|
465
|
+
li.appendChild(leaf);
|
|
466
|
+
}
|
|
467
|
+
return li;
|
|
468
|
+
}
|
|
469
|
+
_renderWindow(rootUl, scrollTop) {
|
|
470
|
+
if (!this._treeData) return;
|
|
471
|
+
const ih = this._itemHeight();
|
|
472
|
+
const expanded = this._expanded || (this._expanded = new Set());
|
|
473
|
+
const flat = [];
|
|
474
|
+
this._flatten(this._treeData, "", 1, expanded, flat);
|
|
475
|
+
const total = flat.length;
|
|
476
|
+
const viewportSize = rootUl.clientHeight || 320;
|
|
477
|
+
const visibleCount = Math.ceil(viewportSize / ih) + 6;
|
|
478
|
+
let start = Math.floor((scrollTop || 0) / ih);
|
|
479
|
+
if (start < 0) start = 0;
|
|
480
|
+
if (start > Math.max(0, total - visibleCount)) start = Math.max(0, total - visibleCount);
|
|
481
|
+
const end = Math.min(total, start + visibleCount);
|
|
482
|
+
const topSize = start * ih;
|
|
483
|
+
const bottomSize = Math.max(0, (total - end) * ih);
|
|
484
|
+
rootUl.innerHTML = "";
|
|
485
|
+
const top = document.createElement("div");
|
|
486
|
+
top.className = "c-tree__spacer c-tree__spacer--top";
|
|
487
|
+
top.style.height = topSize + "px";
|
|
488
|
+
rootUl.appendChild(top);
|
|
489
|
+
for (let i = start; i < end; i++) {
|
|
490
|
+
rootUl.appendChild(this._renderNodeFlat(rootUl, flat[i]));
|
|
491
|
+
}
|
|
492
|
+
const bottom = document.createElement("div");
|
|
493
|
+
bottom.className = "c-tree__spacer c-tree__spacer--bottom";
|
|
494
|
+
bottom.style.height = bottomSize + "px";
|
|
495
|
+
rootUl.appendChild(bottom);
|
|
496
|
+
}
|
|
351
497
|
render() {
|
|
352
498
|
this.classList.add("c-tree");
|
|
353
499
|
// Slot composition wins over the JSON attribute, same as ContourMenu:
|
|
@@ -361,76 +507,84 @@ render() {
|
|
|
361
507
|
if (items && !authored.length) {
|
|
362
508
|
try {
|
|
363
509
|
const parsed = JSON.parse(items);
|
|
364
|
-
|
|
510
|
+
const rootUl = this.ensure("div.c-tree", () => { const el = document.createElement("div"); el.className = "c-tree"; el.setAttribute("role", "tree"); return el; });
|
|
365
511
|
rootUl.innerHTML = "";
|
|
366
512
|
rootUl.className = "c-tree";
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
nodes.forEach((node) => {
|
|
375
|
-
const li = document.createElement("div");
|
|
376
|
-
li.className = "c-tree__node";
|
|
377
|
-
li.setAttribute("role", "treeitem");
|
|
378
|
-
if (node.children) {
|
|
379
|
-
li.setAttribute("aria-expanded", "false");
|
|
380
|
-
const row = document.createElement("div");
|
|
381
|
-
row.className = "c-tree__row" + (node.active ? " c-tree__row--active" : "") + (node.dir ? " c-tree__row--dir" : "");
|
|
382
|
-
if (node.indent) {
|
|
383
|
-
const ind = document.createElement("span");
|
|
384
|
-
ind.className = "c-tree__indent";
|
|
385
|
-
ind.style.inlineSize = (node.indent * 1) + "rem";
|
|
386
|
-
row.appendChild(ind);
|
|
387
|
-
}
|
|
388
|
-
const toggle = document.createElement("button");
|
|
389
|
-
toggle.className = "c-tree__toggle";
|
|
390
|
-
toggle.setAttribute("type", "button");
|
|
391
|
-
toggle.setAttribute("aria-expanded", "false");
|
|
392
|
-
toggle.setAttribute("aria-label", "Toggle");
|
|
393
|
-
toggle.innerHTML = '<svg aria-hidden="true"><use href="#i-chevron-right" /></svg>';
|
|
394
|
-
row.appendChild(toggle);
|
|
395
|
-
const span = document.createElement("span");
|
|
396
|
-
span.textContent = node.label;
|
|
397
|
-
row.appendChild(span);
|
|
398
|
-
li.appendChild(row);
|
|
399
|
-
render(node.children, li);
|
|
400
|
-
} else {
|
|
401
|
-
const leaf = document.createElement("div");
|
|
402
|
-
leaf.className = "c-tree__leaf" + (node.active ? " c-tree__row--active" : "") + (node.dir ? " c-tree__row--dir" : "");
|
|
403
|
-
if (node.indent) {
|
|
404
|
-
const ind = document.createElement("span");
|
|
405
|
-
ind.className = "c-tree__indent";
|
|
406
|
-
ind.style.inlineSize = (node.indent * 1) + "rem";
|
|
407
|
-
leaf.appendChild(ind);
|
|
408
|
-
}
|
|
409
|
-
if (this.hasAttribute("selectable")) {
|
|
410
|
-
const cb = document.createElement("input");
|
|
411
|
-
cb.type = "checkbox";
|
|
412
|
-
cb.className = "c-tree__select";
|
|
413
|
-
cb.setAttribute("aria-label", "Select " + (node.label || node));
|
|
414
|
-
leaf.insertBefore(cb, leaf.firstChild);
|
|
415
|
-
}
|
|
416
|
-
leaf.appendChild(document.createTextNode(node.label || node));
|
|
417
|
-
li.appendChild(leaf);
|
|
418
|
-
}
|
|
419
|
-
ul.appendChild(li);
|
|
420
|
-
});
|
|
421
|
-
if (parent) parent.appendChild(ul);
|
|
422
|
-
};
|
|
423
|
-
render(parsed, null);
|
|
424
|
-
this.classList.remove("c-tree");
|
|
425
|
-
rootUl.classList.add("c-tree");
|
|
426
|
-
if (this.hasAttribute("virtual")) {
|
|
513
|
+
rootUl.setAttribute("role", "tree");
|
|
514
|
+
const virtual = this.hasAttribute("virtual");
|
|
515
|
+
if (virtual) {
|
|
516
|
+
this._treeData = parsed;
|
|
517
|
+
this._expanded = this._expanded || new Set();
|
|
518
|
+
this._treeRoot = rootUl;
|
|
519
|
+
this._restoreExpanded();
|
|
427
520
|
rootUl.style.maxHeight = rootUl.style.maxHeight || "24rem";
|
|
428
521
|
rootUl.style.overflow = "auto";
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
522
|
+
const scrollTop = this._treeScrollTop || 0;
|
|
523
|
+
this._renderWindow(rootUl, scrollTop);
|
|
524
|
+
try { rootUl.scrollTop = scrollTop; } catch (e) {}
|
|
525
|
+
} else {
|
|
526
|
+
this._treeData = null;
|
|
527
|
+
const render = (nodes, parent, depth) => {
|
|
528
|
+
const ul = parent ? document.createElement("div") : rootUl;
|
|
529
|
+
if (parent) {
|
|
530
|
+
ul.className = "c-tree__children";
|
|
531
|
+
ul.setAttribute("role", "group");
|
|
532
|
+
if (supportsUntilFound()) ul.setAttribute("hidden", "until-found"); else ul.setAttribute("hidden", "");
|
|
533
|
+
}
|
|
534
|
+
nodes.forEach((node) => {
|
|
535
|
+
const li = document.createElement("div");
|
|
536
|
+
li.className = "c-tree__node";
|
|
537
|
+
li.setAttribute("role", "treeitem");
|
|
538
|
+
li.setAttribute("aria-level", String(depth));
|
|
539
|
+
if (node.children) {
|
|
540
|
+
li.setAttribute("aria-expanded", "false");
|
|
541
|
+
const row = document.createElement("div");
|
|
542
|
+
row.className = "c-tree__row" + (node.active ? " c-tree__row--active" : "") + (node.dir ? " c-tree__row--dir" : "");
|
|
543
|
+
if (node.indent) {
|
|
544
|
+
const ind = document.createElement("span");
|
|
545
|
+
ind.className = "c-tree__indent";
|
|
546
|
+
ind.style.inlineSize = (node.indent * 1) + "rem";
|
|
547
|
+
row.appendChild(ind);
|
|
548
|
+
}
|
|
549
|
+
const toggle = document.createElement("button");
|
|
550
|
+
toggle.className = "c-tree__toggle";
|
|
551
|
+
toggle.setAttribute("type", "button");
|
|
552
|
+
toggle.setAttribute("aria-expanded", "false");
|
|
553
|
+
toggle.setAttribute("aria-label", "Toggle");
|
|
554
|
+
toggle.innerHTML = '<svg aria-hidden="true"><use href="#i-chevron-right" /></svg>';
|
|
555
|
+
row.appendChild(toggle);
|
|
556
|
+
const span = document.createElement("span");
|
|
557
|
+
span.textContent = node.label;
|
|
558
|
+
row.appendChild(span);
|
|
559
|
+
li.appendChild(row);
|
|
560
|
+
render(node.children, li, depth + 1);
|
|
561
|
+
} else {
|
|
562
|
+
const leaf = document.createElement("div");
|
|
563
|
+
leaf.className = "c-tree__leaf" + (node.active ? " c-tree__row--active" : "") + (node.dir ? " c-tree__row--dir" : "");
|
|
564
|
+
if (node.indent) {
|
|
565
|
+
const ind = document.createElement("span");
|
|
566
|
+
ind.className = "c-tree__indent";
|
|
567
|
+
ind.style.inlineSize = (node.indent * 1) + "rem";
|
|
568
|
+
leaf.appendChild(ind);
|
|
569
|
+
}
|
|
570
|
+
if (this.hasAttribute("selectable")) {
|
|
571
|
+
const cb = document.createElement("input");
|
|
572
|
+
cb.type = "checkbox";
|
|
573
|
+
cb.className = "c-tree__select";
|
|
574
|
+
cb.setAttribute("aria-label", "Select " + (node.label || node));
|
|
575
|
+
leaf.insertBefore(cb, leaf.firstChild);
|
|
576
|
+
}
|
|
577
|
+
leaf.appendChild(document.createTextNode(node.label || node));
|
|
578
|
+
li.appendChild(leaf);
|
|
579
|
+
}
|
|
580
|
+
ul.appendChild(li);
|
|
581
|
+
});
|
|
582
|
+
if (parent) parent.appendChild(ul);
|
|
583
|
+
};
|
|
584
|
+
render(parsed, null, 1);
|
|
433
585
|
}
|
|
586
|
+
this.classList.remove("c-tree");
|
|
587
|
+
rootUl.classList.add("c-tree");
|
|
434
588
|
if (rootUl.parentNode !== this) this.appendChild(rootUl);
|
|
435
589
|
} catch (e) { /* keep existing */ }
|
|
436
590
|
} else if (!items && !authored.length) {
|
|
@@ -438,6 +592,92 @@ render() {
|
|
|
438
592
|
}
|
|
439
593
|
}
|
|
440
594
|
enhance() {
|
|
595
|
+
// Toggle handling via delegation (works for windowed + static trees).
|
|
596
|
+
if (!this._wiredTreeToggle) {
|
|
597
|
+
this._wiredTreeToggle = true;
|
|
598
|
+
this.addEventListener("click", (e) => {
|
|
599
|
+
const toggle = e.target && e.target.closest ? e.target.closest(".c-tree__toggle") : null;
|
|
600
|
+
if (!toggle || !this.contains(toggle)) return;
|
|
601
|
+
e.stopPropagation();
|
|
602
|
+
const nodeEl = toggle.closest(".c-tree__node");
|
|
603
|
+
const path = nodeEl && nodeEl.dataset ? nodeEl.dataset.path : null;
|
|
604
|
+
const expanded = toggle.getAttribute("aria-expanded") === "true";
|
|
605
|
+
if (path && this._expanded) {
|
|
606
|
+
if (expanded) this._expanded.delete(path); else this._expanded.add(path);
|
|
607
|
+
}
|
|
608
|
+
toggle.setAttribute("aria-expanded", String(!expanded));
|
|
609
|
+
const row = toggle.closest(".c-tree__row");
|
|
610
|
+
if (row) row.setAttribute("aria-expanded", String(!expanded));
|
|
611
|
+
if (this.hasAttribute("virtual") && this._treeRoot) {
|
|
612
|
+
const s = this._treeRoot;
|
|
613
|
+
this._treeScrollTop = s.scrollTop || 0;
|
|
614
|
+
this._renderWindow(s, this._treeScrollTop);
|
|
615
|
+
try { s.scrollTop = this._treeScrollTop; } catch (err) {}
|
|
616
|
+
this._persistExpanded();
|
|
617
|
+
}
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
// Scroll-driven windowing for virtual trees.
|
|
621
|
+
if (this.hasAttribute("virtual") && !this._wiredTreeScroll) {
|
|
622
|
+
this._wiredTreeScroll = true;
|
|
623
|
+
const attach = () => {
|
|
624
|
+
const s = this.querySelector(".c-tree");
|
|
625
|
+
if (!s || s._treeScrollWired) return;
|
|
626
|
+
s._treeScrollWired = true;
|
|
627
|
+
let raf = 0;
|
|
628
|
+
const onScroll = () => {
|
|
629
|
+
if (raf) return;
|
|
630
|
+
raf = requestAnimationFrame(() => {
|
|
631
|
+
raf = 0;
|
|
632
|
+
this._treeScrollTop = s.scrollTop || 0;
|
|
633
|
+
this._renderWindow(s, this._treeScrollTop);
|
|
634
|
+
try { s.scrollTop = this._treeScrollTop; } catch (err) {}
|
|
635
|
+
});
|
|
636
|
+
};
|
|
637
|
+
s.addEventListener("scroll", onScroll, { passive: true });
|
|
638
|
+
onDispose(this, () => { s.removeEventListener("scroll", onScroll); if (raf) cancelAnimationFrame(raf); });
|
|
639
|
+
};
|
|
640
|
+
attach();
|
|
641
|
+
// retry if root not ready
|
|
642
|
+
if (!this.querySelector(".c-tree")) {
|
|
643
|
+
const mo = new MutationObserver(() => { if (this.querySelector(".c-tree")) { attach(); mo.disconnect(); } });
|
|
644
|
+
mo.observe(this, { childList: true, subtree: true });
|
|
645
|
+
onDispose(this, () => mo.disconnect());
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
// Auto-scroll during drag for virtual trees (so off-screen targets
|
|
649
|
+
// become reachable). Delegated on the host; only active in virtual mode.
|
|
650
|
+
if (this.hasAttribute("virtual") && !this._wiredTreeDragScroll) {
|
|
651
|
+
this._wiredTreeDragScroll = true;
|
|
652
|
+
let dragScrollRaf = 0;
|
|
653
|
+
let dragScrollDir = 0;
|
|
654
|
+
const tick = () => {
|
|
655
|
+
if (!dragScrollDir) { dragScrollRaf = 0; return; }
|
|
656
|
+
const s = this._treeRoot;
|
|
657
|
+
if (s) {
|
|
658
|
+
s.scrollTop += dragScrollDir * 8;
|
|
659
|
+
this._treeScrollTop = s.scrollTop;
|
|
660
|
+
this._renderWindow(s, this._treeScrollTop);
|
|
661
|
+
}
|
|
662
|
+
dragScrollRaf = requestAnimationFrame(tick);
|
|
663
|
+
};
|
|
664
|
+
this.addEventListener("dragover", (e) => {
|
|
665
|
+
const s = this._treeRoot;
|
|
666
|
+
if (!s) return;
|
|
667
|
+
const rect = s.getBoundingClientRect();
|
|
668
|
+
const edge = 40;
|
|
669
|
+
if (e.clientY < rect.top + edge) dragScrollDir = -1;
|
|
670
|
+
else if (e.clientY > rect.bottom - edge) dragScrollDir = 1;
|
|
671
|
+
else dragScrollDir = 0;
|
|
672
|
+
if (dragScrollDir && !dragScrollRaf) dragScrollRaf = requestAnimationFrame(tick);
|
|
673
|
+
});
|
|
674
|
+
const stop = () => {
|
|
675
|
+
dragScrollDir = 0;
|
|
676
|
+
if (dragScrollRaf) { cancelAnimationFrame(dragScrollRaf); dragScrollRaf = 0; }
|
|
677
|
+
};
|
|
678
|
+
this.addEventListener("dragend", stop);
|
|
679
|
+
this.addEventListener("drop", stop);
|
|
680
|
+
}
|
|
441
681
|
// Interaction lives in behaviours.mjs, which the shadow wrappers call too.
|
|
442
682
|
// One implementation, so the two layers cannot drift apart again: the shadow
|
|
443
683
|
// copy queried its root for slotted nodes, found none, and wired nothing.
|
|
@@ -755,8 +995,8 @@ class ContourTocFull extends ContourBase {
|
|
|
755
995
|
}
|
|
756
996
|
define("contour-toc", ContourTocFull);
|
|
757
997
|
class ContourFilterBar extends ContourBase {
|
|
758
|
-
static get observed() { return ["label", "divider", "items", "input", "placeholder", "mode", "modes", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
759
|
-
static get properties() { return { label: { attribute: "label" }, divider: { attribute: "divider" }, items: { attribute: "items" }, src: { attribute: "src" } }; }
|
|
998
|
+
static get observed() { return ["label", "divider", "items", "input", "placeholder", "mode", "modes", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton", "count", "clearable"]; }
|
|
999
|
+
static get properties() { return { label: { attribute: "label" }, divider: { attribute: "divider" }, items: { attribute: "items" }, src: { attribute: "src" }, count: { attribute: "count" }, clearable: { attribute: "clearable" } }; }
|
|
760
1000
|
render() {
|
|
761
1001
|
this.classList.add("c-filter-bar");
|
|
762
1002
|
wireStates(this);
|
|
@@ -792,7 +1032,7 @@ class ContourFilterBar extends ContourBase {
|
|
|
792
1032
|
if (modesAttr) { try { modes = JSON.parse(modesAttr); } catch (e) { modes = modesAttr.split(",").map((s) => s.trim()); } }
|
|
793
1033
|
if (modes || this.hasAttribute("mode")) {
|
|
794
1034
|
let bar = this.querySelector(".c-filter-bar__modes");
|
|
795
|
-
if (!bar) { bar = document.createElement("div"); bar.className = "c-filter-bar__modes"; this.appendChild(bar); }
|
|
1035
|
+
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); }
|
|
796
1036
|
bar.innerHTML = "";
|
|
797
1037
|
const current = this.getAttribute("mode");
|
|
798
1038
|
const list = Array.isArray(modes) ? modes : ["draw", "erase", "select"];
|
|
@@ -814,8 +1054,13 @@ class ContourFilterBar extends ContourBase {
|
|
|
814
1054
|
// Render filter pills from items.
|
|
815
1055
|
Array.from(this.querySelectorAll(".c-filter-pill")).forEach((n) => n.remove());
|
|
816
1056
|
const items = remoteData(this, "items");
|
|
1057
|
+
// Slotted content: authored .c-filter-pill children take precedence.
|
|
1058
|
+
const authoredPills = Array.from(this.querySelectorAll(":scope > .c-filter-pill"));
|
|
817
1059
|
let parsed = null;
|
|
818
|
-
if (
|
|
1060
|
+
if (authoredPills.length) {
|
|
1061
|
+
parsed = authoredPills.map((p) => p.textContent.trim());
|
|
1062
|
+
authoredPills.forEach((p) => p.remove());
|
|
1063
|
+
} else if (items) { try { parsed = JSON.parse(items); } catch (e) { parsed = null; } }
|
|
819
1064
|
if (Array.isArray(parsed)) {
|
|
820
1065
|
parsed.forEach((it) => {
|
|
821
1066
|
const pill = document.createElement("span");
|
|
@@ -833,6 +1078,16 @@ class ContourFilterBar extends ContourBase {
|
|
|
833
1078
|
this.appendChild(pill);
|
|
834
1079
|
});
|
|
835
1080
|
}
|
|
1081
|
+
// Clear-all affordance (CARTO-inspired): panel-level clear with active count.
|
|
1082
|
+
Array.from(this.querySelectorAll(".c-filter-bar__clear-all")).forEach((n) => n.remove());
|
|
1083
|
+
if (this.hasAttribute("clearable")) {
|
|
1084
|
+
const btn = document.createElement("button");
|
|
1085
|
+
btn.type = "button";
|
|
1086
|
+
btn.className = "c-btn c-btn--ghost c-btn--sm c-filter-bar__clear-all";
|
|
1087
|
+
const count = this.getAttribute("count");
|
|
1088
|
+
btn.textContent = count ? ("Clear all (" + count + ")") : "Clear all";
|
|
1089
|
+
this.appendChild(btn);
|
|
1090
|
+
}
|
|
836
1091
|
if (!parsed && !label) renderEmpty(this, "filter-bar");
|
|
837
1092
|
}
|
|
838
1093
|
enhance() {
|
|
@@ -846,6 +1101,17 @@ class ContourFilterBar extends ContourBase {
|
|
|
846
1101
|
Array.from(this.querySelectorAll(".c-filter-bar__mode")).forEach((b) => b.setAttribute("aria-pressed", String(b === btn)));
|
|
847
1102
|
this.dispatchEvent(new CustomEvent("contour:mode-change", { bubbles: true, composed: true, detail: { mode } }));
|
|
848
1103
|
});
|
|
1104
|
+
this.addEventListener("keydown", (e) => {
|
|
1105
|
+
const btn = e.target && e.target.closest ? e.target.closest(".c-filter-bar__mode") : null;
|
|
1106
|
+
if (!btn || !this.contains(btn)) return;
|
|
1107
|
+
const modes = Array.from(this.querySelectorAll(".c-filter-bar__mode"));
|
|
1108
|
+
const idx = modes.indexOf(btn);
|
|
1109
|
+
let next = -1;
|
|
1110
|
+
if (e.key === "ArrowRight") next = Math.min(modes.length - 1, idx + 1);
|
|
1111
|
+
else if (e.key === "ArrowLeft") next = Math.max(0, idx - 1);
|
|
1112
|
+
if (next >= 0) { e.preventDefault(); try { modes[next].focus(); } catch (err) {} }
|
|
1113
|
+
else if (e.key === "Enter" || e.key === " ") { e.preventDefault(); btn.click(); }
|
|
1114
|
+
});
|
|
849
1115
|
// text input
|
|
850
1116
|
const inp = this.querySelector(".c-filter-bar__input");
|
|
851
1117
|
if (inp && !inp._wiredFilterInput) {
|
|
@@ -857,6 +1123,16 @@ class ContourFilterBar extends ContourBase {
|
|
|
857
1123
|
this.dispatchEvent(new CustomEvent("contour:change", { bubbles: true, composed: true, detail: { value: inp.value } }));
|
|
858
1124
|
});
|
|
859
1125
|
}
|
|
1126
|
+
// Clear-all (CARTO-inspired): delegated on host.
|
|
1127
|
+
if (!this._wiredClearAll) {
|
|
1128
|
+
this._wiredClearAll = true;
|
|
1129
|
+
this.addEventListener("click", (e) => {
|
|
1130
|
+
const btn = e.target && e.target.closest ? e.target.closest(".c-filter-bar__clear-all") : null;
|
|
1131
|
+
if (!btn || !this.contains(btn)) return;
|
|
1132
|
+
e.preventDefault();
|
|
1133
|
+
this.dispatchEvent(new CustomEvent("contour:clear-all", { bubbles: true, composed: true, detail: {} }));
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
860
1136
|
}
|
|
861
1137
|
}
|
|
862
1138
|
define("contour-filter-bar", ContourFilterBar);
|
|
@@ -865,6 +1141,8 @@ class ContourFilterBar extends ContourBase {
|
|
|
865
1141
|
static get properties() { return { placeholder: { attribute: "placeholder" }, items: { attribute: "items" }, recent: { attribute: "recent" }, empty: { attribute: "empty" }, src: { attribute: "src" } }; }
|
|
866
1142
|
render() {
|
|
867
1143
|
this.classList.add("c-command");
|
|
1144
|
+
if (!this.hasAttribute("role")) this.setAttribute("role", "dialog");
|
|
1145
|
+
if (!this.hasAttribute("aria-label")) this.setAttribute("aria-label", "Command palette");
|
|
868
1146
|
if (!this.hasAttribute("popover")) this.setAttribute("popover", "auto");
|
|
869
1147
|
wireStates(this);
|
|
870
1148
|
loadRemote(this, "items");
|
|
@@ -1183,8 +1461,7 @@ class ContourSidebar extends ContourBase {
|
|
|
1183
1461
|
static get properties() { return { title: { attribute: "title" }, items: { attribute: "items" }, collapsed: { attribute: "collapsed", type: Boolean } }; }
|
|
1184
1462
|
render() {
|
|
1185
1463
|
this.classList.add("c-sidebar");
|
|
1186
|
-
if (this.hasAttribute("collapsed")) this.classList.add("c-sidebar--collapsed");
|
|
1187
|
-
else Array.from(this.classList).forEach((c) => { if (c === "c-sidebar--collapsed") this.classList.remove(c); });
|
|
1464
|
+
if (this.hasAttribute("collapsed")) this.classList.add("c-sidebar--collapsed"); else this.classList.remove("c-sidebar--collapsed");
|
|
1188
1465
|
const title = this.getAttribute("title");
|
|
1189
1466
|
if (title) {
|
|
1190
1467
|
const t = this.ensure(".c-sidebar__title", () => { const el = document.createElement("div"); el.className = "c-sidebar__title"; return el; });
|
|
@@ -1215,8 +1492,7 @@ class ContourSidebar extends ContourBase {
|
|
|
1215
1492
|
this.addEventListener("click", (e) => {
|
|
1216
1493
|
const btn = e.target && e.target.closest ? e.target.closest(".c-sidebar__toggle") : null;
|
|
1217
1494
|
if (!btn || !this.contains(btn)) return;
|
|
1218
|
-
|
|
1219
|
-
else this.setAttribute("collapsed", "");
|
|
1495
|
+
this.toggleAttribute("collapsed");
|
|
1220
1496
|
});
|
|
1221
1497
|
}
|
|
1222
1498
|
}
|
|
@@ -1286,3 +1562,76 @@ class ContourToolbar extends ContourBase {
|
|
|
1286
1562
|
}
|
|
1287
1563
|
}
|
|
1288
1564
|
define("contour-toolbar", ContourToolbar);
|
|
1565
|
+
|
|
1566
|
+
/**
|
|
1567
|
+
* Spatial filter (CARTO-inspired): draw-on-map affordance. Engine-agnostic:
|
|
1568
|
+
* Contour renders the mode toolbar and emits `contour:draw-start`/`contour:draw-end`
|
|
1569
|
+
* (with a geometry payload) and `contour:clear`; the consumer runs the spatial
|
|
1570
|
+
* query against its map engine.
|
|
1571
|
+
* Attributes: `modes`, `mode`, `active`, `empty`, `loading`, `error`, `retry`,
|
|
1572
|
+
* `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
1573
|
+
*/
|
|
1574
|
+
class ContourSpatialFilter extends ContourBase {
|
|
1575
|
+
static get observed() { return ["modes", "mode", "active", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
1576
|
+
static get properties() { return { modes: { attribute: "modes" }, mode: { attribute: "mode" }, active: { attribute: "active" }, src: { attribute: "src" } }; }
|
|
1577
|
+
render() {
|
|
1578
|
+
this.classList.add("c-spatial-filter");
|
|
1579
|
+
wireStates(this);
|
|
1580
|
+
loadRemote(this, []);
|
|
1581
|
+
if (renderStates(this, "spatial-filter")) return;
|
|
1582
|
+
const modesAttr = this.getAttribute("modes");
|
|
1583
|
+
let modes = null;
|
|
1584
|
+
if (modesAttr) { try { modes = JSON.parse(modesAttr); } catch (e) { modes = modesAttr.split(",").map((s) => s.trim()); } }
|
|
1585
|
+
const list = Array.isArray(modes) ? modes : ["rect", "circle", "polygon", "clear"];
|
|
1586
|
+
let bar = this.querySelector(".c-spatial-filter__modes");
|
|
1587
|
+
if (!bar) { bar = document.createElement("div"); bar.className = "c-spatial-filter__modes"; bar.setAttribute("role", "toolbar"); this.appendChild(bar); }
|
|
1588
|
+
bar.innerHTML = "";
|
|
1589
|
+
const current = this.getAttribute("mode");
|
|
1590
|
+
list.forEach((m) => {
|
|
1591
|
+
const name = typeof m === "string" ? m : (m.label || m.value || m);
|
|
1592
|
+
const val = typeof m === "string" ? m : (m.value || m.label || m);
|
|
1593
|
+
const btn = document.createElement("button");
|
|
1594
|
+
btn.type = "button";
|
|
1595
|
+
btn.className = "c-spatial-filter__mode c-btn c-btn--ghost c-btn--sm";
|
|
1596
|
+
btn.textContent = name;
|
|
1597
|
+
btn.dataset.mode = val;
|
|
1598
|
+
if (current && current === val) btn.setAttribute("aria-pressed", "true");
|
|
1599
|
+
bar.appendChild(btn);
|
|
1600
|
+
});
|
|
1601
|
+
if (this.hasAttribute("active")) {
|
|
1602
|
+
this.classList.add("c-spatial-filter--active");
|
|
1603
|
+
} else {
|
|
1604
|
+
this.classList.remove("c-spatial-filter--active");
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
enhance() {
|
|
1608
|
+
if (this._wiredSpatialFilter) return;
|
|
1609
|
+
this._wiredSpatialFilter = true;
|
|
1610
|
+
this.addEventListener("click", (e) => {
|
|
1611
|
+
const btn = e.target && e.target.closest ? e.target.closest(".c-spatial-filter__mode") : null;
|
|
1612
|
+
if (!btn || !this.contains(btn)) return;
|
|
1613
|
+
const mode = btn.dataset.mode || btn.textContent.trim();
|
|
1614
|
+
if (mode === "clear") {
|
|
1615
|
+
this.classList.remove("c-spatial-filter--active");
|
|
1616
|
+
Array.from(this.querySelectorAll(".c-spatial-filter__mode")).forEach((b) => b.setAttribute("aria-pressed", "false"));
|
|
1617
|
+
this.dispatchEvent(new CustomEvent("contour:clear", { bubbles: true, composed: true, detail: {} }));
|
|
1618
|
+
return;
|
|
1619
|
+
}
|
|
1620
|
+
this.classList.add("c-spatial-filter--active");
|
|
1621
|
+
Array.from(this.querySelectorAll(".c-spatial-filter__mode")).forEach((b) => b.setAttribute("aria-pressed", String(b === btn)));
|
|
1622
|
+
this.dispatchEvent(new CustomEvent("contour:draw-start", { bubbles: true, composed: true, detail: { mode } }));
|
|
1623
|
+
});
|
|
1624
|
+
this.addEventListener("keydown", (e) => {
|
|
1625
|
+
const btn = e.target && e.target.closest ? e.target.closest(".c-spatial-filter__mode") : null;
|
|
1626
|
+
if (!btn || !this.contains(btn)) return;
|
|
1627
|
+
const modes = Array.from(this.querySelectorAll(".c-spatial-filter__mode"));
|
|
1628
|
+
const idx = modes.indexOf(btn);
|
|
1629
|
+
let next = -1;
|
|
1630
|
+
if (e.key === "ArrowRight") next = Math.min(modes.length - 1, idx + 1);
|
|
1631
|
+
else if (e.key === "ArrowLeft") next = Math.max(0, idx - 1);
|
|
1632
|
+
if (next >= 0) { e.preventDefault(); try { modes[next].focus(); } catch (err) {} }
|
|
1633
|
+
else if (e.key === "Enter" || e.key === " ") { e.preventDefault(); btn.click(); }
|
|
1634
|
+
});
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
define("contour-spatial-filter", ContourSpatialFilter);
|
package/dist/wc/registration.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { define, simple } from './core.mjs';
|
|
2
2
|
// ---- Registration: the class-only wrappers run last ------------------
|
|
3
3
|
//
|
|
4
4
|
// Order is the contract. Every complex component above claims its own name and
|
|
@@ -6,7 +6,11 @@ import { CLASS_ONLY, define, simple } from './core.mjs';
|
|
|
6
6
|
// <contour-menu items='["Cut"]'> builds a <ul> instead of only gaining a class.
|
|
7
7
|
// Move this loop back above the complex components and the scaffolding half of
|
|
8
8
|
// this file becomes dead code again: it did, and no gate noticed.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
// Explicit defines (not a loop) so the coverage gate and tooling can see them.
|
|
10
|
+
define("contour-box", simple(["c-box"]));
|
|
11
|
+
define("contour-cluster", simple(["c-cluster"]));
|
|
12
|
+
define("contour-container", simple(["c-container"]));
|
|
13
|
+
define("contour-row", simple(["c-row"]));
|
|
14
|
+
define("contour-scrim", simple(["c-scrim"]));
|
|
15
|
+
define("contour-stack", simple(["c-stack"]));
|
|
12
16
|
|