igniteui-astro-components 0.0.26 → 0.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/README.md +82 -74
  2. package/package.json +16 -9
  3. package/src/components/CopyCode/CopyCode.astro +21 -7
  4. package/src/components/DocsBreadcrumb/DocsBreadcrumb.astro +33 -21
  5. package/src/components/DocsBreadcrumb/DocsBreadcrumb.scss +44 -43
  6. package/src/components/DocsBreadcrumb/README.md +10 -14
  7. package/src/components/DocsSidebar/DocsSidebar.astro +47 -45
  8. package/src/components/DocsSidebar/DocsSidebar.scss +120 -122
  9. package/src/components/DocsSidebar/README.md +25 -21
  10. package/src/components/DocsSidebar/SidebarFilterInput.astro +24 -29
  11. package/src/components/DocsSidebar/SidebarFilterInput.scss +90 -89
  12. package/src/components/DocsSidebar/SidebarLabel.astro +35 -26
  13. package/src/components/DocsSidebar/sidebar-filter.ts +93 -56
  14. package/src/components/DocsSubHeader/DocsSubHeader.astro +256 -185
  15. package/src/components/DocsSubHeader/DocsSubHeader.scss +181 -169
  16. package/src/components/DocsSubHeader/README.md +18 -16
  17. package/src/components/DocsToc/DocsToc.astro +301 -280
  18. package/src/components/DocsToc/DocsToc.scss +20 -21
  19. package/src/components/DocsToc/README.md +11 -9
  20. package/src/components/DocsToc/toTreeNodes.ts +3 -8
  21. package/src/components/DocsTree/DocsTree.astro +32 -20
  22. package/src/components/DocsTree/DocsTreeItem.astro +35 -30
  23. package/src/components/DocsTree/README.md +16 -15
  24. package/src/components/DocsTree/docs-tree.scss +267 -268
  25. package/src/components/GlobalFooter/GlobalFooter.astro +10 -10
  26. package/src/components/GlobalFooter/README.md +3 -2
  27. package/src/components/GlobalNavBar/GlobalNavBar.astro +4 -2
  28. package/src/components/GlobalNavBar/GlobalNavBar.module.scss +222 -222
  29. package/src/components/GlobalNavBar/README.md +3 -2
  30. package/src/components/LicenseIndicator/LicenseIndicator.astro +7 -5
  31. package/src/components/LicenseIndicator/LicenseIndicator.scss +3 -3
  32. package/src/components/MobileSidebarToggle/MobileSidebarToggle.astro +16 -17
  33. package/src/components/MobileSidebarToggle/README.md +3 -2
  34. package/src/components/MobileTocToggle/MobileTocToggle.astro +75 -61
  35. package/src/components/MobileTocToggle/MobileTocToggle.scss +65 -59
  36. package/src/components/Search/README.md +1 -0
  37. package/src/components/Search/Search.astro +137 -109
  38. package/src/components/Search/Search.scss +20 -20
  39. package/src/components/SearchAdvanced/README.md +21 -15
  40. package/src/components/SearchAdvanced/SearchAdvanced.astro +220 -133
  41. package/src/components/SearchAdvanced/SearchAdvanced.scss +152 -153
  42. package/src/components/mdx/ApiLink/ApiLink.astro +133 -113
  43. package/src/components/mdx/ApiLink/ApiLink.scss +9 -9
  44. package/src/components/mdx/ApiLink/README.md +26 -22
  45. package/src/components/mdx/ApiLink/api-link-index.ts +196 -173
  46. package/src/components/mdx/ApiRef/ApiRef.astro +54 -51
  47. package/src/components/mdx/ApiRef/README.md +20 -15
  48. package/src/components/mdx/Badge/Badge.astro +14 -14
  49. package/src/components/mdx/Badge/Badge.scss +61 -56
  50. package/src/components/mdx/Badge/README.md +24 -19
  51. package/src/components/mdx/DocsAside/DocsAside.astro +30 -37
  52. package/src/components/mdx/DocsAside/DocsAside.scss +82 -82
  53. package/src/components/mdx/DocsAside/README.md +22 -22
  54. package/src/components/mdx/Faq/Faq.astro +86 -0
  55. package/src/components/mdx/Faq/Faq.scss +105 -0
  56. package/src/components/mdx/Faq/FaqItem.astro +117 -0
  57. package/src/components/mdx/Faq/README.md +223 -0
  58. package/src/components/mdx/Faq/types.ts +34 -0
  59. package/src/components/mdx/PlatformBlock/PlatformBlock.astro +3 -2
  60. package/src/components/mdx/PlatformBlock/README.md +6 -8
  61. package/src/components/mdx/Sample/README.md +21 -16
  62. package/src/components/mdx/Sample/Sample.astro +97 -74
  63. package/src/components/mdx/Sample/Sample.scss +132 -132
  64. package/src/content-helper.ts +71 -72
  65. package/src/content.config.ts +1 -6
  66. package/src/integration.ts +566 -512
  67. package/src/layouts/DocsLayout/DocsLayout.astro +228 -182
  68. package/src/layouts/DocsLayout/DocsLayout.scss +261 -261
  69. package/src/layouts/DocsLayout/README.md +24 -35
  70. package/src/lib/nav-helpers.ts +88 -82
  71. package/src/lib/types.ts +76 -76
  72. package/src/llms.ts +205 -166
  73. package/src/platform.ts +312 -162
  74. package/src/plugins/rehype-heading-anchors.ts +45 -45
  75. package/src/plugins/rehype-pagefind-ignore.ts +19 -19
  76. package/src/plugins/rehype-table-wrapper.ts +30 -30
  77. package/src/plugins/remark-docfx.ts +12 -0
  78. package/src/plugins/remark-env-vars.ts +12 -4
  79. package/src/plugins/remark-md-links.ts +10 -4
  80. package/src/scripts/icon-manifest.ts +13 -5
  81. package/src/scripts/sample-widget.ts +557 -501
  82. package/src/sidebar.ts +103 -97
  83. package/src/styles/global/_code-blocks.scss +43 -44
  84. package/src/styles/global/_component-themes.scss +151 -153
  85. package/src/styles/global/_icon-gallery.scss +81 -81
  86. package/src/styles/global/_index.scss +0 -1
  87. package/src/styles/global/_markdown.scss +816 -787
  88. package/src/styles/global/_palette.scss +456 -110
  89. package/src/styles/global/_search-shared.scss +402 -398
  90. package/src/styles/global/_type-scale.scss +127 -127
  91. package/src/styles/global/_variables.scss +138 -111
  92. package/src/styles/theme.scss +49 -40
  93. package/src/virtual-modules.d.ts +11 -2
@@ -13,31 +13,45 @@
13
13
  * Selector: `.igd-code-view[data-platform]`
14
14
  */
15
15
 
16
- import { defineComponents, IgcTabsComponent, IgcTabComponent, IgcButtonComponent, IgcIconButtonComponent, IgcIconComponent, IgcCircularProgressComponent } from 'igniteui-webcomponents';
17
- defineComponents(IgcTabsComponent, IgcTabComponent, IgcButtonComponent, IgcIconButtonComponent, IgcIconComponent, IgcCircularProgressComponent);
16
+ import {
17
+ defineComponents,
18
+ IgcTabsComponent,
19
+ IgcTabComponent,
20
+ IgcButtonComponent,
21
+ IgcIconButtonComponent,
22
+ IgcIconComponent,
23
+ IgcCircularProgressComponent,
24
+ } from 'igniteui-webcomponents';
25
+ defineComponents(
26
+ IgcTabsComponent,
27
+ IgcTabComponent,
28
+ IgcButtonComponent,
29
+ IgcIconButtonComponent,
30
+ IgcIconComponent,
31
+ IgcCircularProgressComponent,
32
+ );
18
33
 
19
34
  import './icon-registry';
20
35
  import type { Highlighter } from 'shiki';
21
36
  import stackblitzSvg from '../assets/logos/stackblitz.svg?raw';
22
- import codeSandboxSvg from '../assets/logos/code-sandbox.svg?raw';
23
37
 
24
38
  // ─── Constants ────────────────────────────────────────────────────────────────
25
39
 
26
40
  const SAMPLES_ORDER = ['modules', 'ts', 'html', 'scss', 'css'];
27
41
 
28
42
  const XPLAT_SAMPLES_ORDER: Record<string, string[]> = {
29
- react: ['tsx', 'ts', 'html', 'css'],
30
- wc: ['tsx', 'ts', 'html', 'css'],
31
- blazor: ['razor', 'cs', 'js', 'css'],
43
+ react: ['tsx', 'ts', 'html', 'css'],
44
+ wc: ['tsx', 'ts', 'html', 'css'],
45
+ blazor: ['razor', 'cs', 'js', 'css'],
32
46
  };
33
47
 
34
48
  const XPLAT_CODE_BASE: Record<string, string> = {
35
- wc: '/assets/code-viewer/',
36
- react: '/code-viewer/',
37
- blazor: '/code-viewer/',
49
+ wc: '/assets/code-viewer/',
50
+ react: '/code-viewer/',
51
+ blazor: '/code-viewer/',
38
52
  };
39
53
 
40
- const DV_PATHS = ['gauges/', 'maps/', 'excel/', 'charts/'];
54
+ const DV_PATHS = ['gauges/', 'maps/', 'excel/', 'charts/'];
41
55
  const ASSETS_RE = /([.]{0,2}\/)*assets\//g;
42
56
  const DEFAULT_CODE_THEME = 'dark-plus';
43
57
 
@@ -46,20 +60,20 @@ declare const __IGD_SAMPLE_CODE_THEME__: string | undefined;
46
60
  // ─── Types ────────────────────────────────────────────────────────────────────
47
61
 
48
62
  interface SampleFile {
49
- fileExtension: string;
50
- fileHeader: string;
51
- content: string;
52
- isMain: boolean;
53
- path?: string;
63
+ fileExtension: string;
64
+ fileHeader: string;
65
+ content: string;
66
+ isMain: boolean;
67
+ path?: string;
54
68
  }
55
69
 
56
70
  interface WidgetContext {
57
- widget: HTMLElement;
58
- iframeSrc: string;
59
- demosBaseUrl: string;
60
- widgetIndex: number;
61
- igcTabs: HTMLElement;
62
- githubSrc: string;
71
+ widget: HTMLElement;
72
+ iframeSrc: string;
73
+ demosBaseUrl: string;
74
+ widgetIndex: number;
75
+ igcTabs: HTMLElement;
76
+ githubSrc: string;
63
77
  }
64
78
 
65
79
  // ─── Helpers ──────────────────────────────────────────────────────────────────
@@ -69,450 +83,471 @@ interface WidgetContext {
69
83
  * platform-context.ts returns 'webcomponents' but XPLAT_* tables use 'wc'.
70
84
  */
71
85
  function normalizePlatform(raw: string): string {
72
- if (raw === 'webcomponents' || raw === 'web-components') return 'wc';
73
- return raw;
86
+ if (raw === 'webcomponents' || raw === 'web-components') return 'wc';
87
+ return raw;
74
88
  }
75
89
 
76
90
  function isXplatPlatform(platform: string): boolean {
77
- return platform === 'react' || platform === 'wc' || platform === 'blazor';
91
+ return platform === 'react' || platform === 'wc' || platform === 'blazor';
78
92
  }
79
93
 
80
94
  function getSamplePath(iframeSrc: string, demosBaseUrl: string): string {
81
- return iframeSrc
82
- .replace(demosBaseUrl + '/', '')
83
- .replace(/\?.*/, '')
84
- .replace(/\/$/, '');
95
+ return iframeSrc
96
+ .replace(demosBaseUrl + '/', '')
97
+ .replace(/\?.*/, '')
98
+ .replace(/\/$/, '');
85
99
  }
86
100
 
87
101
  function isDvSample(samplePath: string): boolean {
88
- return DV_PATHS.some(p => samplePath.startsWith(p));
102
+ return DV_PATHS.some((p) => samplePath.startsWith(p));
89
103
  }
90
104
 
91
105
  function getRepoBranch(demosBaseUrl: string, isDv: boolean): string {
92
- const host = new URL(demosBaseUrl).host;
93
- const isNonProd = host.includes('staging')
94
- || window.location.hostname === 'localhost'
95
- || window.location.hostname === '127.0.0.1';
96
- if (isDv) return 'vnext';
97
- return isNonProd ? 'vNext' : 'master';
106
+ const host = new URL(demosBaseUrl).host;
107
+ const isNonProd =
108
+ host.includes('staging') ||
109
+ window.location.hostname === 'localhost' ||
110
+ window.location.hostname === '127.0.0.1';
111
+ if (isDv) return 'vnext';
112
+ return isNonProd ? 'vNext' : 'master';
98
113
  }
99
114
 
100
115
  function getXplatBranch(demosBaseUrl: string): string {
101
- const host = new URL(demosBaseUrl).host;
102
- const isNonProd = host.includes('staging')
103
- || window.location.hostname === 'localhost'
104
- || window.location.hostname === '127.0.0.1';
105
- return isNonProd ? 'vnext' : 'master';
116
+ const host = new URL(demosBaseUrl).host;
117
+ const isNonProd =
118
+ host.includes('staging') ||
119
+ window.location.hostname === 'localhost' ||
120
+ window.location.hostname === '127.0.0.1';
121
+ return isNonProd ? 'vnext' : 'master';
106
122
  }
107
123
 
108
124
  function replaceRelativeAssetUrls(files: SampleFile[], demosBaseUrl: string): void {
109
- const assetsBase = demosBaseUrl.replace(/\/$/, '') + '/assets/';
110
- files.forEach(f => {
111
- if (f.content && ASSETS_RE.test(f.content)) {
112
- f.content = f.content.replace(ASSETS_RE, assetsBase);
113
- }
114
- ASSETS_RE.lastIndex = 0;
115
- });
125
+ const assetsBase = demosBaseUrl.replace(/\/$/, '') + '/assets/';
126
+ files.forEach((f) => {
127
+ if (f.content && ASSETS_RE.test(f.content)) {
128
+ f.content = f.content.replace(ASSETS_RE, assetsBase);
129
+ }
130
+ ASSETS_RE.lastIndex = 0;
131
+ });
116
132
  }
117
133
 
118
134
  // ─── Code Highlighting ────────────────────────────────────────────────────────
119
135
 
120
136
  const LANG_MAP: Record<string, string> = { js: 'javascript', ts: 'typescript', cs: 'csharp' };
121
137
 
122
- const SHIKI_LANGS = ['text', 'typescript', 'tsx', 'javascript', 'html', 'css', 'scss', 'csharp', 'razor'] as const;
138
+ const SHIKI_LANGS = [
139
+ 'text',
140
+ 'typescript',
141
+ 'tsx',
142
+ 'javascript',
143
+ 'html',
144
+ 'css',
145
+ 'scss',
146
+ 'csharp',
147
+ 'razor',
148
+ ] as const;
123
149
 
124
150
  let _highlighterPromise: Promise<Highlighter> | null = null;
125
151
 
126
152
  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;
153
+ return typeof __IGD_SAMPLE_CODE_THEME__ === 'string' && __IGD_SAMPLE_CODE_THEME__.trim()
154
+ ? __IGD_SAMPLE_CODE_THEME__
155
+ : DEFAULT_CODE_THEME;
130
156
  }
131
157
 
132
158
  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;
159
+ if (!_highlighterPromise) {
160
+ _highlighterPromise = import('shiki')
161
+ .then(({ createHighlighter }) =>
162
+ createHighlighter({ themes: [getCodeTheme()], langs: [...SHIKI_LANGS] }),
163
+ )
164
+ .catch((err) => {
165
+ _highlighterPromise = null;
166
+ throw err;
167
+ });
168
+ }
169
+ return _highlighterPromise;
142
170
  }
143
171
 
144
172
  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);
173
+ const safeLang = (SHIKI_LANGS as readonly string[]).includes(lang) ? lang : 'text';
174
+ getHighlighter()
175
+ .then((h) => {
176
+ const tmp = document.createElement('div');
177
+ tmp.innerHTML = h.codeToHtml(codeEl.textContent ?? '', {
178
+ lang: safeLang,
179
+ theme: getCodeTheme(),
180
+ });
181
+ const shikiPre = tmp.firstElementChild as HTMLElement | null;
182
+ const shikiCode = shikiPre?.querySelector('code');
183
+ if (!shikiPre || !shikiCode) return;
184
+ const parentPre = codeEl.parentElement;
185
+ if (parentPre) parentPre.style.cssText = shikiPre.style.cssText;
186
+ codeEl.innerHTML = shikiCode.innerHTML;
187
+ })
188
+ .catch(console.warn);
156
189
  }
157
190
 
158
191
  function normalizeCodeLang(lang: string | undefined): string {
159
- return LANG_MAP[lang ?? ''] ?? lang ?? 'text';
192
+ return LANG_MAP[lang ?? ''] ?? lang ?? 'text';
160
193
  }
161
194
 
162
195
  // ─── Code Tab Rendering ───────────────────────────────────────────────────────
163
196
 
164
- function addCodeTab(
165
- igcTabs: HTMLElement,
166
- file: SampleFile,
167
- ): void {
168
- const lang = normalizeCodeLang(file.fileExtension);
169
-
170
- const tab = document.createElement('igc-tab');
171
- tab.setAttribute('label', file.fileHeader.toUpperCase());
172
-
173
- const wrapper = document.createElement('div');
174
- wrapper.className = 'code-wrapper';
175
-
176
- const pre = document.createElement('pre');
177
- const code = document.createElement('code');
178
- code.className = `language-${lang}`;
179
- code.textContent = file.content;
180
- pre.appendChild(code);
181
-
182
- const copyBtn = document.createElement('igc-icon-button') as HTMLElement;
183
- copyBtn.setAttribute('variant', 'outlined');
184
- copyBtn.setAttribute('aria-label', 'Copy code');
185
- copyBtn.className = 'cv-hljs-code-copy';
186
-
187
- const copyIcon = document.createElement('igc-icon');
188
- copyIcon.setAttribute('name', 'copy');
189
- copyIcon.setAttribute('collection', 'docs');
190
- copyBtn.appendChild(copyIcon);
191
-
192
- copyBtn.addEventListener('click', () => {
193
- navigator.clipboard.writeText(file.content).then(() => {
194
- copyIcon.setAttribute('name', 'check');
195
- copyBtn.setAttribute('aria-label', 'Code copied');
196
- setTimeout(() => {
197
- copyIcon.setAttribute('name', 'copy');
198
- copyBtn.setAttribute('aria-label', 'Copy code');
199
- }, 1500);
200
- });
197
+ function addCodeTab(igcTabs: HTMLElement, file: SampleFile): void {
198
+ const lang = normalizeCodeLang(file.fileExtension);
199
+
200
+ const tab = document.createElement('igc-tab');
201
+ tab.setAttribute('label', file.fileHeader.toUpperCase());
202
+
203
+ const wrapper = document.createElement('div');
204
+ wrapper.className = 'code-wrapper';
205
+
206
+ const pre = document.createElement('pre');
207
+ const code = document.createElement('code');
208
+ code.className = `language-${lang}`;
209
+ code.textContent = file.content;
210
+ pre.appendChild(code);
211
+
212
+ const copyBtn = document.createElement('igc-icon-button') as HTMLElement;
213
+ copyBtn.setAttribute('variant', 'outlined');
214
+ copyBtn.setAttribute('aria-label', 'Copy code');
215
+ copyBtn.className = 'cv-hljs-code-copy';
216
+
217
+ const copyIcon = document.createElement('igc-icon');
218
+ copyIcon.setAttribute('name', 'copy');
219
+ copyIcon.setAttribute('collection', 'docs');
220
+ copyBtn.appendChild(copyIcon);
221
+
222
+ copyBtn.addEventListener('click', () => {
223
+ navigator.clipboard.writeText(file.content).then(() => {
224
+ copyIcon.setAttribute('name', 'check');
225
+ copyBtn.setAttribute('aria-label', 'Code copied');
226
+ setTimeout(() => {
227
+ copyIcon.setAttribute('name', 'copy');
228
+ copyBtn.setAttribute('aria-label', 'Copy code');
229
+ }, 1500);
201
230
  });
231
+ });
202
232
 
203
- wrapper.appendChild(pre);
204
- wrapper.appendChild(copyBtn);
205
- tab.appendChild(wrapper);
206
- igcTabs.appendChild(tab);
233
+ wrapper.appendChild(pre);
234
+ wrapper.appendChild(copyBtn);
235
+ tab.appendChild(wrapper);
236
+ igcTabs.appendChild(tab);
207
237
 
208
- highlightCode(code, lang);
238
+ highlightCode(code, lang);
209
239
  }
210
240
 
211
241
  // ─── Footer / Live Edit Buttons ───────────────────────────────────────────────
212
242
 
213
243
  function addFooter(
214
- widget: HTMLElement,
215
- iframeSrc: string,
216
- explicitEditor: string | null,
217
- onStackblitz: (() => void) | null,
218
- onCodeSandbox: (() => void) | null,
244
+ widget: HTMLElement,
245
+ iframeSrc: string,
246
+ explicitEditor: string | null,
247
+ onStackblitz: (() => void) | null,
248
+ _onCodeSandbox: (() => void) | null,
219
249
  ): void {
220
- const footer = document.createElement('div');
221
- footer.className = 'igd-code-view__footer-actions';
222
-
223
- if ((!explicitEditor || explicitEditor === 'stackblitz') && onStackblitz) {
224
- const btn = document.createElement('igc-button') as HTMLElement;
225
- btn.setAttribute('variant', 'outlined');
226
- btn.setAttribute('aria-label', 'Edit in StackBlitz');
227
- btn.className = 'stackblitz-btn igd-edit-in-btn';
228
- btn.innerHTML = stackblitzSvg;
229
- btn.addEventListener('click', onStackblitz);
230
- footer.appendChild(btn);
231
- }
232
-
233
- // CodeSandbox hidden, re-enable when https://github.com/codesandbox/codesandbox-client/issues/8884 is fixed.
234
- // https://github.com/codesandbox/codesandbox-client/issues/8883
235
- // https://github.com/codesandbox/codesandbox-client/issues/8074
236
- // if ((!explicitEditor || explicitEditor === 'csb') && onCodeSandbox) {
237
- // const btn = document.createElement('igc-button') as HTMLElement;
238
- // btn.setAttribute('variant', 'outlined');
239
- // btn.setAttribute('aria-label', 'Edit in CodeSandbox');
240
- // btn.className = 'codesandbox-btn igd-edit-in-btn';
241
- // btn.innerHTML = codeSandboxSvg;
242
- // btn.addEventListener('click', onCodeSandbox);
243
- // footer.appendChild(btn);
244
- // }
245
-
246
- const fsBtn = document.createElement('igc-icon-button') as HTMLElement;
247
- fsBtn.setAttribute('name', 'open-link-blank');
248
- fsBtn.setAttribute('collection', 'docs');
249
- fsBtn.setAttribute('variant', 'outlined');
250
- fsBtn.setAttribute('aria-label', 'Open in full screen');
251
- fsBtn.className = 'igd-full-screen-btn igd-edit-in-btn';
252
- if (iframeSrc) {
253
- const fullscreenSrc = iframeSrc + (iframeSrc.includes('?') ? '&' : '?') + 'nav=0';
254
- fsBtn.setAttribute('href', fullscreenSrc);
255
- fsBtn.setAttribute('target', '_blank');
256
- }
257
- footer.appendChild(fsBtn);
258
-
259
- widget.appendChild(footer);
250
+ const footer = document.createElement('div');
251
+ footer.className = 'igd-code-view__footer-actions';
252
+
253
+ if ((!explicitEditor || explicitEditor === 'stackblitz') && onStackblitz) {
254
+ const btn = document.createElement('igc-button') as HTMLElement;
255
+ btn.setAttribute('variant', 'outlined');
256
+ btn.setAttribute('aria-label', 'Edit in StackBlitz');
257
+ btn.className = 'stackblitz-btn igd-edit-in-btn';
258
+ btn.innerHTML = stackblitzSvg;
259
+ btn.addEventListener('click', onStackblitz);
260
+ footer.appendChild(btn);
261
+ }
262
+
263
+ // CodeSandbox hidden, re-enable when https://github.com/codesandbox/codesandbox-client/issues/8884 is fixed.
264
+ // https://github.com/codesandbox/codesandbox-client/issues/8883
265
+ // https://github.com/codesandbox/codesandbox-client/issues/8074
266
+ // if ((!explicitEditor || explicitEditor === 'csb') && onCodeSandbox) {
267
+ // const btn = document.createElement('igc-button') as HTMLElement;
268
+ // btn.setAttribute('variant', 'outlined');
269
+ // btn.setAttribute('aria-label', 'Edit in CodeSandbox');
270
+ // btn.className = 'codesandbox-btn igd-edit-in-btn';
271
+ // btn.innerHTML = codeSandboxSvg;
272
+ // btn.addEventListener('click', onCodeSandbox);
273
+ // footer.appendChild(btn);
274
+ // }
275
+
276
+ const fsBtn = document.createElement('igc-icon-button') as HTMLElement;
277
+ fsBtn.setAttribute('name', 'open-link-blank');
278
+ fsBtn.setAttribute('collection', 'docs');
279
+ fsBtn.setAttribute('variant', 'outlined');
280
+ fsBtn.setAttribute('aria-label', 'Open in full screen');
281
+ fsBtn.className = 'igd-full-screen-btn igd-edit-in-btn';
282
+ if (iframeSrc) {
283
+ const fullscreenSrc = iframeSrc + (iframeSrc.includes('?') ? '&' : '?') + 'nav=0';
284
+ fsBtn.setAttribute('href', fullscreenSrc);
285
+ fsBtn.setAttribute('target', '_blank');
286
+ }
287
+ footer.appendChild(fsBtn);
288
+
289
+ widget.appendChild(footer);
260
290
  }
261
291
 
262
292
  // ─── Angular Code Service ─────────────────────────────────────────────────────
263
293
 
264
294
  class AngularCodeService {
265
- async init(ctx: WidgetContext): Promise<void> {
266
- const { widget, iframeSrc, demosBaseUrl, widgetIndex, igcTabs } = ctx;
267
- const samplePath = getSamplePath(iframeSrc, demosBaseUrl);
268
- const isDv = isDvSample(samplePath);
269
- const assetDir = isDv ? 'code-viewer' : 'samples';
270
- const fallbackStackblitz = () => this._openStackBlitzUrl(samplePath, demosBaseUrl);
271
- const fallbackCodeSandbox = () => this._openCodeSandboxUrl(samplePath, demosBaseUrl);
272
-
273
- try {
274
- const metaRes = await fetch(
275
- `${demosBaseUrl}/assets/samples/meta.json?t=${Date.now()}`,
276
- { credentials: 'omit' },
277
- );
278
- if (!metaRes.ok) throw new Error(`meta.json ${metaRes.status}`);
279
- const { generationTimeStamp } = await metaRes.json();
280
-
281
- const sampleJsonPath = isDv
282
- ? `${demosBaseUrl}/assets/${assetDir}/${samplePath}.json`
283
- : `${demosBaseUrl}/assets/${assetDir}/${samplePath.replace('/', '--')}.json`;
284
-
285
- const [sampleRes, sharedRes] = await Promise.all([
286
- fetch(`${sampleJsonPath}?t=${generationTimeStamp}`, { credentials: 'omit' }),
287
- fetch(`${demosBaseUrl}/assets/samples/shared.json?t=${generationTimeStamp}`, { credentials: 'omit' }),
288
- ]);
289
- if (!sampleRes.ok) throw new Error(`sample JSON ${sampleRes.status}`);
290
-
291
- const [sampleData, sharedData] = await Promise.all([
292
- sampleRes.json(),
293
- sharedRes.ok ? sharedRes.json() : Promise.resolve(null),
294
- ]);
295
-
296
- replaceRelativeAssetUrls(sampleData.sampleFiles || [], demosBaseUrl);
297
- if (sharedData) replaceRelativeAssetUrls(sharedData.files || [], demosBaseUrl);
298
-
299
- (sampleData.sampleFiles || [] as SampleFile[])
300
- .filter((f: SampleFile) => f.isMain)
301
- .sort((a: SampleFile, b: SampleFile) =>
302
- SAMPLES_ORDER.indexOf(a.fileHeader) - SAMPLES_ORDER.indexOf(b.fileHeader))
303
- .forEach((file: SampleFile) =>
304
- addCodeTab(igcTabs, file));
305
-
306
- // DV samples include all boilerplate in their own JSON, sharedData is for non DV only.
307
- const onStackblitz = isDv
308
- ? () => this._openInStackBlitz(sampleData, null)
309
- : () => this._openInStackBlitz(sampleData, sharedData);
310
- addFooter(widget, iframeSrc, null, onStackblitz, fallbackCodeSandbox);
311
-
312
- } catch (err: any) {
313
- console.warn('[sample-widget] Could not fetch Angular sample files:', err.message);
314
- addFooter(widget, iframeSrc, null, fallbackStackblitz, fallbackCodeSandbox);
315
- }
316
- }
317
-
318
- private async _openInStackBlitz(sampleData: any, sharedData: any): Promise<void> {
319
- let sdk: any;
320
- try {
321
- sdk = await this._loadStackBlitzSdk();
322
- } catch (e: any) {
323
- console.warn('[sample-widget] StackBlitz SDK failed to load:', e.message);
324
- return;
325
- }
326
- const files: Record<string, string> = {};
327
- const addFile = (f: any) => {
328
- if (!f.path || f.path.startsWith('..')) return;
329
- files[f.path.replace(/^\.\//, '')] = f.content || '';
330
- };
331
- (sharedData?.files || []).forEach(addFile); // shared boilerplate for non-DV samples
332
- (sampleData.sampleFiles || []).forEach(addFile);
333
- sdk.openProject(
334
- {
335
- title: 'Infragistics Angular Components',
336
- description: 'Auto-generated from Infragistics Angular Docs',
337
- template: 'node',
338
- files,
339
- tags: ['angular', 'material', 'cdk', 'web', 'example'],
340
- },
341
- { openFile: 'src/app/app.component.ts' },
342
- );
343
- }
344
-
345
- private _loadStackBlitzSdk(): Promise<any> {
346
- if ((window as any).StackBlitzSDK) return Promise.resolve((window as any).StackBlitzSDK);
347
- return new Promise((resolve, reject) => {
348
- const s = document.createElement('script');
349
- s.src = 'https://unpkg.com/@stackblitz/sdk/bundles/sdk.umd.js';
350
- s.onload = () => resolve((window as any).StackBlitzSDK);
351
- s.onerror = () => reject(new Error('Failed to load StackBlitz SDK'));
352
- document.head.appendChild(s);
353
- });
295
+ async init(ctx: WidgetContext): Promise<void> {
296
+ const { widget, iframeSrc, demosBaseUrl, igcTabs } = ctx;
297
+ const samplePath = getSamplePath(iframeSrc, demosBaseUrl);
298
+ const isDv = isDvSample(samplePath);
299
+ const assetDir = isDv ? 'code-viewer' : 'samples';
300
+ const fallbackStackblitz = () => this._openStackBlitzUrl(samplePath, demosBaseUrl);
301
+ const fallbackCodeSandbox = () => this._openCodeSandboxUrl(samplePath, demosBaseUrl);
302
+
303
+ try {
304
+ const metaRes = await fetch(`${demosBaseUrl}/assets/samples/meta.json?t=${Date.now()}`, {
305
+ credentials: 'omit',
306
+ });
307
+ if (!metaRes.ok) throw new Error(`meta.json ${metaRes.status}`);
308
+ const { generationTimeStamp } = await metaRes.json();
309
+
310
+ const sampleJsonPath = isDv
311
+ ? `${demosBaseUrl}/assets/${assetDir}/${samplePath}.json`
312
+ : `${demosBaseUrl}/assets/${assetDir}/${samplePath.replace('/', '--')}.json`;
313
+
314
+ const [sampleRes, sharedRes] = await Promise.all([
315
+ fetch(`${sampleJsonPath}?t=${generationTimeStamp}`, { credentials: 'omit' }),
316
+ fetch(`${demosBaseUrl}/assets/samples/shared.json?t=${generationTimeStamp}`, {
317
+ credentials: 'omit',
318
+ }),
319
+ ]);
320
+ if (!sampleRes.ok) throw new Error(`sample JSON ${sampleRes.status}`);
321
+
322
+ const [sampleData, sharedData] = await Promise.all([
323
+ sampleRes.json(),
324
+ sharedRes.ok ? sharedRes.json() : Promise.resolve(null),
325
+ ]);
326
+
327
+ replaceRelativeAssetUrls(sampleData.sampleFiles || [], demosBaseUrl);
328
+ if (sharedData) replaceRelativeAssetUrls(sharedData.files || [], demosBaseUrl);
329
+
330
+ (sampleData.sampleFiles || ([] as SampleFile[]))
331
+ .filter((f: SampleFile) => f.isMain)
332
+ .sort(
333
+ (a: SampleFile, b: SampleFile) =>
334
+ SAMPLES_ORDER.indexOf(a.fileHeader) - SAMPLES_ORDER.indexOf(b.fileHeader),
335
+ )
336
+ .forEach((file: SampleFile) => addCodeTab(igcTabs, file));
337
+
338
+ // DV samples include all boilerplate in their own JSON, sharedData is for non DV only.
339
+ const onStackblitz = isDv
340
+ ? () => this._openInStackBlitz(sampleData, null)
341
+ : () => this._openInStackBlitz(sampleData, sharedData);
342
+ addFooter(widget, iframeSrc, null, onStackblitz, fallbackCodeSandbox);
343
+ } catch (err: any) {
344
+ console.warn('[sample-widget] Could not fetch Angular sample files:', err.message);
345
+ addFooter(widget, iframeSrc, null, fallbackStackblitz, fallbackCodeSandbox);
354
346
  }
355
-
356
- private _openCodeSandboxUrl(samplePath: string, demosBaseUrl: string): void {
357
- const isDv = isDvSample(samplePath);
358
- const branch = getRepoBranch(demosBaseUrl, isDv);
359
- const repo = isDv ? 'igniteui-angular-examples' : 'igniteui-live-editing-samples';
360
- const segs = new URL(demosBaseUrl).pathname.replace(/\/$/, '').split('/').filter(Boolean);
361
- const prefix = isDv ? 'samples/' : (segs.pop() || 'angular-demos') + '/';
362
- window.open(
363
- `https://codesandbox.io/p/sandbox/github/IgniteUI/${repo}/tree/${branch}/${prefix}${samplePath}`,
364
- '_blank',
365
- );
366
- }
367
-
368
- private _openStackBlitzUrl(samplePath: string, demosBaseUrl: string): void {
369
- const isDv = isDvSample(samplePath);
370
- const branch = getRepoBranch(demosBaseUrl, isDv);
371
- const repo = isDv ? 'igniteui-angular-examples' : 'igniteui-live-editing-samples';
372
- const segs = new URL(demosBaseUrl).pathname.replace(/\/$/, '').split('/').filter(Boolean);
373
- const prefix = isDv ? 'samples/' : (segs.pop() || 'angular-demos') + '/';
374
- const params = isDv ? '?startScript=start' : '';
375
- window.open(
376
- `https://stackblitz.com/github/IgniteUI/${repo}/tree/${branch}/${prefix}${samplePath}${params}`,
377
- '_blank',
378
- );
347
+ }
348
+
349
+ private async _openInStackBlitz(sampleData: any, sharedData: any): Promise<void> {
350
+ let sdk: any;
351
+ try {
352
+ sdk = await this._loadStackBlitzSdk();
353
+ } catch (e: any) {
354
+ console.warn('[sample-widget] StackBlitz SDK failed to load:', e.message);
355
+ return;
379
356
  }
357
+ const files: Record<string, string> = {};
358
+ const addFile = (f: any) => {
359
+ if (!f.path || f.path.startsWith('..')) return;
360
+ files[f.path.replace(/^\.\//, '')] = f.content || '';
361
+ };
362
+ (sharedData?.files || []).forEach(addFile); // shared boilerplate for non-DV samples
363
+ (sampleData.sampleFiles || []).forEach(addFile);
364
+ sdk.openProject(
365
+ {
366
+ title: 'Infragistics Angular Components',
367
+ description: 'Auto-generated from Infragistics Angular Docs',
368
+ template: 'node',
369
+ files,
370
+ tags: ['angular', 'material', 'cdk', 'web', 'example'],
371
+ },
372
+ { openFile: 'src/app/app.component.ts' },
373
+ );
374
+ }
375
+
376
+ private _loadStackBlitzSdk(): Promise<any> {
377
+ if ((window as any).StackBlitzSDK) return Promise.resolve((window as any).StackBlitzSDK);
378
+ return new Promise((resolve, reject) => {
379
+ const s = document.createElement('script');
380
+ s.src = 'https://unpkg.com/@stackblitz/sdk/bundles/sdk.umd.js';
381
+ s.onload = () => resolve((window as any).StackBlitzSDK);
382
+ s.onerror = () => reject(new Error('Failed to load StackBlitz SDK'));
383
+ document.head.appendChild(s);
384
+ });
385
+ }
386
+
387
+ private _openCodeSandboxUrl(samplePath: string, demosBaseUrl: string): void {
388
+ const isDv = isDvSample(samplePath);
389
+ const branch = getRepoBranch(demosBaseUrl, isDv);
390
+ const repo = isDv ? 'igniteui-angular-examples' : 'igniteui-live-editing-samples';
391
+ const segs = new URL(demosBaseUrl).pathname.replace(/\/$/, '').split('/').filter(Boolean);
392
+ const prefix = isDv ? 'samples/' : (segs.pop() || 'angular-demos') + '/';
393
+ window.open(
394
+ `https://codesandbox.io/p/sandbox/github/IgniteUI/${repo}/tree/${branch}/${prefix}${samplePath}`,
395
+ '_blank',
396
+ );
397
+ }
398
+
399
+ private _openStackBlitzUrl(samplePath: string, demosBaseUrl: string): void {
400
+ const isDv = isDvSample(samplePath);
401
+ const branch = getRepoBranch(demosBaseUrl, isDv);
402
+ const repo = isDv ? 'igniteui-angular-examples' : 'igniteui-live-editing-samples';
403
+ const segs = new URL(demosBaseUrl).pathname.replace(/\/$/, '').split('/').filter(Boolean);
404
+ const prefix = isDv ? 'samples/' : (segs.pop() || 'angular-demos') + '/';
405
+ const params = isDv ? '?startScript=start' : '';
406
+ window.open(
407
+ `https://stackblitz.com/github/IgniteUI/${repo}/tree/${branch}/${prefix}${samplePath}${params}`,
408
+ '_blank',
409
+ );
410
+ }
380
411
  }
381
412
 
382
413
  // ─── Xplat Code Service ───────────────────────────────────────────────────────
383
414
 
384
415
  class XplatCodeService {
385
- private platform: string;
386
- private samplesOrder: string[];
387
- private codeBase: string;
388
- private enableLiveEditing: boolean;
389
-
390
- constructor(platform: string) {
391
- this.platform = platform;
392
- this.samplesOrder = XPLAT_SAMPLES_ORDER[platform] || ['ts', 'html', 'css'];
393
- this.codeBase = XPLAT_CODE_BASE[platform] || '/code-viewer/';
394
- this.enableLiveEditing = platform !== 'blazor';
416
+ private platform: string;
417
+ private samplesOrder: string[];
418
+ private codeBase: string;
419
+ private enableLiveEditing: boolean;
420
+
421
+ constructor(platform: string) {
422
+ this.platform = platform;
423
+ this.samplesOrder = XPLAT_SAMPLES_ORDER[platform] || ['ts', 'html', 'css'];
424
+ this.codeBase = XPLAT_CODE_BASE[platform] || '/code-viewer/';
425
+ this.enableLiveEditing = platform !== 'blazor';
426
+ }
427
+
428
+ async init(ctx: WidgetContext): Promise<void> {
429
+ const { widget, iframeSrc, demosBaseUrl, igcTabs, githubSrc } = ctx;
430
+ const samplePath = getSamplePath(iframeSrc, demosBaseUrl);
431
+ const fallbackStackblitz = () => this._openStackBlitzUrl(githubSrc, demosBaseUrl);
432
+ const fallbackCodeSandbox = () => this._openCodeSandbox(githubSrc, demosBaseUrl);
433
+
434
+ try {
435
+ // Blazor's local dev server uses a self-signed cert on a non-4200 port,
436
+ // causing CORS errors. Use a relative URL so Vite's proxy handles it.
437
+ // On staging/production, use the full demosBaseUrl like other xplat platforms.
438
+ const isLocalDev =
439
+ window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1';
440
+ const jsonUrl =
441
+ this.platform === 'blazor' && isLocalDev
442
+ ? `${this.codeBase}${samplePath}.json`
443
+ : `${demosBaseUrl}${this.codeBase}${samplePath}.json`;
444
+
445
+ const res = await fetch(jsonUrl, { credentials: 'omit' });
446
+ if (!res.ok) throw new Error(`xplat sample JSON ${res.status}`);
447
+ const data = await res.json();
448
+
449
+ (data.sampleFiles || ([] as SampleFile[]))
450
+ .filter((f: SampleFile) => f.isMain)
451
+ .sort(
452
+ (a: SampleFile, b: SampleFile) =>
453
+ this.samplesOrder.indexOf(a.fileHeader) - this.samplesOrder.indexOf(b.fileHeader),
454
+ )
455
+ .forEach((file: SampleFile) => addCodeTab(igcTabs, file));
456
+
457
+ if (this.enableLiveEditing && githubSrc) {
458
+ // Use sdk.openProject() to avoid the StackBlitz GitHub clone freeze bug.
459
+ addFooter(widget, iframeSrc, null, () => this._openInStackBlitz(data), fallbackCodeSandbox);
460
+ }
461
+ } catch (err: any) {
462
+ console.warn('[sample-widget] Could not fetch xplat sample files:', err.message);
463
+ if (this.enableLiveEditing && githubSrc) {
464
+ addFooter(widget, iframeSrc, null, fallbackStackblitz, fallbackCodeSandbox);
465
+ }
395
466
  }
396
-
397
- async init(ctx: WidgetContext): Promise<void> {
398
- const { widget, iframeSrc, demosBaseUrl, igcTabs, githubSrc } = ctx;
399
- const samplePath = getSamplePath(iframeSrc, demosBaseUrl);
400
- const fallbackStackblitz = () => this._openStackBlitzUrl(githubSrc, demosBaseUrl);
401
- const fallbackCodeSandbox = () => this._openCodeSandbox(githubSrc, demosBaseUrl);
402
-
403
- try {
404
- // Blazor's local dev server uses a self-signed cert on a non-4200 port,
405
- // causing CORS errors. Use a relative URL so Vite's proxy handles it.
406
- // On staging/production, use the full demosBaseUrl like other xplat platforms.
407
- const isLocalDev = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1';
408
- const jsonUrl = (this.platform === 'blazor' && isLocalDev)
409
- ? `${this.codeBase}${samplePath}.json`
410
- : `${demosBaseUrl}${this.codeBase}${samplePath}.json`;
411
-
412
- const res = await fetch(jsonUrl, { credentials: 'omit' });
413
- if (!res.ok) throw new Error(`xplat sample JSON ${res.status}`);
414
- const data = await res.json();
415
-
416
- (data.sampleFiles || [] as SampleFile[])
417
- .filter((f: SampleFile) => f.isMain)
418
- .sort((a: SampleFile, b: SampleFile) =>
419
- this.samplesOrder.indexOf(a.fileHeader) - this.samplesOrder.indexOf(b.fileHeader))
420
- .forEach((file: SampleFile) =>
421
- addCodeTab(igcTabs, file));
422
-
423
- if (this.enableLiveEditing && githubSrc) {
424
- // Use sdk.openProject() to avoid the StackBlitz GitHub clone freeze bug.
425
- addFooter(widget, iframeSrc, null,
426
- () => this._openInStackBlitz(data),
427
- fallbackCodeSandbox);
428
- }
429
- } catch (err: any) {
430
- console.warn('[sample-widget] Could not fetch xplat sample files:', err.message);
431
- if (this.enableLiveEditing && githubSrc) {
432
- addFooter(widget, iframeSrc, null, fallbackStackblitz, fallbackCodeSandbox);
433
- }
434
- }
467
+ }
468
+
469
+ private async _openInStackBlitz(sampleData: any): Promise<void> {
470
+ let sdk: any;
471
+ try {
472
+ sdk = await this._loadStackBlitzSdk();
473
+ } catch (e: any) {
474
+ console.warn('[sample-widget] StackBlitz SDK failed to load:', e.message);
475
+ return;
435
476
  }
436
-
437
- private async _openInStackBlitz(sampleData: any): Promise<void> {
438
- let sdk: any;
439
- try {
440
- sdk = await this._loadStackBlitzSdk();
441
- } catch (e: any) {
442
- console.warn('[sample-widget] StackBlitz SDK failed to load:', e.message);
443
- return;
444
- }
445
- const files: Record<string, string> = {};
446
- const addFile = (f: any) => {
447
- // Skip paths that still have the old full repo prefix (pre-fix JSONs).
448
- if (!f.path || f.path.startsWith('..') || f.path.startsWith('./samples/')) return;
449
- files[f.path.replace(/^\.\//, '')] = f.content || '';
450
- };
451
- (sampleData.sampleFiles || []).forEach(addFile);
452
-
453
- // webpack-dev-server binds to localhost by default; StackBlitz WebContainers need 0.0.0.0.
454
- if (this.platform === 'wc' && files['package.json']) {
455
- try {
456
- const pkg = JSON.parse(files['package.json']);
457
- if (pkg.scripts) {
458
- pkg.scripts['serve:dev'] =
459
- 'node node_modules/webpack-dev-server/bin/webpack-dev-server.js' +
460
- ' --mode development --config ./webpack.config.js --hot --host 0.0.0.0 --allowed-hosts all';
461
- pkg.scripts['start'] = 'npm run serve:dev';
462
- files['package.json'] = JSON.stringify(pkg, null, 2);
463
- }
464
- } catch { /* malformed package.json — leave as-is */ }
477
+ const files: Record<string, string> = {};
478
+ const addFile = (f: any) => {
479
+ // Skip paths that still have the old full repo prefix (pre-fix JSONs).
480
+ if (!f.path || f.path.startsWith('..') || f.path.startsWith('./samples/')) return;
481
+ files[f.path.replace(/^\.\//, '')] = f.content || '';
482
+ };
483
+ (sampleData.sampleFiles || []).forEach(addFile);
484
+
485
+ // webpack-dev-server binds to localhost by default; StackBlitz WebContainers need 0.0.0.0.
486
+ if (this.platform === 'wc' && files['package.json']) {
487
+ try {
488
+ const pkg = JSON.parse(files['package.json']);
489
+ if (pkg.scripts) {
490
+ pkg.scripts['serve:dev'] =
491
+ 'node node_modules/webpack-dev-server/bin/webpack-dev-server.js' +
492
+ ' --mode development --config ./webpack.config.js --hot --host 0.0.0.0 --allowed-hosts all';
493
+ pkg.scripts['start'] = 'npm run serve:dev';
494
+ files['package.json'] = JSON.stringify(pkg, null, 2);
465
495
  }
466
-
467
- // @babel/preset-env with useBuiltIns:"usage" auto-injects core-js polyfill imports,
468
- // but core-js is absent from some samples' package.json, breaking the webpack build.
469
- // StackBlitz runs in modern Chrome so polyfills are unnecessary — disable the injection.
470
- if (this.platform === 'wc' && files['webpack.config.js']) {
471
- files['webpack.config.js'] = files['webpack.config.js']
472
- .replace('"useBuiltIns": "usage"', '"useBuiltIns": false')
473
- .replace(/,?\s*"corejs":\s*3/, '');
474
- }
475
-
476
- const platformLabel = this.platform === 'react' ? 'React' : 'Web Components';
477
- const mainFile = Object.keys(files).find(f => f.endsWith('index.tsx') || f.endsWith('index.ts')) || '';
478
- sdk.openProject(
479
- {
480
- title: `Infragistics ${platformLabel} Components`,
481
- description: `Auto-generated from Infragistics ${platformLabel} Docs`,
482
- template: 'node',
483
- files,
484
- tags: [this.platform, 'igniteui', 'web', 'example'],
485
- },
486
- { openFile: mainFile },
487
- );
488
- }
489
-
490
- private _loadStackBlitzSdk(): Promise<any> {
491
- if ((window as any).StackBlitzSDK) return Promise.resolve((window as any).StackBlitzSDK);
492
- return new Promise((resolve, reject) => {
493
- const s = document.createElement('script');
494
- s.src = 'https://unpkg.com/@stackblitz/sdk/bundles/sdk.umd.js';
495
- s.onload = () => resolve((window as any).StackBlitzSDK);
496
- s.onerror = () => reject(new Error('Failed to load StackBlitz SDK'));
497
- document.head.appendChild(s);
498
- });
496
+ } catch {
497
+ /* malformed package.json — leave as-is */
498
+ }
499
499
  }
500
500
 
501
- private _openStackBlitzUrl(githubSrc: string, demosBaseUrl: string): void {
502
- const branch = getXplatBranch(demosBaseUrl);
503
- window.open(
504
- `https://stackblitz.com/github/IgniteUI/igniteui-${this.platform}-examples/tree/${branch}/samples/${githubSrc}`,
505
- '_blank',
506
- );
501
+ // @babel/preset-env with useBuiltIns:"usage" auto-injects core-js polyfill imports,
502
+ // but core-js is absent from some samples' package.json, breaking the webpack build.
503
+ // StackBlitz runs in modern Chrome so polyfills are unnecessary — disable the injection.
504
+ if (this.platform === 'wc' && files['webpack.config.js']) {
505
+ files['webpack.config.js'] = files['webpack.config.js']
506
+ .replace('"useBuiltIns": "usage"', '"useBuiltIns": false')
507
+ .replace(/,?\s*"corejs":\s*3/, '');
507
508
  }
508
509
 
509
- private _openCodeSandbox(githubSrc: string, demosBaseUrl: string): void {
510
- const branch = getXplatBranch(demosBaseUrl);
511
- window.open(
512
- `https://codesandbox.io/p/sandbox/github/IgniteUI/igniteui-${this.platform}-examples/tree/${branch}/samples/${githubSrc}`,
513
- '_blank',
514
- );
515
- }
510
+ const platformLabel = this.platform === 'react' ? 'React' : 'Web Components';
511
+ const mainFile =
512
+ Object.keys(files).find((f) => f.endsWith('index.tsx') || f.endsWith('index.ts')) || '';
513
+ sdk.openProject(
514
+ {
515
+ title: `Infragistics ${platformLabel} Components`,
516
+ description: `Auto-generated from Infragistics ${platformLabel} Docs`,
517
+ template: 'node',
518
+ files,
519
+ tags: [this.platform, 'igniteui', 'web', 'example'],
520
+ },
521
+ { openFile: mainFile },
522
+ );
523
+ }
524
+
525
+ private _loadStackBlitzSdk(): Promise<any> {
526
+ if ((window as any).StackBlitzSDK) return Promise.resolve((window as any).StackBlitzSDK);
527
+ return new Promise((resolve, reject) => {
528
+ const s = document.createElement('script');
529
+ s.src = 'https://unpkg.com/@stackblitz/sdk/bundles/sdk.umd.js';
530
+ s.onload = () => resolve((window as any).StackBlitzSDK);
531
+ s.onerror = () => reject(new Error('Failed to load StackBlitz SDK'));
532
+ document.head.appendChild(s);
533
+ });
534
+ }
535
+
536
+ private _openStackBlitzUrl(githubSrc: string, demosBaseUrl: string): void {
537
+ const branch = getXplatBranch(demosBaseUrl);
538
+ window.open(
539
+ `https://stackblitz.com/github/IgniteUI/igniteui-${this.platform}-examples/tree/${branch}/samples/${githubSrc}`,
540
+ '_blank',
541
+ );
542
+ }
543
+
544
+ private _openCodeSandbox(githubSrc: string, demosBaseUrl: string): void {
545
+ const branch = getXplatBranch(demosBaseUrl);
546
+ window.open(
547
+ `https://codesandbox.io/p/sandbox/github/IgniteUI/igniteui-${this.platform}-examples/tree/${branch}/samples/${githubSrc}`,
548
+ '_blank',
549
+ );
550
+ }
516
551
  }
517
552
 
518
553
  // ─── Entry Point ──────────────────────────────────────────────────────────────
@@ -526,116 +561,137 @@ class XplatCodeService {
526
561
  * `.ig-code-view` elements managed by code-view.js.
527
562
  */
528
563
  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
-
534
- // Serial iframe-load queue. Loading all iframes simultaneously causes the
535
- // browser to parse and execute many JS bundles at once, freezing the main
536
- // thread. Instead we load one iframe at a time: next starts only after the
537
- // current fires its `load` event.
538
- const iframeQueue: Array<{ iframe: HTMLIFrameElement; samplePane: HTMLElement }> = [];
539
- let iframeLoading = false;
540
-
541
- function processIframeQueue() {
542
- if (iframeLoading || iframeQueue.length === 0) return;
543
- iframeLoading = true;
544
- const { iframe, samplePane } = iframeQueue.shift()!;
545
-
546
- iframe.addEventListener('load', () => {
547
- samplePane.classList.remove('loading');
548
- samplePane.removeAttribute('aria-busy');
549
- iframe.removeAttribute('aria-hidden');
550
- iframeLoading = false;
551
- processIframeQueue();
552
- }, { once: true });
553
-
554
- iframe.src = iframe.dataset.src!;
555
- }
556
-
557
- document.querySelectorAll<HTMLElement>('.igd-code-view[data-platform]').forEach((widget, index) => {
558
- // Skip widgets already initialized (e.g. Astro client router restoring a cached page).
559
- if (widget.dataset.widgetInitialized) return;
560
- widget.dataset.widgetInitialized = 'true';
561
-
562
- const iframeSrc = widget.dataset.iframeSrc || '';
563
- const demosBaseUrl = widget.dataset.demosBaseUrl || '';
564
- const githubSrc = widget.dataset.githubSrc || '';
565
- const platform = normalizePlatform(widget.dataset.platform || 'angular');
566
-
567
- if (!iframeSrc) return;
568
-
569
- const igcTabs = widget.querySelector<HTMLElement>('igc-tabs');
570
- const samplePane = widget.querySelector<HTMLElement>('.igd-sample-container');
571
- const iframe = widget.querySelector<HTMLIFrameElement>('iframe');
572
-
573
- if (!igcTabs) return;
574
-
575
- const exampleTabId = `${widget.id}-example`;
576
-
577
- // Toggle fullscreen button visibility based on active tab.
578
- igcTabs.addEventListener('igcChange', (e: Event) => {
579
- const detail = (e as CustomEvent<HTMLElement>).detail;
580
- const btn = widget.querySelector<HTMLElement>('.igd-full-screen-btn');
581
- if (btn) {
582
- btn.style.display = detail?.id === exampleTabId ? '' : 'none';
583
- }
584
- });
585
-
586
- // Wire copy buttons for pre-rendered code tabs (e.g. MockSample in playground).
587
- widget.querySelectorAll<HTMLElement>('.code-wrapper').forEach(pre => {
588
- const btn = pre.querySelector<HTMLElement>('.cv-hljs-code-copy');
589
- const icon = btn?.querySelector<HTMLElement>('igc-icon');
590
- const code = pre.querySelector<HTMLElement>('code');
591
- if (!btn || !code) return;
592
- const codeLang = (code.className.match(/language-(\S+)/) ?? [])[1] ?? 'text';
593
- highlightCode(code, normalizeCodeLang(codeLang));
594
- btn.addEventListener('click', () => {
595
- navigator.clipboard.writeText(code.textContent ?? '').then(() => {
596
- icon?.setAttribute('name', 'check');
597
- setTimeout(() => { icon?.setAttribute('name', 'copy'); }, 1500);
598
- });
599
- });
600
- });
601
-
602
- // Enqueue iframe loading.
603
- if (iframe && samplePane) {
604
- const enqueue = () => {
605
- iframeQueue.push({ iframe, samplePane });
606
- processIframeQueue();
607
- };
608
- if (index === 0) {
609
- requestAnimationFrame(enqueue);
610
- } else {
611
- const visObs = new IntersectionObserver(entries => {
612
- if (entries[0].isIntersecting) { visObs.disconnect(); enqueue(); }
613
- });
614
- visObs.observe(samplePane);
615
- }
564
+ // Kick off the Shiki download immediately so it is ready before the user
565
+ // opens a code tab (tabs appear only after an IntersectionObserver fires
566
+ // + a JSON fetch completes, giving Shiki time to load in parallel).
567
+ getHighlighter().catch(() => {});
568
+
569
+ // Serial iframe-load queue. Loading all iframes simultaneously causes the
570
+ // browser to parse and execute many JS bundles at once, freezing the main
571
+ // thread. Instead we load one iframe at a time: next starts only after the
572
+ // current fires its `load` event.
573
+ const iframeQueue: Array<{ iframe: HTMLIFrameElement; samplePane: HTMLElement }> = [];
574
+ let iframeLoading = false;
575
+
576
+ function processIframeQueue() {
577
+ if (iframeLoading || iframeQueue.length === 0) return;
578
+ iframeLoading = true;
579
+ const { iframe, samplePane } = iframeQueue.shift()!;
580
+
581
+ iframe.addEventListener(
582
+ 'load',
583
+ () => {
584
+ samplePane.classList.remove('loading');
585
+ samplePane.removeAttribute('aria-busy');
586
+ iframe.removeAttribute('aria-hidden');
587
+ iframeLoading = false;
588
+ processIframeQueue();
589
+ },
590
+ { once: true },
591
+ );
592
+
593
+ iframe.src = iframe.dataset.src!;
594
+ }
595
+
596
+ document
597
+ .querySelectorAll<HTMLElement>('.igd-code-view[data-platform]')
598
+ .forEach((widget, index) => {
599
+ // Skip widgets already initialized (e.g. Astro client router restoring a cached page).
600
+ if (widget.dataset.widgetInitialized) return;
601
+ widget.dataset.widgetInitialized = 'true';
602
+
603
+ const iframeSrc = widget.dataset.iframeSrc || '';
604
+ const demosBaseUrl = widget.dataset.demosBaseUrl || '';
605
+ const githubSrc = widget.dataset.githubSrc || '';
606
+ const platform = normalizePlatform(widget.dataset.platform || 'angular');
607
+
608
+ if (!iframeSrc) return;
609
+
610
+ const igcTabs = widget.querySelector<HTMLElement>('igc-tabs');
611
+ const samplePane = widget.querySelector<HTMLElement>('.igd-sample-container');
612
+ const iframe = widget.querySelector<HTMLIFrameElement>('iframe');
613
+
614
+ if (!igcTabs) return;
615
+
616
+ const exampleTabId = `${widget.id}-example`;
617
+
618
+ // Toggle fullscreen button visibility based on active tab.
619
+ igcTabs.addEventListener('igcChange', (e: Event) => {
620
+ const detail = (e as CustomEvent<HTMLElement>).detail;
621
+ const btn = widget.querySelector<HTMLElement>('.igd-full-screen-btn');
622
+ if (btn) {
623
+ btn.style.display = detail?.id === exampleTabId ? '' : 'none';
616
624
  }
625
+ });
626
+
627
+ // Wire copy buttons for pre-rendered code tabs (e.g. MockSample in playground).
628
+ widget.querySelectorAll<HTMLElement>('.code-wrapper').forEach((pre) => {
629
+ const btn = pre.querySelector<HTMLElement>('.cv-hljs-code-copy');
630
+ const icon = btn?.querySelector<HTMLElement>('igc-icon');
631
+ const code = pre.querySelector<HTMLElement>('code');
632
+ if (!btn || !code) return;
633
+ const codeLang = (code.className.match(/language-(\S+)/) ?? [])[1] ?? 'text';
634
+ highlightCode(code, normalizeCodeLang(codeLang));
635
+ btn.addEventListener('click', () => {
636
+ navigator.clipboard.writeText(code.textContent ?? '').then(() => {
637
+ icon?.setAttribute('name', 'check');
638
+ setTimeout(() => {
639
+ icon?.setAttribute('name', 'copy');
640
+ }, 1500);
641
+ });
642
+ });
643
+ });
617
644
 
618
- if (!demosBaseUrl && !isXplatPlatform(platform)) return;
619
-
620
- const service = isXplatPlatform(platform)
621
- ? new XplatCodeService(platform)
622
- : new AngularCodeService();
623
-
624
- const ctx: WidgetContext = {
625
- widget, iframeSrc, demosBaseUrl, widgetIndex: index, igcTabs, githubSrc,
645
+ // Enqueue iframe loading.
646
+ if (iframe && samplePane) {
647
+ const enqueue = () => {
648
+ iframeQueue.push({ iframe, samplePane });
649
+ processIframeQueue();
626
650
  };
627
-
628
- // Fetch code-tab data only when the widget becomes visible.
629
- const startFetch = () => service.init(ctx);
630
651
  if (index === 0) {
631
- typeof requestIdleCallback !== 'undefined'
632
- ? requestIdleCallback(startFetch)
633
- : requestAnimationFrame(startFetch);
652
+ requestAnimationFrame(enqueue);
634
653
  } else {
635
- const fetchObs = new IntersectionObserver(entries => {
636
- if (entries[0].isIntersecting) { fetchObs.disconnect(); startFetch(); }
637
- });
638
- fetchObs.observe(samplePane ?? widget);
654
+ const visObs = new IntersectionObserver((entries) => {
655
+ if (entries[0].isIntersecting) {
656
+ visObs.disconnect();
657
+ enqueue();
658
+ }
659
+ });
660
+ visObs.observe(samplePane);
639
661
  }
662
+ }
663
+
664
+ if (!demosBaseUrl && !isXplatPlatform(platform)) return;
665
+
666
+ const service = isXplatPlatform(platform)
667
+ ? new XplatCodeService(platform)
668
+ : new AngularCodeService();
669
+
670
+ const ctx: WidgetContext = {
671
+ widget,
672
+ iframeSrc,
673
+ demosBaseUrl,
674
+ widgetIndex: index,
675
+ igcTabs,
676
+ githubSrc,
677
+ };
678
+
679
+ // Fetch code-tab data only when the widget becomes visible.
680
+ const startFetch = () => service.init(ctx);
681
+ if (index === 0) {
682
+ if (typeof requestIdleCallback !== 'undefined') {
683
+ requestIdleCallback(startFetch);
684
+ } else {
685
+ requestAnimationFrame(startFetch);
686
+ }
687
+ } else {
688
+ const fetchObs = new IntersectionObserver((entries) => {
689
+ if (entries[0].isIntersecting) {
690
+ fetchObs.disconnect();
691
+ startFetch();
692
+ }
693
+ });
694
+ fetchObs.observe(samplePane ?? widget);
695
+ }
640
696
  });
641
697
  }