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/behaviours.mjs
CHANGED
|
@@ -40,6 +40,7 @@ import { contourId, supportsUntilFound, onDispose } from './core.mjs';
|
|
|
40
40
|
// calls enhance() after every render — so the guard lives in a WeakMap keyed on
|
|
41
41
|
// the node, where a re-render cannot drop it.
|
|
42
42
|
const WIRED_HOSTS = new WeakMap();
|
|
43
|
+
/** Reset the wired-host claim for a host, allowing re-wiring after disconnect. */
|
|
43
44
|
export const wcReset = (host) => { WIRED_HOSTS.delete(host); };
|
|
44
45
|
const wcClaim = (host, name) => {
|
|
45
46
|
let set = WIRED_HOSTS.get(host);
|
|
@@ -141,6 +142,7 @@ function isRtl(host) {
|
|
|
141
142
|
catch (e) { return false; }
|
|
142
143
|
}
|
|
143
144
|
|
|
145
|
+
/** Wire tab keyboard navigation and selection for a host. */
|
|
144
146
|
export function wireTabs(host) {
|
|
145
147
|
if (!wcClaim(host, "tabs")) return;
|
|
146
148
|
for (const list of wcSelfOrAll(host, ".c-tabs__list, .c-code-tabs__list")) {
|
|
@@ -262,6 +264,7 @@ export function wireTabs(host) {
|
|
|
262
264
|
* markup carries the option value in a `data-*-value` hook, so the event reads
|
|
263
265
|
* the hook it can see and falls back to the label the reader sees.
|
|
264
266
|
*/
|
|
267
|
+
/** Wire segmented-control selection for a host. */
|
|
265
268
|
export function wireSegmented(host) {
|
|
266
269
|
const groups = wcSelfOrAll(host, ".c-segmented");
|
|
267
270
|
// The block's contract is the option class, a group role and an explicit
|
|
@@ -357,6 +360,7 @@ export function wireSegmented(host) {
|
|
|
357
360
|
* Native `<select>` stays native elsewhere — its popup cannot be styled — so the
|
|
358
361
|
* one list this file drives is the one the system does draw.
|
|
359
362
|
*/
|
|
363
|
+
/** Wire combobox filtering, keyboard nav and selection for a host. */
|
|
360
364
|
export function wireCombobox(host) {
|
|
361
365
|
wireComboboxDocDismiss();
|
|
362
366
|
const input = wcOne(host, ".c-combobox__input");
|
|
@@ -408,6 +412,11 @@ export function wireCombobox(host) {
|
|
|
408
412
|
};
|
|
409
413
|
const filter = (query) => {
|
|
410
414
|
const q = (query || "").toLowerCase();
|
|
415
|
+
if (host._comboboxVirtual && typeof host._renderComboboxWindow === "function") {
|
|
416
|
+
host._renderComboboxWindow(q, true);
|
|
417
|
+
cursor = -1;
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
411
420
|
optionList().forEach((o) => { o.hidden = !!(q && !o.textContent.toLowerCase().includes(q)); });
|
|
412
421
|
cursor = -1;
|
|
413
422
|
};
|
|
@@ -435,6 +444,12 @@ export function wireCombobox(host) {
|
|
|
435
444
|
o.setAttribute("aria-selected", "false");
|
|
436
445
|
});
|
|
437
446
|
};
|
|
447
|
+
if (host._comboboxVirtual && list && !list._contourVirtualScroll) {
|
|
448
|
+
list._contourVirtualScroll = true;
|
|
449
|
+
list.addEventListener("scroll", () => {
|
|
450
|
+
if (typeof host._renderComboboxWindow === "function") host._renderComboboxWindow(host._comboboxQuery || "");
|
|
451
|
+
}, { passive: true });
|
|
452
|
+
}
|
|
438
453
|
const commit = (opt) => {
|
|
439
454
|
const field = liveInput();
|
|
440
455
|
if (!field) return;
|
|
@@ -442,7 +457,13 @@ export function wireCombobox(host) {
|
|
|
442
457
|
const now = opt.getAttribute("aria-selected") === "true";
|
|
443
458
|
opt.setAttribute("aria-selected", String(!now));
|
|
444
459
|
opt.classList.toggle("c-combobox__option--selected", !now);
|
|
445
|
-
const selected =
|
|
460
|
+
const selected = (host.getAttribute("value") || "").split(",").map((v) => v.trim()).filter(Boolean);
|
|
461
|
+
const value = host._comboboxVirtual && host._comboboxFiltered
|
|
462
|
+
? host._comboboxFiltered.find((item) => item.index === Number(opt.dataset.optionIndex))?.value
|
|
463
|
+
: opt.textContent.trim();
|
|
464
|
+
const position = selected.indexOf(String(value));
|
|
465
|
+
if (now && position >= 0) selected.splice(position, 1);
|
|
466
|
+
if (!now && position < 0) selected.push(String(value));
|
|
446
467
|
host.setAttribute("value", selected.join(","));
|
|
447
468
|
if (typeof host._syncFormValue === "function") host._syncFormValue();
|
|
448
469
|
wcEmit(host, "contour:select", { value: selected });
|
|
@@ -461,6 +482,7 @@ export function wireCombobox(host) {
|
|
|
461
482
|
const isField = (target) => wcClosest(host, target, ".c-combobox__input") !== null;
|
|
462
483
|
wcListen(host, "input", (e) => {
|
|
463
484
|
if (!isField(e.target)) return;
|
|
485
|
+
host._comboboxQuery = e.target.value;
|
|
464
486
|
filter(e.target.value);
|
|
465
487
|
open();
|
|
466
488
|
// The form-value event (BY-44) rides on the same interaction; the shadow
|
|
@@ -477,7 +499,9 @@ export function wireCombobox(host) {
|
|
|
477
499
|
const visible = optionList().filter((o) => !o.hidden);
|
|
478
500
|
if (e.key === "ArrowDown") { e.preventDefault(); cursor = Math.min(cursor + 1, visible.length - 1); mark(visible); }
|
|
479
501
|
else if (e.key === "ArrowUp") { e.preventDefault(); cursor = Math.max(cursor - 1, 0); mark(visible); }
|
|
480
|
-
else if (e.key === "
|
|
502
|
+
else if (e.key === "Home") { e.preventDefault(); cursor = 0; mark(visible); }
|
|
503
|
+
else if (e.key === "End") { e.preventDefault(); cursor = Math.max(0, visible.length - 1); mark(visible); }
|
|
504
|
+
else if (e.key === "Enter" || e.key === " ") { e.preventDefault(); if (cursor >= 0 && visible[cursor]) commit(visible[cursor]); }
|
|
481
505
|
else if (e.key === "Escape") close();
|
|
482
506
|
});
|
|
483
507
|
wcListen(host, "click", (e) => {
|
|
@@ -515,6 +539,7 @@ function wireComboboxDocDismiss() {
|
|
|
515
539
|
const visibleStops = (host) => wcAll(host, ".c-tree__toggle, .c-tree__leaf").filter((el) => !el.closest(".c-tree__children[hidden]"));
|
|
516
540
|
|
|
517
541
|
/** Tree: one toggle per branch, and `contour:toggle` so a page can persist it. */
|
|
542
|
+
/** Wire tree toggle and keyboard navigation for a host. */
|
|
518
543
|
export function wireTree(host) {
|
|
519
544
|
// The ARIA shape and the tab stop are re-applied on every pass, before the
|
|
520
545
|
// claim. Two reasons, both measured on the shipped guide: the generated items
|
|
@@ -538,7 +563,7 @@ export function wireTree(host) {
|
|
|
538
563
|
if (node.getAttribute("role") !== "treeitem") node.setAttribute("role", "treeitem");
|
|
539
564
|
node.setAttribute("aria-level", String(levelOf(node)));
|
|
540
565
|
const row = node.querySelector(":scope > .c-tree__row");
|
|
541
|
-
if (row) node.setAttribute("aria-expanded", row.getAttribute("aria-expanded") || "false");
|
|
566
|
+
if (row) node.setAttribute("aria-expanded", row.querySelector(":scope > .c-tree__toggle")?.getAttribute("aria-expanded") || "false");
|
|
542
567
|
else if (node.hasAttribute("aria-expanded")) node.removeAttribute("aria-expanded");
|
|
543
568
|
});
|
|
544
569
|
// Exactly one tab stop. The author's own `tabindex="0"` is the choice, then the
|
|
@@ -634,7 +659,8 @@ export function wireTree(host) {
|
|
|
634
659
|
if (Array.isArray(labels)) {
|
|
635
660
|
const want = new Set(labels.map((l) => String(l)));
|
|
636
661
|
wcAll(host, ".c-tree__row").forEach((row) => {
|
|
637
|
-
|
|
662
|
+
const currentToggle = row.querySelector(":scope > .c-tree__toggle");
|
|
663
|
+
if (currentToggle?.getAttribute("aria-expanded") === "true") return;
|
|
638
664
|
const label = (row.textContent || "").trim().slice(0, 120);
|
|
639
665
|
if (!want.has(label)) return;
|
|
640
666
|
const toggle = row.querySelector(":scope > .c-tree__toggle");
|
|
@@ -642,7 +668,6 @@ export function wireTree(host) {
|
|
|
642
668
|
const node = row.closest(".c-tree__node");
|
|
643
669
|
const children = node ? node.querySelector(":scope > .c-tree__children") : null;
|
|
644
670
|
toggle.setAttribute("aria-expanded", "true");
|
|
645
|
-
row.setAttribute("aria-expanded", "true");
|
|
646
671
|
if (node) node.setAttribute("aria-expanded", "true");
|
|
647
672
|
if (children) children.removeAttribute("hidden");
|
|
648
673
|
});
|
|
@@ -657,7 +682,8 @@ export function wireTree(host) {
|
|
|
657
682
|
if (Array.isArray(labels)) {
|
|
658
683
|
const want = new Set(labels.map((l) => String(l)));
|
|
659
684
|
wcAll(host, ".c-tree__row").forEach((row) => {
|
|
660
|
-
|
|
685
|
+
const currentToggle = row.querySelector(":scope > .c-tree__toggle");
|
|
686
|
+
if (currentToggle?.getAttribute("aria-expanded") === "true") return;
|
|
661
687
|
const label = (row.textContent || "").trim().slice(0, 120);
|
|
662
688
|
if (!want.has(label)) return;
|
|
663
689
|
const toggle = row.querySelector(":scope > .c-tree__toggle");
|
|
@@ -665,7 +691,6 @@ export function wireTree(host) {
|
|
|
665
691
|
const node = row.closest(".c-tree__node");
|
|
666
692
|
const children = node ? node.querySelector(":scope > .c-tree__children") : null;
|
|
667
693
|
toggle.setAttribute("aria-expanded", "true");
|
|
668
|
-
row.setAttribute("aria-expanded", "true");
|
|
669
694
|
if (node) node.setAttribute("aria-expanded", "true");
|
|
670
695
|
if (children) children.removeAttribute("hidden");
|
|
671
696
|
});
|
|
@@ -677,7 +702,6 @@ export function wireTree(host) {
|
|
|
677
702
|
const wasOpen = toggle.getAttribute("aria-expanded") === "true";
|
|
678
703
|
toggle.setAttribute("aria-expanded", String(!wasOpen));
|
|
679
704
|
const row = toggle.closest(".c-tree__row") || toggle.parentElement;
|
|
680
|
-
if (row) row.setAttribute("aria-expanded", String(!wasOpen));
|
|
681
705
|
const node = toggle.closest(".c-tree__node");
|
|
682
706
|
const children = node ? node.querySelector(":scope > .c-tree__children") : null;
|
|
683
707
|
if (children) {
|
|
@@ -695,7 +719,8 @@ export function wireTree(host) {
|
|
|
695
719
|
try {
|
|
696
720
|
const open = [];
|
|
697
721
|
wcAll(host, ".c-tree__row").forEach((r) => {
|
|
698
|
-
|
|
722
|
+
const toggle = r.querySelector(":scope > .c-tree__toggle");
|
|
723
|
+
if (toggle?.getAttribute("aria-expanded") === "true") open.push((r.textContent || "").trim().slice(0, 120));
|
|
699
724
|
});
|
|
700
725
|
localStorage.setItem("contour-tree:" + host.id, JSON.stringify(open));
|
|
701
726
|
} catch (e) {}
|
|
@@ -703,7 +728,8 @@ export function wireTree(host) {
|
|
|
703
728
|
try {
|
|
704
729
|
const open = [];
|
|
705
730
|
wcAll(host, ".c-tree__row").forEach((r) => {
|
|
706
|
-
|
|
731
|
+
const toggle = r.querySelector(":scope > .c-tree__toggle");
|
|
732
|
+
if (toggle?.getAttribute("aria-expanded") === "true") open.push((r.textContent || "").trim().slice(0, 120));
|
|
707
733
|
});
|
|
708
734
|
const url = new URL(window.location.href);
|
|
709
735
|
url.searchParams.set("c-tree", JSON.stringify(open));
|
|
@@ -781,6 +807,7 @@ export function wireTree(host) {
|
|
|
781
807
|
}
|
|
782
808
|
|
|
783
809
|
/** Menu: roving focus over items, `contour:select` from key or pointer. */
|
|
810
|
+
/** Wire menu keyboard navigation and selection for a host. */
|
|
784
811
|
export function wireMenu(host) {
|
|
785
812
|
wcAll(host, "[role='menuitem']").forEach((it) => { if (!it.hasAttribute("tabindex")) it.setAttribute("tabindex", it.getAttribute("aria-disabled") === "true" ? "-1" : "-1"); });
|
|
786
813
|
const all = () => wcAll(host, "[role='menuitem']");
|
|
@@ -882,6 +909,7 @@ export function wireMenu(host) {
|
|
|
882
909
|
}
|
|
883
910
|
|
|
884
911
|
/** Pagination: `[aria-current="page"]` is the state the sheet paints. */
|
|
912
|
+
/** Wire pagination controls for a host. */
|
|
885
913
|
export function wirePagination(host) {
|
|
886
914
|
wcAll(host, ".c-pagination__link").forEach((b) => { if (!b.hasAttribute("tabindex")) b.setAttribute("tabindex", "0"); });
|
|
887
915
|
if (!wcClaim(host, "pagination")) return;
|
|
@@ -936,6 +964,7 @@ export function wirePagination(host) {
|
|
|
936
964
|
* handler because both need the same three things: the text, the clipboard, and
|
|
937
965
|
* a `contour:copy` a page can toast from when the clipboard is denied.
|
|
938
966
|
*/
|
|
967
|
+
/** Wire copy-to-clipboard behaviour for a host. */
|
|
939
968
|
export function wireCopy(host) {
|
|
940
969
|
if (!wcClaim(host, "copy")) return;
|
|
941
970
|
wcListen(host, "click", (e) => {
|
|
@@ -963,7 +992,30 @@ export function wireCopy(host) {
|
|
|
963
992
|
}, 1600);
|
|
964
993
|
onDispose(host, () => clearTimeout(timer));
|
|
965
994
|
};
|
|
966
|
-
|
|
995
|
+
const doCopy = async () => {
|
|
996
|
+
try {
|
|
997
|
+
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
998
|
+
await navigator.clipboard.writeText(text);
|
|
999
|
+
return true;
|
|
1000
|
+
}
|
|
1001
|
+
} catch (e) { /* fall through */ }
|
|
1002
|
+
try {
|
|
1003
|
+
const ta = document.createElement("textarea");
|
|
1004
|
+
ta.value = text;
|
|
1005
|
+
ta.setAttribute("readonly", "");
|
|
1006
|
+
ta.style.position = "fixed";
|
|
1007
|
+
ta.style.top = "-9999px";
|
|
1008
|
+
ta.style.opacity = "0";
|
|
1009
|
+
document.body.append(ta);
|
|
1010
|
+
ta.select();
|
|
1011
|
+
const ok = document.execCommand("copy");
|
|
1012
|
+
ta.remove();
|
|
1013
|
+
return ok;
|
|
1014
|
+
} catch (e) {
|
|
1015
|
+
return false;
|
|
1016
|
+
}
|
|
1017
|
+
};
|
|
1018
|
+
doCopy().then((ok) => confirm(ok));
|
|
967
1019
|
wcEmit(host, "contour:copy", { text });
|
|
968
1020
|
});
|
|
969
1021
|
}
|
|
@@ -973,6 +1025,7 @@ export function wireCopy(host) {
|
|
|
973
1025
|
* affordance is the control's job to remove and to say so; keeping the node in
|
|
974
1026
|
* sync with the event is what makes the two copies of this rule agree.
|
|
975
1027
|
*/
|
|
1028
|
+
/** Wire removable-item (chip/tag) dismissal for a host. */
|
|
976
1029
|
export function wireRemovable(host) {
|
|
977
1030
|
if (!wcClaim(host, "removable")) return;
|
|
978
1031
|
wcListen(host, "click", (e) => {
|
|
@@ -1052,6 +1105,7 @@ function modalTrapHandler(e) {
|
|
|
1052
1105
|
}
|
|
1053
1106
|
}
|
|
1054
1107
|
|
|
1108
|
+
/** Contain focus within a modal host while open. */
|
|
1055
1109
|
export function modalContain(host, open) {
|
|
1056
1110
|
if (open) {
|
|
1057
1111
|
if (modalDepth.n === 0) {
|
|
@@ -1087,6 +1141,10 @@ export function modalContain(host, open) {
|
|
|
1087
1141
|
modalInerted.clear();
|
|
1088
1142
|
document.documentElement.style.overflow = modalSavedOverflow || "";
|
|
1089
1143
|
window.scrollTo(modalSavedX, modalSavedY);
|
|
1144
|
+
if (modalTrapWired) {
|
|
1145
|
+
document.removeEventListener("keydown", modalTrapHandler);
|
|
1146
|
+
modalTrapWired = false;
|
|
1147
|
+
}
|
|
1090
1148
|
}
|
|
1091
1149
|
}
|
|
1092
1150
|
}
|
package/dist/wc/content.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ContourBase, define, sanitizeHtml, headingTag } from './core.mjs';
|
|
1
|
+
import { ContourBase, define, sanitizeHtml, headingTag, formatValue } from './core.mjs';
|
|
2
2
|
import { loadRemote, remoteData, renderStates, renderEmpty, wireStates } from './states.mjs';
|
|
3
3
|
import { wireCopy } from './behaviours.mjs';
|
|
4
4
|
class ContourCard extends ContourBase {
|
|
@@ -178,6 +178,8 @@ class ContourLink extends ContourBase {
|
|
|
178
178
|
const a = document.createElement("a");
|
|
179
179
|
a.href = href;
|
|
180
180
|
a.textContent = label;
|
|
181
|
+
const ariaLabel = this.getAttribute("aria-label");
|
|
182
|
+
if (ariaLabel) a.setAttribute("aria-label", ariaLabel);
|
|
181
183
|
this.appendChild(a);
|
|
182
184
|
}
|
|
183
185
|
}
|
|
@@ -262,6 +264,7 @@ class ContourDiff extends ContourBase {
|
|
|
262
264
|
const el = document.createElement("div");
|
|
263
265
|
el.className = kind ? `c-diff__line c-diff__line--${kind}` : "c-diff__line";
|
|
264
266
|
el.setAttribute("role", "listitem");
|
|
267
|
+
el.setAttribute("tabindex", "0");
|
|
265
268
|
const s = document.createElement("span");
|
|
266
269
|
s.className = "c-diff__sign";
|
|
267
270
|
s.textContent = sign;
|
|
@@ -286,6 +289,14 @@ class ContourDiff extends ContourBase {
|
|
|
286
289
|
this.dispatchEvent(new CustomEvent("contour:diff-activate", { bubbles: true, composed: true, detail: { kind, text } }));
|
|
287
290
|
}
|
|
288
291
|
});
|
|
292
|
+
this.addEventListener("keydown", (e) => {
|
|
293
|
+
const line = e.target && e.target.closest ? e.target.closest(".c-diff__line") : null;
|
|
294
|
+
if (!line || !this.contains(line)) return;
|
|
295
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
296
|
+
e.preventDefault();
|
|
297
|
+
line.click();
|
|
298
|
+
}
|
|
299
|
+
});
|
|
289
300
|
}
|
|
290
301
|
}
|
|
291
302
|
define("contour-diff", ContourDiff);
|
|
@@ -329,6 +340,19 @@ class ContourDoDont extends ContourBase {
|
|
|
329
340
|
this.dispatchEvent(new CustomEvent("contour:do-dont-activate", { bubbles: true, composed: true, detail: { kind, text } }));
|
|
330
341
|
}
|
|
331
342
|
});
|
|
343
|
+
// Make items focusable and keyboard-activatable.
|
|
344
|
+
Array.from(this.querySelectorAll(".c-do-dont__item")).forEach((it) => {
|
|
345
|
+
if (!it.hasAttribute("tabindex")) it.setAttribute("tabindex", "0");
|
|
346
|
+
if (!it.hasAttribute("role")) it.setAttribute("role", "button");
|
|
347
|
+
});
|
|
348
|
+
this.addEventListener("keydown", (e) => {
|
|
349
|
+
const item = e.target && e.target.closest ? e.target.closest(".c-do-dont__item") : null;
|
|
350
|
+
if (!item || !this.contains(item)) return;
|
|
351
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
352
|
+
e.preventDefault();
|
|
353
|
+
item.click();
|
|
354
|
+
}
|
|
355
|
+
});
|
|
332
356
|
}
|
|
333
357
|
}
|
|
334
358
|
define("contour-do-dont", ContourDoDont);
|
|
@@ -422,8 +446,7 @@ class ContourShowcaseFull extends ContourBase {
|
|
|
422
446
|
static get properties() { return { title: { attribute: "title" }, text: { attribute: "text" }, media: { attribute: "media" }, reverse: { attribute: "reverse" }, items: { attribute: "items" }, src: { attribute: "src" } }; }
|
|
423
447
|
render() {
|
|
424
448
|
this.classList.add("c-showcase");
|
|
425
|
-
if (this.hasAttribute("reverse")) this.classList.add("c-showcase--reverse");
|
|
426
|
-
else this.classList.remove("c-showcase--reverse");
|
|
449
|
+
if (this.hasAttribute("reverse")) this.classList.add("c-showcase--reverse"); else this.classList.remove("c-showcase--reverse");
|
|
427
450
|
const title = this.getAttribute("title");
|
|
428
451
|
if (title) this.setAttribute("aria-label", title);
|
|
429
452
|
else this.removeAttribute("aria-label");
|
|
@@ -623,12 +646,12 @@ class ContourLinkishFull extends ContourBase {
|
|
|
623
646
|
}
|
|
624
647
|
define("contour-linkish", ContourLinkishFull);
|
|
625
648
|
class ContourPriceFull extends ContourBase {
|
|
626
|
-
static get observed() { return ["value"]; }
|
|
627
|
-
static get properties() { return { value: { attribute: "value" } }; }
|
|
649
|
+
static get observed() { return ["value", "format", "locale"]; }
|
|
650
|
+
static get properties() { return { value: { attribute: "value" }, format: { attribute: "format" }, locale: { attribute: "locale" } }; }
|
|
628
651
|
render() {
|
|
629
652
|
this.classList.add("c-price");
|
|
630
653
|
const value = this.getAttribute("value");
|
|
631
|
-
if (value) this.textContent = value;
|
|
654
|
+
if (value) this.textContent = formatValue(value, this.getAttribute("format"), this.getAttribute("locale"));
|
|
632
655
|
}
|
|
633
656
|
}
|
|
634
657
|
define("contour-price", ContourPriceFull);
|
|
@@ -638,8 +661,8 @@ class ContourProseFull extends ContourBase {
|
|
|
638
661
|
}
|
|
639
662
|
define("contour-prose", ContourProseFull);
|
|
640
663
|
class ContourPanel extends ContourBase {
|
|
641
|
-
static get observed() { return ["title", "subtitle", "status", "heading"]; }
|
|
642
|
-
static get properties() { return { title: { attribute: "title" }, subtitle: { attribute: "subtitle" }, status: { attribute: "status" } }; }
|
|
664
|
+
static get observed() { return ["title", "subtitle", "status", "heading", "collapsible", "collapsed"]; }
|
|
665
|
+
static get properties() { return { title: { attribute: "title" }, subtitle: { attribute: "subtitle" }, status: { attribute: "status" }, collapsible: { attribute: "collapsible", type: Boolean }, collapsed: { attribute: "collapsed", type: Boolean } }; }
|
|
643
666
|
render() {
|
|
644
667
|
this.classList.add("c-panel");
|
|
645
668
|
const title = this.getAttribute("title");
|
|
@@ -667,6 +690,31 @@ class ContourPanel extends ContourBase {
|
|
|
667
690
|
const st = this.querySelector(".c-panel__status");
|
|
668
691
|
if (st) st.remove();
|
|
669
692
|
}
|
|
693
|
+
// Collapsible widget chrome (CARTO-inspired): opt-in via `collapsible`.
|
|
694
|
+
if (this.hasAttribute("collapsible")) {
|
|
695
|
+
let btn = this.querySelector(".c-panel__collapse");
|
|
696
|
+
if (!btn) {
|
|
697
|
+
btn = document.createElement("button");
|
|
698
|
+
btn.type = "button";
|
|
699
|
+
btn.className = "c-panel__collapse c-btn c-btn--ghost c-btn--sm";
|
|
700
|
+
btn.setAttribute("aria-label", "Toggle panel");
|
|
701
|
+
btn.textContent = "▾";
|
|
702
|
+
this.appendChild(btn);
|
|
703
|
+
}
|
|
704
|
+
if (this.hasAttribute("collapsed")) {
|
|
705
|
+
this.classList.add("c-panel--collapsed");
|
|
706
|
+
btn.setAttribute("aria-expanded", "false");
|
|
707
|
+
btn.textContent = "▸";
|
|
708
|
+
} else {
|
|
709
|
+
this.classList.remove("c-panel--collapsed");
|
|
710
|
+
btn.setAttribute("aria-expanded", "true");
|
|
711
|
+
btn.textContent = "▾";
|
|
712
|
+
}
|
|
713
|
+
} else {
|
|
714
|
+
const btn = this.querySelector(".c-panel__collapse");
|
|
715
|
+
if (btn) btn.remove();
|
|
716
|
+
this.classList.remove("c-panel--collapsed");
|
|
717
|
+
}
|
|
670
718
|
// Wrap authored content in a body so it picks up the panel's padding.
|
|
671
719
|
const body = this.ensure(".c-panel__body", () => { const el = document.createElement("div"); el.className = "c-panel__body"; return el; });
|
|
672
720
|
const head = this.querySelector(".c-panel__head");
|
|
@@ -681,6 +729,17 @@ class ContourPanel extends ContourBase {
|
|
|
681
729
|
this.insertBefore(body, head.nextSibling);
|
|
682
730
|
}
|
|
683
731
|
}
|
|
732
|
+
enhance() {
|
|
733
|
+
if (this._wiredPanel) return;
|
|
734
|
+
this._wiredPanel = true;
|
|
735
|
+
this.addEventListener("click", (e) => {
|
|
736
|
+
const btn = e.target && e.target.closest ? e.target.closest(".c-panel__collapse") : null;
|
|
737
|
+
if (!btn || !this.contains(btn)) return;
|
|
738
|
+
e.preventDefault();
|
|
739
|
+
this.toggleAttribute("collapsed");
|
|
740
|
+
this.dispatchEvent(new CustomEvent("contour:collapse", { bubbles: true, composed: true, detail: { collapsed: this.hasAttribute("collapsed") } }));
|
|
741
|
+
});
|
|
742
|
+
}
|
|
684
743
|
}
|
|
685
744
|
define("contour-panel", ContourPanel);
|
|
686
745
|
class ContourCta extends ContourBase {
|
|
@@ -826,8 +885,104 @@ class ContourAnchor extends ContourBase {
|
|
|
826
885
|
const a = document.createElement("a");
|
|
827
886
|
a.href = href;
|
|
828
887
|
a.textContent = label;
|
|
888
|
+
const ariaLabel = this.getAttribute("aria-label");
|
|
889
|
+
if (ariaLabel) a.setAttribute("aria-label", ariaLabel);
|
|
829
890
|
this.appendChild(a);
|
|
830
891
|
}
|
|
831
892
|
}
|
|
832
893
|
}
|
|
833
894
|
define("contour-anchor", ContourAnchor);
|
|
895
|
+
|
|
896
|
+
/**
|
|
897
|
+
* Geocoder (CARTO-inspired): engine-agnostic search input + result list.
|
|
898
|
+
* The consumer runs the geocoding service and passes results via `results`
|
|
899
|
+
* (JSON array of {label, lat, lon}) or `src`. Contour renders the input and
|
|
900
|
+
* list and emits `contour:search` (query) and `contour:select` (result).
|
|
901
|
+
* Attributes: `placeholder`, `value`, `results`, `empty`, `loading`, `error`,
|
|
902
|
+
* `retry`, `src`, `lazy`, `refresh`, `timeout`, `skeleton`.
|
|
903
|
+
*/
|
|
904
|
+
class ContourGeocoder extends ContourBase {
|
|
905
|
+
static get observed() { return ["placeholder", "value", "results", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
906
|
+
static get properties() { return { placeholder: { attribute: "placeholder" }, value: { attribute: "value" }, results: { attribute: "results" }, src: { attribute: "src" } }; }
|
|
907
|
+
render() {
|
|
908
|
+
this.classList.add("c-geocoder");
|
|
909
|
+
wireStates(this);
|
|
910
|
+
loadRemote(this, ["results"]);
|
|
911
|
+
if (renderStates(this, "geocoder")) return;
|
|
912
|
+
// Input
|
|
913
|
+
let inp = this.querySelector(".c-geocoder__input");
|
|
914
|
+
if (!inp) {
|
|
915
|
+
inp = document.createElement("input");
|
|
916
|
+
inp.type = "search";
|
|
917
|
+
inp.className = "c-geocoder__input";
|
|
918
|
+
this.appendChild(inp);
|
|
919
|
+
}
|
|
920
|
+
const ph = this.getAttribute("placeholder");
|
|
921
|
+
if (ph) inp.setAttribute("placeholder", ph);
|
|
922
|
+
const val = this.getAttribute("value");
|
|
923
|
+
if (val !== null && inp.value !== val) inp.value = val;
|
|
924
|
+
// Results
|
|
925
|
+
Array.from(this.querySelectorAll(".c-geocoder__result")).forEach((n) => n.remove());
|
|
926
|
+
let results = [];
|
|
927
|
+
const rAttr = this.getAttribute("results");
|
|
928
|
+
if (rAttr) { try { results = JSON.parse(rAttr); } catch (e) { results = []; } }
|
|
929
|
+
const remote = remoteData(this, "results");
|
|
930
|
+
if (Array.isArray(remote)) results = remote;
|
|
931
|
+
if (Array.isArray(results) && results.length) {
|
|
932
|
+
const list = document.createElement("ul");
|
|
933
|
+
list.className = "c-geocoder__list";
|
|
934
|
+
list.setAttribute("role", "listbox");
|
|
935
|
+
results.forEach((r, idx) => {
|
|
936
|
+
const li = document.createElement("li");
|
|
937
|
+
li.className = "c-geocoder__result";
|
|
938
|
+
li.setAttribute("role", "option");
|
|
939
|
+
li.setAttribute("tabindex", idx === 0 ? "0" : "-1");
|
|
940
|
+
li.textContent = (typeof r === "object") ? (r.label || r.name || "") : String(r);
|
|
941
|
+
if (typeof r === "object") {
|
|
942
|
+
if (r.lat != null) li.dataset.lat = String(r.lat);
|
|
943
|
+
if (r.lon != null) li.dataset.lon = String(r.lon);
|
|
944
|
+
}
|
|
945
|
+
list.appendChild(li);
|
|
946
|
+
});
|
|
947
|
+
this.appendChild(list);
|
|
948
|
+
} else if (!this.hasAttribute("loading") && !this.hasAttribute("error")) {
|
|
949
|
+
renderEmpty(this, "geocoder");
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
enhance() {
|
|
953
|
+
if (this._wiredGeocoder) return;
|
|
954
|
+
this._wiredGeocoder = true;
|
|
955
|
+
const inp = this.querySelector(".c-geocoder__input");
|
|
956
|
+
if (inp) {
|
|
957
|
+
let timer = null;
|
|
958
|
+
inp.addEventListener("input", () => {
|
|
959
|
+
if (timer) clearTimeout(timer);
|
|
960
|
+
timer = setTimeout(() => {
|
|
961
|
+
this.dispatchEvent(new CustomEvent("contour:search", { bubbles: true, composed: true, detail: { query: inp.value } }));
|
|
962
|
+
}, 200);
|
|
963
|
+
});
|
|
964
|
+
inp.addEventListener("keydown", (e) => {
|
|
965
|
+
if (e.key === "Enter") {
|
|
966
|
+
e.preventDefault();
|
|
967
|
+
this.dispatchEvent(new CustomEvent("contour:search", { bubbles: true, composed: true, detail: { query: inp.value } }));
|
|
968
|
+
}
|
|
969
|
+
});
|
|
970
|
+
}
|
|
971
|
+
this.addEventListener("click", (e) => {
|
|
972
|
+
const li = e.target && e.target.closest ? e.target.closest(".c-geocoder__result") : null;
|
|
973
|
+
if (!li || !this.contains(li)) return;
|
|
974
|
+
const result = { label: li.textContent.trim(), lat: li.dataset.lat, lon: li.dataset.lon };
|
|
975
|
+
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { result } }));
|
|
976
|
+
});
|
|
977
|
+
this.addEventListener("keydown", (e) => {
|
|
978
|
+
const li = e.target && e.target.closest ? e.target.closest(".c-geocoder__result") : null;
|
|
979
|
+
if (!li || !this.contains(li)) return;
|
|
980
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
981
|
+
e.preventDefault();
|
|
982
|
+
const result = { label: li.textContent.trim(), lat: li.dataset.lat, lon: li.dataset.lon };
|
|
983
|
+
this.dispatchEvent(new CustomEvent("contour:select", { bubbles: true, composed: true, detail: { result } }));
|
|
984
|
+
}
|
|
985
|
+
});
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
define("contour-geocoder", ContourGeocoder);
|