igniteui-astro-components 0.0.23 → 0.0.25
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 +4 -2
- package/src/components/DocsBreadcrumb/DocsBreadcrumb.astro +6 -1
- package/src/components/DocsSidebar/DocsSidebar.scss +1 -0
- package/src/components/DocsSidebar/sidebar-filter.ts +34 -4
- package/src/components/DocsSubHeader/DocsSubHeader.scss +1 -1
- package/src/components/DocsToc/DocsToc.astro +40 -2
- package/src/components/Search/Search.astro +214 -37
- package/src/components/Search/Search.scss +4 -0
- package/src/components/SearchAdvanced/SearchAdvanced.astro +8 -2
- package/src/components/mdx/DocsAside/DocsAside.scss +3 -0
- package/src/components/mdx/Sample/README.md +21 -0
- package/src/components/mdx/Sample/Sample.astro +3 -1
- package/src/components/mdx/Sample/Sample.scss +7 -0
- package/src/index.ts +1 -0
- package/src/integration.ts +3 -0
- package/src/layouts/DocsLayout/DocsLayout.astro +8 -8
- package/src/layouts/DocsLayout/DocsLayout.scss +18 -0
- package/src/lib/sidebar/types.ts +2 -5
- package/src/plugins/rehype-pagefind-ignore.ts +40 -0
- package/src/scripts/sample-widget.ts +58 -5
- package/src/styles/global/_search-shared.scss +47 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "igniteui-astro-components",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.25",
|
|
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": {
|
|
@@ -74,6 +74,7 @@
|
|
|
74
74
|
"./plugins/remark-html-transforms": "./src/plugins/remark-html-transforms.ts",
|
|
75
75
|
"./plugins/rehype-table-wrapper": "./src/plugins/rehype-table-wrapper.ts",
|
|
76
76
|
"./plugins/rehype-heading-anchors": "./src/plugins/rehype-heading-anchors.ts",
|
|
77
|
+
"./plugins/rehype-pagefind-ignore": "./src/plugins/rehype-pagefind-ignore.ts",
|
|
77
78
|
"./styles/theme.scss": "./src/styles/theme.scss",
|
|
78
79
|
"./package.json": "./package.json"
|
|
79
80
|
},
|
|
@@ -91,7 +92,8 @@
|
|
|
91
92
|
"@fontsource-variable/inter": "^5.2.8",
|
|
92
93
|
"@fontsource-variable/jetbrains-mono": "^5.2.8",
|
|
93
94
|
"igniteui-webcomponents": "^7.1.3",
|
|
94
|
-
"jsdom": "^29.0.1"
|
|
95
|
+
"jsdom": "^29.0.1",
|
|
96
|
+
"shiki": "^3.23.0"
|
|
95
97
|
},
|
|
96
98
|
"devDependencies": {
|
|
97
99
|
"@types/jsdom": "^21.1.7",
|
|
@@ -33,10 +33,15 @@ const resolvedSiteTitle = siteTitleProp ?? siteTitleVirtual;
|
|
|
33
33
|
const resolvedSidebar = (sidebarItems ?? sidebarData) as SidebarEntry[];
|
|
34
34
|
const sidebarCrumbs = currentSlug ? getBreadcrumb(resolvedSidebar, currentSlug) : [];
|
|
35
35
|
const crumbs = sidebarCrumbs.length > 0 ? sidebarCrumbs : (pageTitle ? [pageTitle] : []);
|
|
36
|
+
|
|
37
|
+
// Expose the crumb trail as Pagefind `breadcrumb` meta (this nav is inside <main>)
|
|
38
|
+
// for the location line under each search result. Commas split inline meta — strip them.
|
|
39
|
+
const breadcrumbPath = crumbs.join(' › ');
|
|
40
|
+
const breadcrumbMeta = breadcrumbPath.replace(/,/g, '');
|
|
36
41
|
---
|
|
37
42
|
|
|
38
43
|
{(resolvedSiteTitle || crumbs.length > 0) && (
|
|
39
|
-
<nav class="docs-breadcrumb" aria-label="Breadcrumb">
|
|
44
|
+
<nav class="docs-breadcrumb" aria-label="Breadcrumb" data-pagefind-meta={breadcrumbMeta ? `breadcrumb:${breadcrumbMeta}` : undefined}>
|
|
40
45
|
<ol class="docs-breadcrumb-list">
|
|
41
46
|
{ resolvedSiteTitle && (
|
|
42
47
|
<li class="docs-breadcrumb-item docs-breadcrumb-home">
|
|
@@ -268,18 +268,48 @@ class SidebarFilter extends HTMLElement {
|
|
|
268
268
|
requestAnimationFrame(() => {
|
|
269
269
|
sc.scrollTo({ top: parseInt(safeGet(SCROLL_KEY) || '0', 10) || 0, behavior: 'instant' });
|
|
270
270
|
sc.style.visibility = '';
|
|
271
|
+
// After restoring, ensure the active item is visible — it may
|
|
272
|
+
// have shifted due to expand/collapse changes on the new page.
|
|
273
|
+
requestAnimationFrame(() => {
|
|
274
|
+
const active = this.querySelector<HTMLAnchorElement>('a[aria-current="page"]');
|
|
275
|
+
if (active && !this.isElementVisible(active, sc)) {
|
|
276
|
+
this.scrollToCenter(active, sc);
|
|
277
|
+
}
|
|
278
|
+
});
|
|
271
279
|
});
|
|
272
280
|
} else {
|
|
273
|
-
|
|
281
|
+
// On hard refresh, wait for astro:page-load (which scrolls the page
|
|
282
|
+
// back to top and runs initSidebarHeights) before centering.
|
|
283
|
+
document.addEventListener('astro:page-load', () => {
|
|
274
284
|
requestAnimationFrame(() => {
|
|
285
|
+
if (!this.isConnected) return;
|
|
286
|
+
const sidebar = this.closest<HTMLElement>('.docs-sidebar');
|
|
287
|
+
if (sidebar) {
|
|
288
|
+
sidebar.style.maxHeight = Math.max(0, window.innerHeight - sidebar.getBoundingClientRect().top) + 'px';
|
|
289
|
+
}
|
|
275
290
|
sc.style.visibility = '';
|
|
276
291
|
const active = this.querySelector<HTMLAnchorElement>('a[aria-current="page"]');
|
|
277
|
-
active
|
|
278
|
-
})
|
|
279
|
-
);
|
|
292
|
+
if (active) this.scrollToCenter(active, sc);
|
|
293
|
+
});
|
|
294
|
+
}, { once: true });
|
|
280
295
|
}
|
|
281
296
|
}
|
|
282
297
|
|
|
298
|
+
/** Scroll the container so that `el` is vertically centered within it. */
|
|
299
|
+
private scrollToCenter(el: HTMLElement, container: HTMLElement): void {
|
|
300
|
+
const elRect = el.getBoundingClientRect();
|
|
301
|
+
const cRect = container.getBoundingClientRect();
|
|
302
|
+
const elCenter = elRect.top + elRect.height / 2;
|
|
303
|
+
const cCenter = cRect.top + cRect.height / 2;
|
|
304
|
+
container.scrollTop += elCenter - cCenter;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
private isElementVisible(el: HTMLElement, container: HTMLElement): boolean {
|
|
308
|
+
const elRect = el.getBoundingClientRect();
|
|
309
|
+
const cRect = container.getBoundingClientRect();
|
|
310
|
+
return elRect.top >= cRect.top && elRect.bottom <= cRect.bottom;
|
|
311
|
+
}
|
|
312
|
+
|
|
283
313
|
// ── Filter ───────────────────────────────────────────────────────────────
|
|
284
314
|
|
|
285
315
|
private applyFilter(rawQuery: string, source: 'user' | 'restore'): void {
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
--ig-flat-button-icon-color-focus: var(--igd-accent);
|
|
77
77
|
--border-border-radius: var(--igd-border-radius-xl);
|
|
78
78
|
--border-background: light-dark(var(--ig-gray-50), var(--ig-gray-50));
|
|
79
|
-
--border-color:
|
|
79
|
+
--border-color: transparent;
|
|
80
80
|
--hover-border-color: var(--ig-gray-400);
|
|
81
81
|
--focused-border-color: var(--igd-accent);
|
|
82
82
|
}
|
|
@@ -32,7 +32,7 @@ const nodes = headingsToTreeNodes(headings, tocConfig);
|
|
|
32
32
|
---
|
|
33
33
|
|
|
34
34
|
{nodes.length > 0 && (
|
|
35
|
-
<aside class="toc-wrapper">
|
|
35
|
+
<aside class="toc-wrapper" data-pagefind-ignore="all">
|
|
36
36
|
<docs-toc class="toc-sidebar" data-offset-target={offsetTarget}>
|
|
37
37
|
<h2 class="toc-sidebar__heading" id="toc-heading">{label}</h2>
|
|
38
38
|
<nav aria-labelledby="toc-heading">
|
|
@@ -138,6 +138,24 @@ const nodes = headingsToTreeNodes(headings, tocConfig);
|
|
|
138
138
|
window.addEventListener('touchstart', releasePin, opts);
|
|
139
139
|
window.addEventListener('keydown', releasePin, opts);
|
|
140
140
|
|
|
141
|
+
// Browser back/forward navigation: release the pin and re-run the
|
|
142
|
+
// spy so the active item reflects the restored scroll position.
|
|
143
|
+
window.addEventListener('hashchange', () => {
|
|
144
|
+
this.pinnedIndex = undefined;
|
|
145
|
+
requestAnimationFrame(() => this.update());
|
|
146
|
+
}, opts);
|
|
147
|
+
|
|
148
|
+
// popstate covers back/forward cases that hashchange misses:
|
|
149
|
+
// navigating to a URL with no hash, or the same hash as before.
|
|
150
|
+
// Note: do NOT call scrollToHashIfNeeded() here — Chrome fires
|
|
151
|
+
// popstate on anchor clicks too, which would override smooth scroll
|
|
152
|
+
// with an instant jump. The browser handles scroll restoration on
|
|
153
|
+
// back/forward automatically.
|
|
154
|
+
window.addEventListener('popstate', () => {
|
|
155
|
+
this.pinnedIndex = undefined;
|
|
156
|
+
requestAnimationFrame(() => this.update());
|
|
157
|
+
}, opts);
|
|
158
|
+
|
|
141
159
|
this.addEventListener('click', (e) => {
|
|
142
160
|
const target = (e.target as HTMLElement | null)?.closest('a[href^="#"]');
|
|
143
161
|
if (!(target instanceof HTMLAnchorElement)) return;
|
|
@@ -157,7 +175,17 @@ const nodes = headingsToTreeNodes(headings, tocConfig);
|
|
|
157
175
|
// Safari: getBoundingClientRect() may not reflect final layout
|
|
158
176
|
// during the first rAF (before first paint). Schedule one extra
|
|
159
177
|
// update so the initial active item is always correct.
|
|
160
|
-
|
|
178
|
+
// Also re-scroll to the hash now that syncScrollPadding has run
|
|
179
|
+
// and scroll-padding-top reflects the true sticky header height.
|
|
180
|
+
// Without this, a refresh with a #hash in the URL would scroll
|
|
181
|
+
// before the CSS variable is set, landing the heading behind the header.
|
|
182
|
+
requestAnimationFrame(() => {
|
|
183
|
+
this.update();
|
|
184
|
+
// Nest in a second rAF so igc-tree's internal scrollIntoView
|
|
185
|
+
// (triggered by setActive → selected = true) settles first,
|
|
186
|
+
// and our correction scroll wins.
|
|
187
|
+
requestAnimationFrame(() => this.scrollToHashIfNeeded());
|
|
188
|
+
});
|
|
161
189
|
}
|
|
162
190
|
|
|
163
191
|
private bindOffsetTarget() {
|
|
@@ -186,6 +214,16 @@ const nodes = headingsToTreeNodes(headings, tocConfig);
|
|
|
186
214
|
document.documentElement.style.setProperty('--igd-toc-subheader-bottom', `${px}px`);
|
|
187
215
|
}
|
|
188
216
|
|
|
217
|
+
// Re-scroll to the current URL hash so the heading lands below the sticky
|
|
218
|
+
// header once scroll-padding-top has been set correctly by syncScrollPadding.
|
|
219
|
+
private scrollToHashIfNeeded() {
|
|
220
|
+
const hash = window.location.hash;
|
|
221
|
+
if (!hash) return;
|
|
222
|
+
const id = decodeURIComponent(hash.slice(1));
|
|
223
|
+
const el = document.getElementById(id);
|
|
224
|
+
if (el) el.scrollIntoView({ behavior: 'instant', block: 'start' });
|
|
225
|
+
}
|
|
226
|
+
|
|
189
227
|
private update() {
|
|
190
228
|
if (this.pinnedIndex !== undefined) {
|
|
191
229
|
this.setActive(this.pinnedIndex);
|
|
@@ -66,6 +66,9 @@ import './Search.scss';
|
|
|
66
66
|
<div class="igd-search-content">
|
|
67
67
|
<div class="igd-search-status" aria-live="polite"></div>
|
|
68
68
|
<igc-list class="igd-search-results" hidden></igc-list>
|
|
69
|
+
<igc-button class="igd-search-more-btn" variant="flat" type="button" hidden>
|
|
70
|
+
Show more results
|
|
71
|
+
</igc-button>
|
|
69
72
|
</div>
|
|
70
73
|
<footer class="igd-search-footer">
|
|
71
74
|
<igc-button class="search-close" variant="outlined">
|
|
@@ -103,19 +106,50 @@ import './Search.scss';
|
|
|
103
106
|
const base = import.meta.env.BASE_URL.replace(/\/$/, '');
|
|
104
107
|
const _w = window as any;
|
|
105
108
|
|
|
106
|
-
const
|
|
107
|
-
const
|
|
109
|
+
const SEARCH_DEBOUNCE_MS = 200;
|
|
110
|
+
const MIN_QUERY_LEN = 2; // 1 char matches (and whole-word-highlights) everything
|
|
111
|
+
const PAGE_SIZE = 10; // results shown per display page
|
|
112
|
+
const SCAN_BATCH = 20; // raw results fetched per phrase-filter pass
|
|
108
113
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
114
|
+
// Bumped per query; runSearch/renderNextPage bail after each await if it changed,
|
|
115
|
+
// so a slow query can't overwrite a newer one.
|
|
116
|
+
let searchSeq = 0;
|
|
117
|
+
|
|
118
|
+
// Pagination state for the active query. The phrase filter runs client-side, so
|
|
119
|
+
// we scan Pagefind's lazy handles (pfResults) in batches, keep the phrase matches
|
|
120
|
+
// (matches), and page the display over those. rawConsumed counts handles scanned,
|
|
121
|
+
// displayed counts matches rendered.
|
|
122
|
+
let activeSeq = 0;
|
|
123
|
+
let activeTerm = '';
|
|
124
|
+
let activeTokens: string[] = [];
|
|
125
|
+
let pfResults: any[] = [];
|
|
126
|
+
let rawConsumed = 0;
|
|
127
|
+
let matches: any[] = [];
|
|
128
|
+
let displayed = 0;
|
|
129
|
+
let loadingMore = false;
|
|
130
|
+
|
|
131
|
+
// Cache the promise so concurrent first callers share one import/options/init.
|
|
132
|
+
function loadPagefind(): Promise<any> {
|
|
133
|
+
if (_w.__pagefindPromise) return _w.__pagefindPromise;
|
|
134
|
+
_w.__pagefindPromise = (async () => {
|
|
135
|
+
try {
|
|
136
|
+
const pf = await import(/* @vite-ignore */ `${base}/pagefind/pagefind.js`);
|
|
137
|
+
// Must run before init(). Tuned so keyword-dense API pages don't bury prose.
|
|
138
|
+
await pf.options?.({
|
|
139
|
+
ranking: {
|
|
140
|
+
termSaturation: 1.0, // default 1.4
|
|
141
|
+
pageLength: 0.6, // default 0.75
|
|
142
|
+
termFrequency: 1.0,
|
|
143
|
+
termSimilarity: 1.0,
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
await pf.init();
|
|
147
|
+
return pf;
|
|
148
|
+
} catch {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
})();
|
|
152
|
+
return _w.__pagefindPromise;
|
|
119
153
|
}
|
|
120
154
|
|
|
121
155
|
function escapeHtml(s: string): string {
|
|
@@ -126,10 +160,122 @@ import './Search.scss';
|
|
|
126
160
|
.replace(/"/g, '"');
|
|
127
161
|
}
|
|
128
162
|
|
|
163
|
+
// Keep a result only if it actually contains what was typed: some highlighted
|
|
164
|
+
// word must contain one of the query tokens. This rejects Pagefind's prefix
|
|
165
|
+
// fallback — a gibberish query like "asdaasd…" matching the bare "as" on nearly
|
|
166
|
+
// every page (the short highlight can't contain the long query) — while keeping
|
|
167
|
+
// both as-you-type matches ("grid" finds "gridlines") and compound identifiers
|
|
168
|
+
// ("combo" finds "igxCombo"). No body highlights means the match was in the
|
|
169
|
+
// title/meta, which we keep.
|
|
170
|
+
function looksRelevant(excerpt: string, queryTokens: string[]): boolean {
|
|
171
|
+
if (queryTokens.length === 0) return true;
|
|
172
|
+
const marks = [...excerpt.matchAll(/<mark[^>]*>([\s\S]*?)<\/mark>/gi)]
|
|
173
|
+
.map((m) => m[1].replace(/<[^>]+>/g, '').replace(/[^a-z0-9]/gi, '').toLowerCase())
|
|
174
|
+
.filter(Boolean);
|
|
175
|
+
if (marks.length === 0) return true;
|
|
176
|
+
return marks.some((h) => queryTokens.some((t) => h.includes(t)));
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Pagefind highlights the whole matched word; trim each <mark> down to just the
|
|
180
|
+
// typed portion so only what the user typed is highlighted ("config" stays a
|
|
181
|
+
// prefix of <mark>config</mark>uration). Marks whose word isn't one of the typed
|
|
182
|
+
// tokens (e.g. a stem match) are left whole.
|
|
183
|
+
function trimHighlights(excerpt: string): string {
|
|
184
|
+
if (!activeTokens.length) return excerpt;
|
|
185
|
+
return excerpt.replace(/<mark[^>]*>([\s\S]*?)<\/mark>/gi, (full: string, word: string) => {
|
|
186
|
+
const lower = word.toLowerCase();
|
|
187
|
+
let keep = 0;
|
|
188
|
+
for (const t of activeTokens) if (t.length > keep && lower.startsWith(t)) keep = t.length;
|
|
189
|
+
return keep === 0 || keep >= word.length
|
|
190
|
+
? full
|
|
191
|
+
: `<mark>${word.slice(0, keep)}</mark>${word.slice(keep)}`;
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** HTML for a single result row from its resolved Pagefind data. */
|
|
196
|
+
function renderResultItem(r: any): string {
|
|
197
|
+
const title = escapeHtml(r.meta?.title ?? r.url);
|
|
198
|
+
const path = r.meta?.breadcrumb ? escapeHtml(r.meta.breadcrumb) : '';
|
|
199
|
+
return `<igc-list-item>
|
|
200
|
+
<a href="${escapeHtml(r.url)}" class="igd-search-link">
|
|
201
|
+
<span class="igd-search-result-title">${title}</span>
|
|
202
|
+
${path ? `<span class="igd-search-result-path">${path}</span>` : ''}
|
|
203
|
+
<span class="igd-search-result-excerpt">${trimHighlights(r.excerpt ?? '')}</span>
|
|
204
|
+
</a>
|
|
205
|
+
</igc-list-item>`;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Render the empty state for the active query.
|
|
209
|
+
function showNoResults() {
|
|
210
|
+
const statusEl = document.querySelector<HTMLElement>('.igd-search-status');
|
|
211
|
+
const listEl = document.querySelector<any>('igc-list.igd-search-results');
|
|
212
|
+
const moreBtn = document.querySelector<any>('.igd-search-more-btn');
|
|
213
|
+
if (statusEl) statusEl.innerHTML = `<span class="igd-no-results">No results for <strong class="igd-search-query">${escapeHtml(activeTerm)}.</strong></span>`;
|
|
214
|
+
if (listEl) { listEl.innerHTML = ''; listEl.hidden = true; }
|
|
215
|
+
if (moreBtn) moreBtn.hidden = true;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Scan raw Pagefind handles in batches, keeping the relevant matches, until there
|
|
219
|
+
// is at least one unshown display page or all raw results are scanned. Throws if
|
|
220
|
+
// a data() fetch rejects.
|
|
221
|
+
async function ensureMatches(seq: number) {
|
|
222
|
+
while (matches.length - displayed < PAGE_SIZE && rawConsumed < pfResults.length) {
|
|
223
|
+
const slice = pfResults.slice(rawConsumed, rawConsumed + SCAN_BATCH);
|
|
224
|
+
const data = await Promise.all(slice.map((r: any) => r.data()));
|
|
225
|
+
if (seq !== searchSeq) return;
|
|
226
|
+
rawConsumed += slice.length;
|
|
227
|
+
matches.push(...data.filter((r: any) => looksRelevant(r.excerpt ?? '', activeTokens)));
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Append the next page of phrase-matching results, fetching more raw batches as
|
|
232
|
+
// needed. seq ties the work to its query so a stale page can't render.
|
|
233
|
+
async function renderNextPage(seq: number, isFirst = false) {
|
|
234
|
+
const statusEl = document.querySelector<HTMLElement>('.igd-search-status');
|
|
235
|
+
const listEl = document.querySelector<any>('igc-list.igd-search-results');
|
|
236
|
+
const moreBtn = document.querySelector<any>('.igd-search-more-btn');
|
|
237
|
+
if (!statusEl || !listEl) return;
|
|
238
|
+
|
|
239
|
+
if (seq !== searchSeq || loadingMore) return;
|
|
240
|
+
if (displayed >= matches.length && rawConsumed >= pfResults.length) { // nothing more to show
|
|
241
|
+
if (isFirst) showNoResults();
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
loadingMore = true;
|
|
246
|
+
try {
|
|
247
|
+
await ensureMatches(seq);
|
|
248
|
+
} catch {
|
|
249
|
+
if (seq === searchSeq) statusEl.textContent = 'Failed to load search results.';
|
|
250
|
+
return; // finally still clears loadingMore
|
|
251
|
+
} finally {
|
|
252
|
+
loadingMore = false;
|
|
253
|
+
}
|
|
254
|
+
if (seq !== searchSeq) return; // user typed more while data() resolved
|
|
255
|
+
|
|
256
|
+
const slice = matches.slice(displayed, displayed + PAGE_SIZE);
|
|
257
|
+
if (slice.length === 0) { // scanned all raw, nothing matched
|
|
258
|
+
if (isFirst) showNoResults();
|
|
259
|
+
if (moreBtn) moreBtn.hidden = true;
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
displayed += slice.length;
|
|
263
|
+
listEl.insertAdjacentHTML('beforeend', slice.map(renderResultItem).join(''));
|
|
264
|
+
listEl.hidden = false;
|
|
265
|
+
|
|
266
|
+
const total = pfResults.length;
|
|
267
|
+
const more = displayed < matches.length || rawConsumed < pfResults.length;
|
|
268
|
+
statusEl.textContent = more
|
|
269
|
+
? `Showing ${displayed} of ${total} results`
|
|
270
|
+
: `${displayed} result${displayed === 1 ? '' : 's'}`;
|
|
271
|
+
if (moreBtn) moreBtn.hidden = !more;
|
|
272
|
+
}
|
|
273
|
+
|
|
129
274
|
async function runSearch(query: string) {
|
|
130
275
|
const statusEl = document.querySelector<HTMLElement>('.igd-search-status');
|
|
131
276
|
const listEl = document.querySelector<any>('igc-list.igd-search-results');
|
|
132
277
|
const clearBtn = document.querySelector<any>('.igd-search-clear');
|
|
278
|
+
const moreBtn = document.querySelector<any>('.igd-search-more-btn');
|
|
133
279
|
const input = document.querySelector<any>('igc-input.igd-search-input');
|
|
134
280
|
|
|
135
281
|
if (!statusEl || !listEl) return;
|
|
@@ -137,44 +283,73 @@ import './Search.scss';
|
|
|
137
283
|
if (clearBtn) clearBtn.hidden = !query;
|
|
138
284
|
input?.requestUpdate?.();
|
|
139
285
|
|
|
140
|
-
|
|
286
|
+
const term = query.trim();
|
|
287
|
+
if (!term) {
|
|
288
|
+
searchSeq++; // invalidate any in-flight search so a late result can't repopulate
|
|
141
289
|
statusEl.textContent = '';
|
|
142
290
|
listEl.innerHTML = '';
|
|
143
291
|
listEl.hidden = true;
|
|
292
|
+
if (moreBtn) moreBtn.hidden = true;
|
|
144
293
|
return;
|
|
145
294
|
}
|
|
146
295
|
|
|
296
|
+
if (term.length < MIN_QUERY_LEN) {
|
|
297
|
+
searchSeq++; // cancel any in-flight search
|
|
298
|
+
statusEl.textContent = `Type at least ${MIN_QUERY_LEN} characters to search.`;
|
|
299
|
+
listEl.innerHTML = '';
|
|
300
|
+
listEl.hidden = true;
|
|
301
|
+
if (moreBtn) moreBtn.hidden = true;
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const seq = ++searchSeq;
|
|
147
306
|
statusEl.textContent = 'Searching…';
|
|
148
307
|
|
|
149
308
|
const pf = await loadPagefind();
|
|
309
|
+
if (seq !== searchSeq) return; // superseded while loading the index
|
|
150
310
|
if (!pf) {
|
|
151
311
|
statusEl.textContent = 'Search index not available — run a production build first.';
|
|
152
312
|
return;
|
|
153
313
|
}
|
|
154
314
|
|
|
155
|
-
|
|
156
|
-
const results = await Promise.all(
|
|
157
|
-
search.results.slice(0, MAX_RESULTS).map((r: any) => r.data()),
|
|
158
|
-
);
|
|
315
|
+
pf.preload?.(term); // warm the index chunks during the debounce window
|
|
159
316
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
317
|
+
// debouncedSearch returns null when superseded; search() is a fallback for old bundles.
|
|
318
|
+
const search = typeof pf.debouncedSearch === 'function'
|
|
319
|
+
? await pf.debouncedSearch(term, undefined, SEARCH_DEBOUNCE_MS)
|
|
320
|
+
: await pf.search(term);
|
|
321
|
+
if (search === null) return;
|
|
322
|
+
if (seq !== searchSeq) return;
|
|
166
323
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
324
|
+
// New result set — reset pagination and render the first page.
|
|
325
|
+
activeSeq = seq;
|
|
326
|
+
activeTerm = term;
|
|
327
|
+
pfResults = search.results;
|
|
328
|
+
activeTokens = term.toLowerCase().match(/[a-z0-9]+/g) ?? [];
|
|
329
|
+
rawConsumed = 0;
|
|
330
|
+
matches = [];
|
|
331
|
+
displayed = 0;
|
|
332
|
+
listEl.innerHTML = '';
|
|
333
|
+
|
|
334
|
+
await renderNextPage(seq, true);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// Infinite scroll. Bound to both candidates since either may be the real
|
|
338
|
+
// scroll container; the one that doesn't scroll never fires. Bind-once flag.
|
|
339
|
+
function attachInfiniteScroll() {
|
|
340
|
+
const NEAR_BOTTOM_PX = 200;
|
|
341
|
+
const onScroll = (e: Event) => {
|
|
342
|
+
const el = e.currentTarget as HTMLElement;
|
|
343
|
+
if (el.scrollTop + el.clientHeight >= el.scrollHeight - NEAR_BOTTOM_PX) {
|
|
344
|
+
renderNextPage(activeSeq);
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
['.igd-search-content', 'igc-list.igd-search-results'].forEach((sel) => {
|
|
348
|
+
const el = document.querySelector<any>(sel);
|
|
349
|
+
if (!el || el.__infiniteBound) return;
|
|
350
|
+
el.__infiniteBound = true;
|
|
351
|
+
el.addEventListener('scroll', onScroll, { passive: true });
|
|
352
|
+
});
|
|
178
353
|
}
|
|
179
354
|
|
|
180
355
|
async function openSearch() {
|
|
@@ -185,6 +360,7 @@ import './Search.scss';
|
|
|
185
360
|
document.body.toggleAttribute('data-search-modal-open', true);
|
|
186
361
|
await dialog.show();
|
|
187
362
|
loadPagefind();
|
|
363
|
+
attachInfiniteScroll();
|
|
188
364
|
requestAnimationFrame(() => {
|
|
189
365
|
document.querySelector<any>('igc-input.igd-search-input')?.focus();
|
|
190
366
|
});
|
|
@@ -237,12 +413,11 @@ import './Search.scss';
|
|
|
237
413
|
updateSearchHint();
|
|
238
414
|
});
|
|
239
415
|
|
|
240
|
-
let debounceTimer: ReturnType<typeof setTimeout> | null = null;
|
|
241
416
|
document.addEventListener('igcInput', (e: Event) => {
|
|
242
417
|
if (!(e.target as Element).closest('igc-input.igd-search-input')) return;
|
|
243
|
-
if (debounceTimer !== null) clearTimeout(debounceTimer);
|
|
244
418
|
const val = (document.querySelector<any>('igc-input.igd-search-input')?.value as string) ?? '';
|
|
245
|
-
|
|
419
|
+
// Debouncing + supersession are handled inside runSearch via debouncedSearch.
|
|
420
|
+
runSearch(val);
|
|
246
421
|
});
|
|
247
422
|
|
|
248
423
|
document.addEventListener('click', (e: Event) => {
|
|
@@ -255,6 +430,8 @@ import './Search.scss';
|
|
|
255
430
|
runSearch('');
|
|
256
431
|
} else if (target.closest('.search-close')) {
|
|
257
432
|
document.querySelector<any>('igc-dialog.igd-search-dialog')?.hide();
|
|
433
|
+
} else if (target.closest('.igd-search-more-btn')) {
|
|
434
|
+
renderNextPage(activeSeq);
|
|
258
435
|
} else if (target.closest('.igd-search-shell') && target.closest('a[href]')) {
|
|
259
436
|
document.querySelector<any>('igc-dialog.igd-search-dialog')?.hide();
|
|
260
437
|
}
|
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
mark {
|
|
13
13
|
background: transparent;
|
|
14
14
|
color: var(--igd-accent);
|
|
15
|
+
// No padding/margin: a global `mark` rule adds horizontal padding that
|
|
16
|
+
// shows as a gap once we split a word into <mark>prefix</mark>rest.
|
|
17
|
+
padding: 0;
|
|
18
|
+
margin: 0;
|
|
15
19
|
}
|
|
16
20
|
}
|
|
17
21
|
|
|
@@ -149,7 +149,7 @@ const resolvedIndexUrl = indexUrl ?? `${basePath}api-search-index/manifest.json`
|
|
|
149
149
|
</header>
|
|
150
150
|
<div class="igd-search-content">
|
|
151
151
|
<div class="igd-search-status" aria-live="polite"></div>
|
|
152
|
-
<igc-tabs class="igd-search-tabs"></igc-tabs>
|
|
152
|
+
<igc-tabs class="igd-search-tabs" hidden></igc-tabs>
|
|
153
153
|
<igc-list class="igd-search-results--flat" hidden></igc-list>
|
|
154
154
|
</div>
|
|
155
155
|
<footer class="igd-search-footer">
|
|
@@ -892,8 +892,14 @@ const resolvedIndexUrl = indexUrl ?? `${basePath}api-search-index/manifest.json`
|
|
|
892
892
|
);
|
|
893
893
|
}
|
|
894
894
|
|
|
895
|
+
if (totalCount === 0) {
|
|
896
|
+
this.tabsEl.hidden = true;
|
|
897
|
+
this.tabsEl.innerHTML = '';
|
|
898
|
+
return;
|
|
899
|
+
}
|
|
900
|
+
|
|
895
901
|
this.tabsEl.innerHTML = tabsHtml.join('');
|
|
896
|
-
this.tabsEl.hidden =
|
|
902
|
+
this.tabsEl.hidden = false;
|
|
897
903
|
|
|
898
904
|
// Wire "Show more" buttons — select the target tab (its content is already rendered)
|
|
899
905
|
this.tabsEl.querySelectorAll<HTMLButtonElement>('.igd-search-more-btn').forEach((btn) => {
|
|
@@ -51,6 +51,27 @@ The base URLs are resolved from `environment.json` at build time via `siteMetaIn
|
|
|
51
51
|
| `lobDemosBaseUrl` | LOB / grids |
|
|
52
52
|
| `crmDemoBaseUrl` | CRM demos |
|
|
53
53
|
|
|
54
|
+
## Code highlighting
|
|
55
|
+
|
|
56
|
+
Code tabs are syntax-highlighted client-side using [Shiki](https://shiki.style/) (lazy-loaded via dynamic import and pre-warmed at widget init). Supported languages: `typescript`, `tsx`, `javascript`, `html`, `css`, `scss`, `csharp`, `razor`.
|
|
57
|
+
|
|
58
|
+
The theme defaults to `dark-plus` and can be overridden per project via a Vite define in `astro.config.mjs`:
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
// astro.config.mjs
|
|
62
|
+
export default defineConfig({
|
|
63
|
+
vite: {
|
|
64
|
+
define: {
|
|
65
|
+
__IGD_SAMPLE_CODE_THEME__: JSON.stringify('github-dark'),
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Any [Shiki bundled theme](https://shiki.style/themes) name is accepted. If the define is absent the default `dark-plus` is used.
|
|
72
|
+
|
|
73
|
+
> **Note:** highlight.js is no longer required. Remove any hljs `<script>` / `<link>` head entries from your integration config if they were added solely for code tabs.
|
|
74
|
+
|
|
54
75
|
## MDX global registration
|
|
55
76
|
|
|
56
77
|
```ts
|
|
@@ -46,7 +46,9 @@ const baseUrl = lob ? (env.lobDemosBaseUrl ?? env.demosBaseUrl ?? '').replac
|
|
|
46
46
|
: isDv ? (env.dvDemosBaseUrl ?? env.demosBaseUrl ?? '').replace(/\/$/, '')
|
|
47
47
|
: (env.demosBaseUrl ?? '').replace(/\/$/, '');
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
// In prod/staging, append trailing slash to prevent http→https redirects that cause mixed-content errors.
|
|
50
|
+
// In dev, the demos server doesn't perform that redirect, so the replacement is not needed.
|
|
51
|
+
const iframeSrc = import.meta.env.DEV ? `${baseUrl}${src}/` : `${baseUrl}${src}`.replace(/([^/])(\?|$)/, '$1/$2');
|
|
50
52
|
const githubSrc = srcNoSlash;
|
|
51
53
|
|
|
52
54
|
// Stable, unique element ID derived from the sample path.
|
|
@@ -94,6 +94,10 @@ igc-tab::part(tab-header) {
|
|
|
94
94
|
width: 100%;
|
|
95
95
|
border: rem(1px) solid var(--ig-gray-300);
|
|
96
96
|
margin-block-end: rem(26px);
|
|
97
|
+
|
|
98
|
+
.igd-sample-container {
|
|
99
|
+
margin-block-end: 0;
|
|
100
|
+
}
|
|
97
101
|
}
|
|
98
102
|
|
|
99
103
|
.igd-code-view__inner {
|
|
@@ -109,9 +113,12 @@ igc-tab::part(tab-header) {
|
|
|
109
113
|
min-height: rem(320px);
|
|
110
114
|
max-height: rem(800px);
|
|
111
115
|
overflow: hidden auto;
|
|
116
|
+
margin-block-end: rem(26px);
|
|
112
117
|
|
|
113
118
|
iframe {
|
|
114
119
|
display: block;
|
|
120
|
+
border: none;
|
|
121
|
+
margin: 0;
|
|
115
122
|
}
|
|
116
123
|
|
|
117
124
|
.sample-loading-indicator {
|
package/src/index.ts
CHANGED
package/src/integration.ts
CHANGED
|
@@ -66,6 +66,8 @@ export { rehypeTableWrapper } from './plugins/rehype-table-wrapper';
|
|
|
66
66
|
import { rehypeTableWrapper } from './plugins/rehype-table-wrapper';
|
|
67
67
|
import { rehypeHeadingAnchors } from './plugins/rehype-heading-anchors';
|
|
68
68
|
export { rehypeHeadingAnchors } from './plugins/rehype-heading-anchors';
|
|
69
|
+
import { rehypePagefindIgnore } from './plugins/rehype-pagefind-ignore';
|
|
70
|
+
export { rehypePagefindIgnore } from './plugins/rehype-pagefind-ignore';
|
|
69
71
|
import { remarkMdLinks } from './plugins/remark-md-links';
|
|
70
72
|
import { remarkHtmlTransforms } from './plugins/remark-html-transforms';
|
|
71
73
|
|
|
@@ -669,6 +671,7 @@ export function createDocsSite(options: CreateDocsSiteOptions = {} as CreateDocs
|
|
|
669
671
|
rehypeCodeView,
|
|
670
672
|
rehypeTableWrapper,
|
|
671
673
|
rehypeHeadingAnchors,
|
|
674
|
+
rehypePagefindIgnore,
|
|
672
675
|
...((astroExtra as any).markdown?.rehypePlugins ?? []),
|
|
673
676
|
],
|
|
674
677
|
},
|
|
@@ -175,14 +175,14 @@ type HeadEntry = { tag: string; attrs?: Record<string, string | boolean | undefi
|
|
|
175
175
|
if (!sidebar) return;
|
|
176
176
|
var rafId = 0;
|
|
177
177
|
function update() {
|
|
178
|
+
var sidebarTop = sidebar.getBoundingClientRect().top;
|
|
178
179
|
var footerTop = footer.getBoundingClientRect().top;
|
|
179
|
-
//
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
180
|
+
// Always clamp to viewport bottom; additionally clamp to footer
|
|
181
|
+
// top when the footer is on screen.
|
|
182
|
+
var maxH = Math.max(0, window.innerHeight - sidebarTop);
|
|
183
|
+
if (footerTop < window.innerHeight) {
|
|
184
|
+
maxH = Math.max(0, Math.min(maxH, footerTop - sidebarTop));
|
|
183
185
|
}
|
|
184
|
-
var sidebarTop = sidebar.getBoundingClientRect().top;
|
|
185
|
-
var maxH = Math.max(0, Math.min(window.innerHeight - sidebarTop, footerTop - sidebarTop));
|
|
186
186
|
var next = maxH + 'px';
|
|
187
187
|
if (sidebar.style.maxHeight !== next) sidebar.style.maxHeight = next;
|
|
188
188
|
}
|
|
@@ -196,7 +196,7 @@ type HeadEntry = { tag: string; attrs?: Record<string, string | boolean | undefi
|
|
|
196
196
|
window.addEventListener('resize', schedule, { passive: true });
|
|
197
197
|
var ro = new ResizeObserver(schedule);
|
|
198
198
|
ro.observe(footer);
|
|
199
|
-
|
|
199
|
+
update();
|
|
200
200
|
_cleanupSidebarHeights = function() {
|
|
201
201
|
window.removeEventListener('scroll', schedule);
|
|
202
202
|
window.removeEventListener('resize', schedule);
|
|
@@ -256,7 +256,7 @@ type HeadEntry = { tag: string; attrs?: Record<string, string | boolean | undefi
|
|
|
256
256
|
<div class="igd-main-content__inner">
|
|
257
257
|
|
|
258
258
|
<div class="igd-main-content__page">
|
|
259
|
-
<main class="igd-main-content__markdown">
|
|
259
|
+
<main class="igd-main-content__markdown" data-pagefind-body>
|
|
260
260
|
<Fragment set:html={igLogoRaw} />
|
|
261
261
|
<LicenseIndicator license={licenseType} />
|
|
262
262
|
<DocsBreadcrumb pageTitle={ title } currentSlug={ currentSlug } siteTitle={ siteTitleProp }/>
|
|
@@ -195,6 +195,10 @@
|
|
|
195
195
|
|
|
196
196
|
// ── Mobile only (< 768px) ──────────────────────────────────────────────────
|
|
197
197
|
@media (max-width: #{$bp-mobile-max}) {
|
|
198
|
+
.igd-search-content {
|
|
199
|
+
max-height: 100%;
|
|
200
|
+
}
|
|
201
|
+
|
|
198
202
|
.search-decoration {
|
|
199
203
|
width: 40px;
|
|
200
204
|
aspect-ratio: 1;
|
|
@@ -202,6 +206,12 @@
|
|
|
202
206
|
.search-trigger {
|
|
203
207
|
display: none;
|
|
204
208
|
}
|
|
209
|
+
|
|
210
|
+
&:has(.search-trigger:defined)::before {
|
|
211
|
+
animation: rotation 6s linear infinite;
|
|
212
|
+
opacity: 1;
|
|
213
|
+
transition-delay: 500ms;
|
|
214
|
+
}
|
|
205
215
|
}
|
|
206
216
|
|
|
207
217
|
.search-trigger-mobile {
|
|
@@ -290,6 +300,14 @@
|
|
|
290
300
|
|
|
291
301
|
// ── Tablet + Desktop (≥ 768px) ─────────────────────────────────────────────
|
|
292
302
|
@media (min-width: #{$bp-tablet-min}) {
|
|
303
|
+
.search-decoration {
|
|
304
|
+
&:has(.search-trigger-mobile:defined)::before {
|
|
305
|
+
animation: rotation 6s linear infinite;
|
|
306
|
+
opacity: 1;
|
|
307
|
+
transition-delay: 500ms;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
293
311
|
.sidebar-gutter {
|
|
294
312
|
&:has(.igd-sidebar-logo:only-child) {
|
|
295
313
|
display: none;
|
package/src/lib/sidebar/types.ts
CHANGED
|
@@ -6,11 +6,8 @@
|
|
|
6
6
|
* Single source of truth, no duplication.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
| 'updated'
|
|
12
|
-
| 'preview'
|
|
13
|
-
| 'premium';
|
|
9
|
+
export const SIDEBAR_BADGE_VARIANTS = ['new', 'updated', 'preview', 'premium'] as const;
|
|
10
|
+
export type SidebarBadgeVariant = (typeof SIDEBAR_BADGE_VARIANTS)[number];
|
|
14
11
|
|
|
15
12
|
export interface SidebarBadge {
|
|
16
13
|
text: string;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { visit } from 'unist-util-visit';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Marks code with `data-pagefind-ignore` so Pagefind doesn't index it.
|
|
5
|
+
*
|
|
6
|
+
* Code is full of one-letter tokens (generics `T`, escapes `\t`) that Pagefind
|
|
7
|
+
* matches via weak prefix fallback — a search for "twitter" hits the `t` in
|
|
8
|
+
* `keyof T` across unrelated pages. Excluding `<pre>` (and single-char inline
|
|
9
|
+
* `<code>`) removes that noise; real inline `<code>` like `dataSource` stays.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// Concatenate all descendant text of a HAST node.
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
+
function textContent(node: any): string {
|
|
15
|
+
if (node.type === 'text') return node.value ?? '';
|
|
16
|
+
if (!node.children) return '';
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
+
return node.children.map((c: any) => textContent(c)).join('');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function rehypePagefindIgnore() {
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
|
+
return (tree: any) => {
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
+
visit(tree, 'element', (node: any) => {
|
|
26
|
+
const ignore = () => {
|
|
27
|
+
node.properties = { ...node.properties, 'data-pagefind-ignore': 'all' };
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// Fenced code blocks (covers their inner <code> via subtree ignore).
|
|
31
|
+
if (node.tagName === 'pre') return ignore();
|
|
32
|
+
|
|
33
|
+
// Inline code that reduces to a single alphanumeric token.
|
|
34
|
+
if (node.tagName === 'code') {
|
|
35
|
+
const token = textContent(node).replace(/[^a-z0-9]/gi, '');
|
|
36
|
+
if (token.length <= 1) ignore();
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -17,6 +17,7 @@ import { defineComponents, IgcTabsComponent, IgcTabComponent, IgcButtonComponent
|
|
|
17
17
|
defineComponents(IgcTabsComponent, IgcTabComponent, IgcButtonComponent, IgcIconButtonComponent, IgcIconComponent, IgcCircularProgressComponent);
|
|
18
18
|
|
|
19
19
|
import './icon-registry';
|
|
20
|
+
import type { Highlighter } from 'shiki';
|
|
20
21
|
import stackblitzSvg from '../assets/logos/stackblitz.svg?raw';
|
|
21
22
|
import codeSandboxSvg from '../assets/logos/code-sandbox.svg?raw';
|
|
22
23
|
|
|
@@ -38,6 +39,9 @@ const XPLAT_CODE_BASE: Record<string, string> = {
|
|
|
38
39
|
|
|
39
40
|
const DV_PATHS = ['gauges/', 'maps/', 'excel/', 'charts/'];
|
|
40
41
|
const ASSETS_RE = /([.]{0,2}\/)*assets\//g;
|
|
42
|
+
const DEFAULT_CODE_THEME = 'dark-plus';
|
|
43
|
+
|
|
44
|
+
declare const __IGD_SAMPLE_CODE_THEME__: string | undefined;
|
|
41
45
|
|
|
42
46
|
// ─── Types ────────────────────────────────────────────────────────────────────
|
|
43
47
|
|
|
@@ -111,13 +115,57 @@ function replaceRelativeAssetUrls(files: SampleFile[], demosBaseUrl: string): vo
|
|
|
111
115
|
});
|
|
112
116
|
}
|
|
113
117
|
|
|
118
|
+
// ─── Code Highlighting ────────────────────────────────────────────────────────
|
|
119
|
+
|
|
120
|
+
const LANG_MAP: Record<string, string> = { js: 'javascript', ts: 'typescript', cs: 'csharp' };
|
|
121
|
+
|
|
122
|
+
const SHIKI_LANGS = ['text', 'typescript', 'tsx', 'javascript', 'html', 'css', 'scss', 'csharp', 'razor'] as const;
|
|
123
|
+
|
|
124
|
+
let _highlighterPromise: Promise<Highlighter> | null = null;
|
|
125
|
+
|
|
126
|
+
function getCodeTheme(): string {
|
|
127
|
+
return typeof __IGD_SAMPLE_CODE_THEME__ === 'string' && __IGD_SAMPLE_CODE_THEME__.trim()
|
|
128
|
+
? __IGD_SAMPLE_CODE_THEME__
|
|
129
|
+
: DEFAULT_CODE_THEME;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function getHighlighter(): Promise<Highlighter> {
|
|
133
|
+
if (!_highlighterPromise) {
|
|
134
|
+
_highlighterPromise = import('shiki')
|
|
135
|
+
.then(({ createHighlighter }) => createHighlighter({ themes: [getCodeTheme()], langs: [...SHIKI_LANGS] }))
|
|
136
|
+
.catch((err) => {
|
|
137
|
+
_highlighterPromise = null;
|
|
138
|
+
throw err;
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
return _highlighterPromise;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function highlightCode(codeEl: HTMLElement, lang: string): void {
|
|
145
|
+
const safeLang = (SHIKI_LANGS as readonly string[]).includes(lang) ? lang : 'text';
|
|
146
|
+
getHighlighter().then(h => {
|
|
147
|
+
const tmp = document.createElement('div');
|
|
148
|
+
tmp.innerHTML = h.codeToHtml(codeEl.textContent ?? '', { lang: safeLang, theme: getCodeTheme() });
|
|
149
|
+
const shikiPre = tmp.firstElementChild as HTMLElement | null;
|
|
150
|
+
const shikiCode = shikiPre?.querySelector('code');
|
|
151
|
+
if (!shikiPre || !shikiCode) return;
|
|
152
|
+
const parentPre = codeEl.parentElement;
|
|
153
|
+
if (parentPre) parentPre.style.cssText = shikiPre.style.cssText;
|
|
154
|
+
codeEl.innerHTML = shikiCode.innerHTML;
|
|
155
|
+
}).catch(console.warn);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function normalizeCodeLang(lang: string | undefined): string {
|
|
159
|
+
return LANG_MAP[lang ?? ''] ?? lang ?? 'text';
|
|
160
|
+
}
|
|
161
|
+
|
|
114
162
|
// ─── Code Tab Rendering ───────────────────────────────────────────────────────
|
|
115
163
|
|
|
116
164
|
function addCodeTab(
|
|
117
165
|
igcTabs: HTMLElement,
|
|
118
166
|
file: SampleFile,
|
|
119
167
|
): void {
|
|
120
|
-
const lang =
|
|
168
|
+
const lang = normalizeCodeLang(file.fileExtension);
|
|
121
169
|
|
|
122
170
|
const tab = document.createElement('igc-tab');
|
|
123
171
|
tab.setAttribute('label', file.fileHeader.toUpperCase());
|
|
@@ -157,9 +205,7 @@ function addCodeTab(
|
|
|
157
205
|
tab.appendChild(wrapper);
|
|
158
206
|
igcTabs.appendChild(tab);
|
|
159
207
|
|
|
160
|
-
|
|
161
|
-
(window as any).hljs.highlightElement(code);
|
|
162
|
-
}
|
|
208
|
+
highlightCode(code, lang);
|
|
163
209
|
}
|
|
164
210
|
|
|
165
211
|
// ─── Footer / Live Edit Buttons ───────────────────────────────────────────────
|
|
@@ -480,6 +526,11 @@ class XplatCodeService {
|
|
|
480
526
|
* `.ig-code-view` elements managed by code-view.js.
|
|
481
527
|
*/
|
|
482
528
|
export function initSampleWidgets(): void {
|
|
529
|
+
// Kick off the Shiki download immediately so it is ready before the user
|
|
530
|
+
// opens a code tab (tabs appear only after an IntersectionObserver fires
|
|
531
|
+
// + a JSON fetch completes, giving Shiki time to load in parallel).
|
|
532
|
+
getHighlighter().catch(() => {});
|
|
533
|
+
|
|
483
534
|
// Serial iframe-load queue. Loading all iframes simultaneously causes the
|
|
484
535
|
// browser to parse and execute many JS bundles at once, freezing the main
|
|
485
536
|
// thread. Instead we load one iframe at a time: next starts only after the
|
|
@@ -538,6 +589,8 @@ export function initSampleWidgets(): void {
|
|
|
538
589
|
const icon = btn?.querySelector<HTMLElement>('igc-icon');
|
|
539
590
|
const code = pre.querySelector<HTMLElement>('code');
|
|
540
591
|
if (!btn || !code) return;
|
|
592
|
+
const codeLang = (code.className.match(/language-(\S+)/) ?? [])[1] ?? 'text';
|
|
593
|
+
highlightCode(code, normalizeCodeLang(codeLang));
|
|
541
594
|
btn.addEventListener('click', () => {
|
|
542
595
|
navigator.clipboard.writeText(code.textContent ?? '').then(() => {
|
|
543
596
|
icon?.setAttribute('name', 'check');
|
|
@@ -562,7 +615,7 @@ export function initSampleWidgets(): void {
|
|
|
562
615
|
}
|
|
563
616
|
}
|
|
564
617
|
|
|
565
|
-
if (!demosBaseUrl) return;
|
|
618
|
+
if (!demosBaseUrl && !isXplatPlatform(platform)) return;
|
|
566
619
|
|
|
567
620
|
const service = isXplatPlatform(platform)
|
|
568
621
|
? new XplatCodeService(platform)
|
|
@@ -22,9 +22,13 @@
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
.igd-search-content {
|
|
25
|
-
display:
|
|
26
|
-
|
|
27
|
-
overflow:
|
|
25
|
+
display: flex;
|
|
26
|
+
flex-direction: column;
|
|
27
|
+
overflow: hidden;
|
|
28
|
+
|
|
29
|
+
// Constrain the content area so only the list scrolls, not the whole dialog.
|
|
30
|
+
// --_mh is set on .igd-search-dialog; --search-header-footer-height on .igd-search-shell.
|
|
31
|
+
max-height: calc(var(--_mh) - var(--search-header-footer-height));
|
|
28
32
|
|
|
29
33
|
// min-width: 0 is necessary to allow the content to shrink below its min-content width
|
|
30
34
|
// otherwise igc-tabs won't show the scroll buttons
|
|
@@ -39,7 +43,6 @@
|
|
|
39
43
|
|
|
40
44
|
display: grid;
|
|
41
45
|
place-items: center;
|
|
42
|
-
height: 100%;
|
|
43
46
|
padding: 0 rem(16px) rem(16px) rem(16px) ;
|
|
44
47
|
border-bottom: rem(1px) solid var(--ig-gray-200);
|
|
45
48
|
text-align: center;
|
|
@@ -132,6 +135,20 @@
|
|
|
132
135
|
}
|
|
133
136
|
}
|
|
134
137
|
|
|
138
|
+
// Breadcrumb location line under the result title.
|
|
139
|
+
.igd-search-result-path {
|
|
140
|
+
@include type-style('caption') {
|
|
141
|
+
margin: 0;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
color: light-dark(var(--ig-gray-500), var(--ig-gray-400));
|
|
145
|
+
|
|
146
|
+
mark {
|
|
147
|
+
background: transparent;
|
|
148
|
+
color: var(--igd-accent);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
135
152
|
.igd-search-kind {
|
|
136
153
|
@include type-style('caption') {
|
|
137
154
|
margin-block: 0;
|
|
@@ -187,7 +204,8 @@
|
|
|
187
204
|
|
|
188
205
|
display: flex;
|
|
189
206
|
justify-self: start;
|
|
190
|
-
|
|
207
|
+
padding: rem(16px);
|
|
208
|
+
border-top: rem(1px) solid var(--ig-gray-100);
|
|
191
209
|
}
|
|
192
210
|
|
|
193
211
|
.igd-search-meta {
|
|
@@ -198,14 +216,14 @@
|
|
|
198
216
|
.igd-search-dialog {
|
|
199
217
|
--background: var(--igd-layout-sections-bg);
|
|
200
218
|
--backdrop: #{color($color: gray, $variant: 800, $opacity: .6)};
|
|
219
|
+
--_mh: min(calc(100vh - #{rem(100px)} - #{rem(64px)}), #{rem(768px)});
|
|
201
220
|
|
|
202
221
|
&::part(base) {
|
|
203
|
-
margin: auto;
|
|
222
|
+
margin: rem(100px) auto rem(64px);
|
|
204
223
|
padding: 0;
|
|
205
224
|
width: 90%;
|
|
206
225
|
max-width: rem(672px);
|
|
207
|
-
height:
|
|
208
|
-
max-height: rem(768px);
|
|
226
|
+
max-height: var(--_mh);
|
|
209
227
|
border-radius: rem(8px);
|
|
210
228
|
|
|
211
229
|
overflow: hidden;
|
|
@@ -305,13 +323,31 @@
|
|
|
305
323
|
}
|
|
306
324
|
|
|
307
325
|
.search-decoration {
|
|
326
|
+
--search-decoration-background: conic-gradient(from var(--rot) at 50% 50%, var(--igd-accent) -56.25deg, var(--igd-accent) 43.12deg, var(--ig-secondary-500) 180deg, var(--igd-accent) 303.75deg, var(--igd-accent) 403.12deg);
|
|
327
|
+
|
|
328
|
+
position: relative;
|
|
329
|
+
isolation: isolate;
|
|
308
330
|
padding: 1px;
|
|
309
331
|
border-radius: rem(11px);
|
|
310
|
-
|
|
311
|
-
animation-delay: 1s , 300ms;
|
|
312
|
-
background: conic-gradient(from var(--rot) at 50% 50%, var(--igd-accent) -56.25deg, var(--igd-accent) 43.12deg, var(--ig-secondary-500) 180deg, var(--igd-accent) 303.75deg, var(--igd-accent) 403.12deg);
|
|
332
|
+
background: transparent;
|
|
313
333
|
box-sizing: border-box;
|
|
314
334
|
|
|
335
|
+
&::before {
|
|
336
|
+
content: '';
|
|
337
|
+
position: absolute;
|
|
338
|
+
inset: 0;
|
|
339
|
+
z-index: 0;
|
|
340
|
+
border-radius: inherit;
|
|
341
|
+
background: var(--search-decoration-background);
|
|
342
|
+
opacity: 0;
|
|
343
|
+
transition: opacity 150ms ease;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
> * {
|
|
347
|
+
position: relative;
|
|
348
|
+
z-index: 1;
|
|
349
|
+
}
|
|
350
|
+
|
|
315
351
|
igc-input {
|
|
316
352
|
--border-color: transparent;
|
|
317
353
|
}
|
|
@@ -370,4 +406,3 @@
|
|
|
370
406
|
--rot: 360deg;
|
|
371
407
|
}
|
|
372
408
|
}
|
|
373
|
-
|