igniteui-astro-components 0.0.26 → 0.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +82 -74
- package/package.json +16 -9
- package/src/components/CopyCode/CopyCode.astro +21 -7
- package/src/components/DocsBreadcrumb/DocsBreadcrumb.astro +33 -21
- package/src/components/DocsBreadcrumb/DocsBreadcrumb.scss +44 -43
- package/src/components/DocsBreadcrumb/README.md +10 -14
- package/src/components/DocsSidebar/DocsSidebar.astro +47 -45
- package/src/components/DocsSidebar/DocsSidebar.scss +120 -122
- package/src/components/DocsSidebar/README.md +25 -21
- package/src/components/DocsSidebar/SidebarFilterInput.astro +24 -29
- package/src/components/DocsSidebar/SidebarFilterInput.scss +90 -89
- package/src/components/DocsSidebar/SidebarLabel.astro +35 -26
- package/src/components/DocsSidebar/sidebar-filter.ts +93 -56
- package/src/components/DocsSubHeader/DocsSubHeader.astro +256 -185
- package/src/components/DocsSubHeader/DocsSubHeader.scss +181 -169
- package/src/components/DocsSubHeader/README.md +18 -16
- package/src/components/DocsToc/DocsToc.astro +301 -280
- package/src/components/DocsToc/DocsToc.scss +20 -21
- package/src/components/DocsToc/README.md +11 -9
- package/src/components/DocsToc/toTreeNodes.ts +3 -8
- package/src/components/DocsTree/DocsTree.astro +32 -20
- package/src/components/DocsTree/DocsTreeItem.astro +35 -30
- package/src/components/DocsTree/README.md +16 -15
- package/src/components/DocsTree/docs-tree.scss +267 -268
- package/src/components/GlobalFooter/GlobalFooter.astro +10 -10
- package/src/components/GlobalFooter/README.md +3 -2
- package/src/components/GlobalNavBar/GlobalNavBar.astro +4 -2
- package/src/components/GlobalNavBar/GlobalNavBar.module.scss +222 -222
- package/src/components/GlobalNavBar/README.md +3 -2
- package/src/components/LicenseIndicator/LicenseIndicator.astro +7 -5
- package/src/components/LicenseIndicator/LicenseIndicator.scss +3 -3
- package/src/components/MobileSidebarToggle/MobileSidebarToggle.astro +16 -17
- package/src/components/MobileSidebarToggle/README.md +3 -2
- package/src/components/MobileTocToggle/MobileTocToggle.astro +75 -61
- package/src/components/MobileTocToggle/MobileTocToggle.scss +65 -59
- package/src/components/Search/README.md +1 -0
- package/src/components/Search/Search.astro +137 -109
- package/src/components/Search/Search.scss +20 -20
- package/src/components/SearchAdvanced/README.md +21 -15
- package/src/components/SearchAdvanced/SearchAdvanced.astro +220 -133
- package/src/components/SearchAdvanced/SearchAdvanced.scss +152 -153
- package/src/components/mdx/ApiLink/ApiLink.astro +133 -113
- package/src/components/mdx/ApiLink/ApiLink.scss +9 -9
- package/src/components/mdx/ApiLink/README.md +26 -22
- package/src/components/mdx/ApiLink/api-link-index.ts +196 -173
- package/src/components/mdx/ApiRef/ApiRef.astro +54 -51
- package/src/components/mdx/ApiRef/README.md +20 -15
- package/src/components/mdx/Badge/Badge.astro +14 -14
- package/src/components/mdx/Badge/Badge.scss +61 -56
- package/src/components/mdx/Badge/README.md +24 -19
- package/src/components/mdx/DocsAside/DocsAside.astro +30 -37
- package/src/components/mdx/DocsAside/DocsAside.scss +82 -82
- package/src/components/mdx/DocsAside/README.md +22 -22
- package/src/components/mdx/Faq/Faq.astro +86 -0
- package/src/components/mdx/Faq/Faq.scss +105 -0
- package/src/components/mdx/Faq/FaqItem.astro +117 -0
- package/src/components/mdx/Faq/README.md +223 -0
- package/src/components/mdx/Faq/types.ts +34 -0
- package/src/components/mdx/PlatformBlock/PlatformBlock.astro +3 -2
- package/src/components/mdx/PlatformBlock/README.md +6 -8
- package/src/components/mdx/Sample/README.md +21 -16
- package/src/components/mdx/Sample/Sample.astro +97 -74
- package/src/components/mdx/Sample/Sample.scss +132 -132
- package/src/content-helper.ts +71 -72
- package/src/content.config.ts +1 -6
- package/src/integration.ts +566 -512
- package/src/layouts/DocsLayout/DocsLayout.astro +228 -182
- package/src/layouts/DocsLayout/DocsLayout.scss +261 -261
- package/src/layouts/DocsLayout/README.md +24 -35
- package/src/lib/nav-helpers.ts +88 -82
- package/src/lib/types.ts +76 -76
- package/src/llms.ts +205 -166
- package/src/platform.ts +312 -162
- package/src/plugins/rehype-heading-anchors.ts +45 -45
- package/src/plugins/rehype-pagefind-ignore.ts +19 -19
- package/src/plugins/rehype-table-wrapper.ts +30 -30
- package/src/plugins/remark-docfx.ts +12 -0
- package/src/plugins/remark-env-vars.ts +12 -4
- package/src/plugins/remark-md-links.ts +10 -4
- package/src/scripts/icon-manifest.ts +13 -5
- package/src/scripts/sample-widget.ts +557 -501
- package/src/sidebar.ts +103 -97
- package/src/styles/global/_code-blocks.scss +43 -44
- package/src/styles/global/_component-themes.scss +151 -153
- package/src/styles/global/_icon-gallery.scss +81 -81
- package/src/styles/global/_index.scss +0 -1
- package/src/styles/global/_markdown.scss +816 -787
- package/src/styles/global/_palette.scss +456 -110
- package/src/styles/global/_search-shared.scss +402 -398
- package/src/styles/global/_type-scale.scss +127 -127
- package/src/styles/global/_variables.scss +138 -111
- package/src/styles/theme.scss +49 -40
- package/src/virtual-modules.d.ts +11 -2
|
@@ -13,31 +13,45 @@
|
|
|
13
13
|
* Selector: `.igd-code-view[data-platform]`
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
import {
|
|
17
|
-
defineComponents
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
49
|
+
wc: '/assets/code-viewer/',
|
|
50
|
+
react: '/code-viewer/',
|
|
51
|
+
blazor: '/code-viewer/',
|
|
38
52
|
};
|
|
39
53
|
|
|
40
|
-
const DV_PATHS
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
63
|
+
fileExtension: string;
|
|
64
|
+
fileHeader: string;
|
|
65
|
+
content: string;
|
|
66
|
+
isMain: boolean;
|
|
67
|
+
path?: string;
|
|
54
68
|
}
|
|
55
69
|
|
|
56
70
|
interface WidgetContext {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
73
|
-
|
|
86
|
+
if (raw === 'webcomponents' || raw === 'web-components') return 'wc';
|
|
87
|
+
return raw;
|
|
74
88
|
}
|
|
75
89
|
|
|
76
90
|
function isXplatPlatform(platform: string): boolean {
|
|
77
|
-
|
|
91
|
+
return platform === 'react' || platform === 'wc' || platform === 'blazor';
|
|
78
92
|
}
|
|
79
93
|
|
|
80
94
|
function getSamplePath(iframeSrc: string, demosBaseUrl: string): string {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
95
|
+
return iframeSrc
|
|
96
|
+
.replace(demosBaseUrl + '/', '')
|
|
97
|
+
.replace(/\?.*/, '')
|
|
98
|
+
.replace(/\/$/, '');
|
|
85
99
|
}
|
|
86
100
|
|
|
87
101
|
function isDvSample(samplePath: string): boolean {
|
|
88
|
-
|
|
102
|
+
return DV_PATHS.some((p) => samplePath.startsWith(p));
|
|
89
103
|
}
|
|
90
104
|
|
|
91
105
|
function getRepoBranch(demosBaseUrl: string, isDv: boolean): string {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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 = [
|
|
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
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
|
-
|
|
192
|
+
return LANG_MAP[lang ?? ''] ?? lang ?? 'text';
|
|
160
193
|
}
|
|
161
194
|
|
|
162
195
|
// ─── Code Tab Rendering ───────────────────────────────────────────────────────
|
|
163
196
|
|
|
164
|
-
function addCodeTab(
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
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
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
233
|
+
wrapper.appendChild(pre);
|
|
234
|
+
wrapper.appendChild(copyBtn);
|
|
235
|
+
tab.appendChild(wrapper);
|
|
236
|
+
igcTabs.appendChild(tab);
|
|
207
237
|
|
|
208
|
-
|
|
238
|
+
highlightCode(code, lang);
|
|
209
239
|
}
|
|
210
240
|
|
|
211
241
|
// ─── Footer / Live Edit Buttons ───────────────────────────────────────────────
|
|
212
242
|
|
|
213
243
|
function addFooter(
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
244
|
+
widget: HTMLElement,
|
|
245
|
+
iframeSrc: string,
|
|
246
|
+
explicitEditor: string | null,
|
|
247
|
+
onStackblitz: (() => void) | null,
|
|
248
|
+
_onCodeSandbox: (() => void) | null,
|
|
219
249
|
): void {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
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
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
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
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
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
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
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
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
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
|
-
|
|
468
|
-
|
|
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
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
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
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
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
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
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
|
-
|
|
619
|
-
|
|
620
|
-
const
|
|
621
|
-
|
|
622
|
-
|
|
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
|
-
|
|
632
|
-
? requestIdleCallback(startFetch)
|
|
633
|
-
: requestAnimationFrame(startFetch);
|
|
652
|
+
requestAnimationFrame(enqueue);
|
|
634
653
|
} else {
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
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
|
}
|