@fragments-sdk/cli 0.10.0 → 0.11.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.
Files changed (167) hide show
  1. package/dist/bin.js +26 -8
  2. package/dist/bin.js.map +1 -1
  3. package/dist/{chunk-ZDA3PLQ6.js → chunk-5G3VZH43.js} +2 -2
  4. package/dist/{chunk-566BNPQZ.js → chunk-HRFUSSZI.js} +25 -6
  5. package/dist/chunk-HRFUSSZI.js.map +1 -0
  6. package/dist/{chunk-CAMXG5HJ.js → chunk-ZM4ZQZWZ.js} +2 -2
  7. package/dist/{generate-BGKTKO6E.js → generate-FBHSXR3D.js} +2 -2
  8. package/dist/index.js +2 -2
  9. package/dist/{init-Q53R5Q2T.js → init-UFGK5TCN.js} +77 -6
  10. package/dist/init-UFGK5TCN.js.map +1 -0
  11. package/dist/{scan-OQU7M4GH.js → scan-CJF2DOQW.js} +3 -3
  12. package/dist/{scan-generate-T5QNUG7N.js → scan-generate-SJAN5MVI.js} +2 -2
  13. package/dist/snapshot-SV2JOFZH.js +139 -0
  14. package/dist/snapshot-SV2JOFZH.js.map +1 -0
  15. package/dist/{test-2CSOSS3B.js → test-Z5LVO724.js} +2 -2
  16. package/dist/{tokens-DXEGYTOJ.js → tokens-CE46OTMD.js} +2 -2
  17. package/dist/{viewer-DBEPYM3G.js → viewer-DLLJIMCK.js} +69 -47
  18. package/dist/viewer-DLLJIMCK.js.map +1 -0
  19. package/package.json +6 -14
  20. package/src/bin.ts +30 -0
  21. package/src/commands/init.ts +76 -1
  22. package/src/commands/snapshot.ts +197 -0
  23. package/src/core/loader.ts +38 -8
  24. package/src/viewer/__tests__/viewer-integration.test.ts +85 -74
  25. package/src/viewer/server.ts +37 -22
  26. package/src/viewer/vite-plugin.ts +25 -9
  27. package/dist/chunk-566BNPQZ.js.map +0 -1
  28. package/dist/init-Q53R5Q2T.js.map +0 -1
  29. package/dist/viewer-DBEPYM3G.js.map +0 -1
  30. package/src/viewer/__tests__/a11y-fixes.test.ts +0 -358
  31. package/src/viewer/__tests__/jsx-parser.test.ts +0 -502
  32. package/src/viewer/__tests__/render-utils.test.ts +0 -232
  33. package/src/viewer/__tests__/style-utils.test.ts +0 -404
  34. package/src/viewer/assets/fragments-logo.ts +0 -4
  35. package/src/viewer/components/AccessibilityPanel.tsx +0 -1457
  36. package/src/viewer/components/ActionCapture.tsx +0 -172
  37. package/src/viewer/components/ActionsPanel.tsx +0 -332
  38. package/src/viewer/components/AllVariantsPreview.tsx +0 -78
  39. package/src/viewer/components/App.tsx +0 -582
  40. package/src/viewer/components/BottomPanel.tsx +0 -288
  41. package/src/viewer/components/CodePanel.naming.test.tsx +0 -59
  42. package/src/viewer/components/CodePanel.tsx +0 -118
  43. package/src/viewer/components/CommandPalette.tsx +0 -392
  44. package/src/viewer/components/ComponentDocView.tsx +0 -164
  45. package/src/viewer/components/ComponentGraph.tsx +0 -380
  46. package/src/viewer/components/ComponentHeader.tsx +0 -88
  47. package/src/viewer/components/ContractPanel.tsx +0 -241
  48. package/src/viewer/components/EmptyVariantMessage.tsx +0 -54
  49. package/src/viewer/components/ErrorBoundary.tsx +0 -97
  50. package/src/viewer/components/FigmaEmbed.tsx +0 -238
  51. package/src/viewer/components/FragmentEditor.tsx +0 -525
  52. package/src/viewer/components/FragmentRenderer.tsx +0 -61
  53. package/src/viewer/components/HeaderSearch.tsx +0 -24
  54. package/src/viewer/components/HealthDashboard.tsx +0 -441
  55. package/src/viewer/components/HmrStatusIndicator.tsx +0 -61
  56. package/src/viewer/components/Icons.tsx +0 -479
  57. package/src/viewer/components/InteractionsPanel.tsx +0 -757
  58. package/src/viewer/components/IsolatedPreviewFrame.tsx +0 -346
  59. package/src/viewer/components/IsolatedRender.tsx +0 -113
  60. package/src/viewer/components/KeyboardShortcutsHelp.tsx +0 -53
  61. package/src/viewer/components/LandingPage.tsx +0 -421
  62. package/src/viewer/components/Layout.tsx +0 -27
  63. package/src/viewer/components/LeftSidebar.tsx +0 -472
  64. package/src/viewer/components/LoadErrorMessage.tsx +0 -102
  65. package/src/viewer/components/MultiViewportPreview.tsx +0 -522
  66. package/src/viewer/components/NoVariantsMessage.tsx +0 -59
  67. package/src/viewer/components/PanelShell.tsx +0 -161
  68. package/src/viewer/components/PerformancePanel.tsx +0 -304
  69. package/src/viewer/components/PreviewArea.tsx +0 -472
  70. package/src/viewer/components/PreviewAside.tsx +0 -168
  71. package/src/viewer/components/PreviewFrameHost.tsx +0 -303
  72. package/src/viewer/components/PreviewPane.tsx +0 -149
  73. package/src/viewer/components/PreviewToolbar.tsx +0 -80
  74. package/src/viewer/components/PropsEditor.tsx +0 -506
  75. package/src/viewer/components/PropsTable.tsx +0 -111
  76. package/src/viewer/components/RelationsSection.tsx +0 -88
  77. package/src/viewer/components/ResizablePanel.tsx +0 -271
  78. package/src/viewer/components/RightSidebar.tsx +0 -102
  79. package/src/viewer/components/RuntimeToolsRegistrar.tsx +0 -17
  80. package/src/viewer/components/ScreenshotButton.tsx +0 -90
  81. package/src/viewer/components/Sidebar.tsx +0 -169
  82. package/src/viewer/components/SkeletonLoader.tsx +0 -161
  83. package/src/viewer/components/ThemeProvider.tsx +0 -42
  84. package/src/viewer/components/Toast.tsx +0 -3
  85. package/src/viewer/components/TokenStylePanel.tsx +0 -699
  86. package/src/viewer/components/TopToolbar.tsx +0 -159
  87. package/src/viewer/components/UsageSection.tsx +0 -95
  88. package/src/viewer/components/VariantMatrix.tsx +0 -388
  89. package/src/viewer/components/VariantRenderer.tsx +0 -131
  90. package/src/viewer/components/VariantTabs.tsx +0 -40
  91. package/src/viewer/components/ViewerHeader.tsx +0 -69
  92. package/src/viewer/components/ViewerStateSync.tsx +0 -52
  93. package/src/viewer/components/ViewportSelector.tsx +0 -172
  94. package/src/viewer/components/WebMCPDevTools.tsx +0 -503
  95. package/src/viewer/components/WebMCPIntegration.tsx +0 -47
  96. package/src/viewer/components/WebMCPStatusIndicator.tsx +0 -60
  97. package/src/viewer/components/_future/CreatePage.tsx +0 -836
  98. package/src/viewer/components/viewer-utils.ts +0 -16
  99. package/src/viewer/composition-renderer.ts +0 -381
  100. package/src/viewer/constants/index.ts +0 -1
  101. package/src/viewer/constants/ui.ts +0 -166
  102. package/src/viewer/entry.tsx +0 -335
  103. package/src/viewer/hooks/index.ts +0 -2
  104. package/src/viewer/hooks/useA11yCache.ts +0 -383
  105. package/src/viewer/hooks/useA11yService.ts +0 -364
  106. package/src/viewer/hooks/useActions.ts +0 -138
  107. package/src/viewer/hooks/useAppState.ts +0 -147
  108. package/src/viewer/hooks/useCompiledFragments.ts +0 -42
  109. package/src/viewer/hooks/useFigmaIntegration.ts +0 -132
  110. package/src/viewer/hooks/useHmrStatus.ts +0 -109
  111. package/src/viewer/hooks/useKeyboardShortcuts.ts +0 -270
  112. package/src/viewer/hooks/usePreviewBridge.ts +0 -347
  113. package/src/viewer/hooks/useScrollSpy.ts +0 -78
  114. package/src/viewer/hooks/useUrlState.ts +0 -318
  115. package/src/viewer/hooks/useViewSettings.ts +0 -111
  116. package/src/viewer/index.html +0 -28
  117. package/src/viewer/intelligence/healthReport.ts +0 -505
  118. package/src/viewer/intelligence/styleDrift.ts +0 -340
  119. package/src/viewer/intelligence/usageScanner.ts +0 -309
  120. package/src/viewer/jsx-parser.ts +0 -486
  121. package/src/viewer/preview-frame-entry.tsx +0 -25
  122. package/src/viewer/preview-frame.html +0 -125
  123. package/src/viewer/public/favicon.ico +0 -0
  124. package/src/viewer/render-template.html +0 -68
  125. package/src/viewer/styles/globals.css +0 -278
  126. package/src/viewer/types/a11y.ts +0 -197
  127. package/src/viewer/utils/a11y-fixes.ts +0 -509
  128. package/src/viewer/utils/actionExport.ts +0 -372
  129. package/src/viewer/utils/colorSchemes.ts +0 -201
  130. package/src/viewer/utils/detectRelationships.ts +0 -256
  131. package/src/viewer/vendor/shared/src/ComponentDocContent.module.scss +0 -10
  132. package/src/viewer/vendor/shared/src/ComponentDocContent.module.scss.d.ts +0 -2
  133. package/src/viewer/vendor/shared/src/ComponentDocContent.tsx +0 -274
  134. package/src/viewer/vendor/shared/src/DocsHeaderBar.tsx +0 -129
  135. package/src/viewer/vendor/shared/src/DocsPageAsideHost.tsx +0 -89
  136. package/src/viewer/vendor/shared/src/DocsPageShell.tsx +0 -124
  137. package/src/viewer/vendor/shared/src/DocsSearchCommand.tsx +0 -99
  138. package/src/viewer/vendor/shared/src/DocsSidebarNav.tsx +0 -66
  139. package/src/viewer/vendor/shared/src/PropsTable.module.scss +0 -68
  140. package/src/viewer/vendor/shared/src/PropsTable.module.scss.d.ts +0 -2
  141. package/src/viewer/vendor/shared/src/PropsTable.tsx +0 -76
  142. package/src/viewer/vendor/shared/src/VariantPreviewCard.module.scss +0 -114
  143. package/src/viewer/vendor/shared/src/VariantPreviewCard.module.scss.d.ts +0 -2
  144. package/src/viewer/vendor/shared/src/VariantPreviewCard.tsx +0 -134
  145. package/src/viewer/vendor/shared/src/docs-data/index.ts +0 -32
  146. package/src/viewer/vendor/shared/src/docs-data/mcp-configs.ts +0 -72
  147. package/src/viewer/vendor/shared/src/docs-data/palettes.ts +0 -75
  148. package/src/viewer/vendor/shared/src/docs-data/setup-examples.ts +0 -55
  149. package/src/viewer/vendor/shared/src/docs-layout.scss +0 -28
  150. package/src/viewer/vendor/shared/src/docs-layout.scss.d.ts +0 -2
  151. package/src/viewer/vendor/shared/src/index.ts +0 -34
  152. package/src/viewer/vendor/shared/src/types.ts +0 -53
  153. package/src/viewer/webmcp/__tests__/analytics.test.ts +0 -108
  154. package/src/viewer/webmcp/analytics.ts +0 -165
  155. package/src/viewer/webmcp/index.ts +0 -3
  156. package/src/viewer/webmcp/posthog-bridge.ts +0 -39
  157. package/src/viewer/webmcp/runtime-tools.ts +0 -152
  158. package/src/viewer/webmcp/scan-utils.ts +0 -135
  159. package/src/viewer/webmcp/use-tool-analytics.ts +0 -69
  160. package/src/viewer/webmcp/viewer-state.ts +0 -45
  161. /package/dist/{chunk-ZDA3PLQ6.js.map → chunk-5G3VZH43.js.map} +0 -0
  162. /package/dist/{chunk-CAMXG5HJ.js.map → chunk-ZM4ZQZWZ.js.map} +0 -0
  163. /package/dist/{generate-BGKTKO6E.js.map → generate-FBHSXR3D.js.map} +0 -0
  164. /package/dist/{scan-OQU7M4GH.js.map → scan-CJF2DOQW.js.map} +0 -0
  165. /package/dist/{scan-generate-T5QNUG7N.js.map → scan-generate-SJAN5MVI.js.map} +0 -0
  166. /package/dist/{test-2CSOSS3B.js.map → test-Z5LVO724.js.map} +0 -0
  167. /package/dist/{tokens-DXEGYTOJ.js.map → tokens-CE46OTMD.js.map} +0 -0
@@ -1,472 +0,0 @@
1
- /**
2
- * PreviewArea component - handles rendering the component preview.
3
- * Extracted from App.tsx for better organization and performance.
4
- *
5
- * Now supports iframe-based isolation for CSS isolation between
6
- * the viewer shell and user's component library.
7
- */
8
-
9
- import { memo, type ReactNode } from 'react';
10
- import type { FragmentVariant } from '../../core/index.js';
11
- import { ErrorBoundary } from './ErrorBoundary.js';
12
- import { FigmaEmbed } from './FigmaEmbed.js';
13
- import { VariantMatrix } from './VariantMatrix.js';
14
- import { MultiViewportPreview } from './MultiViewportPreview.js';
15
- import { IsolatedPreviewFrame } from './IsolatedPreviewFrame.js';
16
- import { getViewportWidth, type ZoomLevel, type ViewportPreset, type ViewportSize } from '../constants/ui.js';
17
- import type { PreviewTheme } from '../hooks/useViewSettings.js';
18
-
19
- interface PreviewAreaProps {
20
- // Component data
21
- componentName: string;
22
- fragmentPath: string;
23
- variant: FragmentVariant | undefined;
24
- variants: FragmentVariant[] | undefined;
25
-
26
- // View settings
27
- zoom: ZoomLevel;
28
- viewport: ViewportPreset;
29
- customSize: ViewportSize;
30
- previewTheme: PreviewTheme;
31
-
32
- // Display modes
33
- showMatrixView: boolean;
34
- showMultiViewport: boolean;
35
- showComparison: boolean;
36
-
37
- // Figma
38
- figmaUrl?: string;
39
- allFigmaUrls: string[];
40
-
41
- // Callbacks
42
- onSelectVariant: (index: number) => void;
43
- onRetry: () => void;
44
-
45
- // Render function for variant content (used as fallback and for matrix/multi-viewport)
46
- renderContent: () => ReactNode;
47
-
48
- // Keys for forcing re-renders
49
- previewKey: string;
50
-
51
- // Whether to use iframe isolation (default: true)
52
- useIframeIsolation?: boolean;
53
- }
54
-
55
- // Device mockup component for tablet/mobile preview
56
- interface DeviceMockupProps {
57
- type: 'tablet' | 'mobile';
58
- width: number;
59
- children: React.ReactNode;
60
- }
61
-
62
- const DeviceMockup = memo(function DeviceMockup({ type, width, children }: DeviceMockupProps) {
63
- const isMobile = type === 'mobile';
64
- const frameWidth = width + 24;
65
- const frameHeight = isMobile ? 720 : 1024;
66
- const screenHeight = frameHeight - (isMobile ? 80 : 48);
67
-
68
- return (
69
- <div style={{ position: 'relative', flexShrink: 0, width: `${frameWidth}px` }}>
70
- <div
71
- style={{
72
- position: 'relative',
73
- borderRadius: '40px',
74
- background: '#1a1a1a',
75
- padding: '12px',
76
- boxShadow: '0 25px 50px -12px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255,255,255,0.1)',
77
- }}
78
- >
79
- {isMobile && (
80
- <>
81
- <div style={{ position: 'absolute', left: '-3px', top: '96px', width: '3px', height: '32px', background: '#2a2a2a', borderRadius: '4px 0 0 4px' }} />
82
- <div style={{ position: 'absolute', left: '-3px', top: '144px', width: '3px', height: '48px', background: '#2a2a2a', borderRadius: '4px 0 0 4px' }} />
83
- <div style={{ position: 'absolute', left: '-3px', top: '208px', width: '3px', height: '48px', background: '#2a2a2a', borderRadius: '4px 0 0 4px' }} />
84
- <div style={{ position: 'absolute', right: '-3px', top: '128px', width: '3px', height: '64px', background: '#2a2a2a', borderRadius: '0 4px 4px 0' }} />
85
- </>
86
- )}
87
-
88
- <div
89
- style={{
90
- position: 'relative',
91
- borderRadius: '32px',
92
- overflow: 'hidden',
93
- background: 'white',
94
- height: `${screenHeight}px`,
95
- }}
96
- >
97
- {isMobile ? (
98
- <div style={{
99
- position: 'absolute',
100
- top: 0,
101
- left: '50%',
102
- transform: 'translateX(-50%)',
103
- width: '120px',
104
- height: '30px',
105
- background: '#1a1a1a',
106
- borderRadius: '0 0 16px 16px',
107
- zIndex: 10,
108
- display: 'flex',
109
- alignItems: 'center',
110
- justifyContent: 'center',
111
- gap: '8px',
112
- }}>
113
- <div style={{ width: '8px', height: '8px', borderRadius: '50%', background: '#2a2a2a' }} />
114
- <div style={{ width: '48px', height: '6px', borderRadius: '9999px', background: '#2a2a2a' }} />
115
- </div>
116
- ) : (
117
- <div style={{
118
- position: 'absolute',
119
- top: '8px',
120
- left: '50%',
121
- transform: 'translateX(-50%)',
122
- width: '12px',
123
- height: '12px',
124
- borderRadius: '50%',
125
- background: '#2a2a2a',
126
- zIndex: 10,
127
- }} />
128
- )}
129
-
130
- <div style={{ width: '100%', height: '100%', overflow: 'auto' }}>{children}</div>
131
-
132
- <div style={{
133
- position: 'absolute',
134
- bottom: '8px',
135
- left: '50%',
136
- transform: 'translateX(-50%)',
137
- width: '100px',
138
- height: '4px',
139
- background: 'rgba(0, 0, 0, 0.2)',
140
- borderRadius: '9999px',
141
- zIndex: 10,
142
- }} />
143
- </div>
144
- </div>
145
- </div>
146
- );
147
- });
148
-
149
- // Inner preview content with zoom transform
150
- interface PreviewContentProps {
151
- zoom: ZoomLevel;
152
- previewTheme: PreviewTheme;
153
- children: ReactNode;
154
- }
155
-
156
- const PreviewContent = memo(function PreviewContent({ zoom, previewTheme, children }: PreviewContentProps) {
157
- return (
158
- <div
159
- data-preview-container="true"
160
- data-theme={previewTheme}
161
- style={{
162
- width: '100%',
163
- height: '100%',
164
- overflow: 'auto',
165
- }}
166
- >
167
- <div
168
- style={{
169
- padding: '24px',
170
- transform: `scale(${zoom / 100})`,
171
- transformOrigin: 'top left',
172
- width: zoom !== 100 ? `${100 / (zoom / 100)}%` : '100%',
173
- color: '#1f2937',
174
- }}
175
- >
176
- {children}
177
- </div>
178
- </div>
179
- );
180
- });
181
-
182
- export function PreviewArea({
183
- componentName,
184
- fragmentPath,
185
- variant,
186
- variants,
187
- zoom,
188
- viewport,
189
- customSize,
190
- previewTheme,
191
- showMatrixView,
192
- showMultiViewport,
193
- showComparison,
194
- figmaUrl,
195
- allFigmaUrls,
196
- onSelectVariant,
197
- onRetry,
198
- renderContent,
199
- previewKey,
200
- useIframeIsolation = true,
201
- }: PreviewAreaProps) {
202
- // Matrix view
203
- if (showMatrixView && variants) {
204
- return (
205
- <VariantMatrix
206
- variants={variants}
207
- componentName={componentName}
208
- fragmentPath={fragmentPath}
209
- zoom={zoom}
210
- previewTheme={previewTheme}
211
- useIframeIsolation={useIframeIsolation}
212
- onSelectVariant={(index) => {
213
- onSelectVariant(index);
214
- }}
215
- />
216
- );
217
- }
218
-
219
- // Multi-viewport view
220
- if (showMultiViewport && variant) {
221
- return (
222
- <MultiViewportPreview
223
- componentName={componentName}
224
- fragmentPath={fragmentPath}
225
- variantName={variant.name}
226
- renderContent={renderContent}
227
- previewTheme={previewTheme}
228
- zoom={zoom}
229
- useIframeIsolation={useIframeIsolation}
230
- />
231
- );
232
- }
233
-
234
- const viewportWidth = getViewportWidth(viewport, customSize);
235
- const viewportHeight = viewport === 'custom' ? customSize.height : null;
236
- const isDevice = viewport === 'tablet' || viewport === 'mobile';
237
-
238
- // Device mockup view (tablet/mobile)
239
- if (isDevice && viewportWidth && variant) {
240
- const deviceScreenHeight = viewport === 'mobile' ? 640 : 976;
241
-
242
- if (showComparison && figmaUrl) {
243
- return (
244
- <div style={{ minHeight: '100%', display: 'flex', flexDirection: 'column', padding: '24px' }}>
245
- <div style={{ display: 'flex', gap: '16px', flex: 1 }}>
246
- <div style={{ flex: 1, display: 'flex', flexDirection: 'column' }}>
247
- <div style={{ fontSize: '12px', fontWeight: 500, color: 'var(--text-tertiary)', marginBottom: '8px', textAlign: 'center' }}>Rendered</div>
248
- <div style={{ flex: 1, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
249
- <DeviceMockup type={viewport as 'tablet' | 'mobile'} width={viewportWidth}>
250
- {useIframeIsolation ? (
251
- <IsolatedPreviewFrame
252
- fragmentPath={fragmentPath}
253
- variantName={variant.name}
254
- theme={previewTheme}
255
- width={viewportWidth}
256
- height={deviceScreenHeight}
257
- previewKey={previewKey}
258
- />
259
- ) : (
260
- <PreviewContent zoom={zoom} previewTheme={previewTheme}>
261
- <ErrorBoundary key={previewKey} componentName={componentName} onRetry={onRetry}>
262
- {renderContent()}
263
- </ErrorBoundary>
264
- </PreviewContent>
265
- )}
266
- </DeviceMockup>
267
- </div>
268
- </div>
269
-
270
- <div style={{ flex: 1, display: 'flex', flexDirection: 'column' }}>
271
- <div style={{ fontSize: '12px', fontWeight: 500, color: 'var(--text-tertiary)', marginBottom: '8px', textAlign: 'center' }}>Figma Design</div>
272
- <FigmaEmbed
273
- figmaUrl={figmaUrl}
274
- allFigmaUrls={allFigmaUrls}
275
- zoom={zoom}
276
- style={{
277
- flex: 1,
278
- borderRadius: '8px',
279
- border: '1px solid var(--border)',
280
- overflow: 'hidden',
281
- }}
282
- />
283
- </div>
284
- </div>
285
- </div>
286
- );
287
- }
288
-
289
- return (
290
- <div style={{ minHeight: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center', padding: '32px' }}>
291
- <DeviceMockup type={viewport as 'tablet' | 'mobile'} width={viewportWidth}>
292
- {useIframeIsolation ? (
293
- <IsolatedPreviewFrame
294
- fragmentPath={fragmentPath}
295
- variantName={variant.name}
296
- theme={previewTheme}
297
- width={viewportWidth}
298
- height={deviceScreenHeight}
299
- previewKey={previewKey}
300
- />
301
- ) : (
302
- <PreviewContent zoom={zoom} previewTheme={previewTheme}>
303
- <ErrorBoundary key={previewKey} componentName={componentName} onRetry={onRetry}>
304
- {renderContent()}
305
- </ErrorBoundary>
306
- </PreviewContent>
307
- )}
308
- </DeviceMockup>
309
- </div>
310
- );
311
- }
312
-
313
- // Side-by-side comparison view
314
- if (showComparison && figmaUrl && variant) {
315
- return (
316
- <div style={{ minHeight: '100%', display: 'flex', flexDirection: 'column', padding: '24px' }}>
317
- <div style={{ display: 'flex', gap: '16px', flex: 1 }}>
318
- <div style={{ flex: 1, display: 'flex', flexDirection: 'column' }}>
319
- <div style={{ fontSize: '12px', fontWeight: 500, color: 'var(--text-tertiary)', marginBottom: '8px', textAlign: 'center' }}>Rendered</div>
320
- <div
321
- style={{
322
- flex: 1,
323
- borderRadius: '8px',
324
- border: '1px solid var(--border)',
325
- overflow: 'auto',
326
- }}
327
- >
328
- {useIframeIsolation ? (
329
- <IsolatedPreviewFrame
330
- fragmentPath={fragmentPath}
331
- variantName={variant.name}
332
- theme={previewTheme}
333
- width="100%"
334
- height="100%"
335
- minHeight={300}
336
- previewKey={previewKey}
337
- />
338
- ) : (
339
- <div
340
- style={{
341
- display: 'flex',
342
- alignItems: 'center',
343
- justifyContent: 'center',
344
- padding: '32px',
345
- }}
346
- data-preview-container="true"
347
- data-theme={previewTheme}
348
- >
349
- <div
350
- style={{
351
- transform: `scale(${zoom / 100})`,
352
- transformOrigin: 'top left',
353
- width: zoom !== 100 ? `${100 / (zoom / 100)}%` : '100%',
354
- color: '#1f2937',
355
- }}
356
- >
357
- <ErrorBoundary key={previewKey} componentName={componentName} onRetry={onRetry}>
358
- {renderContent()}
359
- </ErrorBoundary>
360
- </div>
361
- </div>
362
- )}
363
- </div>
364
- </div>
365
-
366
- <div style={{ flex: 1, display: 'flex', flexDirection: 'column' }}>
367
- <div style={{ fontSize: '12px', fontWeight: 500, color: 'var(--text-tertiary)', marginBottom: '8px', textAlign: 'center' }}>Figma Design</div>
368
- <FigmaEmbed
369
- figmaUrl={figmaUrl}
370
- allFigmaUrls={allFigmaUrls}
371
- zoom={zoom}
372
- style={{
373
- flex: 1,
374
- borderRadius: '8px',
375
- border: '1px solid var(--border)',
376
- overflow: 'hidden',
377
- }}
378
- />
379
- </div>
380
- </div>
381
- </div>
382
- );
383
- }
384
-
385
- // Regular preview (responsive or desktop)
386
- // Use iframe isolation when enabled for complete CSS isolation
387
- if (useIframeIsolation && variant) {
388
- // When no specific viewport width, fill the container
389
- const isFullWidth = !viewportWidth;
390
- const scaleFactor = zoom / 100;
391
-
392
- return (
393
- <div style={isFullWidth
394
- ? { height: '100%', display: 'flex', flexDirection: 'column', overflow: 'auto' }
395
- : { minHeight: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center', padding: '24px', overflow: 'auto' }
396
- }>
397
- <div
398
- style={{
399
- position: 'relative',
400
- transition: 'all 200ms',
401
- width: viewportWidth ? `${viewportWidth}px` : '100%',
402
- maxWidth: viewportWidth ? undefined : '100%',
403
- height: isFullWidth ? '100%' : undefined,
404
- minHeight: viewportHeight ? `${viewportHeight}px` : (isFullWidth ? undefined : '200px'),
405
- ...(viewportWidth && {
406
- backgroundColor: 'var(--bg-primary)',
407
- borderRadius: '8px',
408
- boxShadow: '0 0 0 1px var(--border), 0 4px 12px rgba(0,0,0,0.15)',
409
- }),
410
- }}
411
- >
412
- <div
413
- style={{
414
- transform: `scale(${scaleFactor})`,
415
- transformOrigin: 'top left',
416
- width: zoom !== 100 ? `${100 / scaleFactor}%` : '100%',
417
- height: zoom !== 100 ? `${100 / scaleFactor}%` : '100%',
418
- }}
419
- >
420
- <IsolatedPreviewFrame
421
- fragmentPath={fragmentPath}
422
- variantName={variant.name}
423
- theme={previewTheme}
424
- width="100%"
425
- height="100%"
426
- minHeight={viewportHeight || 400}
427
- previewKey={previewKey}
428
- />
429
- </div>
430
- </div>
431
- </div>
432
- );
433
- }
434
-
435
- // Fallback: Direct rendering without iframe isolation
436
- return (
437
- <div style={{ minHeight: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center', padding: '24px' }}>
438
- <div
439
- style={{
440
- position: 'relative',
441
- transition: 'all 200ms',
442
- width: viewportWidth ? `${viewportWidth}px` : '100%',
443
- maxWidth: viewportWidth ? undefined : '100%',
444
- minHeight: viewportHeight ? `${viewportHeight}px` : '100%',
445
- ...(viewportWidth && {
446
- backgroundColor: 'var(--bg-primary)',
447
- borderRadius: '8px',
448
- boxShadow: '0 0 0 1px var(--border), 0 4px 12px rgba(0,0,0,0.15)',
449
- }),
450
- }}
451
- data-preview-container="true"
452
- data-theme={previewTheme}
453
- >
454
- <div
455
- style={{
456
- padding: '32px',
457
- transform: `scale(${zoom / 100})`,
458
- transformOrigin: 'top left',
459
- width: zoom !== 100 ? `${100 / (zoom / 100)}%` : '100%',
460
- color: '#1f2937',
461
- }}
462
- >
463
- <ErrorBoundary key={previewKey} componentName={componentName} onRetry={onRetry}>
464
- {renderContent()}
465
- </ErrorBoundary>
466
- </div>
467
- </div>
468
- </div>
469
- );
470
- }
471
-
472
- export { DeviceMockup };
@@ -1,168 +0,0 @@
1
- import { useState, useEffect, useMemo } from "react";
2
- import type { FragmentDefinition, FragmentVariant } from "../../core/index.js";
3
- import { Box, Stack, Text, Separator, Button, TableOfContents } from "@fragments-sdk/ui";
4
- import { getVariantSectionId } from "./viewer-utils.js";
5
-
6
- interface TocHeading {
7
- id: string;
8
- text: string;
9
- level: 2 | 3;
10
- }
11
-
12
- interface PreviewAsideProps {
13
- fragment: FragmentDefinition;
14
- variants: FragmentVariant[];
15
- focusedVariantIndex: number;
16
- activePanel: string;
17
- onSelectVariant: (index: number) => void;
18
- onCopyLink: () => void;
19
- onShowShortcuts: () => void;
20
- }
21
-
22
- function buildHeadings(fragment: FragmentDefinition): TocHeading[] {
23
- const headings: TocHeading[] = [{ id: "setup", text: "Setup", level: 2 }];
24
-
25
- if (fragment.variants.length > 0) {
26
- headings.push({ id: "examples", text: "Examples", level: 2 });
27
- }
28
-
29
- headings.push({ id: "props", text: "Props", level: 2 });
30
- headings.push({ id: "usage-guidelines", text: "Usage Guidelines", level: 2 });
31
- headings.push({ id: "when-to-use", text: "When to use", level: 3 });
32
- headings.push({ id: "when-not-to-use", text: "When not to use", level: 3 });
33
-
34
- if ((fragment.usage?.guidelines?.length ?? 0) > 0) {
35
- headings.push({ id: "best-practices", text: "Best practices", level: 3 });
36
- }
37
-
38
- if ((fragment.relations?.length ?? 0) > 0) {
39
- headings.push({ id: "related-components", text: "Related Components", level: 2 });
40
- }
41
-
42
- return headings;
43
- }
44
-
45
- function useActiveHeading(ids: string[]): string | null {
46
- const [activeId, setActiveId] = useState<string | null>(null);
47
-
48
- useEffect(() => {
49
- if (ids.length === 0) return;
50
-
51
- const observer = new IntersectionObserver(
52
- (entries) => {
53
- for (const entry of entries) {
54
- if (entry.isIntersecting) {
55
- setActiveId(entry.target.id);
56
- }
57
- }
58
- },
59
- { rootMargin: "-80px 0px -60% 0px", threshold: 0 }
60
- );
61
-
62
- for (const id of ids) {
63
- const el = document.getElementById(id);
64
- if (el) observer.observe(el);
65
- }
66
-
67
- return () => observer.disconnect();
68
- }, [ids]);
69
-
70
- return activeId;
71
- }
72
-
73
- export function PreviewAside({
74
- fragment,
75
- variants,
76
- focusedVariantIndex,
77
- activePanel,
78
- onSelectVariant,
79
- onCopyLink,
80
- onShowShortcuts,
81
- }: PreviewAsideProps) {
82
- const focusedVariant = variants[focusedVariantIndex] || null;
83
-
84
- const headings = useMemo(() => buildHeadings(fragment), [fragment]);
85
- const headingIds = useMemo(() => headings.map((h) => h.id), [headings]);
86
- const activeId = useActiveHeading(headingIds);
87
-
88
- return (
89
- <Box padding="md" style={{ position: "sticky", top: "80px" }}>
90
- <Stack gap="md">
91
- {/* On This Page — same TOC component as docs site */}
92
- <TableOfContents>
93
- {headings.map((heading) => (
94
- <TableOfContents.Item
95
- key={heading.id}
96
- id={heading.id}
97
- active={activeId === heading.id}
98
- indent={heading.level === 3}
99
- >
100
- {heading.text}
101
- </TableOfContents.Item>
102
- ))}
103
- </TableOfContents>
104
-
105
- {/* Variant list */}
106
- {variants.length > 0 && (
107
- <>
108
- <Separator />
109
- <Stack gap="xs">
110
- <Text
111
- size="xs"
112
- color="tertiary"
113
- style={{ textTransform: "uppercase", letterSpacing: "0.08em" }}
114
- >
115
- Variants
116
- </Text>
117
- {variants.map((variant, index) => {
118
- const active = index === focusedVariantIndex;
119
- const anchorId = getVariantSectionId(fragment.meta.name, variant.name);
120
-
121
- return (
122
- <Button
123
- key={variant.name}
124
- as="a"
125
- variant={active ? "secondary" : "ghost"}
126
- size="sm"
127
- href={`#${anchorId}`}
128
- onClick={(event: React.MouseEvent) => {
129
- event.preventDefault();
130
- onSelectVariant(index);
131
- }}
132
- style={{ justifyContent: "flex-start" }}
133
- >
134
- {variant.name}
135
- </Button>
136
- );
137
- })}
138
- </Stack>
139
- </>
140
- )}
141
-
142
- <Separator />
143
- <Stack gap="xs">
144
- <Text size="sm" weight="medium">
145
- {fragment.meta.name}
146
- </Text>
147
- <Text size="xs" color="secondary">
148
- {focusedVariant
149
- ? `Variant: ${focusedVariant.name}`
150
- : "Select a variant"}
151
- </Text>
152
- <Text size="xs" color="tertiary">
153
- Active panel: {activePanel}
154
- </Text>
155
- </Stack>
156
- <Separator />
157
- <Stack gap="xs">
158
- <Button variant="ghost" size="sm" onClick={onCopyLink}>
159
- Copy Link
160
- </Button>
161
- <Button variant="ghost" size="sm" onClick={onShowShortcuts}>
162
- Keyboard Shortcuts
163
- </Button>
164
- </Stack>
165
- </Stack>
166
- </Box>
167
- );
168
- }