igniteui-astro-components 1.6.0 → 1.7.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/package.json +1 -1
- package/src/components/DocsSidebar/DocsSidebar.astro +14 -2
- package/src/components/DocsSidebar/sidebar-filter.ts +53 -5
- package/src/components/DocsSidebar/toTreeNodes.ts +21 -5
- package/src/components/DocsSubHeader/DocsSubHeader.astro +22 -9
- package/src/components/DocsSubHeader/README.md +14 -1
- package/src/virtual-modules.d.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "igniteui-astro-components",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "Reusable Astro components, layouts, and integrations for Infragistics / Ignite UI documentation sites. Replaces the Starlight defaults with project-specific implementations.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -41,6 +41,12 @@ interface Props {
|
|
|
41
41
|
logoText?: string;
|
|
42
42
|
/** Platform label shown below logoText (e.g. 'Angular'). Auto-detected from virtual module when omitted. */
|
|
43
43
|
platformLabel?: string | null;
|
|
44
|
+
/**
|
|
45
|
+
* Keep one branch of the tree open at a time: only the current page's
|
|
46
|
+
* groups are open on load, and expanding a group collapses the others.
|
|
47
|
+
* The filter still opens every group with a match. Defaults to true.
|
|
48
|
+
*/
|
|
49
|
+
singleBranchExpand?: boolean;
|
|
44
50
|
}
|
|
45
51
|
|
|
46
52
|
const useTrailingSlash = configuredTrailingSlash !== 'never';
|
|
@@ -51,13 +57,19 @@ const {
|
|
|
51
57
|
trailingSlash = useTrailingSlash,
|
|
52
58
|
logoText = ULTIMATE_UI_PLATFORMS.has(virtualPlatform ?? '') ? 'Ultimate UI' : 'Ignite UI',
|
|
53
59
|
platformLabel = platformLabelFor(virtualPlatform),
|
|
60
|
+
singleBranchExpand = true,
|
|
54
61
|
} = Astro.props;
|
|
55
62
|
const items = (itemsProp ?? sidebarData) as SidebarEntry[];
|
|
56
|
-
const nodes = toTreeNodes(items, currentSlug, { trailingSlash });
|
|
63
|
+
const nodes = toTreeNodes(items, currentSlug, { trailingSlash, singleBranch: singleBranchExpand });
|
|
57
64
|
const activeId = normalizeSlug(currentSlug);
|
|
58
65
|
---
|
|
59
66
|
|
|
60
|
-
<sidebar-filter
|
|
67
|
+
<sidebar-filter
|
|
68
|
+
class="docs-sidebar"
|
|
69
|
+
id="docs-sidebar"
|
|
70
|
+
data-no-results="No topics match"
|
|
71
|
+
data-single-branch-expand={singleBranchExpand ? '' : undefined}
|
|
72
|
+
>
|
|
61
73
|
<div class="igd-sidebar-logo">
|
|
62
74
|
{/* Keep as <span>, not <h1> — avoids competing with the page <h1> in search. */}
|
|
63
75
|
<span class="igd-logo-text">{logoText}</span>
|
|
@@ -75,8 +75,13 @@ const collectExpandedKeys = (root: ParentNode): string[] => {
|
|
|
75
75
|
/**
|
|
76
76
|
* Apply expanded state using setAttribute / removeAttribute.
|
|
77
77
|
* Used ONLY in astro:before-swap on not-yet-upgraded DOM nodes.
|
|
78
|
+
* With `onlyActiveBranch`, the saved keys are ignored.
|
|
78
79
|
*/
|
|
79
|
-
const applyExpandedAttr = (
|
|
80
|
+
const applyExpandedAttr = (
|
|
81
|
+
root: ParentNode,
|
|
82
|
+
openKeys: Set<string>,
|
|
83
|
+
onlyActiveBranch: boolean,
|
|
84
|
+
): void => {
|
|
80
85
|
root.querySelectorAll<HTMLElement>(GROUP_SELECTOR).forEach((el) => {
|
|
81
86
|
// Always keep ancestors of the active page open.
|
|
82
87
|
if (el.querySelector('a[aria-current="page"]')) {
|
|
@@ -84,7 +89,7 @@ const applyExpandedAttr = (root: ParentNode, openKeys: Set<string>): void => {
|
|
|
84
89
|
return;
|
|
85
90
|
}
|
|
86
91
|
const key = el.dataset.groupKey;
|
|
87
|
-
if (key && openKeys.has(key)) el.setAttribute('expanded', '');
|
|
92
|
+
if (!onlyActiveBranch && key && openKeys.has(key)) el.setAttribute('expanded', '');
|
|
88
93
|
else el.removeAttribute('expanded');
|
|
89
94
|
});
|
|
90
95
|
};
|
|
@@ -115,13 +120,20 @@ document.addEventListener('astro:before-swap', (e) => {
|
|
|
115
120
|
const newScroll = newDoc.querySelector<HTMLElement>(SCROLL_SELECTOR);
|
|
116
121
|
if (newScroll) newScroll.style.visibility = 'hidden';
|
|
117
122
|
|
|
123
|
+
// Single-branch: the new page's branch replaces the saved one, unless the
|
|
124
|
+
// filter carries over and keeps every group it opened.
|
|
125
|
+
const onlyActiveBranch =
|
|
126
|
+
!!newDoc.querySelector('sidebar-filter[data-single-branch-expand]') &&
|
|
127
|
+
!!newDoc.querySelector(`${GROUP_SELECTOR} a[aria-current="page"]`) &&
|
|
128
|
+
!safeGet(FILTER_KEY);
|
|
129
|
+
|
|
118
130
|
const raw = safeGet(DETAILS_KEY);
|
|
119
|
-
applyExpandedAttr(newDoc, new Set(raw ? raw.split('\n').filter(Boolean) : []));
|
|
131
|
+
applyExpandedAttr(newDoc, new Set(raw ? raw.split('\n').filter(Boolean) : []), onlyActiveBranch);
|
|
120
132
|
});
|
|
121
133
|
|
|
122
134
|
// ── Custom element ───────────────────────────────────────────────────────────
|
|
123
135
|
|
|
124
|
-
type ExpandableEl = HTMLElement & { expanded: boolean };
|
|
136
|
+
type ExpandableEl = HTMLElement & { expanded: boolean; collapseWithEvent(): Promise<void> };
|
|
125
137
|
type FilterInputEl = HTMLElement & { value: string; focus(): void };
|
|
126
138
|
type FilterClearEl = HTMLElement & { hidden: boolean };
|
|
127
139
|
|
|
@@ -185,6 +197,7 @@ class SidebarFilter extends HTMLElement {
|
|
|
185
197
|
// the igc-tree-item instance in event.detail — NOT in e.target.
|
|
186
198
|
this.addEventListener('igcItemExpanded', this.onItemToggle as EventListener);
|
|
187
199
|
this.addEventListener('igcItemCollapsed', this.onItemToggle as EventListener);
|
|
200
|
+
this.addEventListener('igcItemExpanding', this.onItemExpanding as EventListener);
|
|
188
201
|
}
|
|
189
202
|
|
|
190
203
|
private onFilterInput = (): void => {
|
|
@@ -259,6 +272,22 @@ class SidebarFilter extends HTMLElement {
|
|
|
259
272
|
safeSet(DETAILS_KEY, [...keys].join('\n'));
|
|
260
273
|
};
|
|
261
274
|
|
|
275
|
+
/**
|
|
276
|
+
* Single-branch: a user expand collapses every open group outside the new
|
|
277
|
+
* branch. igc-tree's own `singleBranchExpand` isn't used: turning it on
|
|
278
|
+
* collapses every group, the current page's included, and while filtering
|
|
279
|
+
* the next expand would collapse the groups the filter opened.
|
|
280
|
+
*/
|
|
281
|
+
private onItemExpanding = (e: Event): void => {
|
|
282
|
+
// While filtering, every group with a match stays open.
|
|
283
|
+
if (!this.singleBranch || this.openSnapshot) return;
|
|
284
|
+
|
|
285
|
+
const item = (e as CustomEvent<HTMLElement>).detail;
|
|
286
|
+
for (const el of this.groups as ExpandableEl[]) {
|
|
287
|
+
if (el.expanded && !el.contains(item)) void el.collapseWithEvent();
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
|
|
262
291
|
private syncSnapshotAttr(): void {
|
|
263
292
|
if (this.openSnapshot) this.dataset.openSnapshot = [...this.openSnapshot].join('\n');
|
|
264
293
|
else delete this.dataset.openSnapshot;
|
|
@@ -384,7 +413,11 @@ class SidebarFilter extends HTMLElement {
|
|
|
384
413
|
// Clear match marks — CSS restores visibility automatically.
|
|
385
414
|
for (const el of this.items) delete el.dataset.filterMatch;
|
|
386
415
|
|
|
387
|
-
|
|
416
|
+
// Single-branch: return to the current page's branch, not to the groups
|
|
417
|
+
// that were open before filtering, which may be a second branch.
|
|
418
|
+
const restore = this.singleBranch
|
|
419
|
+
? this.activeBranchKeys()
|
|
420
|
+
: (this.preFilterSnapshot ?? this.openSnapshot);
|
|
388
421
|
if (restore) {
|
|
389
422
|
this.withSuppressed(() => this.setExpandedState(restore!));
|
|
390
423
|
safeSet(DETAILS_KEY, [...restore].join('\n'));
|
|
@@ -462,6 +495,21 @@ class SidebarFilter extends HTMLElement {
|
|
|
462
495
|
}
|
|
463
496
|
}
|
|
464
497
|
|
|
498
|
+
private get singleBranch(): boolean {
|
|
499
|
+
return this.hasAttribute('data-single-branch-expand');
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/** Keys of the groups that contain the active page. */
|
|
503
|
+
private activeBranchKeys(): Set<string> {
|
|
504
|
+
const keys = new Set<string>();
|
|
505
|
+
for (const el of this.groups) {
|
|
506
|
+
if (el.dataset.groupKey && el.querySelector('a[aria-current="page"]')) {
|
|
507
|
+
keys.add(el.dataset.groupKey);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
return keys;
|
|
511
|
+
}
|
|
512
|
+
|
|
465
513
|
private ensureActiveAncestorsExpanded(): void {
|
|
466
514
|
const active = this.querySelector<HTMLAnchorElement>('a[aria-current="page"]');
|
|
467
515
|
if (!active) return;
|
|
@@ -14,7 +14,13 @@
|
|
|
14
14
|
|
|
15
15
|
import type { TreeNode } from '../DocsTree/types';
|
|
16
16
|
import type { SidebarEntry } from '../../lib/sidebar/types';
|
|
17
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
hasActive,
|
|
19
|
+
isGroup,
|
|
20
|
+
isInitiallyOpen,
|
|
21
|
+
joinPath,
|
|
22
|
+
normalizeSlug,
|
|
23
|
+
} from '../../lib/sidebar/helpers';
|
|
18
24
|
|
|
19
25
|
const base = import.meta.env.BASE_URL.replace(/\/$/, '');
|
|
20
26
|
|
|
@@ -33,16 +39,20 @@ const toNode = (
|
|
|
33
39
|
ancestors: string[],
|
|
34
40
|
currentSlug: string,
|
|
35
41
|
trailingSlash: boolean,
|
|
42
|
+
singleBranch: boolean,
|
|
36
43
|
): TreeNode => {
|
|
37
44
|
const path = joinPath(ancestors, entry.label);
|
|
38
45
|
|
|
39
46
|
if (isGroup(entry)) {
|
|
47
|
+
const expanded = singleBranch
|
|
48
|
+
? hasActive(entry.items, currentSlug)
|
|
49
|
+
: isInitiallyOpen(entry, currentSlug);
|
|
40
50
|
return {
|
|
41
51
|
id: path,
|
|
42
52
|
label: entry.label,
|
|
43
|
-
expanded:
|
|
53
|
+
expanded: expanded || undefined,
|
|
44
54
|
children: entry.items.map((child) =>
|
|
45
|
-
toNode(child, [...ancestors, entry.label], currentSlug, trailingSlash),
|
|
55
|
+
toNode(child, [...ancestors, entry.label], currentSlug, trailingSlash, singleBranch),
|
|
46
56
|
),
|
|
47
57
|
itemData: {
|
|
48
58
|
path,
|
|
@@ -69,10 +79,16 @@ const toNode = (
|
|
|
69
79
|
export interface ToTreeNodesOptions {
|
|
70
80
|
/** Append trailing slash to sidebar links. Defaults to `true`. */
|
|
71
81
|
trailingSlash?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Open only the groups that contain the current page, ignoring each
|
|
84
|
+
* group's `collapsed` flag. Defaults to `false`.
|
|
85
|
+
*/
|
|
86
|
+
singleBranch?: boolean;
|
|
72
87
|
}
|
|
73
88
|
|
|
74
89
|
export const toTreeNodes = (
|
|
75
90
|
entries: SidebarEntry[],
|
|
76
91
|
currentSlug: string,
|
|
77
|
-
{ trailingSlash = true }: ToTreeNodesOptions = {},
|
|
78
|
-
): TreeNode[] =>
|
|
92
|
+
{ trailingSlash = true, singleBranch = false }: ToTreeNodesOptions = {},
|
|
93
|
+
): TreeNode[] =>
|
|
94
|
+
entries.map((entry) => toNode(entry, [], currentSlug, trailingSlash, singleBranch));
|
|
@@ -73,8 +73,11 @@ interface Props {
|
|
|
73
73
|
* Items for the package/platform selector dropdown. When omitted the selector is hidden.
|
|
74
74
|
* Each entry is either a plain string label, or an object with a `label`, optional `value`
|
|
75
75
|
* (defaults to `label`), and optional `href` to navigate to when selected.
|
|
76
|
+
* Set `base` to the root URL of the entry's docs site to keep the reader on the current
|
|
77
|
+
* page: selecting the entry goes to the current URL with this site's base swapped for `base`.
|
|
78
|
+
* Nothing checks that the page exists there; redirect missing pages on the server.
|
|
76
79
|
*/
|
|
77
|
-
packages?: Array<string | { label: string; value?: string; href?: string }>;
|
|
80
|
+
packages?: Array<string | { label: string; value?: string; href?: string; base?: string }>;
|
|
78
81
|
/** Currently selected package value (must match one of `packages`). */
|
|
79
82
|
selectedPackage?: string;
|
|
80
83
|
/** Label rendered before the package selector. Defaults to `'Package'`. */
|
|
@@ -117,12 +120,12 @@ const resolvedSiteTitle = siteTitleProp ?? siteTitle;
|
|
|
117
120
|
const currentPlatform = virtualPlatform ?? null;
|
|
118
121
|
const resolvedLinks = (productLinksProp ?? productLinks) as ProductLink[];
|
|
119
122
|
const filteredLinks = resolvedLinks.filter((l: ProductLink) => l.platform !== currentPlatform);
|
|
120
|
-
type PackageEntry = string | { label: string; value?: string; href?: string };
|
|
123
|
+
type PackageEntry = string | { label: string; value?: string; href?: string; base?: string };
|
|
121
124
|
const rawPackages = packagesProp ?? (virtualPackages?.length > 0 ? virtualPackages : undefined);
|
|
122
125
|
const packages = (rawPackages as PackageEntry[] | undefined)?.map((p: PackageEntry) =>
|
|
123
126
|
typeof p === 'string'
|
|
124
|
-
? { label: p, value: p, href: undefined }
|
|
125
|
-
: { label: p.label, value: p.value ?? p.label, href: p.href },
|
|
127
|
+
? { label: p, value: p, href: undefined, base: undefined }
|
|
128
|
+
: { label: p.label, value: p.value ?? p.label, href: p.href, base: p.base },
|
|
126
129
|
);
|
|
127
130
|
const selectedPackage =
|
|
128
131
|
selectedPackageProp ?? (virtualSelectedPackage || undefined) ?? packages?.[0]?.value;
|
|
@@ -181,7 +184,7 @@ const platformLabel = platformLabelFor(currentPlatform);
|
|
|
181
184
|
{packages.map((p) => {
|
|
182
185
|
const icon = getPlatformIcon(p.value ?? '') ?? getPlatformIcon(p.label ?? '');
|
|
183
186
|
return (
|
|
184
|
-
<igc-select-item value={p.value} data-href={p.href}>
|
|
187
|
+
<igc-select-item value={p.value} data-href={p.href} data-base={p.base}>
|
|
185
188
|
{icon && (
|
|
186
189
|
<igc-icon slot="prefix" name={icon} collection="docs" aria-hidden="true" />
|
|
187
190
|
)}
|
|
@@ -233,6 +236,18 @@ const platformLabel = platformLabelFor(currentPlatform);
|
|
|
233
236
|
</docs-subheader-menu>
|
|
234
237
|
|
|
235
238
|
<script>
|
|
239
|
+
/**
|
|
240
|
+
* Where selecting a package entry should navigate. With a `base` (root URL of the entry's
|
|
241
|
+
* docs site) it is this page's URL with the site's own base swapped for the entry's; the
|
|
242
|
+
* server handles a page that does not exist there. Otherwise it is the entry's `href`.
|
|
243
|
+
*/
|
|
244
|
+
function packageHref({ href, base }: DOMStringMap): string | undefined {
|
|
245
|
+
const currentBase = import.meta.env.BASE_URL.replace(/\/$/, '');
|
|
246
|
+
const { pathname, search, hash } = window.location;
|
|
247
|
+
if (!base || !pathname.startsWith(currentBase)) return href;
|
|
248
|
+
return `${base.replace(/\/$/, '')}${pathname.slice(currentBase.length)}${search}${hash}`;
|
|
249
|
+
}
|
|
250
|
+
|
|
236
251
|
if (!customElements.get('docs-subheader-menu')) {
|
|
237
252
|
class DocsSubHeaderMenu extends HTMLElement {
|
|
238
253
|
connectedCallback() {
|
|
@@ -276,7 +291,7 @@ const platformLabel = platformLabelFor(currentPlatform);
|
|
|
276
291
|
const item = packageSelect.querySelector<HTMLElement>(
|
|
277
292
|
`igc-select-item[value="${val}"]`,
|
|
278
293
|
);
|
|
279
|
-
const href = item
|
|
294
|
+
const href = item && packageHref(item.dataset);
|
|
280
295
|
if (href) window.location.href = href;
|
|
281
296
|
// Sync tooltip content with the new selection label
|
|
282
297
|
if (packageTooltip) {
|
|
@@ -387,12 +402,10 @@ const platformLabel = platformLabelFor(currentPlatform);
|
|
|
387
402
|
function initSelectors() {
|
|
388
403
|
const packageSelect = document.querySelector('#package-select');
|
|
389
404
|
if (packageSelect) {
|
|
405
|
+
// Navigation on change is handled by <docs-subheader-menu>.
|
|
390
406
|
packageSelect.addEventListener('igcChange', (e: Event) => {
|
|
391
407
|
const val = (e as CustomEvent).detail?.value ?? (packageSelect as any).value;
|
|
392
|
-
const item = packageSelect.querySelector<HTMLElement>(`igc-select-item[value="${val}"]`);
|
|
393
408
|
syncTriggerIcon(packageSelect, val);
|
|
394
|
-
const href = item?.dataset?.href;
|
|
395
|
-
if (href) window.location.href = href;
|
|
396
409
|
});
|
|
397
410
|
}
|
|
398
411
|
}
|
|
@@ -16,7 +16,7 @@ import DocsSubHeader from 'igniteui-astro-components/components/DocsSubHeader.as
|
|
|
16
16
|
| ----------------- | ------------------------------------------------------ | -------------- | ---------------------------------------------------------------------- |
|
|
17
17
|
| `productLinks` | `{ label: string; href: string; platform?: string }[]` | virtual module | Override the cross-product navigation links. |
|
|
18
18
|
| `sidebarItems` | `SidebarEntry[]` | virtual module | Override the sidebar tree used for breadcrumb generation. |
|
|
19
|
-
| `packages` | `string[]`
|
|
19
|
+
| `packages` | `(string \| PackageEntry)[]` | virtual module | Entries for the package selector dropdown. Hidden when omitted. |
|
|
20
20
|
| `selectedPackage` | `string` | — | Currently selected package (must match one of `packages`). |
|
|
21
21
|
| `packageLabel` | `string` | `'Package'` | Label rendered before the package selector. |
|
|
22
22
|
| `versions` | `string[]` | — | Version labels for the version selector dropdown. Hidden when omitted. |
|
|
@@ -25,6 +25,15 @@ import DocsSubHeader from 'igniteui-astro-components/components/DocsSubHeader.as
|
|
|
25
25
|
| `showThemeToggle` | `boolean` | `false` | Show a light/dark theme toggle button. |
|
|
26
26
|
| `themeStorageKey` | `string` | `'docs-theme'` | `localStorage` key for persisting the theme preference. |
|
|
27
27
|
|
|
28
|
+
`PackageEntry` is `{ label: string; value?: string; href?: string; base?: string }`:
|
|
29
|
+
|
|
30
|
+
| Field | Description |
|
|
31
|
+
| ------- | -------------------------------------------------------------------------------- |
|
|
32
|
+
| `label` | Text shown in the dropdown. |
|
|
33
|
+
| `value` | Value matched against `selectedPackage`. Defaults to `label`. |
|
|
34
|
+
| `href` | Where selecting the entry navigates, e.g. the platform's getting started page. |
|
|
35
|
+
| `base` | Root URL of the entry's docs site. Switching keeps the current page (see below). |
|
|
36
|
+
|
|
28
37
|
## Slots
|
|
29
38
|
|
|
30
39
|
| Slot | Default | Description |
|
|
@@ -33,6 +42,10 @@ import DocsSubHeader from 'igniteui-astro-components/components/DocsSubHeader.as
|
|
|
33
42
|
|
|
34
43
|
## Behaviour
|
|
35
44
|
|
|
45
|
+
- Selecting a package navigates to its `href`. When the entry also has a `base`, it goes to the same
|
|
46
|
+
page on that site instead: the current URL with this site's base (`import.meta.env.BASE_URL`)
|
|
47
|
+
swapped for `base`, keeping the query and `#hash`. Nothing checks that the page exists there, so
|
|
48
|
+
the server should redirect missing pages, e.g. to the platform's getting started page.
|
|
36
49
|
- Product links from the virtual module are shown; the currently active platform link is hidden.
|
|
37
50
|
- The search button opens the Pagefind dialog (see `Search` component).
|
|
38
51
|
- CSS custom properties used for positioning:
|
package/src/virtual-modules.d.ts
CHANGED
|
@@ -36,7 +36,7 @@ declare module 'virtual:docs-template/site-meta' {
|
|
|
36
36
|
export const trailingSlash: 'always' | 'never' | 'ignore';
|
|
37
37
|
/** Optional package switcher entries. */
|
|
38
38
|
export const packages:
|
|
39
|
-
Array<string | { label: string; value?: string; href?: string }> | undefined;
|
|
39
|
+
Array<string | { label: string; value?: string; href?: string; base?: string }> | undefined;
|
|
40
40
|
/** Currently selected package. */
|
|
41
41
|
export const selectedPackage: string | undefined;
|
|
42
42
|
}
|