@fragments-sdk/cli 0.7.10 → 0.7.12

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.
@@ -43,7 +43,6 @@ describe('CodePanel authored code pipeline', () => {
43
43
  const code = __buildFallbackSnippetForTest('Button', variant);
44
44
 
45
45
  expect(code).toContain("import { Button } from '@/components/Button';");
46
- expect(code).toContain('TODO: Add explicit `code` for variant "Primary"');
47
46
  expect(code).toContain("<Button variant='primary' disabled={false}>Save Changes</Button>");
48
47
  });
49
48
 
@@ -76,7 +76,6 @@ function buildFallbackSnippet(componentName: string, variant: FragmentVariant):
76
76
 
77
77
  return `import { ${componentName} } from '@/components/${componentName}';
78
78
 
79
- // TODO: Add explicit \`code\` for variant "${variant.name}" in this fragment file.
80
79
  ${usage}`;
81
80
  }
82
81
 
@@ -336,10 +336,16 @@ export function CommandPalette({
336
336
  function fuzzyScore(text: string, query: string): number {
337
337
  if (!query) return 1;
338
338
 
339
+ // Require substring match for short queries to avoid scattered single-char noise
340
+ if (query.length <= 3 && !text.includes(query)) {
341
+ return 0;
342
+ }
343
+
339
344
  let score = 0;
340
345
  let queryIndex = 0;
341
346
  let consecutiveBonus = 0;
342
347
  let lastMatchIndex = -2;
348
+ let maxGap = 0;
343
349
 
344
350
  for (let i = 0; i < text.length && queryIndex < query.length; i++) {
345
351
  if (text[i] === query[queryIndex]) {
@@ -351,6 +357,11 @@ function fuzzyScore(text: string, query: string): number {
351
357
  score += consecutiveBonus;
352
358
  } else {
353
359
  consecutiveBonus = 0;
360
+ // Track max gap between matches
361
+ if (lastMatchIndex >= 0) {
362
+ const gap = i - lastMatchIndex;
363
+ if (gap > maxGap) maxGap = gap;
364
+ }
354
365
  }
355
366
 
356
367
  // Bonus for matching at word start
@@ -366,6 +377,11 @@ function fuzzyScore(text: string, query: string): number {
366
377
  // Only return score if all query characters were found
367
378
  if (queryIndex < query.length) return 0;
368
379
 
380
+ // Penalize large gaps between matched characters
381
+ if (maxGap > 5) {
382
+ score -= maxGap;
383
+ }
384
+
369
385
  // Bonus for shorter results (more relevant)
370
386
  score += Math.max(0, 20 - text.length);
371
387
 
@@ -375,5 +391,5 @@ function fuzzyScore(text: string, query: string): number {
375
391
  // Bonus for starts with
376
392
  if (text.startsWith(query)) score += 30;
377
393
 
378
- return score;
394
+ return Math.max(score, 0) || 0;
379
395
  }
@@ -162,91 +162,88 @@ export const IsolatedPreviewFrame = memo(function IsolatedPreviewFrame({
162
162
  onMouseLeave={() => setIsHovered(false)}
163
163
  >
164
164
  {/* Skeleton loading overlay (initial load) */}
165
- <div
166
- style={{
167
- position: 'absolute',
168
- inset: 0,
169
- zIndex: 10,
170
- transition: 'opacity 150ms',
171
- opacity: showSkeleton ? 1 : 0,
172
- pointerEvents: showSkeleton ? 'auto' : 'none',
173
- background: 'rgba(255, 255, 255, 0.95)',
174
- }}
175
- >
176
- <PreviewSkeleton />
177
- </div>
165
+ {showSkeleton && (
166
+ <div
167
+ style={{
168
+ position: 'absolute',
169
+ inset: 0,
170
+ zIndex: 10,
171
+ background: 'var(--bg-primary, rgba(255, 255, 255, 0.95))',
172
+ }}
173
+ >
174
+ <PreviewSkeleton />
175
+ </div>
176
+ )}
178
177
 
179
178
  {/* Spinner overlay (subsequent renders) */}
180
- <div
181
- style={{
182
- position: 'absolute',
183
- inset: 0,
184
- zIndex: 10,
185
- display: 'flex',
186
- alignItems: 'center',
187
- justifyContent: 'center',
188
- transition: 'opacity 150ms',
189
- opacity: showSpinner ? 1 : 0,
190
- pointerEvents: showSpinner ? 'auto' : 'none',
191
- background: 'rgba(255, 255, 255, 0.8)',
192
- }}
193
- >
194
- <div style={{ display: 'flex', alignItems: 'center', gap: 8, color: '#6b7280', fontSize: 14 }}>
195
- <LoadingSpinner />
196
- <span>Rendering...</span>
179
+ {showSpinner && (
180
+ <div
181
+ style={{
182
+ position: 'absolute',
183
+ inset: 0,
184
+ zIndex: 10,
185
+ display: 'flex',
186
+ alignItems: 'center',
187
+ justifyContent: 'center',
188
+ background: 'color-mix(in srgb, var(--bg-primary, white) 80%, transparent)',
189
+ }}
190
+ >
191
+ <div style={{ display: 'flex', alignItems: 'center', gap: 8, color: 'var(--text-tertiary, #6b7280)', fontSize: 14 }}>
192
+ <LoadingSpinner />
193
+ <span>Rendering...</span>
194
+ </div>
197
195
  </div>
198
- </div>
196
+ )}
199
197
 
200
198
  {/* Error overlay */}
201
- <div
202
- style={{
203
- position: 'absolute',
204
- inset: 0,
205
- zIndex: 10,
206
- display: 'flex',
207
- alignItems: 'center',
208
- justifyContent: 'center',
209
- padding: '16px',
210
- transition: 'opacity 150ms',
211
- opacity: frameError && !isLoading ? 1 : 0,
212
- pointerEvents: frameError && !isLoading ? 'auto' : 'none',
213
- background: 'rgba(254, 242, 242, 0.95)',
214
- }}
215
- >
199
+ {frameError && !isLoading && (
216
200
  <div
217
201
  style={{
218
- background: 'white',
219
- border: '1px solid #fecaca',
220
- borderRadius: 8,
221
- padding: 16,
222
- maxWidth: 400,
202
+ position: 'absolute',
203
+ inset: 0,
204
+ zIndex: 10,
205
+ display: 'flex',
206
+ alignItems: 'center',
207
+ justifyContent: 'center',
208
+ padding: '16px',
209
+ background: 'rgba(254, 242, 242, 0.95)',
223
210
  }}
224
211
  >
225
- <div style={{ color: '#dc2626', fontWeight: 500, marginBottom: 8 }}>
226
- Preview Error
227
- </div>
228
- <div style={{ color: '#991b1b', fontSize: 13, marginBottom: retryCount < MAX_RETRIES ? 12 : 0 }}>
229
- {frameError}
212
+ <div
213
+ style={{
214
+ background: 'white',
215
+ border: '1px solid #fecaca',
216
+ borderRadius: 8,
217
+ padding: 16,
218
+ maxWidth: 400,
219
+ }}
220
+ >
221
+ <div style={{ color: '#dc2626', fontWeight: 500, marginBottom: 8 }}>
222
+ Preview Error
223
+ </div>
224
+ <div style={{ color: '#991b1b', fontSize: 13, marginBottom: retryCount < MAX_RETRIES ? 12 : 0 }}>
225
+ {frameError}
226
+ </div>
227
+ {retryCount < MAX_RETRIES && (
228
+ <button
229
+ onClick={handleRetry}
230
+ style={{
231
+ padding: '6px 12px',
232
+ fontSize: 13,
233
+ fontWeight: 500,
234
+ color: 'white',
235
+ background: '#dc2626',
236
+ border: 'none',
237
+ borderRadius: 6,
238
+ cursor: 'pointer',
239
+ }}
240
+ >
241
+ Retry ({MAX_RETRIES - retryCount} remaining)
242
+ </button>
243
+ )}
230
244
  </div>
231
- {retryCount < MAX_RETRIES && (
232
- <button
233
- onClick={handleRetry}
234
- style={{
235
- padding: '6px 12px',
236
- fontSize: 13,
237
- fontWeight: 500,
238
- color: 'white',
239
- background: '#dc2626',
240
- border: 'none',
241
- borderRadius: 6,
242
- cursor: 'pointer',
243
- }}
244
- >
245
- Retry ({MAX_RETRIES - retryCount} remaining)
246
- </button>
247
- )}
248
245
  </div>
249
- </div>
246
+ )}
250
247
 
251
248
  {/* The iframe */}
252
249
  <iframe
@@ -1,24 +1,27 @@
1
1
  import type { ReactNode } from 'react';
2
- import { AppShell } from '@fragments-sdk/ui';
2
+ import { DocsPageShell } from '@fragments-sdk/shared';
3
3
 
4
4
  interface LayoutProps {
5
5
  leftSidebar: ReactNode;
6
6
  header: ReactNode;
7
7
  children: ReactNode;
8
+ aside?: ReactNode;
8
9
  }
9
10
 
10
- export function Layout({ leftSidebar, header, children }: LayoutProps) {
11
+ export function Layout({ leftSidebar, header, children, aside }: LayoutProps) {
11
12
  return (
12
- <AppShell>
13
- <AppShell.Header>
14
- {header}
15
- </AppShell.Header>
16
- <AppShell.Sidebar width="260px" collapsible="icon">
17
- {leftSidebar}
18
- </AppShell.Sidebar>
19
- <AppShell.Main padding="none">
20
- {children}
21
- </AppShell.Main>
22
- </AppShell>
13
+ <DocsPageShell
14
+ header={header}
15
+ sidebar={leftSidebar}
16
+ sidebarWidth="260px"
17
+ sidebarCollapsible="icon"
18
+ sidebarAriaLabel="Preview sidebar"
19
+ mainAriaLabel="Preview content"
20
+ mainPadding="none"
21
+ aside={aside}
22
+ asideWidth="240px"
23
+ >
24
+ {children}
25
+ </DocsPageShell>
23
26
  );
24
27
  }
@@ -14,16 +14,26 @@ function fuzzyMatch(text: string, pattern: string): FuzzyMatch | null {
14
14
  const textLower = text.toLowerCase();
15
15
  const patternLower = pattern.toLowerCase();
16
16
 
17
+ // Require substring match for short queries (<=3 chars) to avoid scattered single-char noise
18
+ if (patternLower.length <= 3 && !textLower.includes(patternLower)) {
19
+ return null;
20
+ }
21
+
17
22
  const indices: number[] = [];
18
23
  let patternIdx = 0;
19
24
  let score = 0;
20
25
  let consecutiveBonus = 0;
26
+ let maxGap = 0;
21
27
 
22
28
  for (let i = 0; i < textLower.length && patternIdx < patternLower.length; i++) {
23
29
  if (textLower[i] === patternLower[patternIdx]) {
24
30
  indices.push(i);
25
- if (indices.length > 1 && indices[indices.length - 2] === i - 1) {
26
- consecutiveBonus += 5;
31
+ if (indices.length > 1) {
32
+ const gap = i - indices[indices.length - 2];
33
+ if (gap === 1) {
34
+ consecutiveBonus += 5;
35
+ }
36
+ if (gap > maxGap) maxGap = gap;
27
37
  }
28
38
  if (i === 0 || text[i - 1] === ' ' || text[i - 1] === '-' || text[i - 1] === '_') {
29
39
  score += 10;
@@ -36,9 +46,19 @@ function fuzzyMatch(text: string, pattern: string): FuzzyMatch | null {
36
46
  return null;
37
47
  }
38
48
 
49
+ // Penalize large gaps between matched characters
50
+ if (maxGap > 5) {
51
+ score -= maxGap * 2;
52
+ }
53
+
39
54
  score += consecutiveBonus;
40
55
  score += (patternLower.length / textLower.length) * 20;
41
56
 
57
+ // Reject very low scores (scattered single-char matches)
58
+ if (score <= 0 && patternLower.length > 1) {
59
+ return null;
60
+ }
61
+
42
62
  return { score, indices };
43
63
  }
44
64
 
@@ -364,7 +384,7 @@ export function LeftSidebar({ fragments, activeFragment, searchQuery, onSelect,
364
384
  <Sidebar.Footer>
365
385
  <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', width: '100%' }}>
366
386
  <Text size="xs" color="tertiary">
367
- {isFilterActive ? `${flatItems.length} / ${fragments.length}` : fragments.length} components
387
+ {isFilterActive || searchResults ? `${flatItems.length} of ${fragments.length}` : fragments.length} components
368
388
  </Text>
369
389
  <Sidebar.CollapseToggle />
370
390
  </div>
@@ -397,11 +397,12 @@ export function PreviewArea({
397
397
  if (useIframeIsolation && variant) {
398
398
  // When no specific viewport width, fill the container
399
399
  const isFullWidth = !viewportWidth;
400
+ const scaleFactor = zoom / 100;
400
401
 
401
402
  return (
402
403
  <div style={isFullWidth
403
- ? { height: '100%', display: 'flex', flexDirection: 'column' }
404
- : { minHeight: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center', padding: '24px' }
404
+ ? { height: '100%', display: 'flex', flexDirection: 'column', overflow: 'auto' }
405
+ : { minHeight: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center', padding: '24px', overflow: 'auto' }
405
406
  }>
406
407
  <div
407
408
  style={{
@@ -418,15 +419,24 @@ export function PreviewArea({
418
419
  }),
419
420
  }}
420
421
  >
421
- <IsolatedPreviewFrame
422
- fragmentPath={fragmentPath}
423
- variantName={variant.name}
424
- theme={previewTheme}
425
- width="100%"
426
- height="100%"
427
- minHeight={viewportHeight || 200}
428
- previewKey={previewKey}
429
- />
422
+ <div
423
+ style={{
424
+ transform: `scale(${scaleFactor})`,
425
+ transformOrigin: 'top left',
426
+ width: zoom !== 100 ? `${100 / scaleFactor}%` : '100%',
427
+ height: zoom !== 100 ? `${100 / scaleFactor}%` : '100%',
428
+ }}
429
+ >
430
+ <IsolatedPreviewFrame
431
+ fragmentPath={fragmentPath}
432
+ variantName={variant.name}
433
+ theme={previewTheme}
434
+ width="100%"
435
+ height="100%"
436
+ minHeight={viewportHeight || 200}
437
+ previewKey={previewKey}
438
+ />
439
+ </div>
430
440
  </div>
431
441
  </div>
432
442
  );
@@ -262,7 +262,7 @@ export const SHORTCUTS = [
262
262
  { keys: ["p"], description: "Toggle addons panel" },
263
263
  { keys: ["m"], description: "Matrix view" },
264
264
  { keys: ["v"], description: "Responsive view" },
265
- { keys: ["/", "⌘K"], description: "Search" },
265
+ { keys: ["/", "⌘K"], description: "Command palette" },
266
266
  { keys: ["?"], description: "Show shortcuts" },
267
267
  { keys: ["Esc"], description: "Close / Clear" },
268
268
  ];
@@ -30,6 +30,8 @@ const cliPackageRoot = resolve(__dirname, "..");
30
30
  const viewerRoot = resolve(cliPackageRoot, "src/viewer");
31
31
  const packagesRoot = resolve(cliPackageRoot, "..");
32
32
  const localUiLibRoot = resolve(packagesRoot, "../libs/ui/src");
33
+ const localSharedLibRoot = resolve(packagesRoot, "../libs/shared/src");
34
+ const vendoredSharedLibRoot = resolve(viewerRoot, "vendor/shared/src");
33
35
 
34
36
  /**
35
37
  * Resolve the @fragments/ui alias to the correct path.
@@ -55,6 +57,24 @@ function resolveUiLib(nodeModulesDir: string): string {
55
57
  return localUiLibRoot;
56
58
  }
57
59
 
60
+ /**
61
+ * Resolve the @fragments-sdk/shared alias to either monorepo source
62
+ * or vendored viewer fallback for npm installs.
63
+ */
64
+ function resolveSharedLib(): string {
65
+ const localIndex = join(localSharedLibRoot, "index.ts");
66
+ if (existsSync(localIndex)) {
67
+ return localSharedLibRoot;
68
+ }
69
+
70
+ const vendoredIndex = join(vendoredSharedLibRoot, "index.ts");
71
+ if (existsSync(vendoredIndex)) {
72
+ return vendoredSharedLibRoot;
73
+ }
74
+
75
+ return localSharedLibRoot;
76
+ }
77
+
58
78
  /**
59
79
  * Vite plugin to handle CJS-only packages imported from within node_modules.
60
80
  * Vite's optimizeDeps only redirects imports from source files to pre-bundled ESM,
@@ -189,6 +209,8 @@ export async function createDevServer(
189
209
 
190
210
  // Find node_modules (handles monorepo setups)
191
211
  const nodeModulesPath = findNodeModules(projectRoot);
212
+ const uiLibRoot = resolveUiLib(nodeModulesPath);
213
+ const sharedLibRoot = resolveSharedLib();
192
214
  console.log(`📁 Using node_modules: ${nodeModulesPath}`);
193
215
 
194
216
  // Collect installed package roots so Vite can serve files from node_modules
@@ -214,8 +236,8 @@ export async function createDevServer(
214
236
  port,
215
237
  open: open ? "/fragments/" : false,
216
238
  fs: {
217
- // Allow serving files from viewer package, project, UI library, and node_modules root
218
- allow: [viewerRoot, resolveUiLib(nodeModulesPath), projectRoot, configDir, dirname(nodeModulesPath), ...installedPkgRoots],
239
+ // Allow serving files from viewer package, project, shared libs, and node_modules root
240
+ allow: [viewerRoot, uiLibRoot, sharedLibRoot, projectRoot, configDir, dirname(nodeModulesPath), ...installedPkgRoots],
219
241
  },
220
242
  },
221
243
 
@@ -248,7 +270,9 @@ export async function createDevServer(
248
270
  dedupe: ["react", "react-dom"],
249
271
  alias: {
250
272
  // Resolve @fragments-sdk/ui to local source or installed package
251
- "@fragments-sdk/ui": resolveUiLib(nodeModulesPath),
273
+ "@fragments-sdk/ui": uiLibRoot,
274
+ // Resolve @fragments-sdk/shared to monorepo source or vendored fallback
275
+ "@fragments-sdk/shared": sharedLibRoot,
252
276
  // Resolve @fragments-sdk/cli/core to the CLI's own core source
253
277
  "@fragments-sdk/cli/core": resolve(cliPackageRoot, "src/core/index.ts"),
254
278
  // Ensure ALL react imports resolve to project's node_modules
@@ -0,0 +1,110 @@
1
+ 'use client';
2
+
3
+ import { Header, NavigationMenu } from '@fragments-sdk/ui';
4
+ import type { ReactNode } from 'react';
5
+ import { DocsSearchCommand } from './DocsSearchCommand';
6
+ import type { DocsNavLinkRenderer, HeaderNavEntry, NavSection, SearchItem } from './types';
7
+ import { isDropdown } from './types';
8
+
9
+ interface DocsHeaderBarProps {
10
+ brand: ReactNode;
11
+ headerNav: HeaderNavEntry[];
12
+ mobileSections?: NavSection[];
13
+ currentPath: string;
14
+ searchItems: SearchItem[];
15
+ onSearchSelect: (item: SearchItem) => void;
16
+ renderLink?: DocsNavLinkRenderer;
17
+ isActive?: (href: string, currentPath: string) => boolean;
18
+ actions?: ReactNode;
19
+ showSkipLink?: boolean;
20
+ navAriaLabel?: string;
21
+ }
22
+
23
+ const defaultLinkRenderer: DocsNavLinkRenderer = ({ href, label, onClick }) => (
24
+ <a href={href} onClick={onClick}>
25
+ {label}
26
+ </a>
27
+ );
28
+
29
+ function defaultIsActive(href: string, currentPath: string): boolean {
30
+ return currentPath === href || currentPath.startsWith(`${href}/`);
31
+ }
32
+
33
+ export function DocsHeaderBar({
34
+ brand,
35
+ headerNav,
36
+ mobileSections = [],
37
+ currentPath,
38
+ searchItems,
39
+ onSearchSelect,
40
+ renderLink = defaultLinkRenderer,
41
+ isActive = defaultIsActive,
42
+ actions,
43
+ showSkipLink = true,
44
+ navAriaLabel = 'Primary navigation',
45
+ }: DocsHeaderBarProps) {
46
+ return (
47
+ <Header aria-label="Documentation header">
48
+ <Header.Brand>{brand}</Header.Brand>
49
+ {showSkipLink ? <Header.SkipLink /> : null}
50
+
51
+ <NavigationMenu aria-label={navAriaLabel}>
52
+ <NavigationMenu.List>
53
+ {headerNav.map((entry) =>
54
+ isDropdown(entry) ? (
55
+ <NavigationMenu.Item key={entry.label} value={entry.label}>
56
+ <NavigationMenu.Trigger>{entry.label}</NavigationMenu.Trigger>
57
+ <NavigationMenu.Content>
58
+ <div style={{ display: 'flex', flexDirection: 'column', padding: '4px', minWidth: '180px' }}>
59
+ {entry.items.map((child) => (
60
+ <NavigationMenu.Link
61
+ key={child.href}
62
+ href={child.href}
63
+ active={isActive(child.href, currentPath)}
64
+ asChild
65
+ >
66
+ {renderLink({ href: child.href, label: child.label })}
67
+ </NavigationMenu.Link>
68
+ ))}
69
+ </div>
70
+ </NavigationMenu.Content>
71
+ </NavigationMenu.Item>
72
+ ) : (
73
+ <NavigationMenu.Item key={entry.href}>
74
+ <NavigationMenu.Link
75
+ href={entry.href}
76
+ active={isActive(entry.href, currentPath)}
77
+ asChild
78
+ >
79
+ {renderLink({ href: entry.href, label: entry.label })}
80
+ </NavigationMenu.Link>
81
+ </NavigationMenu.Item>
82
+ )
83
+ )}
84
+ </NavigationMenu.List>
85
+
86
+ <NavigationMenu.Viewport />
87
+
88
+ <NavigationMenu.MobileContent>
89
+ {mobileSections.map((section) => (
90
+ <NavigationMenu.MobileSection key={section.title} label={section.title}>
91
+ {section.items.map((item) => (
92
+ <NavigationMenu.Link key={item.href} href={item.href} asChild>
93
+ {renderLink({ href: item.href, label: item.label })}
94
+ </NavigationMenu.Link>
95
+ ))}
96
+ </NavigationMenu.MobileSection>
97
+ ))}
98
+ </NavigationMenu.MobileContent>
99
+ </NavigationMenu>
100
+
101
+ <Header.Spacer />
102
+
103
+ <Header.Search>
104
+ <DocsSearchCommand searchItems={searchItems} onSelect={onSearchSelect} />
105
+ </Header.Search>
106
+
107
+ <Header.Actions>{actions}</Header.Actions>
108
+ </Header>
109
+ );
110
+ }
@@ -0,0 +1,89 @@
1
+ 'use client';
2
+
3
+ import { createPortal } from 'react-dom';
4
+ import * as React from 'react';
5
+
6
+ interface DocsPageAsideContextValue {
7
+ asideVisible: boolean;
8
+ setAsideVisible: (visible: boolean) => void;
9
+ asideWidth: string;
10
+ setAsideWidth: (width: string) => void;
11
+ asideContainer: HTMLDivElement | null;
12
+ setAsideContainer: (container: HTMLDivElement | null) => void;
13
+ }
14
+
15
+ const DocsPageAsideContext = React.createContext<DocsPageAsideContextValue | null>(null);
16
+
17
+ export function DocsPageAsideProvider({
18
+ children,
19
+ defaultWidth = '320px',
20
+ }: {
21
+ children: React.ReactNode;
22
+ defaultWidth?: string;
23
+ }) {
24
+ const [asideVisible, setAsideVisible] = React.useState(false);
25
+ const [asideWidth, setAsideWidth] = React.useState(defaultWidth);
26
+ const [asideContainer, setAsideContainer] = React.useState<HTMLDivElement | null>(null);
27
+
28
+ return (
29
+ <DocsPageAsideContext.Provider
30
+ value={{
31
+ asideVisible,
32
+ setAsideVisible,
33
+ asideWidth,
34
+ setAsideWidth,
35
+ asideContainer,
36
+ setAsideContainer,
37
+ }}
38
+ >
39
+ {children}
40
+ </DocsPageAsideContext.Provider>
41
+ );
42
+ }
43
+
44
+ export function useDocsPageAside() {
45
+ const context = React.useContext(DocsPageAsideContext);
46
+ if (!context) {
47
+ throw new Error('useDocsPageAside must be used within DocsPageAsideProvider');
48
+ }
49
+ return context;
50
+ }
51
+
52
+ export function DocsPageAsidePortal({ children, width = '320px' }: { children: React.ReactNode; width?: string }) {
53
+ const { setAsideVisible, setAsideWidth, asideContainer } = useDocsPageAside();
54
+
55
+ React.useEffect(() => {
56
+ setAsideVisible(true);
57
+ setAsideWidth(width);
58
+
59
+ return () => {
60
+ setAsideVisible(false);
61
+ };
62
+ }, [setAsideVisible, setAsideWidth, width]);
63
+
64
+ if (!asideContainer) {
65
+ return null;
66
+ }
67
+
68
+ return createPortal(children, asideContainer);
69
+ }
70
+
71
+ interface DocsPageAsideHostProps {
72
+ className?: string;
73
+ style?: React.CSSProperties;
74
+ }
75
+
76
+ export function DocsPageAsideHost({ className, style }: DocsPageAsideHostProps) {
77
+ const { setAsideContainer } = useDocsPageAside();
78
+
79
+ const asideContainerCallback = React.useCallback(
80
+ (node: HTMLDivElement | null) => {
81
+ setAsideContainer(node);
82
+ },
83
+ [setAsideContainer]
84
+ );
85
+
86
+ return (
87
+ <div ref={asideContainerCallback} className={className} style={{ height: '100%', ...style }} />
88
+ );
89
+ }