@uvalib/web-components 1.1.1 → 1.3.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/CHANGELOG.md +140 -0
- package/README.md +1310 -80
- package/dist/analytics.d.ts +10 -0
- package/dist/analytics.js +9 -0
- package/dist/analytics.js.map +1 -0
- package/dist/base/UvalibElement.js +8 -5
- package/dist/base/UvalibElement.js.map +1 -1
- package/dist/base/analytics-state.d.ts +7 -0
- package/dist/base/analytics-state.js.map +1 -1
- package/dist/base/light-dom-styles.d.ts +13 -0
- package/dist/base/light-dom-styles.js +26 -0
- package/dist/base/light-dom-styles.js.map +1 -1
- package/dist/base/search-tracker.d.ts +57 -0
- package/dist/base/search-tracker.js +51 -0
- package/dist/base/search-tracker.js.map +1 -0
- package/dist/base/url-param.d.ts +23 -0
- package/dist/base/url-param.js +49 -0
- package/dist/base/url-param.js.map +1 -0
- package/dist/base.css +562 -2
- package/dist/base.d.ts +2 -0
- package/dist/base.js +1 -0
- package/dist/base.js.map +1 -1
- package/dist/components/site-analytics/SiteAnalytics.d.ts +20 -1
- package/dist/components/site-analytics/SiteAnalytics.js +93 -12
- package/dist/components/site-analytics/SiteAnalytics.js.map +1 -1
- package/dist/components/site-page/SitePage.d.ts +23 -0
- package/dist/components/site-page/SitePage.js +77 -0
- package/dist/components/site-page/SitePage.js.map +1 -1
- package/dist/components/uvalib-back-to-top/UvalibBackToTop.d.ts +58 -0
- package/dist/components/uvalib-back-to-top/UvalibBackToTop.js +250 -0
- package/dist/components/uvalib-back-to-top/UvalibBackToTop.js.map +1 -0
- package/dist/components/uvalib-back-to-top/uvalib-back-to-top.d.ts +1 -0
- package/dist/components/uvalib-back-to-top/uvalib-back-to-top.js +4 -0
- package/dist/components/uvalib-back-to-top/uvalib-back-to-top.js.map +1 -0
- package/dist/components/uvalib-breadcrumbs/UvalibBreadcrumbs.d.ts +14 -0
- package/dist/components/uvalib-breadcrumbs/UvalibBreadcrumbs.js +56 -4
- package/dist/components/uvalib-breadcrumbs/UvalibBreadcrumbs.js.map +1 -1
- package/dist/components/uvalib-card/UvalibCard.d.ts +19 -5
- package/dist/components/uvalib-card/UvalibCard.js +112 -9
- package/dist/components/uvalib-card/UvalibCard.js.map +1 -1
- package/dist/components/uvalib-chip-group/UvalibChipGroup.d.ts +178 -0
- package/dist/components/uvalib-chip-group/UvalibChipGroup.js +817 -0
- package/dist/components/uvalib-chip-group/UvalibChipGroup.js.map +1 -0
- package/dist/components/uvalib-chip-group/uvalib-chip-group.d.ts +1 -0
- package/dist/components/uvalib-chip-group/uvalib-chip-group.js +4 -0
- package/dist/components/uvalib-chip-group/uvalib-chip-group.js.map +1 -0
- package/dist/components/uvalib-combobox/UvalibCombobox.d.ts +212 -0
- package/dist/components/uvalib-combobox/UvalibCombobox.js +1088 -0
- package/dist/components/uvalib-combobox/UvalibCombobox.js.map +1 -0
- package/dist/components/uvalib-combobox/uvalib-combobox.d.ts +1 -0
- package/dist/components/uvalib-combobox/uvalib-combobox.js +4 -0
- package/dist/components/uvalib-combobox/uvalib-combobox.js.map +1 -0
- package/dist/components/uvalib-contents/UvalibContents.d.ts +53 -0
- package/dist/components/uvalib-contents/UvalibContents.js +202 -3
- package/dist/components/uvalib-contents/UvalibContents.js.map +1 -1
- package/dist/components/uvalib-date-histogram/UvalibDateHistogram.d.ts +187 -0
- package/dist/components/uvalib-date-histogram/UvalibDateHistogram.js +1452 -0
- package/dist/components/uvalib-date-histogram/UvalibDateHistogram.js.map +1 -0
- package/dist/components/uvalib-date-histogram/uvalib-date-histogram.d.ts +1 -0
- package/dist/components/uvalib-date-histogram/uvalib-date-histogram.js +4 -0
- package/dist/components/uvalib-date-histogram/uvalib-date-histogram.js.map +1 -0
- package/dist/components/uvalib-date-range/UvalibDateRange.d.ts +6 -0
- package/dist/components/uvalib-date-range/UvalibDateRange.js +23 -0
- package/dist/components/uvalib-date-range/UvalibDateRange.js.map +1 -1
- package/dist/components/uvalib-filter-drawer/UvalibFilterDrawer.d.ts +113 -0
- package/dist/components/uvalib-filter-drawer/UvalibFilterDrawer.js +589 -0
- package/dist/components/uvalib-filter-drawer/UvalibFilterDrawer.js.map +1 -0
- package/dist/components/uvalib-filter-drawer/uvalib-filter-drawer.d.ts +1 -0
- package/dist/components/uvalib-filter-drawer/uvalib-filter-drawer.js +4 -0
- package/dist/components/uvalib-filter-drawer/uvalib-filter-drawer.js.map +1 -0
- package/dist/components/uvalib-image-regions/UvalibImageRegions.d.ts +130 -0
- package/dist/components/uvalib-image-regions/UvalibImageRegions.js +658 -0
- package/dist/components/uvalib-image-regions/UvalibImageRegions.js.map +1 -0
- package/dist/components/uvalib-image-regions/regions.d.ts +57 -0
- package/dist/components/uvalib-image-regions/regions.js +117 -0
- package/dist/components/uvalib-image-regions/regions.js.map +1 -0
- package/dist/components/uvalib-image-regions/uvalib-image-regions.d.ts +1 -0
- package/dist/components/uvalib-image-regions/uvalib-image-regions.js +4 -0
- package/dist/components/uvalib-image-regions/uvalib-image-regions.js.map +1 -0
- package/dist/components/uvalib-lightbox/UvalibLightbox.d.ts +40 -0
- package/dist/components/uvalib-lightbox/UvalibLightbox.js +152 -17
- package/dist/components/uvalib-lightbox/UvalibLightbox.js.map +1 -1
- package/dist/components/uvalib-lightbox/media.d.ts +1 -18
- package/dist/components/uvalib-lightbox/media.js +1 -42
- package/dist/components/uvalib-lightbox/media.js.map +1 -1
- package/dist/components/uvalib-map/UvalibMap.d.ts +182 -0
- package/dist/components/uvalib-map/UvalibMap.js +1001 -0
- package/dist/components/uvalib-map/UvalibMap.js.map +1 -0
- package/dist/components/uvalib-map/uvalib-map.d.ts +1 -0
- package/dist/components/uvalib-map/uvalib-map.js +4 -0
- package/dist/components/uvalib-map/uvalib-map.js.map +1 -0
- package/dist/components/uvalib-metadata/UvalibMetadata.d.ts +39 -2
- package/dist/components/uvalib-metadata/UvalibMetadata.js +214 -8
- package/dist/components/uvalib-metadata/UvalibMetadata.js.map +1 -1
- package/dist/components/uvalib-pager/UvalibPager.d.ts +77 -4
- package/dist/components/uvalib-pager/UvalibPager.js +270 -8
- package/dist/components/uvalib-pager/UvalibPager.js.map +1 -1
- package/dist/components/uvalib-photo-grid/UvalibPhotoGrid.d.ts +27 -1
- package/dist/components/uvalib-photo-grid/UvalibPhotoGrid.js +192 -26
- package/dist/components/uvalib-photo-grid/UvalibPhotoGrid.js.map +1 -1
- package/dist/components/uvalib-results-count/UvalibResultsCount.d.ts +62 -0
- package/dist/components/uvalib-results-count/UvalibResultsCount.js +208 -0
- package/dist/components/uvalib-results-count/UvalibResultsCount.js.map +1 -0
- package/dist/components/uvalib-results-count/uvalib-results-count.d.ts +1 -0
- package/dist/components/uvalib-results-count/uvalib-results-count.js +4 -0
- package/dist/components/uvalib-results-count/uvalib-results-count.js.map +1 -0
- package/dist/components/uvalib-tabs/UvalibTabs.d.ts +127 -0
- package/dist/components/uvalib-tabs/UvalibTabs.js +821 -0
- package/dist/components/uvalib-tabs/UvalibTabs.js.map +1 -0
- package/dist/components/uvalib-tabs/uvalib-tabs.d.ts +1 -0
- package/dist/components/uvalib-tabs/uvalib-tabs.js +4 -0
- package/dist/components/uvalib-tabs/uvalib-tabs.js.map +1 -0
- package/dist/components/uvalib-tag-list/UvalibTagList.d.ts +89 -0
- package/dist/components/uvalib-tag-list/UvalibTagList.js +411 -0
- package/dist/components/uvalib-tag-list/UvalibTagList.js.map +1 -0
- package/dist/components/uvalib-tag-list/uvalib-tag-list.d.ts +1 -0
- package/dist/components/uvalib-tag-list/uvalib-tag-list.js +4 -0
- package/dist/components/uvalib-tag-list/uvalib-tag-list.js.map +1 -0
- package/dist/custom-elements.json +14007 -3497
- package/dist/index.d.ts +16 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -1
- package/dist/pagefind.css +4 -0
- package/dist/styles/base.js +154 -1
- package/dist/styles/base.js.map +1 -1
- package/dist/styles/color-scheme.js +9 -0
- package/dist/styles/color-scheme.js.map +1 -1
- package/dist/styles/controls.js +8 -0
- package/dist/styles/controls.js.map +1 -1
- package/dist/styles/hidden.d.ts +2 -0
- package/dist/styles/hidden.js +51 -0
- package/dist/styles/hidden.js.map +1 -0
- package/dist/styles/message.d.ts +1 -0
- package/dist/styles/message.js +82 -0
- package/dist/styles/message.js.map +1 -0
- package/dist/styles/pagefind.js +4 -0
- package/dist/styles/pagefind.js.map +1 -1
- package/dist/styles/result-list.d.ts +1 -0
- package/dist/styles/result-list.js +111 -0
- package/dist/styles/result-list.js.map +1 -0
- package/dist/styles/results.d.ts +1 -0
- package/dist/styles/results.js +242 -0
- package/dist/styles/results.js.map +1 -0
- package/dist/testing/index.d.ts +110 -0
- package/dist/testing/index.js +100 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/lighthouse-rules.d.ts +10 -0
- package/dist/testing/lighthouse-rules.js +44 -0
- package/dist/testing/lighthouse-rules.js.map +1 -0
- package/dist/tokens.css +9 -0
- package/dist-cdn/analytics.js +32 -0
- package/dist-cdn/analytics.js.map +1 -0
- package/dist-cdn/base.css +562 -2
- package/dist-cdn/bento-box.js +3 -3
- package/dist-cdn/chunks/{SiteAnalytics-Cm-FyhYS.js → SiteAnalytics-B9gu5aGO.js} +59 -30
- package/dist-cdn/chunks/SiteAnalytics-B9gu5aGO.js.map +1 -0
- package/dist-cdn/chunks/{UvalibElement-BnI-eRRR.js → UvalibElement-pGONDAwB.js} +108 -101
- package/dist-cdn/chunks/UvalibElement-pGONDAwB.js.map +1 -0
- package/dist-cdn/chunks/{accessible-GqhVn5_H.js → accessible-DJv7YOtS.js} +2 -2
- package/dist-cdn/chunks/{accessible-GqhVn5_H.js.map → accessible-DJv7YOtS.js.map} +1 -1
- package/dist-cdn/chunks/analytics-state-Ce8DKe4F.js.map +1 -1
- package/dist-cdn/chunks/base-BI8h0Gf3.js +281 -0
- package/dist-cdn/chunks/base-BI8h0Gf3.js.map +1 -0
- package/dist-cdn/chunks/inline-copy-BANQSMIR.js +69 -0
- package/dist-cdn/chunks/inline-copy-BANQSMIR.js.map +1 -0
- package/dist-cdn/chunks/{library-weekly-hours-COE7Vv6V.js → library-weekly-hours-CrV3TlP5.js} +3 -3
- package/dist-cdn/chunks/{library-weekly-hours-COE7Vv6V.js.map → library-weekly-hours-CrV3TlP5.js.map} +1 -1
- package/dist-cdn/chunks/regions-B8ExwUGP.js +86 -0
- package/dist-cdn/chunks/regions-B8ExwUGP.js.map +1 -0
- package/dist-cdn/chunks/{repeat-CIFUYkyh.js → repeat-m5Zd_QeP.js} +2 -2
- package/dist-cdn/chunks/{repeat-CIFUYkyh.js.map → repeat-m5Zd_QeP.js.map} +1 -1
- package/dist-cdn/chunks/{site-header-C9V7Wuw2.js → site-header-DYRMpdBj.js} +13 -4
- package/dist-cdn/chunks/site-header-DYRMpdBj.js.map +1 -0
- package/dist-cdn/chunks/{site-main-nav-AaxZ9rQf.js → site-main-nav-DURrQMal.js} +3 -3
- package/dist-cdn/chunks/{site-main-nav-AaxZ9rQf.js.map → site-main-nav-DURrQMal.js.map} +1 -1
- package/dist-cdn/chunks/source-children-BHsDwCvL.js +53 -0
- package/dist-cdn/chunks/source-children-BHsDwCvL.js.map +1 -0
- package/dist-cdn/chunks/{static-html-1mTAG6nS.js → static-html-C1rhtCHu.js} +2 -2
- package/dist-cdn/chunks/{static-html-1mTAG6nS.js.map → static-html-C1rhtCHu.js.map} +1 -1
- package/dist-cdn/chunks/url-param-C1sk_F1d.js +28 -0
- package/dist-cdn/chunks/url-param-C1sk_F1d.js.map +1 -0
- package/dist-cdn/custom-elements.json +14007 -3497
- package/dist-cdn/events-section.js +3 -3
- package/dist-cdn/library-hours-setup.js +2 -2
- package/dist-cdn/library-weekly-hours.js +1 -1
- package/dist-cdn/manifest.json +15 -2
- package/dist-cdn/pagefind.css +4 -0
- package/dist-cdn/site-alerts.js +4 -4
- package/dist-cdn/site-analytics.js +2 -2
- package/dist-cdn/site-footer.js +2 -2
- package/dist-cdn/site-header.js +1 -1
- package/dist-cdn/site-hours-section.js +4 -4
- package/dist-cdn/site-main-nav.js +1 -1
- package/dist-cdn/site-page.js +56 -11
- package/dist-cdn/site-page.js.map +1 -1
- package/dist-cdn/site-style.js +2 -2
- package/dist-cdn/skills/uvalib-web-components/SKILL.md +269 -24
- package/dist-cdn/skills/uvalib-web-components/reference/accessibility-testing.md +34 -2
- package/dist-cdn/skills/uvalib-web-components/reference/components.md +514 -13
- package/dist-cdn/skills/uvalib-web-components/reference/snippets.md +1 -1
- package/dist-cdn/tokens.css +9 -0
- package/dist-cdn/uvalib-analytics.js +2 -2
- package/dist-cdn/uvalib-back-to-top.js +156 -0
- package/dist-cdn/uvalib-back-to-top.js.map +1 -0
- package/dist-cdn/uvalib-breadcrumbs.js +31 -11
- package/dist-cdn/uvalib-breadcrumbs.js.map +1 -1
- package/dist-cdn/uvalib-card-grid.js +1 -1
- package/dist-cdn/uvalib-card.js +97 -23
- package/dist-cdn/uvalib-card.js.map +1 -1
- package/dist-cdn/uvalib-chip-group.js +535 -0
- package/dist-cdn/uvalib-chip-group.js.map +1 -0
- package/dist-cdn/uvalib-combobox.js +667 -0
- package/dist-cdn/uvalib-combobox.js.map +1 -0
- package/dist-cdn/uvalib-contents.js +102 -23
- package/dist-cdn/uvalib-contents.js.map +1 -1
- package/dist-cdn/uvalib-date-histogram.js +960 -0
- package/dist-cdn/uvalib-date-histogram.js.map +1 -0
- package/dist-cdn/uvalib-date-range.js +14 -2
- package/dist-cdn/uvalib-date-range.js.map +1 -1
- package/dist-cdn/uvalib-filter-drawer.js +355 -0
- package/dist-cdn/uvalib-filter-drawer.js.map +1 -0
- package/dist-cdn/uvalib-filter.js +3 -3
- package/dist-cdn/uvalib-image-regions.js +447 -0
- package/dist-cdn/uvalib-image-regions.js.map +1 -0
- package/dist-cdn/uvalib-lightbox.js +145 -78
- package/dist-cdn/uvalib-lightbox.js.map +1 -1
- package/dist-cdn/uvalib-map.js +471 -0
- package/dist-cdn/uvalib-map.js.map +1 -0
- package/dist-cdn/uvalib-metadata.js +152 -25
- package/dist-cdn/uvalib-metadata.js.map +1 -1
- package/dist-cdn/uvalib-pager.js +164 -18
- package/dist-cdn/uvalib-pager.js.map +1 -1
- package/dist-cdn/uvalib-photo-grid.js +123 -21
- package/dist-cdn/uvalib-photo-grid.js.map +1 -1
- package/dist-cdn/uvalib-results-count.js +101 -0
- package/dist-cdn/uvalib-results-count.js.map +1 -0
- package/dist-cdn/uvalib-tabs.js +436 -0
- package/dist-cdn/uvalib-tabs.js.map +1 -0
- package/dist-cdn/uvalib-tag-list.js +267 -0
- package/dist-cdn/uvalib-tag-list.js.map +1 -0
- package/package.json +66 -3
- package/skills/uvalib-web-components/SKILL.md +269 -24
- package/skills/uvalib-web-components/reference/accessibility-testing.md +34 -2
- package/skills/uvalib-web-components/reference/components.md +514 -13
- package/skills/uvalib-web-components/reference/snippets.md +1 -1
- package/dist-cdn/chunks/SiteAnalytics-Cm-FyhYS.js.map +0 -1
- package/dist-cdn/chunks/UvalibElement-BnI-eRRR.js.map +0 -1
- package/dist-cdn/chunks/base-CAFQWnZG.js +0 -128
- package/dist-cdn/chunks/base-CAFQWnZG.js.map +0 -1
- package/dist-cdn/chunks/site-header-C9V7Wuw2.js.map +0 -1
- package/dist-cdn/chunks/source-children-RuAec527.js +0 -119
- package/dist-cdn/chunks/source-children-RuAec527.js.map +0 -1
|
@@ -0,0 +1,821 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { css, html, unsafeCSS } from 'lit';
|
|
8
|
+
import { property } from 'lit/decorators.js';
|
|
9
|
+
import { trackEvent } from '../../base/analytics.js';
|
|
10
|
+
import { UvalibElement } from '../../base/UvalibElement.js';
|
|
11
|
+
import { installLightDomStyles } from '../../base/light-dom-styles.js';
|
|
12
|
+
import { accessible } from '../../styles/accessible.js';
|
|
13
|
+
/**
|
|
14
|
+
* Kept with `no-style`: a wrapping tab row, 44px targets, `[hidden]` panels, and a
|
|
15
|
+
* visible focus outline. `host` is `:host` (shadow) or the tag (light DOM).
|
|
16
|
+
*/
|
|
17
|
+
const structuralRules = (host) => `
|
|
18
|
+
${host} { display: block; min-width: 0; max-width: 100%; }
|
|
19
|
+
${host} .tablist {
|
|
20
|
+
display: flex;
|
|
21
|
+
flex-wrap: wrap;
|
|
22
|
+
align-items: stretch;
|
|
23
|
+
max-width: 100%;
|
|
24
|
+
gap: 0.25rem;
|
|
25
|
+
}
|
|
26
|
+
${host} button.tab {
|
|
27
|
+
flex: 0 1 auto;
|
|
28
|
+
box-sizing: border-box;
|
|
29
|
+
max-width: 100%;
|
|
30
|
+
min-width: 44px;
|
|
31
|
+
min-height: 44px;
|
|
32
|
+
margin: 0;
|
|
33
|
+
white-space: normal;
|
|
34
|
+
overflow-wrap: anywhere;
|
|
35
|
+
}
|
|
36
|
+
${host} button.tab:focus-visible {
|
|
37
|
+
outline: 3px solid var(--uva-color-focus, var(--uva-brand-orange, #e57200));
|
|
38
|
+
outline-offset: 2px;
|
|
39
|
+
}
|
|
40
|
+
${host} > .mount { display: none !important; }
|
|
41
|
+
${host}[hidden], ${host} [hidden] { display: none !important; }
|
|
42
|
+
@media (forced-colors: active) {
|
|
43
|
+
${host} button.tab { border: 1px solid ButtonText; }
|
|
44
|
+
${host} button.tab[aria-selected='true'] {
|
|
45
|
+
outline: 2px solid Highlight;
|
|
46
|
+
background: Highlight;
|
|
47
|
+
color: HighlightText;
|
|
48
|
+
forced-color-adjust: none;
|
|
49
|
+
}
|
|
50
|
+
${host} button.tab:focus-visible { outline: 3px solid Highlight; }
|
|
51
|
+
}
|
|
52
|
+
`;
|
|
53
|
+
const shadowStructure = unsafeCSS(structuralRules(':host'));
|
|
54
|
+
const look = css `
|
|
55
|
+
.tablist {
|
|
56
|
+
margin: 0 0 1rem;
|
|
57
|
+
}
|
|
58
|
+
button.tab {
|
|
59
|
+
appearance: none;
|
|
60
|
+
padding: 0.5rem 1rem;
|
|
61
|
+
border: 0;
|
|
62
|
+
border-bottom: 4px solid transparent;
|
|
63
|
+
background: var(--uva-color-button-bg, var(--uva-blue-alt-base, #007bac));
|
|
64
|
+
color: var(--uva-color-button-text, #fff);
|
|
65
|
+
font: inherit;
|
|
66
|
+
font-weight: 600;
|
|
67
|
+
line-height: 1.2;
|
|
68
|
+
letter-spacing: 0.02em;
|
|
69
|
+
text-align: center;
|
|
70
|
+
text-transform: uppercase;
|
|
71
|
+
cursor: pointer;
|
|
72
|
+
}
|
|
73
|
+
button.tab:hover {
|
|
74
|
+
background: var(--uva-color-button-hover-bg, var(--uva-blue-alt-dark, #005679));
|
|
75
|
+
color: var(--uva-color-button-text, #fff);
|
|
76
|
+
}
|
|
77
|
+
button.tab[aria-selected='true'],
|
|
78
|
+
button.tab[aria-selected='true']:hover {
|
|
79
|
+
background: var(--uva-color-accent-bg, var(--uva-brand-blue, #232d4b));
|
|
80
|
+
color: var(--uva-color-on-accent, #fff);
|
|
81
|
+
font-weight: 700;
|
|
82
|
+
border-bottom-color: var(--uva-color-on-accent, #fff);
|
|
83
|
+
}
|
|
84
|
+
@media (forced-colors: active) {
|
|
85
|
+
button.tab {
|
|
86
|
+
border: 2px solid ButtonText;
|
|
87
|
+
background: ButtonFace;
|
|
88
|
+
color: ButtonText;
|
|
89
|
+
}
|
|
90
|
+
button.tab[aria-selected='true'],
|
|
91
|
+
button.tab[aria-selected='true']:hover {
|
|
92
|
+
background: Highlight;
|
|
93
|
+
color: HighlightText;
|
|
94
|
+
border-color: Highlight;
|
|
95
|
+
font-weight: 700;
|
|
96
|
+
}
|
|
97
|
+
button.tab:focus-visible {
|
|
98
|
+
outline: 3px solid Highlight;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
`;
|
|
102
|
+
const normalize = (value) => String(value ?? '')
|
|
103
|
+
.replace(/\s+/g, ' ')
|
|
104
|
+
.trim();
|
|
105
|
+
/** A hash used as a route (`#/…`, `#!/…`) or that already carries a query string. */
|
|
106
|
+
const usesHashParam = (hash) => hash.startsWith('#/') || hash.startsWith('#!/') || hash.includes('?');
|
|
107
|
+
/**
|
|
108
|
+
* The deep-link value in `loc`. Copied from the lightbox helpers so this bundle does not
|
|
109
|
+
* import the IIIF parser. Hash routes keep the param in the hash; other URLs use search.
|
|
110
|
+
*/
|
|
111
|
+
const paramFromLocation = (loc, name) => {
|
|
112
|
+
if (!name)
|
|
113
|
+
return null;
|
|
114
|
+
if (usesHashParam(loc.hash)) {
|
|
115
|
+
const q = loc.hash.indexOf('?');
|
|
116
|
+
const params = new URLSearchParams(q >= 0 ? loc.hash.slice(q + 1) : '');
|
|
117
|
+
return params.get(name);
|
|
118
|
+
}
|
|
119
|
+
return new URLSearchParams(loc.search).get(name);
|
|
120
|
+
};
|
|
121
|
+
/** `loc` with `name` set to `id`. Hash routes keep the param in the hash. */
|
|
122
|
+
const hrefWithParam = (loc, name, id) => {
|
|
123
|
+
if (usesHashParam(loc.hash)) {
|
|
124
|
+
const q = loc.hash.indexOf('?');
|
|
125
|
+
const path = q >= 0 ? loc.hash.slice(0, q) : loc.hash;
|
|
126
|
+
const params = new URLSearchParams(q >= 0 ? loc.hash.slice(q + 1) : '');
|
|
127
|
+
params.set(name, id);
|
|
128
|
+
const qs = params.toString();
|
|
129
|
+
return loc.pathname + loc.search + (qs ? `${path}?${qs}` : path);
|
|
130
|
+
}
|
|
131
|
+
const params = new URLSearchParams(loc.search);
|
|
132
|
+
params.set(name, id);
|
|
133
|
+
const qs = params.toString();
|
|
134
|
+
return loc.pathname + (qs ? `?${qs}` : '') + loc.hash;
|
|
135
|
+
};
|
|
136
|
+
let seq = 0;
|
|
137
|
+
/**
|
|
138
|
+
* Tabs, as on library.virginia.edu: a row of buttons over one visible panel.
|
|
139
|
+
*
|
|
140
|
+
* Each panel is a child with `data-tab="Events"` (and an `id` when the tab should be
|
|
141
|
+
* linkable). Or put `<button slot="tab">` elements first and one panel element after
|
|
142
|
+
* each; the button text is the label and those buttons are hidden, because the component
|
|
143
|
+
* draws the real tabs. The selected panel stays visible across the upgrade. With
|
|
144
|
+
* `base.css`, later `data-tab` panels stay hidden before the element upgrades, and
|
|
145
|
+
* space is reserved for the tab row so the first panel does not jump. The tab row
|
|
146
|
+
* wraps on a narrow screen.
|
|
147
|
+
*
|
|
148
|
+
* Arrow keys, Home and End move between tabs. Selection follows the arrow unless
|
|
149
|
+
* `activation="manual"`, in which case Enter or Space selects the focused tab. `selected`
|
|
150
|
+
* is the panel id (a label or a 0-based index also selects). It reflects the panel id.
|
|
151
|
+
* `url-param` writes that id into the query string, or into the hash when the page is a
|
|
152
|
+
* hash route (`#/stories?tab=events`). `url-param="hash"` uses the hash itself (`#events`)
|
|
153
|
+
* and leaves a hash route (`#/…`) alone.
|
|
154
|
+
*
|
|
155
|
+
* @tagname uvalib-tabs
|
|
156
|
+
* @slot - The panels. Each element with `data-tab` is a panel, or each element that is not a `slot="tab"` button.
|
|
157
|
+
* @slot tab - A `<button>` whose text labels the panel that follows. Hidden once the tabs are drawn.
|
|
158
|
+
* @fires change - The selected tab changed after the first render, including a script setting `selected` and the Back button. `detail` is `{ id, label, index }` (`id` is the panel id, `index` from 0). Not fired on the first render. Bubbles and is composed.
|
|
159
|
+
* @fires uvalib-analytics-event - For `<site-analytics>`: a click or arrow-key selection, `['uvalib-tabs', 'change', '<tab label>']`. The label is cut to 100 characters. Not fired on the first render, when `selected` is set from script, or when Back or the hash restores a tab.
|
|
160
|
+
* @cssprop --uva-color-button-bg - Dark-mode role token: unselected tab background (else `--uva-blue-alt-base`).
|
|
161
|
+
* @cssprop --uva-color-button-text - Text on an unselected tab (else #fff).
|
|
162
|
+
* @cssprop --uva-color-button-hover-bg - Dark-mode role token: unselected tab hover (else `--uva-blue-alt-dark`).
|
|
163
|
+
* @cssprop --uva-color-accent-bg - Dark-mode role token: selected tab background (else `--uva-brand-blue`).
|
|
164
|
+
* @cssprop --uva-color-on-accent - Selected tab text and the selected underline (else #fff).
|
|
165
|
+
* @cssprop --uva-color-focus - Dark-mode role token: focus outline (else `--uva-brand-orange`).
|
|
166
|
+
* @cssprop [--uva-blue-alt-base=#007BAC] - Unselected tab when `--uva-color-button-bg` is unset.
|
|
167
|
+
* @cssprop [--uva-blue-alt-dark=#005679] - Unselected hover when `--uva-color-button-hover-bg` is unset.
|
|
168
|
+
* @cssprop [--uva-brand-blue=#232D4B] - Selected tab when `--uva-color-accent-bg` is unset.
|
|
169
|
+
* @cssprop [--uva-brand-orange=#E57200] - Focus outline when `--uva-color-focus` is unset.
|
|
170
|
+
*/
|
|
171
|
+
export class UvalibTabs extends UvalibElement {
|
|
172
|
+
constructor() {
|
|
173
|
+
super(...arguments);
|
|
174
|
+
/**
|
|
175
|
+
* The selected tab. A panel id, the tab label, or a 0-based index. Reflects the
|
|
176
|
+
* panel id once the tabs have been read. Empty selects the first tab.
|
|
177
|
+
*/
|
|
178
|
+
this.selected = '';
|
|
179
|
+
/**
|
|
180
|
+
* `manual`: arrow keys move focus and Enter or Space selects. Anything else,
|
|
181
|
+
* including empty, selects as the arrow moves.
|
|
182
|
+
*/
|
|
183
|
+
this.activation = '';
|
|
184
|
+
/**
|
|
185
|
+
* Name of the query parameter that stores the selected panel id, so the tab is
|
|
186
|
+
* linkable and Back restores it. `hash` stores it in the hash (`#panel-id`)
|
|
187
|
+
* instead. Empty does not touch the URL.
|
|
188
|
+
*/
|
|
189
|
+
this.urlParam = '';
|
|
190
|
+
/** Accessible name of the tab list. Empty uses “Tabs”. */
|
|
191
|
+
this.label = '';
|
|
192
|
+
this.uid = `uvalib-tabs-${++seq}`;
|
|
193
|
+
this.buttons = new Map();
|
|
194
|
+
/** Shadow-only tabpanels. Ids cannot point out of a shadow root, so the panel lives beside the tab. */
|
|
195
|
+
this.panelHosts = new Map();
|
|
196
|
+
this.boundLists = new WeakSet();
|
|
197
|
+
this.listening = false;
|
|
198
|
+
this.booted = false;
|
|
199
|
+
this.userAct = false;
|
|
200
|
+
this.fromHistory = false;
|
|
201
|
+
this.pendingFocus = false;
|
|
202
|
+
this.cursor = 0;
|
|
203
|
+
this.lastKey = '';
|
|
204
|
+
/** `selected` as authored, before a URL param replaces it. Back to a URL with no param restores this. */
|
|
205
|
+
this.initialSelected = '';
|
|
206
|
+
this.view = [];
|
|
207
|
+
this.viewIndex = -1;
|
|
208
|
+
this.warnedValue = false;
|
|
209
|
+
this.warnedShape = false;
|
|
210
|
+
this.onMutations = (records) => {
|
|
211
|
+
const relevant = records.some((record) => {
|
|
212
|
+
const target = record.target;
|
|
213
|
+
if (target === this)
|
|
214
|
+
return true;
|
|
215
|
+
return (target instanceof Element && target.parentElement === this && !this.insideChrome(target));
|
|
216
|
+
});
|
|
217
|
+
if (relevant)
|
|
218
|
+
this.requestUpdate();
|
|
219
|
+
};
|
|
220
|
+
this.onHistory = (event) => {
|
|
221
|
+
const name = this.urlParam.trim();
|
|
222
|
+
if (!name || !this.booted)
|
|
223
|
+
return;
|
|
224
|
+
// A named query param is not the page hash. An in-page `#anchor` must not reset the tab.
|
|
225
|
+
// A hash route (`#/path?tab=`) still carries the param, so that hashchange counts.
|
|
226
|
+
if (event.type === 'hashchange' && name !== 'hash' && !usesHashParam(location.hash))
|
|
227
|
+
return;
|
|
228
|
+
const items = this.collect();
|
|
229
|
+
if (!items.length)
|
|
230
|
+
return;
|
|
231
|
+
const raw = this.readUrl();
|
|
232
|
+
if (raw != null && this.indexFor(items, raw) < 0)
|
|
233
|
+
return;
|
|
234
|
+
const match = this.indexFor(items, raw == null ? this.initialSelected : raw);
|
|
235
|
+
const index = match < 0 ? 0 : match;
|
|
236
|
+
const key = items[index].key;
|
|
237
|
+
if (key === this.lastKey)
|
|
238
|
+
return;
|
|
239
|
+
this.fromHistory = true;
|
|
240
|
+
this.selected = key;
|
|
241
|
+
};
|
|
242
|
+
this.onClick = (event) => {
|
|
243
|
+
if (event.button !== 0 || event.defaultPrevented)
|
|
244
|
+
return;
|
|
245
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
246
|
+
const btn = target?.closest('button.tab');
|
|
247
|
+
if (!(btn instanceof HTMLButtonElement) || !btn.parentElement?.classList.contains('tablist'))
|
|
248
|
+
return;
|
|
249
|
+
const index = [...btn.parentElement.children].indexOf(btn);
|
|
250
|
+
const item = this.collect()[index];
|
|
251
|
+
if (!item)
|
|
252
|
+
return;
|
|
253
|
+
if (this.booted && item.key === this.lastKey) {
|
|
254
|
+
if (this.cursor !== index) {
|
|
255
|
+
this.cursor = index;
|
|
256
|
+
this.requestUpdate();
|
|
257
|
+
}
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
this.cursor = index;
|
|
261
|
+
this.userAct = true;
|
|
262
|
+
this.selected = item.key;
|
|
263
|
+
};
|
|
264
|
+
this.onKeydown = (event) => {
|
|
265
|
+
if (event.altKey || event.ctrlKey || event.metaKey || event.defaultPrevented)
|
|
266
|
+
return;
|
|
267
|
+
if (event.key !== 'ArrowLeft' &&
|
|
268
|
+
event.key !== 'ArrowRight' &&
|
|
269
|
+
event.key !== 'Home' &&
|
|
270
|
+
event.key !== 'End')
|
|
271
|
+
return;
|
|
272
|
+
const items = this.collect();
|
|
273
|
+
if (!items.length)
|
|
274
|
+
return;
|
|
275
|
+
event.preventDefault();
|
|
276
|
+
const rtl = getComputedStyle(this).direction === 'rtl';
|
|
277
|
+
const focus = event.target instanceof Element ? event.target.closest('button.tab') : null;
|
|
278
|
+
const focused = focus instanceof HTMLButtonElement && focus.parentElement?.classList.contains('tablist')
|
|
279
|
+
? [...focus.parentElement.children].indexOf(focus)
|
|
280
|
+
: -1;
|
|
281
|
+
const start = focused >= 0 ? focused : this.cursor;
|
|
282
|
+
let next = start;
|
|
283
|
+
if (event.key === 'Home')
|
|
284
|
+
next = 0;
|
|
285
|
+
else if (event.key === 'End')
|
|
286
|
+
next = items.length - 1;
|
|
287
|
+
else {
|
|
288
|
+
const forward = event.key === 'ArrowRight' ? !rtl : rtl;
|
|
289
|
+
next = (start + (forward ? 1 : -1) + items.length) % items.length;
|
|
290
|
+
}
|
|
291
|
+
this.pendingFocus = true;
|
|
292
|
+
if (this.manual) {
|
|
293
|
+
this.cursor = next;
|
|
294
|
+
this.requestUpdate();
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
const item = items[next];
|
|
298
|
+
if (!item)
|
|
299
|
+
return;
|
|
300
|
+
if (this.booted && item.key === this.lastKey) {
|
|
301
|
+
this.requestUpdate();
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
this.cursor = next;
|
|
305
|
+
this.userAct = true;
|
|
306
|
+
this.selected = item.key;
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
static { this.styles = [accessible, shadowStructure, look]; }
|
|
310
|
+
get isLight() {
|
|
311
|
+
return this.noShadowDom || this.hasAttribute('no-shadow-dom');
|
|
312
|
+
}
|
|
313
|
+
get manual() {
|
|
314
|
+
return this.activation.trim().toLowerCase() === 'manual';
|
|
315
|
+
}
|
|
316
|
+
get listLabel() {
|
|
317
|
+
return this.label.trim() || 'Tabs';
|
|
318
|
+
}
|
|
319
|
+
createRenderRoot() {
|
|
320
|
+
if (!this.isLight) {
|
|
321
|
+
const root = super.createRenderRoot();
|
|
322
|
+
if (root instanceof ShadowRoot) {
|
|
323
|
+
if (this.noStyle) {
|
|
324
|
+
const sheet = shadowStructure.styleSheet;
|
|
325
|
+
if (sheet)
|
|
326
|
+
root.adoptedStyleSheets = [sheet];
|
|
327
|
+
}
|
|
328
|
+
// Light children are invisible until a slot exists. Lit renders on a
|
|
329
|
+
// microtask, so the slot has to be here before that, then removed once
|
|
330
|
+
// the template's own slot is in place (updated, still before paint).
|
|
331
|
+
if (!root.querySelector('slot')) {
|
|
332
|
+
const slot = this.ownerDocument.createElement('slot');
|
|
333
|
+
root.append(slot);
|
|
334
|
+
this.earlySlot = slot;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return root;
|
|
338
|
+
}
|
|
339
|
+
const mount = this.ownerDocument.createElement('div');
|
|
340
|
+
mount.className = 'mount';
|
|
341
|
+
mount.hidden = true;
|
|
342
|
+
this.mount = mount;
|
|
343
|
+
this.append(mount);
|
|
344
|
+
return mount;
|
|
345
|
+
}
|
|
346
|
+
connectedCallback() {
|
|
347
|
+
if (!this.booted) {
|
|
348
|
+
this.initialSelected = this.selected;
|
|
349
|
+
const fromUrl = this.readUrl();
|
|
350
|
+
if (fromUrl)
|
|
351
|
+
this.selected = fromUrl;
|
|
352
|
+
}
|
|
353
|
+
const light = this.isLight;
|
|
354
|
+
super.connectedCallback();
|
|
355
|
+
this.suppressUnselected();
|
|
356
|
+
this.install(light);
|
|
357
|
+
this.observe();
|
|
358
|
+
this.listen();
|
|
359
|
+
}
|
|
360
|
+
disconnectedCallback() {
|
|
361
|
+
super.disconnectedCallback();
|
|
362
|
+
this.observer?.disconnect();
|
|
363
|
+
this.unlisten();
|
|
364
|
+
}
|
|
365
|
+
render() {
|
|
366
|
+
if (this.isLight)
|
|
367
|
+
return html ``;
|
|
368
|
+
return html `
|
|
369
|
+
<div
|
|
370
|
+
class="tablist"
|
|
371
|
+
role="tablist"
|
|
372
|
+
aria-orientation="horizontal"
|
|
373
|
+
aria-label=${this.listLabel}
|
|
374
|
+
@click=${this.onClick}
|
|
375
|
+
@keydown=${this.onKeydown}
|
|
376
|
+
></div>
|
|
377
|
+
<div class="panels"></div>
|
|
378
|
+
`;
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Resolve `selected` to a panel id before render. Setting it here does not
|
|
382
|
+
* schedule another update; setting it in `updated()` does, and warns.
|
|
383
|
+
*/
|
|
384
|
+
willUpdate() {
|
|
385
|
+
const items = this.collect();
|
|
386
|
+
const match = items.length ? this.indexFor(items, this.selected) : -1;
|
|
387
|
+
const index = items.length ? (match < 0 ? 0 : match) : -1;
|
|
388
|
+
const key = index >= 0 ? items[index].key : '';
|
|
389
|
+
if (items.length && this.selected !== key) {
|
|
390
|
+
if (match < 0 && this.selected.trim())
|
|
391
|
+
this.warnValue();
|
|
392
|
+
this.selected = key;
|
|
393
|
+
}
|
|
394
|
+
if (index >= 0 && (!this.manual || !this.booted || key !== this.lastKey))
|
|
395
|
+
this.cursor = index;
|
|
396
|
+
if (this.cursor >= items.length)
|
|
397
|
+
this.cursor = Math.max(0, items.length - 1);
|
|
398
|
+
this.view = items;
|
|
399
|
+
this.viewIndex = index;
|
|
400
|
+
}
|
|
401
|
+
updated() {
|
|
402
|
+
this.earlySlot?.remove();
|
|
403
|
+
this.earlySlot = undefined;
|
|
404
|
+
const items = this.view;
|
|
405
|
+
const index = this.viewIndex;
|
|
406
|
+
const key = index >= 0 ? items[index].key : '';
|
|
407
|
+
this.observer?.disconnect();
|
|
408
|
+
try {
|
|
409
|
+
this.sync(items, index);
|
|
410
|
+
if (!items.length) {
|
|
411
|
+
this.booted = true;
|
|
412
|
+
this.lastKey = '';
|
|
413
|
+
this.userAct = false;
|
|
414
|
+
this.fromHistory = false;
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
if (!this.booted) {
|
|
418
|
+
this.booted = true;
|
|
419
|
+
this.lastKey = key;
|
|
420
|
+
this.userAct = false;
|
|
421
|
+
this.fromHistory = false;
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
if (key !== this.lastKey)
|
|
425
|
+
this.emit(items[index], index);
|
|
426
|
+
else {
|
|
427
|
+
this.userAct = false;
|
|
428
|
+
this.fromHistory = false;
|
|
429
|
+
}
|
|
430
|
+
this.focusPending(items);
|
|
431
|
+
}
|
|
432
|
+
finally {
|
|
433
|
+
if (this.isConnected)
|
|
434
|
+
this.observe();
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
install(light) {
|
|
438
|
+
if (!light)
|
|
439
|
+
return;
|
|
440
|
+
const node = this.getRootNode();
|
|
441
|
+
const root = node instanceof Document || node instanceof ShadowRoot ? node : undefined;
|
|
442
|
+
if (this.noStyle) {
|
|
443
|
+
installLightDomStyles(`${this.localName}::structure`, unsafeCSS(structuralRules(this.localName)), { root, scope: false });
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
installLightDomStyles(this.localName, this.constructor.elementStyles, {
|
|
447
|
+
root,
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
/** Hide every panel except the selected one before the first paint. Never hides that one. */
|
|
451
|
+
suppressUnselected() {
|
|
452
|
+
const items = this.collect();
|
|
453
|
+
if (!items.length)
|
|
454
|
+
return;
|
|
455
|
+
const index = this.resolve(items);
|
|
456
|
+
items.forEach((item, i) => {
|
|
457
|
+
const hide = i !== index;
|
|
458
|
+
if (item.panel.hidden !== hide)
|
|
459
|
+
item.panel.hidden = hide;
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
observe() {
|
|
463
|
+
this.observer ??= new MutationObserver(this.onMutations);
|
|
464
|
+
this.observer.disconnect();
|
|
465
|
+
this.observer.observe(this, {
|
|
466
|
+
childList: true,
|
|
467
|
+
subtree: true,
|
|
468
|
+
attributes: true,
|
|
469
|
+
attributeFilter: ['data-tab', 'slot', 'id'],
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
insideChrome(node) {
|
|
473
|
+
const el = node instanceof Element ? node : node.parentElement;
|
|
474
|
+
if (!el || el === this)
|
|
475
|
+
return false;
|
|
476
|
+
return !!el.closest('.tablist, .mount');
|
|
477
|
+
}
|
|
478
|
+
listen() {
|
|
479
|
+
if (this.listening)
|
|
480
|
+
return;
|
|
481
|
+
this.listening = true;
|
|
482
|
+
window.addEventListener('popstate', this.onHistory);
|
|
483
|
+
window.addEventListener('hashchange', this.onHistory);
|
|
484
|
+
}
|
|
485
|
+
unlisten() {
|
|
486
|
+
if (!this.listening)
|
|
487
|
+
return;
|
|
488
|
+
this.listening = false;
|
|
489
|
+
window.removeEventListener('popstate', this.onHistory);
|
|
490
|
+
window.removeEventListener('hashchange', this.onHistory);
|
|
491
|
+
}
|
|
492
|
+
childrenOf() {
|
|
493
|
+
return [...this.children].filter((node) => {
|
|
494
|
+
if (!(node instanceof HTMLElement))
|
|
495
|
+
return false;
|
|
496
|
+
if (node === this.mount)
|
|
497
|
+
return false;
|
|
498
|
+
if (node.classList.contains('tablist') || node.classList.contains('mount'))
|
|
499
|
+
return false;
|
|
500
|
+
return true;
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
collect() {
|
|
504
|
+
const kids = this.childrenOf();
|
|
505
|
+
const sources = kids.filter((node) => node.localName === 'button' && node.getAttribute('slot') === 'tab');
|
|
506
|
+
const panelCandidates = sources.length
|
|
507
|
+
? kids.filter((node) => !(node.localName === 'button' && node.getAttribute('slot') === 'tab'))
|
|
508
|
+
: kids.filter((node) => node.hasAttribute('data-tab'));
|
|
509
|
+
// Extra sections beside too few slot="tab" buttons are not tabs. The warning
|
|
510
|
+
// still counts them, so "a child was skipped" stays true.
|
|
511
|
+
const panels = sources.length > 0 ? panelCandidates.slice(0, sources.length) : panelCandidates;
|
|
512
|
+
this.warnShape(kids, sources.length, panelCandidates.length);
|
|
513
|
+
const used = new Set();
|
|
514
|
+
return panels.map((panel, i) => {
|
|
515
|
+
let panelId = panel.id.trim();
|
|
516
|
+
if (!panelId || used.has(panelId)) {
|
|
517
|
+
panelId = `${this.uid}-panel-${i}`;
|
|
518
|
+
let n = 2;
|
|
519
|
+
while (used.has(panelId))
|
|
520
|
+
panelId = `${this.uid}-panel-${i}-${n++}`;
|
|
521
|
+
}
|
|
522
|
+
used.add(panelId);
|
|
523
|
+
const source = sources[i] ?? null;
|
|
524
|
+
const label = normalize(source?.textContent) ||
|
|
525
|
+
normalize(panel.getAttribute('data-tab')) ||
|
|
526
|
+
`Tab ${i + 1}`;
|
|
527
|
+
return { label, panel, key: panelId, panelId, tabId: `${this.uid}-${panelId}-tab` };
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
warnShape(kids, sources, panels) {
|
|
531
|
+
if (this.warnedShape || !kids.length)
|
|
532
|
+
return;
|
|
533
|
+
const stray = (sources > 0 && sources !== panels) ||
|
|
534
|
+
(sources === 0 && kids.some((node) => !node.hasAttribute('data-tab')));
|
|
535
|
+
if (!stray)
|
|
536
|
+
return;
|
|
537
|
+
this.warnedShape = true;
|
|
538
|
+
console.warn(`${this.localName}: each panel needs data-tab, or one button slot="tab" per panel. A child was skipped.`);
|
|
539
|
+
}
|
|
540
|
+
warnValue() {
|
|
541
|
+
if (this.warnedValue)
|
|
542
|
+
return;
|
|
543
|
+
this.warnedValue = true;
|
|
544
|
+
console.warn(`${this.localName}: selected does not match a tab; showing the first tab.`);
|
|
545
|
+
}
|
|
546
|
+
/** Panel id, then label, then a 0-based index. `-1` when nothing matches. */
|
|
547
|
+
indexFor(items, value) {
|
|
548
|
+
const raw = value.trim();
|
|
549
|
+
if (!raw)
|
|
550
|
+
return 0;
|
|
551
|
+
const byId = items.findIndex((item) => item.key === raw || item.panelId === raw);
|
|
552
|
+
if (byId >= 0)
|
|
553
|
+
return byId;
|
|
554
|
+
const byLabel = items.findIndex((item) => item.label === raw);
|
|
555
|
+
if (byLabel >= 0)
|
|
556
|
+
return byLabel;
|
|
557
|
+
if (/^\d+$/.test(raw)) {
|
|
558
|
+
const n = Number(raw);
|
|
559
|
+
if (n >= 0 && n < items.length)
|
|
560
|
+
return n;
|
|
561
|
+
}
|
|
562
|
+
return -1;
|
|
563
|
+
}
|
|
564
|
+
resolve(items) {
|
|
565
|
+
const match = this.indexFor(items, this.selected);
|
|
566
|
+
return match < 0 ? 0 : match;
|
|
567
|
+
}
|
|
568
|
+
sync(items, selectedIndex) {
|
|
569
|
+
for (const node of this.children) {
|
|
570
|
+
if (node instanceof HTMLButtonElement && node.getAttribute('slot') === 'tab') {
|
|
571
|
+
if (!node.hidden)
|
|
572
|
+
node.hidden = true;
|
|
573
|
+
if (node.tabIndex !== -1)
|
|
574
|
+
node.tabIndex = -1;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
const list = this.ensureList();
|
|
578
|
+
if (list)
|
|
579
|
+
this.syncButtons(list, items, selectedIndex);
|
|
580
|
+
this.syncPanels(items, selectedIndex);
|
|
581
|
+
}
|
|
582
|
+
ensureList() {
|
|
583
|
+
if (!this.isLight) {
|
|
584
|
+
const found = this.renderRoot.querySelector('.tablist');
|
|
585
|
+
return found instanceof HTMLElement ? found : null;
|
|
586
|
+
}
|
|
587
|
+
const found = [...this.children].find((node) => node instanceof HTMLElement && node.classList.contains('tablist'));
|
|
588
|
+
const list = found ?? this.ownerDocument.createElement('div');
|
|
589
|
+
if (!found) {
|
|
590
|
+
list.className = 'tablist';
|
|
591
|
+
this.prepend(list);
|
|
592
|
+
}
|
|
593
|
+
else if (this.firstElementChild !== list) {
|
|
594
|
+
this.prepend(list);
|
|
595
|
+
}
|
|
596
|
+
this.setAttr(list, 'role', 'tablist');
|
|
597
|
+
this.setAttr(list, 'aria-orientation', 'horizontal');
|
|
598
|
+
this.setAttr(list, 'aria-label', this.listLabel);
|
|
599
|
+
if (!this.boundLists.has(list)) {
|
|
600
|
+
this.boundLists.add(list);
|
|
601
|
+
list.addEventListener('click', this.onClick);
|
|
602
|
+
list.addEventListener('keydown', this.onKeydown);
|
|
603
|
+
}
|
|
604
|
+
return list;
|
|
605
|
+
}
|
|
606
|
+
syncButtons(list, items, selectedIndex) {
|
|
607
|
+
this.setAttr(list, 'aria-label', this.listLabel);
|
|
608
|
+
const live = new Set(items.map((item) => item.key));
|
|
609
|
+
for (const [key, btn] of this.buttons) {
|
|
610
|
+
if (!live.has(key)) {
|
|
611
|
+
btn.remove();
|
|
612
|
+
this.buttons.delete(key);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
items.forEach((item, i) => {
|
|
616
|
+
let btn = this.buttons.get(item.key);
|
|
617
|
+
if (!btn) {
|
|
618
|
+
btn = this.ownerDocument.createElement('button');
|
|
619
|
+
btn.type = 'button';
|
|
620
|
+
btn.className = 'tab';
|
|
621
|
+
btn.setAttribute('role', 'tab');
|
|
622
|
+
this.buttons.set(item.key, btn);
|
|
623
|
+
}
|
|
624
|
+
if (btn.id !== item.tabId)
|
|
625
|
+
btn.id = item.tabId;
|
|
626
|
+
this.setAttr(btn, 'aria-controls', this.controlledId(item));
|
|
627
|
+
this.setAttr(btn, 'aria-selected', i === selectedIndex ? 'true' : 'false');
|
|
628
|
+
const tabbable = this.manual ? i === this.cursor : i === selectedIndex;
|
|
629
|
+
if (btn.tabIndex !== (tabbable ? 0 : -1))
|
|
630
|
+
btn.tabIndex = tabbable ? 0 : -1;
|
|
631
|
+
if (btn.textContent !== item.label)
|
|
632
|
+
btn.textContent = item.label;
|
|
633
|
+
if (list.children[i] !== btn)
|
|
634
|
+
list.insertBefore(btn, list.children[i] ?? null);
|
|
635
|
+
});
|
|
636
|
+
while (list.children.length > items.length)
|
|
637
|
+
list.lastElementChild?.remove();
|
|
638
|
+
}
|
|
639
|
+
/** The id of the element that is `role="tabpanel"`. In shadow that element is not the light child. */
|
|
640
|
+
controlledId(item) {
|
|
641
|
+
return this.isLight ? item.panelId : `${item.panelId}-tabpanel`;
|
|
642
|
+
}
|
|
643
|
+
syncPanels(items, selectedIndex) {
|
|
644
|
+
const shown = new Set(items.map((item) => item.panel));
|
|
645
|
+
for (const node of this.childrenOf()) {
|
|
646
|
+
if (shown.has(node))
|
|
647
|
+
continue;
|
|
648
|
+
if (node.localName === 'button' && node.getAttribute('slot') === 'tab')
|
|
649
|
+
continue;
|
|
650
|
+
if (!node.hidden)
|
|
651
|
+
node.hidden = true;
|
|
652
|
+
}
|
|
653
|
+
if (!this.isLight) {
|
|
654
|
+
this.syncShadowPanels(items, selectedIndex);
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
items.forEach((item, i) => this.markPanel(item.panel, item, i !== selectedIndex));
|
|
658
|
+
}
|
|
659
|
+
/**
|
|
660
|
+
* A shadow button cannot reference a light-DOM id. The tabpanel is a shadow
|
|
661
|
+
* element; the author's panel is slotted into it and hidden with it.
|
|
662
|
+
*/
|
|
663
|
+
syncShadowPanels(items, selectedIndex) {
|
|
664
|
+
const box = this.renderRoot.querySelector('.panels');
|
|
665
|
+
if (!(box instanceof HTMLElement))
|
|
666
|
+
return;
|
|
667
|
+
const live = new Set(items.map((item) => item.key));
|
|
668
|
+
for (const [key, host] of this.panelHosts) {
|
|
669
|
+
if (!live.has(key)) {
|
|
670
|
+
host.remove();
|
|
671
|
+
this.panelHosts.delete(key);
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
items.forEach((item, i) => {
|
|
675
|
+
let host = this.panelHosts.get(item.key);
|
|
676
|
+
if (!host) {
|
|
677
|
+
host = this.ownerDocument.createElement('div');
|
|
678
|
+
host.className = 'panel';
|
|
679
|
+
this.panelHosts.set(item.key, host);
|
|
680
|
+
}
|
|
681
|
+
const hostId = this.controlledId(item);
|
|
682
|
+
if (host.id !== hostId)
|
|
683
|
+
host.id = hostId;
|
|
684
|
+
this.setAttr(host, 'role', 'tabpanel');
|
|
685
|
+
this.setAttr(host, 'aria-labelledby', item.tabId);
|
|
686
|
+
let slot = host.querySelector('slot');
|
|
687
|
+
if (!(slot instanceof HTMLSlotElement)) {
|
|
688
|
+
slot = this.ownerDocument.createElement('slot');
|
|
689
|
+
host.append(slot);
|
|
690
|
+
}
|
|
691
|
+
const slotName = `${this.uid}-${i}`;
|
|
692
|
+
if (slot.name !== slotName)
|
|
693
|
+
slot.name = slotName;
|
|
694
|
+
if (box.children[i] !== host)
|
|
695
|
+
box.insertBefore(host, box.children[i] ?? null);
|
|
696
|
+
if (item.panel.getAttribute('slot') !== slotName)
|
|
697
|
+
item.panel.setAttribute('slot', slotName);
|
|
698
|
+
if (item.panel.getAttribute('role') === 'tabpanel')
|
|
699
|
+
item.panel.removeAttribute('role');
|
|
700
|
+
if (item.panel.getAttribute('aria-labelledby') === item.tabId)
|
|
701
|
+
item.panel.removeAttribute('aria-labelledby');
|
|
702
|
+
const hide = i !== selectedIndex;
|
|
703
|
+
if (host.hidden !== hide)
|
|
704
|
+
host.hidden = hide;
|
|
705
|
+
if (item.panel.hidden !== hide)
|
|
706
|
+
item.panel.hidden = hide;
|
|
707
|
+
if (item.panel.id !== item.panelId)
|
|
708
|
+
item.panel.id = item.panelId;
|
|
709
|
+
});
|
|
710
|
+
while (box.children.length > items.length)
|
|
711
|
+
box.lastElementChild?.remove();
|
|
712
|
+
}
|
|
713
|
+
markPanel(panel, item, hide) {
|
|
714
|
+
if (panel.id !== item.panelId)
|
|
715
|
+
panel.id = item.panelId;
|
|
716
|
+
this.setAttr(panel, 'role', 'tabpanel');
|
|
717
|
+
this.setAttr(panel, 'aria-labelledby', item.tabId);
|
|
718
|
+
if (panel.hidden !== hide)
|
|
719
|
+
panel.hidden = hide;
|
|
720
|
+
}
|
|
721
|
+
setAttr(el, name, value) {
|
|
722
|
+
if (el.getAttribute(name) !== value)
|
|
723
|
+
el.setAttribute(name, value);
|
|
724
|
+
}
|
|
725
|
+
focusPending(items) {
|
|
726
|
+
if (!this.pendingFocus)
|
|
727
|
+
return;
|
|
728
|
+
this.pendingFocus = false;
|
|
729
|
+
const btn = this.buttons.get(items[this.cursor]?.key ?? '');
|
|
730
|
+
if (!btn)
|
|
731
|
+
return;
|
|
732
|
+
btn.focus();
|
|
733
|
+
try {
|
|
734
|
+
btn.scrollIntoView({ block: 'nearest', inline: 'nearest' });
|
|
735
|
+
}
|
|
736
|
+
catch {
|
|
737
|
+
/* not every document can scroll */
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
emit(item, index) {
|
|
741
|
+
const user = this.userAct;
|
|
742
|
+
const fromHistory = this.fromHistory;
|
|
743
|
+
this.userAct = false;
|
|
744
|
+
this.fromHistory = false;
|
|
745
|
+
this.lastKey = item.key;
|
|
746
|
+
if (user)
|
|
747
|
+
trackEvent(this, ['uvalib-tabs', 'change', item.label]);
|
|
748
|
+
if (!fromHistory)
|
|
749
|
+
this.writeUrl(user ? 'push' : 'replace', item.key);
|
|
750
|
+
this.dispatchEvent(new CustomEvent('change', {
|
|
751
|
+
bubbles: true,
|
|
752
|
+
composed: true,
|
|
753
|
+
detail: { id: item.panelId, label: item.label, index },
|
|
754
|
+
}));
|
|
755
|
+
}
|
|
756
|
+
page() {
|
|
757
|
+
return { pathname: location.pathname, search: location.search, hash: location.hash };
|
|
758
|
+
}
|
|
759
|
+
/** The id in the URL, or null when this component should not read one. */
|
|
760
|
+
readUrl() {
|
|
761
|
+
const name = this.urlParam.trim();
|
|
762
|
+
if (!name)
|
|
763
|
+
return null;
|
|
764
|
+
const loc = this.page();
|
|
765
|
+
if (name === 'hash') {
|
|
766
|
+
const raw = loc.hash.startsWith('#') ? loc.hash.slice(1) : '';
|
|
767
|
+
if (!raw || raw.startsWith('/') || raw.startsWith('!') || raw.includes('?'))
|
|
768
|
+
return null;
|
|
769
|
+
try {
|
|
770
|
+
return decodeURIComponent(raw);
|
|
771
|
+
}
|
|
772
|
+
catch {
|
|
773
|
+
return raw;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
return paramFromLocation(loc, name);
|
|
777
|
+
}
|
|
778
|
+
writeUrl(mode, key) {
|
|
779
|
+
const name = this.urlParam.trim();
|
|
780
|
+
if (!name || !key)
|
|
781
|
+
return;
|
|
782
|
+
const loc = this.page();
|
|
783
|
+
let next;
|
|
784
|
+
if (name === 'hash') {
|
|
785
|
+
if (usesHashParam(loc.hash))
|
|
786
|
+
return;
|
|
787
|
+
next = loc.pathname + loc.search + `#${encodeURIComponent(key)}`;
|
|
788
|
+
}
|
|
789
|
+
else {
|
|
790
|
+
next = hrefWithParam(loc, name, key);
|
|
791
|
+
}
|
|
792
|
+
if (next === loc.pathname + loc.search + loc.hash)
|
|
793
|
+
return;
|
|
794
|
+
const current = history.state;
|
|
795
|
+
const state = current && typeof current === 'object'
|
|
796
|
+
? { ...current, uvalibTabs: this.uid }
|
|
797
|
+
: { uvalibTabs: this.uid };
|
|
798
|
+
try {
|
|
799
|
+
if (mode === 'push')
|
|
800
|
+
history.pushState(state, '', next);
|
|
801
|
+
else
|
|
802
|
+
history.replaceState(state, '', next);
|
|
803
|
+
}
|
|
804
|
+
catch {
|
|
805
|
+
/* a sandboxed document can refuse history */
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
__decorate([
|
|
810
|
+
property({ reflect: true })
|
|
811
|
+
], UvalibTabs.prototype, "selected", void 0);
|
|
812
|
+
__decorate([
|
|
813
|
+
property()
|
|
814
|
+
], UvalibTabs.prototype, "activation", void 0);
|
|
815
|
+
__decorate([
|
|
816
|
+
property({ attribute: 'url-param' })
|
|
817
|
+
], UvalibTabs.prototype, "urlParam", void 0);
|
|
818
|
+
__decorate([
|
|
819
|
+
property()
|
|
820
|
+
], UvalibTabs.prototype, "label", void 0);
|
|
821
|
+
//# sourceMappingURL=UvalibTabs.js.map
|