igniteui-astro-components 0.0.29 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +17 -14
- package/src/components/DocsSidebar/DocsSidebar.scss +3 -2
- package/src/components/DocsSidebar/SidebarFilterInput.scss +1 -3
- package/src/components/DocsSubHeader/DocsSubHeader.scss +1 -1
- package/src/components/DocsTree/docs-tree.scss +0 -1
- package/src/components/mdx/Sample/README.md +16 -10
- package/src/components/mdx/Sample/Sample.astro +156 -19
- package/src/components/mdx/Sample/Sample.scss +238 -9
- package/src/integration.ts +26 -14
- package/src/layouts/DocsLayout/DocsLayout.scss +0 -4
- package/src/plugins/rehype-heading-anchors.ts +53 -61
- package/src/plugins/rehype-pagefind-ignore.ts +19 -28
- package/src/plugins/rehype-table-wrapper.ts +38 -36
- package/src/plugins/remark-env-vars.ts +26 -20
- package/src/plugins/remark-html-transforms.ts +21 -18
- package/src/plugins/remark-md-links.ts +43 -31
- package/src/scripts/sample-widget.ts +288 -1
- package/src/styles/global/_code-blocks.scss +2 -23
- package/src/styles/global/_copy-button.scss +32 -0
- package/src/styles/global/_search-shared.scss +1 -1
- package/src/styles/global/_variables.scss +1 -1
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* DOCS_ENV (or NODE_ENV) selects the env block: development | staging | production.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import {
|
|
17
|
+
import { defineMdastPlugin } from 'satteri';
|
|
18
18
|
import fs from 'node:fs';
|
|
19
19
|
import path from 'node:path';
|
|
20
20
|
|
|
@@ -95,24 +95,30 @@ export function replaceEnvVars(str: string): string {
|
|
|
95
95
|
return str.replace(ENV_PATTERN, (_match, key) => env[key] ?? `{environment:${key}}`);
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
/**
|
|
98
|
+
/**
|
|
99
|
+
* Sätteri MDAST plugin that substitutes `{environment:key}` tokens.
|
|
100
|
+
*
|
|
101
|
+
* Exported as a factory so Sätteri calls it once per compile; the `loadEnv()`
|
|
102
|
+
* cache is module-level and intentionally shared across documents.
|
|
103
|
+
*/
|
|
99
104
|
export function remarkEnvVars() {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (node.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
105
|
+
return defineMdastPlugin({
|
|
106
|
+
name: 'env-vars',
|
|
107
|
+
text(node, ctx) {
|
|
108
|
+
const value = replaceEnvVars(node.value);
|
|
109
|
+
if (value !== node.value) ctx.setProperty(node, 'value', value);
|
|
110
|
+
},
|
|
111
|
+
html(node, ctx) {
|
|
112
|
+
const value = replaceEnvVars(node.value);
|
|
113
|
+
if (value !== node.value) ctx.setProperty(node, 'value', value);
|
|
114
|
+
},
|
|
115
|
+
link(node, ctx) {
|
|
116
|
+
const url = replaceEnvVars(node.url);
|
|
117
|
+
if (url !== node.url) ctx.setProperty(node, 'url', url);
|
|
118
|
+
},
|
|
119
|
+
image(node, ctx) {
|
|
120
|
+
const url = replaceEnvVars(node.url);
|
|
121
|
+
if (url !== node.url) ctx.setProperty(node, 'url', url);
|
|
122
|
+
},
|
|
123
|
+
});
|
|
118
124
|
}
|
|
@@ -1,32 +1,35 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Sätteri MDAST plugin: inline HTML transforms.
|
|
3
3
|
*
|
|
4
4
|
* Handles legacy HTML patterns in markdown content:
|
|
5
5
|
* - `<div class="divider--half"></div>` → `<hr/>`
|
|
6
6
|
* - Normalizes code block language identifiers to lowercase
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import { defineMdastPlugin } from 'satteri';
|
|
10
10
|
|
|
11
11
|
const DIVIDER_PATTERN = /<div\s+class="divider--half"\s*>\s*<\/div>/g;
|
|
12
12
|
const IMG_SRC_PATTERN = /src="(\.\.\/)+images\//g;
|
|
13
13
|
|
|
14
|
-
/**
|
|
14
|
+
/** Sätteri MDAST plugin that transforms legacy HTML patterns in the AST. */
|
|
15
15
|
export function remarkHtmlTransforms() {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
|
-
visit(tree, (node: any) => {
|
|
20
|
-
// Inline HTML: divider → hr, relative img src → root-relative
|
|
21
|
-
if (node.type === 'html' && node.value) {
|
|
22
|
-
node.value = (node.value as string).replace(DIVIDER_PATTERN, '<hr/>');
|
|
23
|
-
node.value = (node.value as string).replace(IMG_SRC_PATTERN, 'src="/images/');
|
|
24
|
-
}
|
|
16
|
+
return defineMdastPlugin({
|
|
17
|
+
name: 'html-transforms',
|
|
25
18
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
19
|
+
// Inline HTML: divider → hr, relative img src → root-relative
|
|
20
|
+
html(node, ctx) {
|
|
21
|
+
if (!node.value) return;
|
|
22
|
+
const value = node.value
|
|
23
|
+
.replace(DIVIDER_PATTERN, '<hr/>')
|
|
24
|
+
.replace(IMG_SRC_PATTERN, 'src="/images/');
|
|
25
|
+
if (value !== node.value) ctx.setProperty(node, 'value', value);
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
// Code blocks: normalize language to lowercase
|
|
29
|
+
code(node, ctx) {
|
|
30
|
+
if (!node.lang) return;
|
|
31
|
+
const lang = node.lang.toLowerCase();
|
|
32
|
+
if (lang !== node.lang) ctx.setProperty(node, 'lang', lang);
|
|
33
|
+
},
|
|
34
|
+
});
|
|
32
35
|
}
|
|
@@ -8,8 +8,9 @@
|
|
|
8
8
|
* that are already absolute but missing the site base path.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import {
|
|
11
|
+
import { defineMdastPlugin } from 'satteri';
|
|
12
12
|
import path from 'node:path';
|
|
13
|
+
import { fileURLToPath } from 'node:url';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Resolve a relative .md link to an absolute Astro URL.
|
|
@@ -43,39 +44,50 @@ function rewriteMdLink(url: string, filePath: string, docsDir: string): string {
|
|
|
43
44
|
return docsBase + '/' + slug.toLowerCase() + '/' + suffix;
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
/**
|
|
47
|
+
/** Resolve the source file path and docs root for the document being compiled. */
|
|
48
|
+
function resolvePaths(fileURL: URL | undefined): { filePath: string; docsDir: string } {
|
|
49
|
+
const filePath = fileURL ? fileURLToPath(fileURL) : '';
|
|
50
|
+
const docsDir = process.env.DOCS_SOURCE_PATH
|
|
51
|
+
? path.resolve(process.env.DOCS_SOURCE_PATH)
|
|
52
|
+
: filePath
|
|
53
|
+
? path.dirname(filePath)
|
|
54
|
+
: '';
|
|
55
|
+
return { filePath, docsDir };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Satteri MDAST plugin that rewrites relative .md links, prepends DOCS_BASE,
|
|
60
|
+
* and fixes relative image paths.
|
|
61
|
+
*/
|
|
47
62
|
export function remarkMdLinks() {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const filePath = (file.path as string) ?? '';
|
|
51
|
-
const docsDir = process.env.DOCS_SOURCE_PATH
|
|
52
|
-
? path.resolve(process.env.DOCS_SOURCE_PATH)
|
|
53
|
-
: filePath
|
|
54
|
-
? path.dirname(filePath)
|
|
55
|
-
: '';
|
|
63
|
+
return defineMdastPlugin({
|
|
64
|
+
name: 'md-links',
|
|
56
65
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
66
|
+
link(node, ctx) {
|
|
67
|
+
if (!node.url) return;
|
|
68
|
+
const { filePath, docsDir } = resolvePaths(ctx.fileURL);
|
|
69
|
+
let url = rewriteMdLink(node.url, filePath, docsDir);
|
|
61
70
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
71
|
+
// Prepend DOCS_BASE to root-relative internal links not already prefixed.
|
|
72
|
+
const docsBase = (process.env.DOCS_BASE ?? '').replace(/[/]$/, '');
|
|
73
|
+
if (
|
|
74
|
+
docsBase &&
|
|
75
|
+
url.startsWith('/') &&
|
|
76
|
+
!url.startsWith('//') &&
|
|
77
|
+
!url.startsWith(docsBase + '/')
|
|
78
|
+
) {
|
|
79
|
+
url = docsBase + url;
|
|
72
80
|
}
|
|
73
81
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
82
|
+
if (url !== node.url) ctx.setProperty(node, 'url', url);
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
// Rewrite relative `../images/` paths in markdown image nodes to root-relative `/images/`.
|
|
86
|
+
// Generated MDX files may contain relative image references that Vite cannot resolve.
|
|
87
|
+
image(node, ctx) {
|
|
88
|
+
if (!node.url) return;
|
|
89
|
+
const url = node.url.replace(/^([.][.][/])+images[/]/, '/images/');
|
|
90
|
+
if (url !== node.url) ctx.setProperty(node, 'url', url);
|
|
91
|
+
},
|
|
92
|
+
});
|
|
81
93
|
}
|
|
@@ -209,8 +209,10 @@ function addCodeTab(igcTabs: HTMLElement, file: SampleFile): void {
|
|
|
209
209
|
code.textContent = file.content;
|
|
210
210
|
pre.appendChild(code);
|
|
211
211
|
|
|
212
|
+
// Same flat variant as the page-level CopyCode button so both copy
|
|
213
|
+
// affordances look identical.
|
|
212
214
|
const copyBtn = document.createElement('igc-icon-button') as HTMLElement;
|
|
213
|
-
copyBtn.setAttribute('variant', '
|
|
215
|
+
copyBtn.setAttribute('variant', 'flat');
|
|
214
216
|
copyBtn.setAttribute('aria-label', 'Copy code');
|
|
215
217
|
copyBtn.className = 'cv-hljs-code-copy';
|
|
216
218
|
|
|
@@ -247,6 +249,10 @@ function addFooter(
|
|
|
247
249
|
onStackblitz: (() => void) | null,
|
|
248
250
|
_onCodeSandbox: (() => void) | null,
|
|
249
251
|
): void {
|
|
252
|
+
// A footer may already be server-rendered (e.g. the playground's MockSample);
|
|
253
|
+
// don't append a second one.
|
|
254
|
+
if (widget.querySelector('.igd-code-view__footer-actions')) return;
|
|
255
|
+
|
|
250
256
|
const footer = document.createElement('div');
|
|
251
257
|
footer.className = 'igd-code-view__footer-actions';
|
|
252
258
|
|
|
@@ -550,6 +556,280 @@ class XplatCodeService {
|
|
|
550
556
|
}
|
|
551
557
|
}
|
|
552
558
|
|
|
559
|
+
// ─── Fit-to-content sizing ──────────────────────────────────────────────────────
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Message a demo can post to resize its host `<Sample fitContent>` iframe:
|
|
563
|
+
* parent.postMessage({ type: 'igd-sample-height', height: <px>, width: <px?> }, '*')
|
|
564
|
+
* This is the path for cross-origin demos, where the host page can't read the
|
|
565
|
+
* iframe's contentDocument to measure it directly. `width` is optional — post
|
|
566
|
+
* it when the sample is horizontally aligned via `position`.
|
|
567
|
+
*/
|
|
568
|
+
const FIT_CONTENT_MESSAGE = 'igd-sample-height';
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* Posted INTO the iframe once it loads, telling the embedded demo that its
|
|
572
|
+
* host sizes itself to the content. The demo's reporter script reacts by
|
|
573
|
+
* neutralizing viewport-bound sizing (`html, body { height: 100% }` — which
|
|
574
|
+
* would otherwise just echo the iframe height back) and starts posting
|
|
575
|
+
* FIT_CONTENT_MESSAGE sizes. Demos in fixed-height samples never receive this
|
|
576
|
+
* and keep their percentage-height layouts.
|
|
577
|
+
*/
|
|
578
|
+
const FIT_CONTENT_ENABLE_MESSAGE = 'igd-sample-fit';
|
|
579
|
+
|
|
580
|
+
let _fitContentMessageBound = false;
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Apply a measured content size to a fit-content iframe. The size goes on the
|
|
584
|
+
* iframe itself; the container has `height: auto` in fit-content mode, so it
|
|
585
|
+
* grows around the iframe (including any `spacing` padding). Width is only
|
|
586
|
+
* applied when reported/measured — see measureContentWidth().
|
|
587
|
+
*/
|
|
588
|
+
function setFitSize(iframe: HTMLIFrameElement, size: { height?: number; width?: number }): void {
|
|
589
|
+
if (size.height && size.height > 0) {
|
|
590
|
+
iframe.style.height = `${Math.ceil(size.height)}px`;
|
|
591
|
+
// Distinguish a real measured/reported size from the server-rendered
|
|
592
|
+
// `height` fallback the iframe starts with.
|
|
593
|
+
iframe.dataset.fitSized = 'true';
|
|
594
|
+
}
|
|
595
|
+
if (size.width && size.width > 0) {
|
|
596
|
+
iframe.style.width = `${Math.ceil(size.width)}px`;
|
|
597
|
+
// The frame defaults to full width (see Sample.scss); once the iframe
|
|
598
|
+
// has a definite px width, let the frame shrink-wrap it so the host's
|
|
599
|
+
// flex alignment (position) can move the content-sized box around.
|
|
600
|
+
const frame = iframe.closest<HTMLElement>('.igd-sample-frame');
|
|
601
|
+
if (frame) frame.style.width = 'auto';
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* Measure the intrinsic width of a same-origin demo's content. Only used when
|
|
607
|
+
* the host container aligns the iframe horizontally (`position` → data-justify):
|
|
608
|
+
* block-level demo content stretches to the viewport width, so instead we take
|
|
609
|
+
* the right-most element box. Demos with intrinsically sized content (a lone
|
|
610
|
+
* avatar, a button…) shrink the iframe to that content, letting the host's
|
|
611
|
+
* flex alignment actually center/end-align it. Full-width demos measure the
|
|
612
|
+
* viewport width and are left as-is.
|
|
613
|
+
*
|
|
614
|
+
* Resizable containers are excluded entirely: there the user's drag owns the
|
|
615
|
+
* width, and applying a measured width would clobber it on every observer tick.
|
|
616
|
+
*/
|
|
617
|
+
function measureContentWidth(iframe: HTMLIFrameElement, body: HTMLElement): number | undefined {
|
|
618
|
+
const container = iframe.closest<HTMLElement>('.igd-sample-container');
|
|
619
|
+
if (!container?.dataset.justify || container.dataset.resizable) return undefined;
|
|
620
|
+
const left = body.getBoundingClientRect().left;
|
|
621
|
+
let right = left;
|
|
622
|
+
body.querySelectorAll('*').forEach((el) => {
|
|
623
|
+
right = Math.max(right, el.getBoundingClientRect().right);
|
|
624
|
+
});
|
|
625
|
+
if (right <= left) return undefined;
|
|
626
|
+
// The right-most element edge includes the body's leading padding but not
|
|
627
|
+
// its trailing padding. Demos use body padding to reserve room for ink
|
|
628
|
+
// overflow (shadows, glows) — keep that room on the trailing side too.
|
|
629
|
+
const cs = iframe.contentWindow?.getComputedStyle(body);
|
|
630
|
+
const trailing = cs
|
|
631
|
+
? parseFloat(cs.paddingRight || '0') + parseFloat(cs.borderRightWidth || '0')
|
|
632
|
+
: 0;
|
|
633
|
+
return right - left + trailing;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
function bindFitContentMessages(): void {
|
|
637
|
+
if (_fitContentMessageBound) return;
|
|
638
|
+
_fitContentMessageBound = true;
|
|
639
|
+
window.addEventListener('message', (e: MessageEvent) => {
|
|
640
|
+
const data = e.data;
|
|
641
|
+
if (
|
|
642
|
+
!data ||
|
|
643
|
+
data.type !== FIT_CONTENT_MESSAGE ||
|
|
644
|
+
typeof data.height !== 'number' ||
|
|
645
|
+
!Number.isFinite(data.height) ||
|
|
646
|
+
data.height <= 0
|
|
647
|
+
)
|
|
648
|
+
return;
|
|
649
|
+
document
|
|
650
|
+
.querySelectorAll<HTMLIFrameElement>('.igd-sample-container[data-fit-content] iframe')
|
|
651
|
+
.forEach((iframe) => {
|
|
652
|
+
if (iframe.contentWindow !== e.source) return;
|
|
653
|
+
// Width only matters when the host aligns the iframe
|
|
654
|
+
// horizontally (position → data-justify); otherwise the iframe
|
|
655
|
+
// stays full-width and a reported width is ignored. Resizable
|
|
656
|
+
// containers ignore it too — the user's drag owns the width.
|
|
657
|
+
const container = iframe.closest<HTMLElement>('.igd-sample-container');
|
|
658
|
+
const useWidth = Boolean(container?.dataset.justify) && !container?.dataset.resizable;
|
|
659
|
+
setFitSize(iframe, {
|
|
660
|
+
height: data.height,
|
|
661
|
+
width: useWidth && typeof data.width === 'number' ? data.width : undefined,
|
|
662
|
+
});
|
|
663
|
+
});
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
* Wire an iframe whose container opted into fit-content sizing.
|
|
669
|
+
*
|
|
670
|
+
* Same-origin demos (e.g. the playground mock) are measured directly and kept
|
|
671
|
+
* in sync with a ResizeObserver on their <body>. Cross-origin demos can't be
|
|
672
|
+
* read, so they must post their height (see FIT_CONTENT_MESSAGE).
|
|
673
|
+
*
|
|
674
|
+
* The `height` prop is only the placeholder/fallback in fit-content mode —
|
|
675
|
+
* once a size is measured/reported, the content dictates it. Measurement uses
|
|
676
|
+
* the html/body offset heights (not the document scrollHeight, which is
|
|
677
|
+
* clamped to the viewport) so the iframe can shrink below its current height
|
|
678
|
+
* as well as grow.
|
|
679
|
+
*/
|
|
680
|
+
function wireFitContent(iframe: HTMLIFrameElement): void {
|
|
681
|
+
if (iframe.dataset.fitContentWired) return;
|
|
682
|
+
iframe.dataset.fitContentWired = 'true';
|
|
683
|
+
bindFitContentMessages();
|
|
684
|
+
|
|
685
|
+
let bodyObserver: ResizeObserver | null = null;
|
|
686
|
+
|
|
687
|
+
const measure = () => {
|
|
688
|
+
try {
|
|
689
|
+
const doc = iframe.contentDocument;
|
|
690
|
+
const body = doc?.body;
|
|
691
|
+
if (!body) return; // cross-origin — rely on postMessage instead
|
|
692
|
+
setFitSize(iframe, {
|
|
693
|
+
height: Math.max(doc!.documentElement.offsetHeight, body.offsetHeight, body.scrollHeight),
|
|
694
|
+
width: measureContentWidth(iframe, body),
|
|
695
|
+
});
|
|
696
|
+
} catch {
|
|
697
|
+
/* cross-origin — rely on postMessage instead */
|
|
698
|
+
}
|
|
699
|
+
};
|
|
700
|
+
|
|
701
|
+
const onLoad = () => {
|
|
702
|
+
// Tell the demo this is a fit-content embed (see the constant's doc).
|
|
703
|
+
// `width: true` additionally asks it to shrink-wrap and report its
|
|
704
|
+
// intrinsic width, so the host's `position` can center/align it.
|
|
705
|
+
// Not on resizable containers — there the user's drag owns the width
|
|
706
|
+
// and the demo should keep filling whatever width it is given.
|
|
707
|
+
const container = iframe.closest<HTMLElement>('.igd-sample-container');
|
|
708
|
+
iframe.contentWindow?.postMessage(
|
|
709
|
+
{
|
|
710
|
+
type: FIT_CONTENT_ENABLE_MESSAGE,
|
|
711
|
+
width: Boolean(container?.dataset.justify) && !container?.dataset.resizable,
|
|
712
|
+
},
|
|
713
|
+
'*',
|
|
714
|
+
);
|
|
715
|
+
measure();
|
|
716
|
+
try {
|
|
717
|
+
const body = iframe.contentDocument?.body;
|
|
718
|
+
if (body && 'ResizeObserver' in window) {
|
|
719
|
+
// onLoad can run more than once (wire time + load event, or an
|
|
720
|
+
// iframe navigation) — replace the observer, never stack them.
|
|
721
|
+
bodyObserver?.disconnect();
|
|
722
|
+
bodyObserver = new ResizeObserver(measure);
|
|
723
|
+
bodyObserver.observe(body);
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
} catch {
|
|
727
|
+
/* cross-origin — nothing to observe */
|
|
728
|
+
}
|
|
729
|
+
// Cross-origin demo: it must post its size (see FIT_CONTENT_MESSAGE) or
|
|
730
|
+
// the iframe stays at the `height` prop fallback. Surface that loudly —
|
|
731
|
+
// a silently non-fitting sample is hard to diagnose from the docs side.
|
|
732
|
+
setTimeout(() => {
|
|
733
|
+
if (!iframe.dataset.fitSized) {
|
|
734
|
+
console.warn(
|
|
735
|
+
`[sample-widget] fitContent: cross-origin demo "${iframe.src}" hasn't reported its size. ` +
|
|
736
|
+
`The demo must run: parent.postMessage({ type: '${FIT_CONTENT_MESSAGE}', height: document.documentElement.scrollHeight }, '*') ` +
|
|
737
|
+
`on load/resize; until then the iframe keeps the \`height\` prop as a fallback.`,
|
|
738
|
+
);
|
|
739
|
+
}
|
|
740
|
+
}, 3000);
|
|
741
|
+
};
|
|
742
|
+
|
|
743
|
+
// iframeOnly renders `src` directly, so the iframe may already be loaded —
|
|
744
|
+
// and a cross-origin iframe gives no way to detect that (contentDocument is
|
|
745
|
+
// null whether it's loaded or not). Run the handler once at wire time as
|
|
746
|
+
// well: on a not-yet-loaded iframe the enable message is simply lost and
|
|
747
|
+
// the `load` listener below re-sends it; on an already-loaded one this is
|
|
748
|
+
// the only chance to deliver it. Widget iframes load lazily (data-src, no
|
|
749
|
+
// src yet) and are handled purely by the `load` event.
|
|
750
|
+
if (iframe.src) onLoad();
|
|
751
|
+
iframe.addEventListener('load', onLoad);
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
function initFitContentIframes(): void {
|
|
755
|
+
document
|
|
756
|
+
.querySelectorAll<HTMLIFrameElement>('.igd-sample-container[data-fit-content] iframe')
|
|
757
|
+
.forEach(wireFitContent);
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
// ─── Resizable samples ──────────────────────────────────────────────────────────
|
|
761
|
+
|
|
762
|
+
const RESIZE_MIN_WIDTH = 200; // px — narrowest the iframe can be dragged.
|
|
763
|
+
const RESIZE_KEY_STEP = 24; // px — width change per arrow-key press.
|
|
764
|
+
|
|
765
|
+
/**
|
|
766
|
+
* Wire a `<Sample resizable>` container: a right-edge drag handle plus left/right
|
|
767
|
+
* arrow keys resize the iframe's width (only the iframe, horizontally) so
|
|
768
|
+
* responsive demos can be previewed at different widths. The container's own
|
|
769
|
+
* footprint never changes.
|
|
770
|
+
*/
|
|
771
|
+
function wireResizable(container: HTMLElement): void {
|
|
772
|
+
if (container.dataset.resizableWired) return;
|
|
773
|
+
container.dataset.resizableWired = 'true';
|
|
774
|
+
|
|
775
|
+
const frame = container.querySelector<HTMLElement>('.igd-sample-frame');
|
|
776
|
+
const handle = container.querySelector<HTMLElement>('.igd-sample-resize-handle');
|
|
777
|
+
if (!frame) return;
|
|
778
|
+
|
|
779
|
+
// Widest the frame can be: the container's content box (minus padding).
|
|
780
|
+
const maxWidth = (): number => {
|
|
781
|
+
const cs = getComputedStyle(container);
|
|
782
|
+
const pad = parseFloat(cs.paddingLeft || '0') + parseFloat(cs.paddingRight || '0');
|
|
783
|
+
return Math.max(RESIZE_MIN_WIDTH, container.clientWidth - pad);
|
|
784
|
+
};
|
|
785
|
+
|
|
786
|
+
const setWidth = (px: number): void => {
|
|
787
|
+
const clamped = Math.round(Math.min(maxWidth(), Math.max(RESIZE_MIN_WIDTH, px)));
|
|
788
|
+
frame.style.width = `${clamped}px`;
|
|
789
|
+
};
|
|
790
|
+
|
|
791
|
+
// ─ Pointer drag ─
|
|
792
|
+
if (handle) {
|
|
793
|
+
handle.addEventListener('pointerdown', (e: PointerEvent) => {
|
|
794
|
+
e.preventDefault();
|
|
795
|
+
container.classList.add('resizing');
|
|
796
|
+
handle.setPointerCapture(e.pointerId);
|
|
797
|
+
|
|
798
|
+
const startX = e.clientX;
|
|
799
|
+
const startW = frame.getBoundingClientRect().width;
|
|
800
|
+
// A centered frame grows from both sides, so the handle covers half
|
|
801
|
+
// the width change per pixel moved.
|
|
802
|
+
const factor = getComputedStyle(container).justifyContent === 'center' ? 2 : 1;
|
|
803
|
+
|
|
804
|
+
const onMove = (ev: PointerEvent) => setWidth(startW + (ev.clientX - startX) * factor);
|
|
805
|
+
const onUp = (ev: PointerEvent) => {
|
|
806
|
+
container.classList.remove('resizing');
|
|
807
|
+
handle.releasePointerCapture?.(ev.pointerId);
|
|
808
|
+
handle.removeEventListener('pointermove', onMove);
|
|
809
|
+
handle.removeEventListener('pointerup', onUp);
|
|
810
|
+
handle.removeEventListener('pointercancel', onUp);
|
|
811
|
+
};
|
|
812
|
+
handle.addEventListener('pointermove', onMove);
|
|
813
|
+
handle.addEventListener('pointerup', onUp);
|
|
814
|
+
handle.addEventListener('pointercancel', onUp);
|
|
815
|
+
});
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
// ─ Keyboard (container is focusable via tabindex) ─
|
|
819
|
+
container.addEventListener('keydown', (e: KeyboardEvent) => {
|
|
820
|
+
if (e.key !== 'ArrowLeft' && e.key !== 'ArrowRight') return;
|
|
821
|
+
e.preventDefault();
|
|
822
|
+
const current = frame.getBoundingClientRect().width;
|
|
823
|
+
setWidth(current + (e.key === 'ArrowRight' ? RESIZE_KEY_STEP : -RESIZE_KEY_STEP));
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
function initResizableSamples(): void {
|
|
828
|
+
document
|
|
829
|
+
.querySelectorAll<HTMLElement>('.igd-sample-container[data-resizable]')
|
|
830
|
+
.forEach(wireResizable);
|
|
831
|
+
}
|
|
832
|
+
|
|
553
833
|
// ─── Entry Point ──────────────────────────────────────────────────────────────
|
|
554
834
|
|
|
555
835
|
/**
|
|
@@ -561,6 +841,13 @@ class XplatCodeService {
|
|
|
561
841
|
* `.ig-code-view` elements managed by code-view.js.
|
|
562
842
|
*/
|
|
563
843
|
export function initSampleWidgets(): void {
|
|
844
|
+
// Wire fit-content iframes (both full widgets and iframeOnly samples) up front
|
|
845
|
+
// so they start measuring as soon as their content loads.
|
|
846
|
+
initFitContentIframes();
|
|
847
|
+
|
|
848
|
+
// Wire resizable samples so their drag handle / arrow keys work immediately.
|
|
849
|
+
initResizableSamples();
|
|
850
|
+
|
|
564
851
|
// Kick off the Shiki download immediately so it is ready before the user
|
|
565
852
|
// opens a code tab (tabs appear only after an IntersectionObserver fires
|
|
566
853
|
// + a JSON fetch completes, giving Shiki time to load in parallel).
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
@use 'igniteui-theming' as *;
|
|
2
|
+
@use 'copy-button' as *;
|
|
2
3
|
|
|
3
4
|
/* ============================================================
|
|
4
5
|
Code Blocks (Shiki dual-theme)
|
|
@@ -45,29 +46,7 @@ pre.shiki {
|
|
|
45
46
|
opacity: 0;
|
|
46
47
|
z-index: 1;
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
--hover-foreground: var(--ig-primary-600-contrast);
|
|
50
|
-
--focus-foreground: var(--ig-primary-600-contrast);
|
|
51
|
-
--active-foreground: var(--ig-primary-600-contrast);
|
|
52
|
-
--background: var(--ig-primary-500);
|
|
53
|
-
--hover-background: var(--ig-primary-500);
|
|
54
|
-
--focus-background: var(--ig-primary-500);
|
|
55
|
-
--active-background: var(--ig-primary-500);
|
|
56
|
-
--border-color: transparent;
|
|
57
|
-
--border-color-hover: transparent;
|
|
58
|
-
--border-color-focus: transparent;
|
|
59
|
-
|
|
60
|
-
&:has([name='check']) {
|
|
61
|
-
--foreground: var(--ig-success-300-contrast);
|
|
62
|
-
--hover-foreground: var(--ig-success-300-contrast);
|
|
63
|
-
--focus-foreground: var(--ig-success-300-contrast);
|
|
64
|
-
--active-foreground: var(--ig-success-300-contrast);
|
|
65
|
-
|
|
66
|
-
--background: var(--ig-success-300);
|
|
67
|
-
--hover-background: var(--ig-success-300);
|
|
68
|
-
--focus-background: var(--ig-success-300);
|
|
69
|
-
--active-background: var(--ig-success-300);
|
|
70
|
-
}
|
|
49
|
+
@include copy-button-colors;
|
|
71
50
|
}
|
|
72
51
|
|
|
73
52
|
.copy-code-wrapper:hover > .copy-btn,
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/// Explicit palette for copy-code icon buttons (igc-icon-button).
|
|
2
|
+
///
|
|
3
|
+
/// Code panes always render the dark Shiki theme, while the icon-button's
|
|
4
|
+
/// default colors follow the site theme — in light mode that leaves the icon
|
|
5
|
+
/// near-invisible on the dark background until a hover state recolors it.
|
|
6
|
+
/// Pinning the full state palette keeps the button legible in both themes.
|
|
7
|
+
/// The success palette kicks in while the icon shows the post-copy check.
|
|
8
|
+
@mixin copy-button-colors {
|
|
9
|
+
--foreground: var(--ig-primary-600-contrast);
|
|
10
|
+
--hover-foreground: var(--ig-primary-600-contrast);
|
|
11
|
+
--focus-foreground: var(--ig-primary-600-contrast);
|
|
12
|
+
--active-foreground: var(--ig-primary-600-contrast);
|
|
13
|
+
--background: var(--ig-primary-500);
|
|
14
|
+
--hover-background: var(--ig-primary-500);
|
|
15
|
+
--focus-background: var(--ig-primary-500);
|
|
16
|
+
--active-background: var(--ig-primary-500);
|
|
17
|
+
--border-color: transparent;
|
|
18
|
+
--border-color-hover: transparent;
|
|
19
|
+
--border-color-focus: transparent;
|
|
20
|
+
|
|
21
|
+
&:has([name='check']) {
|
|
22
|
+
--foreground: var(--ig-success-300-contrast);
|
|
23
|
+
--hover-foreground: var(--ig-success-300-contrast);
|
|
24
|
+
--focus-foreground: var(--ig-success-300-contrast);
|
|
25
|
+
--active-foreground: var(--ig-success-300-contrast);
|
|
26
|
+
|
|
27
|
+
--background: var(--ig-success-300);
|
|
28
|
+
--hover-background: var(--ig-success-300);
|
|
29
|
+
--focus-background: var(--ig-success-300);
|
|
30
|
+
--active-background: var(--ig-success-300);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -253,12 +253,12 @@
|
|
|
253
253
|
--ig-size: var(--ig-size-large);
|
|
254
254
|
padding: rem(16px);
|
|
255
255
|
gap: rem(8px);
|
|
256
|
-
height: var(--search-header-footer-height);
|
|
257
256
|
}
|
|
258
257
|
|
|
259
258
|
// Visible only on mobile devices
|
|
260
259
|
.igd-search-footer {
|
|
261
260
|
display: none;
|
|
261
|
+
height: var(--search-header-footer-height);
|
|
262
262
|
}
|
|
263
263
|
|
|
264
264
|
.igd-search-header {
|