igniteui-astro-components 0.0.24 → 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 +3 -2
- 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 +6 -4
- 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/layouts/DocsLayout/DocsLayout.astro +8 -8
- package/src/layouts/DocsLayout/DocsLayout.scss +18 -0
- package/src/lib/sidebar/types.ts +2 -5
- package/src/scripts/sample-widget.ts +58 -5
- package/src/styles/global/_search-shared.scss +33 -11
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": {
|
|
@@ -92,7 +92,8 @@
|
|
|
92
92
|
"@fontsource-variable/inter": "^5.2.8",
|
|
93
93
|
"@fontsource-variable/jetbrains-mono": "^5.2.8",
|
|
94
94
|
"igniteui-webcomponents": "^7.1.3",
|
|
95
|
-
"jsdom": "^29.0.1"
|
|
95
|
+
"jsdom": "^29.0.1",
|
|
96
|
+
"shiki": "^3.23.0"
|
|
96
97
|
},
|
|
97
98
|
"devDependencies": {
|
|
98
99
|
"@types/jsdom": "^21.1.7",
|
|
@@ -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);
|
|
@@ -161,17 +161,19 @@ import './Search.scss';
|
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
// Keep a result only if it actually contains what was typed: some highlighted
|
|
164
|
-
// word must
|
|
164
|
+
// word must contain one of the query tokens. This rejects Pagefind's prefix
|
|
165
165
|
// fallback — a gibberish query like "asdaasd…" matching the bare "as" on nearly
|
|
166
|
-
// every page
|
|
167
|
-
//
|
|
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.
|
|
168
170
|
function looksRelevant(excerpt: string, queryTokens: string[]): boolean {
|
|
169
171
|
if (queryTokens.length === 0) return true;
|
|
170
172
|
const marks = [...excerpt.matchAll(/<mark[^>]*>([\s\S]*?)<\/mark>/gi)]
|
|
171
173
|
.map((m) => m[1].replace(/<[^>]+>/g, '').replace(/[^a-z0-9]/gi, '').toLowerCase())
|
|
172
174
|
.filter(Boolean);
|
|
173
175
|
if (marks.length === 0) return true;
|
|
174
|
-
return marks.some((h) => queryTokens.some((t) => h.
|
|
176
|
+
return marks.some((h) => queryTokens.some((t) => h.includes(t)));
|
|
175
177
|
}
|
|
176
178
|
|
|
177
179
|
// Pagefind highlights the whole matched word; trim each <mark> down to just the
|
|
@@ -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
|
@@ -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;
|
|
@@ -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;
|
|
@@ -201,7 +204,8 @@
|
|
|
201
204
|
|
|
202
205
|
display: flex;
|
|
203
206
|
justify-self: start;
|
|
204
|
-
|
|
207
|
+
padding: rem(16px);
|
|
208
|
+
border-top: rem(1px) solid var(--ig-gray-100);
|
|
205
209
|
}
|
|
206
210
|
|
|
207
211
|
.igd-search-meta {
|
|
@@ -212,13 +216,14 @@
|
|
|
212
216
|
.igd-search-dialog {
|
|
213
217
|
--background: var(--igd-layout-sections-bg);
|
|
214
218
|
--backdrop: #{color($color: gray, $variant: 800, $opacity: .6)};
|
|
219
|
+
--_mh: min(calc(100vh - #{rem(100px)} - #{rem(64px)}), #{rem(768px)});
|
|
215
220
|
|
|
216
221
|
&::part(base) {
|
|
217
|
-
margin: rem(
|
|
222
|
+
margin: rem(100px) auto rem(64px);
|
|
218
223
|
padding: 0;
|
|
219
224
|
width: 90%;
|
|
220
225
|
max-width: rem(672px);
|
|
221
|
-
max-height:
|
|
226
|
+
max-height: var(--_mh);
|
|
222
227
|
border-radius: rem(8px);
|
|
223
228
|
|
|
224
229
|
overflow: hidden;
|
|
@@ -318,13 +323,31 @@
|
|
|
318
323
|
}
|
|
319
324
|
|
|
320
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;
|
|
321
330
|
padding: 1px;
|
|
322
331
|
border-radius: rem(11px);
|
|
323
|
-
|
|
324
|
-
animation-delay: 1s , 300ms;
|
|
325
|
-
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;
|
|
326
333
|
box-sizing: border-box;
|
|
327
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
|
+
|
|
328
351
|
igc-input {
|
|
329
352
|
--border-color: transparent;
|
|
330
353
|
}
|
|
@@ -383,4 +406,3 @@
|
|
|
383
406
|
--rot: 360deg;
|
|
384
407
|
}
|
|
385
408
|
}
|
|
386
|
-
|