igniteui-astro-components 1.7.0 → 1.8.1
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 +322 -158
- package/llms-full.txt +3216 -0
- package/llms.txt +103 -0
- package/package.json +17 -5
- package/src/assets/icons/figma-logo.svg +10 -0
- package/src/code-theme/README.md +77 -0
- package/src/code-theme/index.ts +76 -0
- package/src/components/CopyCode/CopyCode.astro +6 -1
- package/src/components/CopyCode/README.md +38 -0
- package/src/components/DocsBreadcrumb/DocsBreadcrumb.astro +28 -30
- package/src/components/DocsSidebar/README.md +58 -30
- package/src/components/DocsSidebar/SidebarLabel.astro +34 -36
- package/src/components/DocsSubHeader/README.md +24 -31
- package/src/components/DocsToc/DocsToc.astro +12 -14
- package/src/components/DocsToc/README.md +7 -7
- package/src/components/DocsTree/DocsTree.astro +9 -11
- package/src/components/DocsTree/DocsTreeItem.astro +36 -40
- package/src/components/DocsTree/README.md +12 -9
- package/src/components/GlobalFooter/GlobalFooter.astro +6 -8
- package/src/components/GlobalNavBar/GlobalNavBar.astro +2 -4
- package/src/components/LicenseIndicator/LicenseIndicator.astro +6 -8
- package/src/components/MobileTocToggle/MobileTocToggle.astro +31 -33
- package/src/components/MobileTocToggle/README.md +45 -0
- package/src/components/Search/README.md +10 -10
- package/src/components/Search/Search.astro +12 -6
- package/src/components/SearchAdvanced/README.md +15 -8
- package/src/components/SearchAdvanced/SearchAdvanced.astro +17 -15
- package/src/components/ThemingWidget/ThemingWidget.astro +62 -60
- package/src/components/mdx/Anatomy/Anatomy.scss +1 -1
- package/src/components/mdx/Anatomy/README.md +40 -0
- package/src/components/mdx/ApiLink/ApiLink.astro +7 -9
- package/src/components/mdx/ApiLink/README.md +1 -0
- package/src/components/mdx/ApiRef/ApiRef.astro +7 -9
- package/src/components/mdx/ApiRef/README.md +1 -1
- package/src/components/mdx/Badge/Badge.astro +3 -1
- package/src/components/mdx/Badge/README.md +1 -3
- package/src/components/mdx/DocsAside/DocsAside.astro +3 -5
- package/src/components/mdx/DocsAside/README.md +47 -29
- package/src/components/mdx/Faq/Faq.astro +11 -13
- package/src/components/mdx/Faq/FaqItem.astro +20 -26
- package/src/components/mdx/FigmaUiKits/FigmaUiKits.astro +126 -0
- package/src/components/mdx/FigmaUiKits/FigmaUiKits.scss +165 -0
- package/src/components/mdx/FigmaUiKits/README.md +115 -0
- package/src/components/mdx/FigmaUiKits/kits.ts +26 -0
- package/src/components/mdx/PlatformBlock/README.md +5 -18
- package/src/components/mdx/Sample/README.md +71 -50
- package/src/components/mdx/Sample/Sample.astro +108 -33
- package/src/components/mdx/Sample/Sample.scss +38 -17
- package/src/integration.ts +6 -21
- package/src/layouts/DocsLayout/README.md +63 -28
- package/src/lib/warn-once.ts +8 -0
- package/src/scripts/copy-status.ts +35 -0
- package/src/scripts/icon-manifest.ts +1 -0
- package/src/scripts/sample-widget.ts +162 -42
- package/src/styles/global/_code-blocks.scss +58 -36
- package/src/styles/global/_copy-button.scss +18 -25
- package/src/styles/global/_markdown.scss +15 -8
- package/src/styles/global/_variables.scss +57 -0
- package/src/styles/theme.scss +4 -1
- package/src/virtual-modules.d.ts +1 -1
|
@@ -10,23 +10,58 @@ import DocsLayout from 'igniteui-astro-components/layouts/DocsLayout.astro';
|
|
|
10
10
|
|
|
11
11
|
## Props
|
|
12
12
|
|
|
13
|
-
| Prop
|
|
14
|
-
|
|
|
15
|
-
| `title`
|
|
16
|
-
| `description`
|
|
17
|
-
| `keywords`
|
|
18
|
-
| `hasSidebar`
|
|
19
|
-
| `currentSlug`
|
|
20
|
-
| `siteTitle`
|
|
13
|
+
| Prop | Type | Default | Description |
|
|
14
|
+
| ----------------- | ---------------- | -------------- | ------------------------------------------------------------------------------------------------------------- |
|
|
15
|
+
| `title` | `string` | — | Page `<title>` prepended to the site name. Omit to show the site name only. |
|
|
16
|
+
| `description` | `string \| null` | — | `<meta name="description">` value. |
|
|
17
|
+
| `keywords` | `string \| null` | — | `<meta name="keywords">` value. |
|
|
18
|
+
| `hasSidebar` | `boolean` | `true` | Renders the sidebar rail when `true`. Provide content via `<… slot="sidebar">`. |
|
|
19
|
+
| `currentSlug` | `string` | `''` | Slug of the current page — used for the breadcrumb above the content. |
|
|
20
|
+
| `siteTitle` | `string` | virtual module | Override the site name used in `<title>` and the breadcrumb. Use this when not running `siteMetaIntegration`. |
|
|
21
|
+
| `license` | `string` | — | `license` frontmatter value. `'commercial'` shows a Premium badge, `'MIT'` an Open Source badge. |
|
|
22
|
+
| `is404` | `boolean` | `false` | Adds the `igd-page-layout--404` modifier class on 404 pages. |
|
|
23
|
+
| `packages` | `string[]` | — | Entries for the sub-header package selector. Hidden when omitted. |
|
|
24
|
+
| `selectedPackage` | `string` | — | Currently selected package (must match one of `packages`). |
|
|
25
|
+
| `packageLabel` | `string` | `'Package'` | `aria-label` of the sub-header package selector (not a visible label). |
|
|
26
|
+
| `versions` | `string[]` | — | Entries for the sub-header version selector. Hidden when omitted. |
|
|
27
|
+
| `selectedVersion` | `string` | — | Currently selected version (must match one of `versions`). |
|
|
28
|
+
| `versionLabel` | `string` | `'Version'` | `aria-label` of the sub-header version selector (not a visible label). |
|
|
29
|
+
| `showThemeToggle` | `boolean` | `false` | Forwarded to `DocsSubHeader`, which does not render a toggle; no effect today. |
|
|
30
|
+
| `themeStorageKey` | `string` | `'docs-theme'` | Forwarded to `DocsSubHeader` and unused; the layout's restore script reads the `'docs-theme'` key only. |
|
|
31
|
+
|
|
32
|
+
`hasToc` (`boolean`, default `true`) is also read at runtime and hides the `toc`
|
|
33
|
+
slot when `false`, but it is not yet declared in the `Props` interface (issue #161), so
|
|
34
|
+
TypeScript consumers must spread it in (`{...{ hasToc: false }}`).
|
|
21
35
|
|
|
22
36
|
## Slots
|
|
23
37
|
|
|
24
|
-
| Slot
|
|
25
|
-
|
|
|
26
|
-
| _(default)_
|
|
27
|
-
| `sidebar`
|
|
28
|
-
| `toc`
|
|
29
|
-
| `
|
|
38
|
+
| Slot | Description |
|
|
39
|
+
| ------------ | ---------------------------------------------------------------------------------------------------------------------- |
|
|
40
|
+
| _(default)_ | Main page content, rendered inside `<main data-pagefind-body>`. |
|
|
41
|
+
| `sidebar` | Sidebar content — typically `<DocsSidebar>`. Only rendered when `hasSidebar={true}`. |
|
|
42
|
+
| `toc` | "On this page" column — pass `<DocsToc slot="toc" headings={headings} />` here. Omit to hide the TOC sidebar entirely. |
|
|
43
|
+
| `mobile-toc` | Mobile-only TOC row below the sub-header — pass `<MobileTocToggle slot="mobile-toc" headings={headings} />`. |
|
|
44
|
+
| `subheader` | Replaces the default `<DocsSubHeader>`; use it to mount your own sub-header (for example with `SearchAdvanced`). |
|
|
45
|
+
| `head` | Extra `<head>` entries injected after platform defaults. |
|
|
46
|
+
|
|
47
|
+
## What the layout brings in
|
|
48
|
+
|
|
49
|
+
- `styles/theme.scss` (the package's global stylesheet) and the JetBrains Mono
|
|
50
|
+
variable font from `@fontsource-variable/jetbrains-mono`. You do not need to
|
|
51
|
+
import either yourself.
|
|
52
|
+
- `GlobalNavBar`, `DocsSubHeader`, `DocsBreadcrumb`, `LicenseIndicator`,
|
|
53
|
+
`CopyCode` and `GlobalFooter`.
|
|
54
|
+
- `<html data-theme="light|dark">`, restored from `localStorage` before paint.
|
|
55
|
+
- Astro's `<ClientRouter>` for view transitions.
|
|
56
|
+
|
|
57
|
+
## Host requirements
|
|
58
|
+
|
|
59
|
+
- The two virtual modules below must resolve (stub them if you do not use the
|
|
60
|
+
integration).
|
|
61
|
+
- Components rendered inside the layout that read
|
|
62
|
+
`Astro.locals.platformContext` or `Astro.locals.envVars` (`ApiLink`,
|
|
63
|
+
`ApiRef`, `PlatformBlock`, `Sample`, `ThemingWidget`) need a middleware that
|
|
64
|
+
sets them — see [Quick start](../../../README.md#quick-start) step 3.
|
|
30
65
|
|
|
31
66
|
## Example
|
|
32
67
|
|
|
@@ -34,12 +69,12 @@ import DocsLayout from 'igniteui-astro-components/layouts/DocsLayout.astro';
|
|
|
34
69
|
|
|
35
70
|
Pass all data directly as props. The `virtual:docs-template/site-meta` module
|
|
36
71
|
still needs to be resolvable at Vite build time — supply a minimal stub (see
|
|
37
|
-
[
|
|
72
|
+
[Quick start](../../../README.md#quick-start) step 2).
|
|
38
73
|
|
|
39
74
|
```astro
|
|
40
75
|
---
|
|
41
76
|
import DocsLayout from 'igniteui-astro-components/layouts/DocsLayout.astro';
|
|
42
|
-
import DocsSidebar from 'igniteui-astro-components/components/
|
|
77
|
+
import DocsSidebar from 'igniteui-astro-components/components/DocsSidebar/DocsSidebar.astro';
|
|
43
78
|
import DocsToc from 'igniteui-astro-components/components/DocsToc.astro';
|
|
44
79
|
import type { SidebarEntry } from 'igniteui-astro-components/lib/sidebar/types';
|
|
45
80
|
import type { MarkdownHeading } from 'astro';
|
|
@@ -55,7 +90,7 @@ const sidebar: SidebarEntry[] = [
|
|
|
55
90
|
|
|
56
91
|
<DocsLayout title="Toast" siteTitle="My Library" hasSidebar currentSlug={slug}>
|
|
57
92
|
<DocsSidebar slot="sidebar" items={sidebar} currentSlug={slug} />
|
|
58
|
-
<DocsToc slot="toc" headings={headings}
|
|
93
|
+
<DocsToc slot="toc" headings={headings} />
|
|
59
94
|
<slot />
|
|
60
95
|
</DocsLayout>
|
|
61
96
|
```
|
|
@@ -67,7 +102,7 @@ Omit the `toc` slot entirely — the TOC sidebar collapses automatically via CSS
|
|
|
67
102
|
```astro
|
|
68
103
|
---
|
|
69
104
|
import DocsLayout from 'igniteui-astro-components/layouts/DocsLayout.astro';
|
|
70
|
-
import DocsSidebar from 'igniteui-astro-components/components/
|
|
105
|
+
import DocsSidebar from 'igniteui-astro-components/components/DocsSidebar/DocsSidebar.astro';
|
|
71
106
|
|
|
72
107
|
const slug = Astro.params.slug ?? '';
|
|
73
108
|
---
|
|
@@ -86,7 +121,7 @@ can be omitted — it is read from the virtual module automatically.
|
|
|
86
121
|
```astro
|
|
87
122
|
---
|
|
88
123
|
import DocsLayout from 'igniteui-astro-components/layouts/DocsLayout.astro';
|
|
89
|
-
import DocsSidebar from 'igniteui-astro-components/components/
|
|
124
|
+
import DocsSidebar from 'igniteui-astro-components/components/DocsSidebar/DocsSidebar.astro';
|
|
90
125
|
import DocsToc from 'igniteui-astro-components/components/DocsToc.astro';
|
|
91
126
|
|
|
92
127
|
const { headings } = Astro.props;
|
|
@@ -95,7 +130,7 @@ const slug = Astro.params.slug ?? '';
|
|
|
95
130
|
|
|
96
131
|
<DocsLayout title="Toast" description="Toast component documentation" hasSidebar currentSlug={slug}>
|
|
97
132
|
<DocsSidebar slot="sidebar" currentSlug={slug} />
|
|
98
|
-
<DocsToc slot="toc" headings={headings}
|
|
133
|
+
<DocsToc slot="toc" headings={headings} />
|
|
99
134
|
<slot />
|
|
100
135
|
</DocsLayout>
|
|
101
136
|
```
|
|
@@ -119,12 +154,12 @@ with `data-igd-footer`, persisted across navigations. See
|
|
|
119
154
|
|
|
120
155
|
## Virtual module dependencies
|
|
121
156
|
|
|
122
|
-
`DocsLayout` imports from two virtual modules.
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
157
|
+
`DocsLayout` imports from two virtual modules. Supply them with a Vite plugin
|
|
158
|
+
(see [Quick start](../../../README.md#quick-start) step 2; `siteMetaIntegration`
|
|
159
|
+
does not emit `packages` and `selectedPackage`, so it cannot provide them
|
|
160
|
+
today):
|
|
126
161
|
|
|
127
|
-
| Module | Used for
|
|
128
|
-
| --------------------------------- |
|
|
129
|
-
| `virtual:docs-template/site-meta` |
|
|
130
|
-
| `virtual:docs-template/nav-html` | Pre-fetched nav/footer HTML, widget script URL, platform key
|
|
162
|
+
| Module | Used for | Can be overridden by prop |
|
|
163
|
+
| --------------------------------- | ------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------- |
|
|
164
|
+
| `virtual:docs-template/site-meta` | `title`, `sidebar`, `productLinks`, `headEntries`, `trailingSlash`, `navLang`, `packages`, `selectedPackage` | `siteTitle` on `DocsLayout`, `items`/`trailingSlash` on `DocsSidebar`, `packages`/`selectedPackage` on `DocsSubHeader` |
|
|
165
|
+
| `virtual:docs-template/nav-html` | Pre-fetched nav/footer HTML, widget script URL, platform key | — (not yet prop-overridable) |
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Visually hidden live region that announces the copy-code result to screen readers. */
|
|
2
|
+
const REGION_CLASS = 'igd-copy-status';
|
|
3
|
+
|
|
4
|
+
// Visually hidden styles, set inline.
|
|
5
|
+
const HIDDEN_STYLE =
|
|
6
|
+
'position:absolute;width:1px;height:1px;margin:-1px;padding:0;border:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap';
|
|
7
|
+
|
|
8
|
+
function getRegion(host: HTMLElement): HTMLElement {
|
|
9
|
+
let region = host.querySelector<HTMLElement>(`:scope > .${REGION_CLASS}`);
|
|
10
|
+
if (!region) {
|
|
11
|
+
region = document.createElement('span');
|
|
12
|
+
region.className = REGION_CLASS;
|
|
13
|
+
region.setAttribute('role', 'status');
|
|
14
|
+
region.setAttribute('aria-live', 'polite');
|
|
15
|
+
region.style.cssText = HIDDEN_STYLE;
|
|
16
|
+
host.appendChild(region);
|
|
17
|
+
}
|
|
18
|
+
return region;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Announces `message` from the live region inside `host`. */
|
|
22
|
+
export function announceCopyStatus(host: HTMLElement, message: string): void {
|
|
23
|
+
const region = getRegion(host);
|
|
24
|
+
region.textContent = '';
|
|
25
|
+
// Sets the text on the next frame so a repeated message is announced again.
|
|
26
|
+
requestAnimationFrame(() => {
|
|
27
|
+
region.textContent = message;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Clears the live region inside `host`. */
|
|
32
|
+
export function clearCopyStatus(host: HTMLElement): void {
|
|
33
|
+
const region = host.querySelector<HTMLElement>(`:scope > .${REGION_CLASS}`);
|
|
34
|
+
if (region) region.textContent = '';
|
|
35
|
+
}
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
IgcIconButtonComponent,
|
|
21
21
|
IgcIconComponent,
|
|
22
22
|
IgcCircularProgressComponent,
|
|
23
|
+
IgcTooltipComponent,
|
|
23
24
|
registerIconFromText,
|
|
24
25
|
} from 'igniteui-webcomponents';
|
|
25
26
|
defineComponents(
|
|
@@ -28,10 +29,12 @@ defineComponents(
|
|
|
28
29
|
IgcIconButtonComponent,
|
|
29
30
|
IgcIconComponent,
|
|
30
31
|
IgcCircularProgressComponent,
|
|
32
|
+
IgcTooltipComponent,
|
|
31
33
|
);
|
|
32
34
|
|
|
33
35
|
import './icon-registry';
|
|
34
36
|
import type { BundledLanguage, Highlighter } from 'shiki';
|
|
37
|
+
import { announceCopyStatus, clearCopyStatus } from './copy-status';
|
|
35
38
|
import { ULTIMATE_UI_PLATFORMS } from '../lib/ultimate-ui-platforms';
|
|
36
39
|
import footerStackblitzIcon from '../components/mdx/Sample/assets/stackblitz.svg?raw';
|
|
37
40
|
import footerOpenExternalIcon from '../components/mdx/Sample/assets/open-external.svg?raw';
|
|
@@ -71,9 +74,6 @@ const SANDBOX_UNSUPPORTED_PLATFORMS = new Set(['blazor', 'winui', 'uno']);
|
|
|
71
74
|
|
|
72
75
|
const DV_PATHS = ['gauges/', 'maps/', 'excel/', 'charts/'];
|
|
73
76
|
const ASSETS_RE = /([.]{0,2}\/)*assets\//g;
|
|
74
|
-
const DEFAULT_CODE_THEME = 'dark-plus';
|
|
75
|
-
|
|
76
|
-
declare const __IGD_SAMPLE_CODE_THEME__: string | undefined;
|
|
77
77
|
|
|
78
78
|
// ─── Types ────────────────────────────────────────────────────────────────────
|
|
79
79
|
|
|
@@ -187,17 +187,12 @@ const HIGHLIGHT_LANGS: ReadonlySet<string> = new Set([...SHIKI_LANGS, ...SHIKI_L
|
|
|
187
187
|
|
|
188
188
|
let _highlighterPromise: Promise<Highlighter> | null = null;
|
|
189
189
|
|
|
190
|
-
|
|
191
|
-
return typeof __IGD_SAMPLE_CODE_THEME__ === 'string' && __IGD_SAMPLE_CODE_THEME__.trim()
|
|
192
|
-
? __IGD_SAMPLE_CODE_THEME__
|
|
193
|
-
: DEFAULT_CODE_THEME;
|
|
194
|
-
}
|
|
195
|
-
|
|
190
|
+
// Shiki and the brand theme load lazily, only once a code tab exists.
|
|
196
191
|
function getHighlighter(): Promise<Highlighter> {
|
|
197
192
|
if (!_highlighterPromise) {
|
|
198
|
-
_highlighterPromise = import('shiki')
|
|
199
|
-
.then(({ createHighlighter }) =>
|
|
200
|
-
createHighlighter({ themes: [
|
|
193
|
+
_highlighterPromise = Promise.all([import('shiki'), import('../code-theme')])
|
|
194
|
+
.then(([{ createHighlighter }, { igCodeTheme }]) =>
|
|
195
|
+
createHighlighter({ themes: [igCodeTheme], langs: [...SHIKI_LANGS] }),
|
|
201
196
|
)
|
|
202
197
|
.catch((err) => {
|
|
203
198
|
_highlighterPromise = null;
|
|
@@ -207,6 +202,7 @@ function getHighlighter(): Promise<Highlighter> {
|
|
|
207
202
|
return _highlighterPromise;
|
|
208
203
|
}
|
|
209
204
|
|
|
205
|
+
/** Highlight a code tab with the brand theme the page's fenced blocks use. */
|
|
210
206
|
function highlightCode(codeEl: HTMLElement, lang: string): void {
|
|
211
207
|
const safeLang = HIGHLIGHT_LANGS.has(lang) ? lang : 'text';
|
|
212
208
|
getHighlighter()
|
|
@@ -217,13 +213,17 @@ function highlightCode(codeEl: HTMLElement, lang: string): void {
|
|
|
217
213
|
const tmp = document.createElement('div');
|
|
218
214
|
tmp.innerHTML = h.codeToHtml(codeEl.textContent ?? '', {
|
|
219
215
|
lang: safeLang,
|
|
220
|
-
theme:
|
|
216
|
+
theme: h.getLoadedThemes()[0],
|
|
221
217
|
});
|
|
222
218
|
const shikiPre = tmp.firstElementChild as HTMLElement | null;
|
|
223
219
|
const shikiCode = shikiPre?.querySelector('code');
|
|
224
220
|
if (!shikiPre || !shikiCode) return;
|
|
225
221
|
const parentPre = codeEl.parentElement;
|
|
226
|
-
if (parentPre)
|
|
222
|
+
if (parentPre) {
|
|
223
|
+
// Shiki's inline background and text colour.
|
|
224
|
+
parentPre.style.cssText = shikiPre.style.cssText;
|
|
225
|
+
parentPre.classList.add('igd-code');
|
|
226
|
+
}
|
|
227
227
|
codeEl.innerHTML = shikiCode.innerHTML;
|
|
228
228
|
})
|
|
229
229
|
.catch(console.warn);
|
|
@@ -233,6 +233,70 @@ function normalizeCodeLang(lang: string | undefined): string {
|
|
|
233
233
|
return LANG_MAP[lang ?? ''] ?? lang ?? 'text';
|
|
234
234
|
}
|
|
235
235
|
|
|
236
|
+
// ─── Action Tooltips ──────────────────────────────────────────────────────────
|
|
237
|
+
|
|
238
|
+
const COPY_CODE_LABEL = 'Copy code';
|
|
239
|
+
const CODE_COPIED_LABEL = 'Code copied';
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Give an icon-only action button a hover/focus tooltip that names its action.
|
|
243
|
+
* The text is the button's `aria-label`, so the visible and accessible names
|
|
244
|
+
* stay the same. Call after the button is in the DOM: the tooltip is inserted
|
|
245
|
+
* as its next sibling.
|
|
246
|
+
*/
|
|
247
|
+
function addActionTooltip(btn: HTMLElement): IgcTooltipComponent {
|
|
248
|
+
const tooltip = document.createElement('igc-tooltip') as IgcTooltipComponent;
|
|
249
|
+
tooltip.className = 'igd-sample-action-tooltip';
|
|
250
|
+
tooltip.withArrow = true;
|
|
251
|
+
tooltip.message = btn.getAttribute('aria-label') ?? '';
|
|
252
|
+
tooltip.anchor = btn;
|
|
253
|
+
btn.after(tooltip);
|
|
254
|
+
return tooltip;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Wire a code-tab copy button: copy on click, then switch its icon,
|
|
259
|
+
* `aria-label` and tooltip to the "copied" state for a moment.
|
|
260
|
+
*/
|
|
261
|
+
function wireCopyButton(btn: HTMLElement, getText: () => string): void {
|
|
262
|
+
const icon = btn.querySelector<HTMLElement>('igc-icon');
|
|
263
|
+
const tooltip = addActionTooltip(btn);
|
|
264
|
+
// `click` is a default hide trigger; drop it so the tooltip stays open to
|
|
265
|
+
// confirm the copy.
|
|
266
|
+
tooltip.hideTriggers = 'pointerleave,focusout';
|
|
267
|
+
|
|
268
|
+
const setLabel = (label: string) => {
|
|
269
|
+
btn.setAttribute('aria-label', label);
|
|
270
|
+
tooltip.message = label;
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
// Element that holds the copy-status live region.
|
|
274
|
+
const host = btn.parentElement ?? btn;
|
|
275
|
+
|
|
276
|
+
btn.addEventListener('click', () => {
|
|
277
|
+
navigator.clipboard
|
|
278
|
+
.writeText(getText())
|
|
279
|
+
.then(() => {
|
|
280
|
+
icon?.setAttribute('name', 'check');
|
|
281
|
+
setLabel(CODE_COPIED_LABEL);
|
|
282
|
+
announceCopyStatus(host, 'Code copied to clipboard');
|
|
283
|
+
// A click inside the show delay cancels the pending show; open it now.
|
|
284
|
+
void tooltip.show();
|
|
285
|
+
})
|
|
286
|
+
.catch(() => {
|
|
287
|
+
setLabel('Copy failed');
|
|
288
|
+
announceCopyStatus(host, 'Copy failed');
|
|
289
|
+
})
|
|
290
|
+
.then(() =>
|
|
291
|
+
setTimeout(() => {
|
|
292
|
+
icon?.setAttribute('name', 'copy');
|
|
293
|
+
setLabel(COPY_CODE_LABEL);
|
|
294
|
+
clearCopyStatus(host);
|
|
295
|
+
}, 1500),
|
|
296
|
+
);
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
|
|
236
300
|
// ─── Code Tab Rendering ───────────────────────────────────────────────────────
|
|
237
301
|
|
|
238
302
|
function addCodeTab(igcTabs: HTMLElement, file: SampleFile, useFileName = false): void {
|
|
@@ -245,6 +309,7 @@ function addCodeTab(igcTabs: HTMLElement, file: SampleFile, useFileName = false)
|
|
|
245
309
|
wrapper.className = 'code-wrapper';
|
|
246
310
|
|
|
247
311
|
const pre = document.createElement('pre');
|
|
312
|
+
pre.className = 'igd-code';
|
|
248
313
|
const code = document.createElement('code');
|
|
249
314
|
code.className = `language-${lang}`;
|
|
250
315
|
code.textContent = file.content;
|
|
@@ -254,7 +319,7 @@ function addCodeTab(igcTabs: HTMLElement, file: SampleFile, useFileName = false)
|
|
|
254
319
|
// affordances look identical.
|
|
255
320
|
const copyBtn = document.createElement('igc-icon-button') as HTMLElement;
|
|
256
321
|
copyBtn.setAttribute('variant', 'flat');
|
|
257
|
-
copyBtn.setAttribute('aria-label',
|
|
322
|
+
copyBtn.setAttribute('aria-label', COPY_CODE_LABEL);
|
|
258
323
|
copyBtn.className = 'cv-hljs-code-copy';
|
|
259
324
|
|
|
260
325
|
const copyIcon = document.createElement('igc-icon');
|
|
@@ -262,19 +327,9 @@ function addCodeTab(igcTabs: HTMLElement, file: SampleFile, useFileName = false)
|
|
|
262
327
|
copyIcon.setAttribute('collection', 'docs');
|
|
263
328
|
copyBtn.appendChild(copyIcon);
|
|
264
329
|
|
|
265
|
-
copyBtn.addEventListener('click', () => {
|
|
266
|
-
navigator.clipboard.writeText(file.content).then(() => {
|
|
267
|
-
copyIcon.setAttribute('name', 'check');
|
|
268
|
-
copyBtn.setAttribute('aria-label', 'Code copied');
|
|
269
|
-
setTimeout(() => {
|
|
270
|
-
copyIcon.setAttribute('name', 'copy');
|
|
271
|
-
copyBtn.setAttribute('aria-label', 'Copy code');
|
|
272
|
-
}, 1500);
|
|
273
|
-
});
|
|
274
|
-
});
|
|
275
|
-
|
|
276
330
|
wrapper.appendChild(pre);
|
|
277
331
|
wrapper.appendChild(copyBtn);
|
|
332
|
+
wireCopyButton(copyBtn, () => file.content);
|
|
278
333
|
tab.appendChild(wrapper);
|
|
279
334
|
igcTabs.appendChild(tab);
|
|
280
335
|
|
|
@@ -314,6 +369,7 @@ function addFooter(
|
|
|
314
369
|
btn.className = 'stackblitz-btn igd-edit-in-btn';
|
|
315
370
|
btn.addEventListener('click', onStackblitz);
|
|
316
371
|
actions.appendChild(btn);
|
|
372
|
+
addActionTooltip(btn);
|
|
317
373
|
}
|
|
318
374
|
|
|
319
375
|
// CodeSandbox hidden, re-enable when https://github.com/codesandbox/codesandbox-client/issues/8884 is fixed.
|
|
@@ -341,6 +397,7 @@ function addFooter(
|
|
|
341
397
|
fsBtn.setAttribute('target', '_blank');
|
|
342
398
|
}
|
|
343
399
|
actions.appendChild(fsBtn);
|
|
400
|
+
addActionTooltip(fsBtn);
|
|
344
401
|
}
|
|
345
402
|
if (actions.childElementCount) footer.appendChild(actions);
|
|
346
403
|
|
|
@@ -349,7 +406,7 @@ function addFooter(
|
|
|
349
406
|
footer.appendChild(themingBar);
|
|
350
407
|
}
|
|
351
408
|
|
|
352
|
-
// Nothing to show (e.g. a `
|
|
409
|
+
// Nothing to show (e.g. a `chrome="demo"` sample without a theme picker): no footer.
|
|
353
410
|
if (footer.childElementCount) widget.appendChild(footer);
|
|
354
411
|
}
|
|
355
412
|
|
|
@@ -657,6 +714,14 @@ const FIT_CONTENT_ENABLE_MESSAGE = 'igd-sample-fit';
|
|
|
657
714
|
|
|
658
715
|
let _fitContentMessageBound = false;
|
|
659
716
|
|
|
717
|
+
/**
|
|
718
|
+
* The document of each fit-content iframe that has reported its own size.
|
|
719
|
+
* Keyed by document, not set on the iframe, so that navigating the iframe to
|
|
720
|
+
* a page that does not report resumes direct measurement. A report that
|
|
721
|
+
* arrives before the new page's load event is already from the new document.
|
|
722
|
+
*/
|
|
723
|
+
const _reportingDocuments = new WeakMap<HTMLIFrameElement, Document | null>();
|
|
724
|
+
|
|
660
725
|
/**
|
|
661
726
|
* Apply a measured content size to a fit-content iframe. The size goes on the
|
|
662
727
|
* iframe itself; the container has `height: auto` in fit-content mode, so it
|
|
@@ -728,6 +793,9 @@ function bindFitContentMessages(): void {
|
|
|
728
793
|
.querySelectorAll<HTMLIFrameElement>('.igd-sample-container[data-fit-content] iframe')
|
|
729
794
|
.forEach((iframe) => {
|
|
730
795
|
if (iframe.contentWindow !== e.source) return;
|
|
796
|
+
// A demo that reports its own size knows it best. Direct measurement
|
|
797
|
+
// of this same-origin document stops from here on (see wireFitContent).
|
|
798
|
+
_reportingDocuments.set(iframe, iframe.contentDocument);
|
|
731
799
|
// Width only matters when the host aligns the iframe
|
|
732
800
|
// horizontally (position → data-justify); otherwise the iframe
|
|
733
801
|
// stays full-width and a reported width is ignored. Resizable
|
|
@@ -749,6 +817,12 @@ function bindFitContentMessages(): void {
|
|
|
749
817
|
* in sync with a ResizeObserver on their <body>. Cross-origin demos can't be
|
|
750
818
|
* read, so they must post their height (see FIT_CONTENT_MESSAGE).
|
|
751
819
|
*
|
|
820
|
+
* A same-origin demo that also posts its height is sized by its messages
|
|
821
|
+
* alone. Its page may fill the iframe (`html, body { height: 100% }`), and
|
|
822
|
+
* then the direct measurement only echoes the iframe height back. Both paths
|
|
823
|
+
* writing the height race: a stale echo can land after the demo's last
|
|
824
|
+
* report and leave the iframe cut off.
|
|
825
|
+
*
|
|
752
826
|
* The `height` prop is only the placeholder/fallback in fit-content mode —
|
|
753
827
|
* once a size is measured/reported, the content dictates it. Measurement uses
|
|
754
828
|
* the html/body offset heights (not the document scrollHeight, which is
|
|
@@ -767,6 +841,7 @@ function wireFitContent(iframe: HTMLIFrameElement): void {
|
|
|
767
841
|
const doc = iframe.contentDocument;
|
|
768
842
|
const body = doc?.body;
|
|
769
843
|
if (!body) return; // cross-origin — rely on postMessage instead
|
|
844
|
+
if (_reportingDocuments.get(iframe) === doc) return; // the demo reports its own size
|
|
770
845
|
setFitSize(iframe, {
|
|
771
846
|
height: Math.max(doc!.documentElement.offsetHeight, body.offsetHeight, body.scrollHeight),
|
|
772
847
|
width: measureContentWidth(iframe, body),
|
|
@@ -818,7 +893,7 @@ function wireFitContent(iframe: HTMLIFrameElement): void {
|
|
|
818
893
|
}, 3000);
|
|
819
894
|
};
|
|
820
895
|
|
|
821
|
-
//
|
|
896
|
+
// chrome="bare" renders `src` directly, so the iframe may already be loaded —
|
|
822
897
|
// and a cross-origin iframe gives no way to detect that (contentDocument is
|
|
823
898
|
// null whether it's loaded or not). Run the handler once at wire time as
|
|
824
899
|
// well: on a not-yet-loaded iframe the enable message is simply lost and
|
|
@@ -908,6 +983,56 @@ function initResizableSamples(): void {
|
|
|
908
983
|
.forEach(wireResizable);
|
|
909
984
|
}
|
|
910
985
|
|
|
986
|
+
// ─── Click forwarding ───────────────────────────────────────────────────────────
|
|
987
|
+
|
|
988
|
+
/**
|
|
989
|
+
* Forwards a `pointerdown` or `click` on the container's empty area to a
|
|
990
|
+
* same-origin demo's `<html>` element.
|
|
991
|
+
*/
|
|
992
|
+
function wireClickForwarding(container: HTMLElement): void {
|
|
993
|
+
if (container.dataset.clickForwardingWired) return;
|
|
994
|
+
container.dataset.clickForwardingWired = 'true';
|
|
995
|
+
|
|
996
|
+
const forward = (event: MouseEvent): void => {
|
|
997
|
+
if (event.target !== container) return;
|
|
998
|
+
const iframe = container.querySelector('iframe');
|
|
999
|
+
let doc: Document | null = null;
|
|
1000
|
+
try {
|
|
1001
|
+
doc = iframe?.contentDocument ?? null;
|
|
1002
|
+
} catch {
|
|
1003
|
+
// A cross-origin demo cannot be reached.
|
|
1004
|
+
}
|
|
1005
|
+
const win = iframe?.contentWindow as (Window & typeof globalThis) | null | undefined;
|
|
1006
|
+
if (!doc?.documentElement || !win) return;
|
|
1007
|
+
|
|
1008
|
+
const init = {
|
|
1009
|
+
bubbles: true,
|
|
1010
|
+
composed: true,
|
|
1011
|
+
cancelable: true,
|
|
1012
|
+
view: win,
|
|
1013
|
+
button: event.button,
|
|
1014
|
+
buttons: event.buttons,
|
|
1015
|
+
};
|
|
1016
|
+
doc.documentElement.dispatchEvent(
|
|
1017
|
+
event.type === 'pointerdown'
|
|
1018
|
+
? new win.PointerEvent('pointerdown', {
|
|
1019
|
+
...init,
|
|
1020
|
+
pointerId: 1,
|
|
1021
|
+
pointerType: 'mouse',
|
|
1022
|
+
isPrimary: true,
|
|
1023
|
+
})
|
|
1024
|
+
: new win.MouseEvent('click', init),
|
|
1025
|
+
);
|
|
1026
|
+
};
|
|
1027
|
+
|
|
1028
|
+
container.addEventListener('pointerdown', forward);
|
|
1029
|
+
container.addEventListener('click', forward);
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
function initClickForwarding(): void {
|
|
1033
|
+
document.querySelectorAll<HTMLElement>('.igd-sample-container').forEach(wireClickForwarding);
|
|
1034
|
+
}
|
|
1035
|
+
|
|
911
1036
|
// ─── Entry Point ──────────────────────────────────────────────────────────────
|
|
912
1037
|
|
|
913
1038
|
/**
|
|
@@ -919,13 +1044,16 @@ function initResizableSamples(): void {
|
|
|
919
1044
|
* `.ig-code-view` elements managed by code-view.js.
|
|
920
1045
|
*/
|
|
921
1046
|
export function initSampleWidgets(): void {
|
|
922
|
-
// Wire fit-content iframes (
|
|
1047
|
+
// Wire fit-content iframes (widgets and chrome="bare" samples alike) up front
|
|
923
1048
|
// so they start measuring as soon as their content loads.
|
|
924
1049
|
initFitContentIframes();
|
|
925
1050
|
|
|
926
1051
|
// Wire resizable samples so their drag handle / arrow keys work immediately.
|
|
927
1052
|
initResizableSamples();
|
|
928
1053
|
|
|
1054
|
+
// Forward clicks on the empty sample area to same-origin demos.
|
|
1055
|
+
initClickForwarding();
|
|
1056
|
+
|
|
929
1057
|
// Kick off the Shiki download immediately so it is ready before the user
|
|
930
1058
|
// opens a code tab (tabs appear only after an IntersectionObserver fires
|
|
931
1059
|
// + a JSON fetch completes, giving Shiki time to load in parallel).
|
|
@@ -969,8 +1097,8 @@ export function initSampleWidgets(): void {
|
|
|
969
1097
|
const demosBaseUrl = widget.dataset.demosBaseUrl || '';
|
|
970
1098
|
const githubSrc = widget.dataset.githubSrc || '';
|
|
971
1099
|
const platform = normalizePlatform(widget.dataset.platform || 'angular');
|
|
972
|
-
// `
|
|
973
|
-
const
|
|
1100
|
+
// `chrome="demo"` samples render no tabs: only the demo and the theme picker.
|
|
1101
|
+
const isDemo = widget.dataset.chrome === 'demo';
|
|
974
1102
|
|
|
975
1103
|
if (!iframeSrc) return;
|
|
976
1104
|
|
|
@@ -978,7 +1106,7 @@ export function initSampleWidgets(): void {
|
|
|
978
1106
|
const samplePane = widget.querySelector<HTMLElement>('.igd-sample-container');
|
|
979
1107
|
const iframe = widget.querySelector<HTMLIFrameElement>('iframe');
|
|
980
1108
|
|
|
981
|
-
if (!igcTabs && !
|
|
1109
|
+
if (!igcTabs && !isDemo) return;
|
|
982
1110
|
|
|
983
1111
|
const exampleTabId = `${widget.id}-example`;
|
|
984
1112
|
|
|
@@ -1046,19 +1174,11 @@ export function initSampleWidgets(): void {
|
|
|
1046
1174
|
// Wire copy buttons for pre-rendered code tabs (e.g. MockSample in playground).
|
|
1047
1175
|
widget.querySelectorAll<HTMLElement>('.code-wrapper').forEach((pre) => {
|
|
1048
1176
|
const btn = pre.querySelector<HTMLElement>('.cv-hljs-code-copy');
|
|
1049
|
-
const icon = btn?.querySelector<HTMLElement>('igc-icon');
|
|
1050
1177
|
const code = pre.querySelector<HTMLElement>('code');
|
|
1051
1178
|
if (!btn || !code) return;
|
|
1052
1179
|
const codeLang = (code.className.match(/language-(\S+)/) ?? [])[1] ?? 'text';
|
|
1053
1180
|
highlightCode(code, normalizeCodeLang(codeLang));
|
|
1054
|
-
btn
|
|
1055
|
-
navigator.clipboard.writeText(code.textContent ?? '').then(() => {
|
|
1056
|
-
icon?.setAttribute('name', 'check');
|
|
1057
|
-
setTimeout(() => {
|
|
1058
|
-
icon?.setAttribute('name', 'copy');
|
|
1059
|
-
}, 1500);
|
|
1060
|
-
});
|
|
1061
|
-
});
|
|
1181
|
+
wireCopyButton(btn, () => code.textContent ?? '');
|
|
1062
1182
|
});
|
|
1063
1183
|
|
|
1064
1184
|
// Enqueue iframe loading.
|
|
@@ -1082,7 +1202,7 @@ export function initSampleWidgets(): void {
|
|
|
1082
1202
|
|
|
1083
1203
|
// No code to fetch and nothing to live-edit or open in full screen: the
|
|
1084
1204
|
// footer carries only the theme picker, right away.
|
|
1085
|
-
if (
|
|
1205
|
+
if (isDemo || !igcTabs) {
|
|
1086
1206
|
addFooter(widget, iframeSrc, null, null, null, false);
|
|
1087
1207
|
return;
|
|
1088
1208
|
}
|