igniteui-astro-components 0.0.26 → 0.0.28
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 +82 -74
- package/package.json +16 -9
- package/src/components/CopyCode/CopyCode.astro +21 -7
- package/src/components/DocsBreadcrumb/DocsBreadcrumb.astro +33 -21
- package/src/components/DocsBreadcrumb/DocsBreadcrumb.scss +44 -43
- package/src/components/DocsBreadcrumb/README.md +10 -14
- package/src/components/DocsSidebar/DocsSidebar.astro +47 -45
- package/src/components/DocsSidebar/DocsSidebar.scss +120 -122
- package/src/components/DocsSidebar/README.md +25 -21
- package/src/components/DocsSidebar/SidebarFilterInput.astro +24 -29
- package/src/components/DocsSidebar/SidebarFilterInput.scss +90 -89
- package/src/components/DocsSidebar/SidebarLabel.astro +35 -26
- package/src/components/DocsSidebar/sidebar-filter.ts +93 -56
- package/src/components/DocsSubHeader/DocsSubHeader.astro +256 -185
- package/src/components/DocsSubHeader/DocsSubHeader.scss +181 -169
- package/src/components/DocsSubHeader/README.md +18 -16
- package/src/components/DocsToc/DocsToc.astro +301 -280
- package/src/components/DocsToc/DocsToc.scss +20 -21
- package/src/components/DocsToc/README.md +11 -9
- package/src/components/DocsToc/toTreeNodes.ts +3 -8
- package/src/components/DocsTree/DocsTree.astro +32 -20
- package/src/components/DocsTree/DocsTreeItem.astro +35 -30
- package/src/components/DocsTree/README.md +16 -15
- package/src/components/DocsTree/docs-tree.scss +267 -268
- package/src/components/GlobalFooter/GlobalFooter.astro +10 -10
- package/src/components/GlobalFooter/README.md +3 -2
- package/src/components/GlobalNavBar/GlobalNavBar.astro +4 -2
- package/src/components/GlobalNavBar/GlobalNavBar.module.scss +222 -222
- package/src/components/GlobalNavBar/README.md +3 -2
- package/src/components/LicenseIndicator/LicenseIndicator.astro +7 -5
- package/src/components/LicenseIndicator/LicenseIndicator.scss +3 -3
- package/src/components/MobileSidebarToggle/MobileSidebarToggle.astro +16 -17
- package/src/components/MobileSidebarToggle/README.md +3 -2
- package/src/components/MobileTocToggle/MobileTocToggle.astro +75 -61
- package/src/components/MobileTocToggle/MobileTocToggle.scss +65 -59
- package/src/components/Search/README.md +1 -0
- package/src/components/Search/Search.astro +137 -109
- package/src/components/Search/Search.scss +20 -20
- package/src/components/SearchAdvanced/README.md +21 -15
- package/src/components/SearchAdvanced/SearchAdvanced.astro +220 -133
- package/src/components/SearchAdvanced/SearchAdvanced.scss +152 -153
- package/src/components/mdx/ApiLink/ApiLink.astro +133 -113
- package/src/components/mdx/ApiLink/ApiLink.scss +9 -9
- package/src/components/mdx/ApiLink/README.md +26 -22
- package/src/components/mdx/ApiLink/api-link-index.ts +196 -173
- package/src/components/mdx/ApiRef/ApiRef.astro +54 -51
- package/src/components/mdx/ApiRef/README.md +20 -15
- package/src/components/mdx/Badge/Badge.astro +14 -14
- package/src/components/mdx/Badge/Badge.scss +61 -56
- package/src/components/mdx/Badge/README.md +24 -19
- package/src/components/mdx/DocsAside/DocsAside.astro +30 -37
- package/src/components/mdx/DocsAside/DocsAside.scss +82 -82
- package/src/components/mdx/DocsAside/README.md +22 -22
- package/src/components/mdx/Faq/Faq.astro +86 -0
- package/src/components/mdx/Faq/Faq.scss +105 -0
- package/src/components/mdx/Faq/FaqItem.astro +117 -0
- package/src/components/mdx/Faq/README.md +223 -0
- package/src/components/mdx/Faq/types.ts +34 -0
- package/src/components/mdx/PlatformBlock/PlatformBlock.astro +3 -2
- package/src/components/mdx/PlatformBlock/README.md +6 -8
- package/src/components/mdx/Sample/README.md +21 -16
- package/src/components/mdx/Sample/Sample.astro +97 -74
- package/src/components/mdx/Sample/Sample.scss +132 -132
- package/src/content-helper.ts +71 -72
- package/src/content.config.ts +1 -6
- package/src/integration.ts +566 -512
- package/src/layouts/DocsLayout/DocsLayout.astro +228 -182
- package/src/layouts/DocsLayout/DocsLayout.scss +261 -261
- package/src/layouts/DocsLayout/README.md +24 -35
- package/src/lib/nav-helpers.ts +88 -82
- package/src/lib/types.ts +76 -76
- package/src/llms.ts +205 -166
- package/src/platform.ts +312 -162
- package/src/plugins/rehype-heading-anchors.ts +45 -45
- package/src/plugins/rehype-pagefind-ignore.ts +19 -19
- package/src/plugins/rehype-table-wrapper.ts +30 -30
- package/src/plugins/remark-docfx.ts +12 -0
- package/src/plugins/remark-env-vars.ts +12 -4
- package/src/plugins/remark-md-links.ts +10 -4
- package/src/scripts/icon-manifest.ts +13 -5
- package/src/scripts/sample-widget.ts +557 -501
- package/src/sidebar.ts +103 -97
- package/src/styles/global/_code-blocks.scss +43 -44
- package/src/styles/global/_component-themes.scss +151 -153
- package/src/styles/global/_icon-gallery.scss +81 -81
- package/src/styles/global/_index.scss +0 -1
- package/src/styles/global/_markdown.scss +816 -787
- package/src/styles/global/_palette.scss +456 -110
- package/src/styles/global/_search-shared.scss +402 -398
- package/src/styles/global/_type-scale.scss +127 -127
- package/src/styles/global/_variables.scss +138 -111
- package/src/styles/theme.scss +49 -40
- package/src/virtual-modules.d.ts +11 -2
|
@@ -15,312 +15,333 @@ import { headingsToTreeNodes, type TocConfig } from './toTreeNodes';
|
|
|
15
15
|
import './DocsToc.scss';
|
|
16
16
|
|
|
17
17
|
interface Props {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
headings?: MarkdownHeading[];
|
|
19
|
+
tocConfig?: TocConfig;
|
|
20
|
+
label?: string;
|
|
21
|
+
offsetTarget?: string;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
const {
|
|
25
|
-
headings = [],
|
|
26
|
-
tocConfig,
|
|
27
|
-
label = 'On this page',
|
|
28
|
-
offsetTarget,
|
|
29
|
-
} = Astro.props;
|
|
24
|
+
const { headings = [], tocConfig, label = 'On this page', offsetTarget } = Astro.props;
|
|
30
25
|
|
|
31
26
|
const nodes = headingsToTreeNodes(headings, tocConfig);
|
|
32
27
|
---
|
|
33
28
|
|
|
34
|
-
{
|
|
29
|
+
{
|
|
30
|
+
nodes.length > 0 && (
|
|
35
31
|
<aside class="toc-wrapper" data-pagefind-ignore="all">
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
32
|
+
<docs-toc class="toc-sidebar" data-offset-target={offsetTarget}>
|
|
33
|
+
<h2 class="toc-sidebar__heading" id="toc-heading">
|
|
34
|
+
{label}
|
|
35
|
+
</h2>
|
|
36
|
+
<nav aria-labelledby="toc-heading">
|
|
37
|
+
<DocsTree nodes={nodes} variant="toc" />
|
|
38
|
+
</nav>
|
|
39
|
+
</docs-toc>
|
|
42
40
|
</aside>
|
|
43
|
-
)
|
|
41
|
+
)
|
|
42
|
+
}
|
|
44
43
|
|
|
45
44
|
<script>
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
45
|
+
type ExpandableEl = HTMLElement & { expanded: boolean };
|
|
46
|
+
|
|
47
|
+
class DocsToc extends HTMLElement {
|
|
48
|
+
private static readonly DEFAULT_THRESHOLD = 160;
|
|
49
|
+
|
|
50
|
+
private pageController: AbortController | undefined;
|
|
51
|
+
private rafId: number | undefined;
|
|
52
|
+
private initId = 0;
|
|
53
|
+
private headings: HTMLElement[] = [];
|
|
54
|
+
private links: HTMLAnchorElement[] = [];
|
|
55
|
+
private currentLink: HTMLAnchorElement | undefined;
|
|
56
|
+
private offsetEl: Element | null = null;
|
|
57
|
+
private resizeObserver: ResizeObserver | undefined;
|
|
58
|
+
private pinnedIndex: number | undefined;
|
|
59
|
+
|
|
60
|
+
connectedCallback() {
|
|
61
|
+
this.init();
|
|
62
|
+
}
|
|
64
63
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
disconnectedCallback() {
|
|
65
|
+
this.teardown();
|
|
66
|
+
}
|
|
68
67
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
68
|
+
private teardown() {
|
|
69
|
+
this.pageController?.abort();
|
|
70
|
+
this.pageController = undefined;
|
|
71
|
+
this.resizeObserver?.disconnect();
|
|
72
|
+
this.resizeObserver = undefined;
|
|
73
|
+
this.offsetEl = null;
|
|
74
|
+
document.documentElement.style.removeProperty('--igd-toc-subheader-bottom');
|
|
75
|
+
if (this.rafId !== undefined) {
|
|
76
|
+
cancelAnimationFrame(this.rafId);
|
|
77
|
+
this.rafId = undefined;
|
|
78
|
+
}
|
|
79
|
+
this.currentLink = undefined;
|
|
80
|
+
this.pinnedIndex = undefined;
|
|
81
|
+
}
|
|
83
82
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
83
|
+
init() {
|
|
84
|
+
this.teardown();
|
|
85
|
+
|
|
86
|
+
// Invalidate any pending deferred _init from a previous call.
|
|
87
|
+
const id = ++this.initId;
|
|
88
|
+
|
|
89
|
+
// Wait for igc-tree to be defined before querying slotted links,
|
|
90
|
+
// since the links live inside igc-tree-item light DOM and igc-tree
|
|
91
|
+
// may not have upgraded yet when init() runs.
|
|
92
|
+
customElements.whenDefined('igc-tree').then(() =>
|
|
93
|
+
requestAnimationFrame(() => {
|
|
94
|
+
// Bail if init() was called again since we scheduled, or the
|
|
95
|
+
// element was disconnected (e.g. a view transition swapped the DOM).
|
|
96
|
+
if (this.initId !== id || !this.isConnected) return;
|
|
97
|
+
this._init();
|
|
98
|
+
}),
|
|
99
|
+
);
|
|
100
|
+
}
|
|
100
101
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
102
|
+
private _init() {
|
|
103
|
+
// Clear any stale aria-current left over from a previous page.
|
|
104
|
+
this.querySelectorAll('a[aria-current]').forEach((a) => a.removeAttribute('aria-current'));
|
|
105
|
+
// Clear any stale selected / active state on tree items.
|
|
106
|
+
this.querySelectorAll('igc-tree-item').forEach((item) => {
|
|
107
|
+
const treeItem = item as HTMLElement & { selected: boolean; active: boolean };
|
|
108
|
+
treeItem.selected = false;
|
|
109
|
+
treeItem.active = false;
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
this.links = Array.from(this.querySelectorAll<HTMLAnchorElement>('a[href^="#"]'));
|
|
113
|
+
this.headings = this.links
|
|
114
|
+
.map((link) => document.getElementById(decodeURIComponent(link.hash.slice(1))))
|
|
115
|
+
.filter((el): el is HTMLElement => el !== null);
|
|
116
|
+
|
|
117
|
+
if (this.headings.length === 0) return;
|
|
118
|
+
|
|
119
|
+
const schedule = () => {
|
|
120
|
+
if (this.rafId !== undefined) return;
|
|
121
|
+
this.rafId = requestAnimationFrame(() => {
|
|
122
|
+
this.rafId = undefined;
|
|
123
|
+
this.update();
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
this.pageController = new AbortController();
|
|
128
|
+
const opts = { passive: true, signal: this.pageController.signal };
|
|
129
|
+
|
|
130
|
+
window.addEventListener('scroll', schedule, opts);
|
|
131
|
+
window.addEventListener(
|
|
132
|
+
'resize',
|
|
133
|
+
() => {
|
|
134
|
+
this.syncScrollPadding();
|
|
135
|
+
schedule();
|
|
136
|
+
},
|
|
137
|
+
opts,
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
// Any user-initiated scroll input releases the click pin so the
|
|
141
|
+
// spy can take over again immediately.
|
|
142
|
+
const releasePin = () => {
|
|
143
|
+
this.pinnedIndex = undefined;
|
|
144
|
+
};
|
|
145
|
+
window.addEventListener('wheel', releasePin, opts);
|
|
146
|
+
window.addEventListener('touchstart', releasePin, opts);
|
|
147
|
+
window.addEventListener('keydown', releasePin, opts);
|
|
148
|
+
|
|
149
|
+
// Browser back/forward navigation: release the pin and re-run the
|
|
150
|
+
// spy so the active item reflects the restored scroll position.
|
|
151
|
+
window.addEventListener(
|
|
152
|
+
'hashchange',
|
|
153
|
+
() => {
|
|
154
|
+
this.pinnedIndex = undefined;
|
|
155
|
+
requestAnimationFrame(() => this.update());
|
|
156
|
+
},
|
|
157
|
+
opts,
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
// popstate covers back/forward cases that hashchange misses:
|
|
161
|
+
// navigating to a URL with no hash, or the same hash as before.
|
|
162
|
+
// Note: do NOT call scrollToHashIfNeeded() here — Chrome fires
|
|
163
|
+
// popstate on anchor clicks too, which would override smooth scroll
|
|
164
|
+
// with an instant jump. The browser handles scroll restoration on
|
|
165
|
+
// back/forward automatically.
|
|
166
|
+
window.addEventListener(
|
|
167
|
+
'popstate',
|
|
168
|
+
() => {
|
|
169
|
+
this.pinnedIndex = undefined;
|
|
170
|
+
requestAnimationFrame(() => this.update());
|
|
171
|
+
},
|
|
172
|
+
opts,
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
this.addEventListener(
|
|
176
|
+
'click',
|
|
177
|
+
(e) => {
|
|
178
|
+
const target = (e.target as HTMLElement | null)?.closest('a[href^="#"]');
|
|
179
|
+
if (!(target instanceof HTMLAnchorElement)) return;
|
|
180
|
+
const idx = this.links.indexOf(target);
|
|
181
|
+
if (idx === -1) return;
|
|
182
|
+
this.pinnedIndex = idx;
|
|
183
|
+
this.setActive(idx);
|
|
184
|
+
},
|
|
185
|
+
{ signal: this.pageController.signal },
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
this.bindOffsetTarget();
|
|
189
|
+
|
|
190
|
+
// Immediately highlight the first node so there is always a
|
|
191
|
+
// visible active state, even before layout is fully settled.
|
|
192
|
+
// this.setActive(0);
|
|
193
|
+
|
|
194
|
+
this.update();
|
|
195
|
+
// Safari: getBoundingClientRect() may not reflect final layout
|
|
196
|
+
// during the first rAF (before first paint). Schedule one extra
|
|
197
|
+
// update so the initial active item is always correct.
|
|
198
|
+
// Also re-scroll to the hash now that syncScrollPadding has run
|
|
199
|
+
// and scroll-padding-top reflects the true sticky header height.
|
|
200
|
+
// Without this, a refresh with a #hash in the URL would scroll
|
|
201
|
+
// before the CSS variable is set, landing the heading behind the header.
|
|
202
|
+
requestAnimationFrame(() => {
|
|
203
|
+
this.update();
|
|
204
|
+
// Nest in a second rAF so igc-tree's internal scrollIntoView
|
|
205
|
+
// (triggered by setActive → selected = true) settles first,
|
|
206
|
+
// and our correction scroll wins.
|
|
207
|
+
requestAnimationFrame(() => this.scrollToHashIfNeeded());
|
|
208
|
+
});
|
|
209
|
+
}
|
|
190
210
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
211
|
+
private bindOffsetTarget() {
|
|
212
|
+
const selector = this.dataset.offsetTarget ?? null;
|
|
213
|
+
// If an explicit selector is given, use it; otherwise fall back to
|
|
214
|
+
// the docs subheader which is always present in the layout.
|
|
215
|
+
this.offsetEl =
|
|
216
|
+
(selector ? document.querySelector(selector) : null) ??
|
|
217
|
+
document.querySelector('docs-subheader-menu') ??
|
|
218
|
+
null;
|
|
219
|
+
if (!this.offsetEl) return;
|
|
220
|
+
|
|
221
|
+
this.syncScrollPadding();
|
|
222
|
+
// Re-sync after layout settles (fonts, reflow) on initial load / navigation.
|
|
223
|
+
requestAnimationFrame(() => this.syncScrollPadding());
|
|
224
|
+
|
|
225
|
+
// Re-measure when the header itself resizes (responsive collapse,
|
|
226
|
+
// font-load reflow, etc.).
|
|
227
|
+
this.resizeObserver = new ResizeObserver(() => this.syncScrollPadding());
|
|
228
|
+
this.resizeObserver.observe(this.offsetEl);
|
|
229
|
+
}
|
|
209
230
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
231
|
+
private syncScrollPadding() {
|
|
232
|
+
if (!this.offsetEl) return;
|
|
233
|
+
const px = Math.round(this.offsetEl.getBoundingClientRect().bottom);
|
|
234
|
+
// Write only the measured subheader height; the CSS adds --igd-toc-scroll-offset on top.
|
|
235
|
+
document.documentElement.style.setProperty('--igd-toc-subheader-bottom', `${px}px`);
|
|
236
|
+
}
|
|
216
237
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
238
|
+
// Re-scroll to the current URL hash so the heading lands below the sticky
|
|
239
|
+
// header once scroll-padding-top has been set correctly by syncScrollPadding.
|
|
240
|
+
private scrollToHashIfNeeded() {
|
|
241
|
+
const hash = window.location.hash;
|
|
242
|
+
if (!hash) return;
|
|
243
|
+
const id = decodeURIComponent(hash.slice(1));
|
|
244
|
+
const el = document.getElementById(id);
|
|
245
|
+
if (el) el.scrollIntoView({ behavior: 'instant', block: 'start' });
|
|
246
|
+
}
|
|
226
247
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// Favor the closer heading: if the next heading is nearer to
|
|
244
|
-
// the threshold than the current one, jump forward.
|
|
245
|
-
if (activeIndex >= 0 && activeIndex + 1 < this.headings.length) {
|
|
246
|
-
const currentDist = threshold - this.headings[activeIndex].getBoundingClientRect().top;
|
|
247
|
-
const nextDist = this.headings[activeIndex + 1].getBoundingClientRect().top - threshold;
|
|
248
|
-
if (nextDist < currentDist) {
|
|
249
|
-
activeIndex = activeIndex + 1;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
// Above the first heading: default to the first item so there
|
|
254
|
-
// is always an active entry when at the top of the page.
|
|
255
|
-
if (activeIndex === -1) {
|
|
256
|
-
activeIndex = 0;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
this.setActive(activeIndex);
|
|
248
|
+
private update() {
|
|
249
|
+
if (this.pinnedIndex !== undefined) {
|
|
250
|
+
this.setActive(this.pinnedIndex);
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const threshold = this.computeThreshold();
|
|
255
|
+
let activeIndex = -1;
|
|
256
|
+
for (let i = 0; i < this.headings.length; i++) {
|
|
257
|
+
if (this.headings[i].getBoundingClientRect().top <= threshold) {
|
|
258
|
+
activeIndex = i;
|
|
259
|
+
} else {
|
|
260
|
+
break;
|
|
260
261
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// Favor the closer heading: if the next heading is nearer to
|
|
265
|
+
// the threshold than the current one, jump forward.
|
|
266
|
+
if (activeIndex >= 0 && activeIndex + 1 < this.headings.length) {
|
|
267
|
+
const currentDist = threshold - this.headings[activeIndex].getBoundingClientRect().top;
|
|
268
|
+
const nextDist = this.headings[activeIndex + 1].getBoundingClientRect().top - threshold;
|
|
269
|
+
if (nextDist < currentDist) {
|
|
270
|
+
activeIndex = activeIndex + 1;
|
|
268
271
|
}
|
|
272
|
+
}
|
|
269
273
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
if (prevItem) {
|
|
276
|
-
prevItem.selected = false;
|
|
277
|
-
prevItem.active = false;
|
|
278
|
-
}
|
|
279
|
-
this.currentLink?.removeAttribute('aria-current');
|
|
280
|
-
|
|
281
|
-
next.setAttribute('aria-current', 'true');
|
|
282
|
-
const nextItem = next.closest<HTMLElement & { selected: boolean; active: boolean }>('igc-tree-item');
|
|
283
|
-
if (nextItem) nextItem.selected = true;
|
|
274
|
+
// Above the first heading: default to the first item so there
|
|
275
|
+
// is always an active entry when at the top of the page.
|
|
276
|
+
if (activeIndex === -1) {
|
|
277
|
+
activeIndex = 0;
|
|
278
|
+
}
|
|
284
279
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}
|
|
280
|
+
this.setActive(activeIndex);
|
|
281
|
+
}
|
|
288
282
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
* past or back. Sections the user has never reached stay
|
|
296
|
-
* collapsed.
|
|
297
|
-
*/
|
|
298
|
-
private syncExpansion(activeLink: HTMLAnchorElement) {
|
|
299
|
-
let item: Element | null = activeLink.closest('igc-tree-item');
|
|
300
|
-
while (
|
|
301
|
-
item &&
|
|
302
|
-
item.tagName === 'IGC-TREE-ITEM' &&
|
|
303
|
-
this.contains(item)
|
|
304
|
-
) {
|
|
305
|
-
if (!(item as ExpandableEl).expanded) {
|
|
306
|
-
(item as ExpandableEl).expanded = true;
|
|
307
|
-
}
|
|
308
|
-
item = item.parentElement?.closest('igc-tree-item') ?? null;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
283
|
+
private computeThreshold(): number {
|
|
284
|
+
// The bottom edge of the sticky header is the line below which
|
|
285
|
+
// a heading is considered "passed". Add a small fudge so a
|
|
286
|
+
// heading flush against the header still activates.
|
|
287
|
+
if (this.offsetEl) return this.offsetEl.getBoundingClientRect().bottom + 8;
|
|
288
|
+
return DocsToc.DEFAULT_THRESHOLD;
|
|
311
289
|
}
|
|
312
290
|
|
|
313
|
-
|
|
314
|
-
|
|
291
|
+
private setActive(index: number) {
|
|
292
|
+
const next = this.links[index];
|
|
293
|
+
if (!next || next === this.currentLink) return;
|
|
294
|
+
|
|
295
|
+
const prevItem = this.currentLink?.closest<
|
|
296
|
+
HTMLElement & { selected: boolean; active: boolean }
|
|
297
|
+
>('igc-tree-item');
|
|
298
|
+
if (prevItem) {
|
|
299
|
+
prevItem.selected = false;
|
|
300
|
+
prevItem.active = false;
|
|
301
|
+
}
|
|
302
|
+
this.currentLink?.removeAttribute('aria-current');
|
|
303
|
+
|
|
304
|
+
next.setAttribute('aria-current', 'true');
|
|
305
|
+
const nextItem = next.closest<HTMLElement & { selected: boolean; active: boolean }>(
|
|
306
|
+
'igc-tree-item',
|
|
307
|
+
);
|
|
308
|
+
if (nextItem) nextItem.selected = true;
|
|
309
|
+
|
|
310
|
+
this.currentLink = next;
|
|
311
|
+
this.syncExpansion(next);
|
|
315
312
|
}
|
|
316
313
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
314
|
+
/**
|
|
315
|
+
* Additive expansion: walk up from the active anchor through
|
|
316
|
+
* every ancestor <igc-tree-item> (including the active item
|
|
317
|
+
* itself when it has children) and ensure each is `expanded`.
|
|
318
|
+
* Items outside the active path are left untouched, so
|
|
319
|
+
* previously visited sections stay open as the user scrolls
|
|
320
|
+
* past or back. Sections the user has never reached stay
|
|
321
|
+
* collapsed.
|
|
322
|
+
*/
|
|
323
|
+
private syncExpansion(activeLink: HTMLAnchorElement) {
|
|
324
|
+
let item: Element | null = activeLink.closest('igc-tree-item');
|
|
325
|
+
while (item && item.tagName === 'IGC-TREE-ITEM' && this.contains(item)) {
|
|
326
|
+
if (!(item as ExpandableEl).expanded) {
|
|
327
|
+
(item as ExpandableEl).expanded = true;
|
|
328
|
+
}
|
|
329
|
+
item = item.parentElement?.closest('igc-tree-item') ?? null;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
if (!customElements.get('docs-toc')) {
|
|
335
|
+
customElements.define('docs-toc', DocsToc);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// Astro View Transitions: bundled module scripts run only once, so
|
|
339
|
+
// connectedCallback alone won't re-fire after a page swap if the
|
|
340
|
+
// element is morphed rather than replaced. This top-level listener
|
|
341
|
+
// fires on both initial load and after every navigation.
|
|
342
|
+
document.addEventListener('astro:page-load', () => {
|
|
343
|
+
document.querySelectorAll('docs-toc').forEach((el) => {
|
|
344
|
+
if (el instanceof DocsToc) el.init();
|
|
325
345
|
});
|
|
346
|
+
});
|
|
326
347
|
</script>
|