igniteui-astro-components 0.0.21 → 0.0.22

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "igniteui-astro-components",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "description": "Reusable Astro components, layouts, and integrations for Infragistics / Ignite UI documentation sites. Replaces the Starlight defaults with project-specific implementations.",
5
5
  "type": "module",
6
6
  "engines": {
@@ -72,38 +72,6 @@ import { remarkHtmlTransforms } from './plugins/remark-html-transforms';
72
72
  /** Build / deployment mode. Drives env-var `DOCS_BUILD_MODE`. */
73
73
  export type DocsMode = 'development' | 'staging' | 'production';
74
74
 
75
- /**
76
- * Read `themeApiUrl` and `themingWidgetVersion` from the project's
77
- * environment.json at build time. Uses the same lookup order as remark-env-vars.ts
78
- * so both always resolve from the same file.
79
- */
80
- function readThemingEnv(sourcePath: string | undefined, envKey: string): {
81
- themeApiUrl: string;
82
- widgetVersion: string;
83
- } {
84
- if (!sourcePath) return { themeApiUrl: '', widgetVersion: 'latest' };
85
- const root = path.resolve(sourcePath);
86
- const parent = path.dirname(root);
87
- const candidates = [
88
- path.join(root, 'en', 'environment.json'),
89
- path.join(root, 'environment.json'),
90
- path.join(parent, 'environment.json'),
91
- path.join(parent, 'en', 'environment.json'),
92
- ];
93
- const envPath = candidates.find(c => fs.existsSync(c));
94
- if (!envPath) return { themeApiUrl: '', widgetVersion: 'latest' };
95
- try {
96
- const data = JSON.parse(fs.readFileSync(envPath, 'utf-8'));
97
- const env = data[envKey] ?? data.production ?? {};
98
- return {
99
- themeApiUrl: (env.themeApiUrl as string) ?? '',
100
- widgetVersion: (env.themingWidgetVersion as string) ?? 'latest',
101
- };
102
- } catch {
103
- return { themeApiUrl: '', widgetVersion: 'latest' };
104
- }
105
- }
106
-
107
75
  // ---------------------------------------------------------------------------
108
76
  // Site meta virtual module
109
77
  // ---------------------------------------------------------------------------
@@ -259,18 +227,7 @@ export const navLang = ${JSON.stringify(navLang)};
259
227
  if (id === resolvedId) return siteMetaCode;
260
228
  if (id !== navResolvedId) return;
261
229
 
262
- // ── Theming env ──────────────────────────────────────────────
263
- const envKey = process.env.DOCS_ENV ?? process.env.NODE_ENV ?? 'production';
264
- const { themeApiUrl, widgetVersion } = readThemingEnv(process.env.DOCS_SOURCE_PATH, envKey);
265
- const widgetScriptSrc = widgetVersion
266
- ? `https://cdn-na.infragistics.com/igniteui/theming-widget/${widgetVersion}/igniteui-theming-widget.js`
267
- : '';
268
-
269
- return [
270
- `export const platform = ${JSON.stringify(platform ?? null)};`,
271
- `export const themeApiUrl = ${JSON.stringify(themeApiUrl)};`,
272
- `export const widgetScriptSrc = ${JSON.stringify(widgetScriptSrc)};`,
273
- ].join('\n');
230
+ return `export const platform = ${JSON.stringify(platform ?? null)};`;
274
231
  },
275
232
  }],
276
233
  },
@@ -10,7 +10,7 @@ import LicenseIndicator from '../../components/LicenseIndicator/LicenseIndicator
10
10
  import igLogoRaw from '../../assets/ig-logo.svg?raw';
11
11
  import MobileSidebarToggle from '../../components/MobileSidebarToggle/MobileSidebarToggle.astro';
12
12
  import CopyCode from '../../components/CopyCode/CopyCode.astro';
13
- import { widgetScriptSrc, platform as virtualPlatform } from 'virtual:docs-template/nav-html';
13
+ import { platform as virtualPlatform } from 'virtual:docs-template/nav-html';
14
14
  import { title as siteTitle, headEntries, navLang } from 'virtual:docs-template/site-meta';
15
15
  import '../../styles/theme.scss';
16
16
  import './DocsLayout.scss';
@@ -73,7 +73,6 @@ type HeadEntry = { tag: string; attrs?: Record<string, string | boolean | undefi
73
73
  {keywords && <meta name="keywords" content={keywords} />}
74
74
  <link rel="icon" href="/favicon.svg" type="image/svg+xml" />
75
75
  <link rel="stylesheet" href="https://use.typekit.net/bng2zgw.css" />
76
- {widgetScriptSrc && <script is:inline src={widgetScriptSrc} async></script>}
77
76
  {(headEntries as HeadEntry[]).map(({ tag: Tag, attrs = {}, content }) =>
78
77
  content ? <Tag {...attrs} set:html={content} /> : <Tag {...attrs} />
79
78
  )}
@@ -35,6 +35,4 @@ declare module 'virtual:docs-template/site-meta' {
35
35
 
36
36
  declare module 'virtual:docs-template/nav-html' {
37
37
  export const platform: 'igniteui' | 'angular' | 'react' | 'blazor' | 'web-components' | 'slingshot' | 'appbuilder' | null;
38
- export const themeApiUrl: string;
39
- export const widgetScriptSrc: string;
40
38
  }
@@ -1,35 +0,0 @@
1
- # ThemingWidget
2
-
3
- Renders the `<igniteui-theming-widget>` web component that lets readers switch the component theme live inside embedded sample iframes.
4
-
5
- ## Import
6
-
7
- ```astro
8
- import ThemingWidget from 'igniteui-astro-components/components/ThemingWidget.astro';
9
- ```
10
-
11
- ## Props
12
-
13
- | Prop | Type | Default | Description |
14
- |------|------|---------|-------------|
15
- | `language` | `NavLang` | `'en'` | Locale passed to the web component (`'en'` \| `'jp'` \| `'kr'`). |
16
-
17
- ## Behaviour
18
-
19
- - Renders nothing when `themeApiUrl` is absent from the environment config.
20
- - The widget container starts hidden and is revealed client-side only when at least one themeable `<iframe>` is detected on the page.
21
- - Forwards `themeChange` events to all themeable frames via `postMessage`.
22
- - Re-initialises on Astro View Transitions navigation (`astro:page-load`).
23
-
24
- ## Environment variable
25
-
26
- `themeApiUrl` is resolved at build time from `environment.json` by `siteMetaIntegration` and exposed through the `virtual:docs-template/nav-html` virtual module.
27
-
28
- ## Example
29
-
30
- ```astro
31
- ---
32
- import ThemingWidget from 'igniteui-astro-components/components/ThemingWidget.astro';
33
- ---
34
- <ThemingWidget language="en" />
35
- ```
@@ -1,143 +0,0 @@
1
- ---
2
- /**
3
- * ThemingWidget
4
- *
5
- * Renders the `<igniteui-theming-widget>` web component.
6
- * Behaviour:
7
- * - `themeApiUrl` and `widgetVersion` are resolved from environment.json at
8
- * build time via the `virtual:docs-template/nav-html` virtual module.
9
- * - Renders nothing when `themeApiUrl` is unavailable.
10
- * - The widget container starts hidden and is revealed client-side only
11
- * when at least one themeable `<iframe>` is found on the page.
12
- * - Forwards `themeChange` events from the widget to every themeable frame
13
- * via `postMessage`.
14
- * - Re-initialises on Astro View-Transitions navigation (`astro:page-load`).
15
- *
16
- * Props:
17
- * language – locale passed to the web component. Defaults to 'en'.
18
- */
19
-
20
- import { themeApiUrl } from 'virtual:docs-template/nav-html';
21
- import type { NavLang } from '../../platform.ts';
22
- import './ThemingWidget.scss';
23
-
24
- interface Props {
25
- language?: NavLang;
26
- }
27
-
28
- const { language = 'en' } = Astro.props;
29
-
30
- // Only add the `language` attribute for japanese, which the widget currently supports. For the other languages the widget falls back to english.
31
- const lang = language === 'jp' ? 'ja' : undefined;
32
- ---
33
-
34
- {themeApiUrl && (
35
- <>
36
- {/*
37
- Widget container — always visible when themeApiUrl is set.
38
- The client script below wires up theme→iframe forwarding.
39
- */}
40
- <div id="theming-widget-container" class="theming-widget-container" transition:persist transition:animate="none">
41
- {lang
42
- ? <igniteui-theming-widget theme-url={themeApiUrl} language={lang} />
43
- : <igniteui-theming-widget theme-url={themeApiUrl} />
44
- }
45
- </div>
46
- </>
47
- )}
48
-
49
- {/*
50
- Init script — always bundled by Astro but self-guards by checking the
51
- container element. When themeApiUrl was empty at build time the container
52
- is absent, so this script becomes a no-op.
53
- */}
54
- <script>
55
- // Module-level cleanup reference so re-init on View Transitions tears down
56
- // the previous observer + event listener before creating new ones.
57
- let _cleanup: (() => void) | null = null;
58
-
59
- function initThemingWidget() {
60
- if (_cleanup) { _cleanup(); _cleanup = null; }
61
-
62
- const container = document.getElementById('theming-widget-container');
63
- if (!container) return;
64
-
65
- // Must query the widget element directly — themeChange is likely non-bubbling,
66
- // so attaching to the parent container div would miss it.
67
- const widget = container.querySelector('igniteui-theming-widget') as
68
- (HTMLElement & { theme?: { globalTheme: string } }) | null;
69
- if (!widget) return;
70
-
71
- // ── postMessage helper ───────────────────────────────────────────────────
72
- // Uses the iframe's origin (not the full URL path) as targetOrigin.
73
- function postToIframe(iframe: HTMLIFrameElement, themeStyle: string) {
74
- const src = iframe.src;
75
- if (!src || src.startsWith('about:') || src.startsWith('javascript:')) return;
76
- try {
77
- const targetOrigin = new URL(src).origin;
78
- iframe.contentWindow?.postMessage(
79
- { themeStyle, origin: location.origin, themeName: widget?.theme?.globalTheme ?? '' },
80
- targetOrigin,
81
- );
82
- } catch { /* cross-origin or invalid URL — ignore */ }
83
- }
84
-
85
- // ── Replay theme into a newly loaded iframe ──────────────────────────────
86
- // When an iframe finishes loading we immediately push the persisted
87
- // themeStyle into it so samples that loaded after a theme was already
88
- // selected pick it up.
89
- function onIframeLoad(e: Event) {
90
- const iframe = e.target as HTMLIFrameElement;
91
- if (iframe.classList.contains('no-theming')) return;
92
- const stored = sessionStorage.getItem('themeStyle');
93
- if (stored) postToIframe(iframe, stored);
94
- }
95
-
96
- function attachLoadListener(node: Element) {
97
- if (node instanceof HTMLIFrameElement && !node.classList.contains('no-theming')) {
98
- node.addEventListener('load', onIframeLoad, { once: true });
99
- }
100
- node.querySelectorAll?.('iframe:not(.no-theming)').forEach(iframe => {
101
- (iframe as HTMLIFrameElement).addEventListener('load', onIframeLoad, { once: true });
102
- });
103
- }
104
-
105
- // Attach to iframes already in the DOM (e.g. first load, frame 0 queued immediately).
106
- document.querySelectorAll<HTMLIFrameElement>('iframe:not(.no-theming)')
107
- .forEach(iframe => iframe.addEventListener('load', onIframeLoad, { once: true }));
108
-
109
- // ── themeChange → broadcast to all loaded iframes ───────────────────────
110
- function onThemeChange(e: Event) {
111
- const themeStyle = (e as CustomEvent<string>).detail;
112
- sessionStorage.setItem('themeStyle', themeStyle);
113
- document.querySelectorAll<HTMLIFrameElement>('iframe:not(.no-theming)').forEach(iframe => {
114
- if (!iframe.src || iframe.src.startsWith('about:')) return;
115
- // Skip lazy iframes that haven't received a real src yet.
116
- if (iframe.classList.contains('lazyload') && !iframe.classList.contains('lazyloaded')) return;
117
- postToIframe(iframe, themeStyle);
118
- });
119
- }
120
-
121
- widget.addEventListener('themeChange', onThemeChange);
122
-
123
- // ── MutationObserver: watch for iframes injected after init ──────────────
124
- const observer = new MutationObserver((mutations) => {
125
- for (const mut of mutations) {
126
- mut.addedNodes.forEach(node => {
127
- if (node instanceof Element) attachLoadListener(node);
128
- });
129
- }
130
- });
131
- observer.observe(document.body, { childList: true, subtree: true });
132
-
133
- _cleanup = () => {
134
- observer.disconnect();
135
- widget.removeEventListener('themeChange', onThemeChange);
136
- };
137
- }
138
-
139
- // Run on initial load and after every View-Transitions navigation.
140
- document.addEventListener('astro:page-load', initThemingWidget);
141
- initThemingWidget();
142
- </script>
143
-
@@ -1,3 +0,0 @@
1
- .theming-widget-container {
2
- display: block;
3
- }