@fragments-sdk/viewer 0.2.1 → 0.2.4

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 (60) hide show
  1. package/package.json +10 -3
  2. package/src/components/App.tsx +67 -4
  3. package/src/components/BottomPanel.tsx +31 -1
  4. package/src/components/ComponentGraph.tsx +1 -1
  5. package/src/components/EmptyVariantMessage.tsx +1 -1
  6. package/src/components/ErrorBoundary.tsx +2 -4
  7. package/src/components/FragmentRenderer.tsx +27 -4
  8. package/src/components/HeaderSearch.tsx +1 -1
  9. package/src/components/InteractionsPanel.tsx +5 -5
  10. package/src/components/LoadErrorMessage.tsx +26 -30
  11. package/src/components/NoVariantsMessage.tsx +1 -1
  12. package/src/components/PanelShell.tsx +1 -1
  13. package/src/components/PerformancePanel.tsx +4 -4
  14. package/src/components/PreviewArea.tsx +6 -0
  15. package/src/components/PropsEditor.tsx +33 -17
  16. package/src/components/SkeletonLoader.tsx +0 -1
  17. package/src/components/TokenStylePanel.tsx +3 -3
  18. package/src/components/TopToolbar.tsx +1 -1
  19. package/src/components/VariantMatrix.tsx +11 -1
  20. package/src/components/ViewerHeader.tsx +1 -1
  21. package/src/components/WebMCPDevTools.tsx +2 -2
  22. package/src/entry.tsx +4 -6
  23. package/src/hooks/useAppState.ts +1 -1
  24. package/src/preview-frame-entry.tsx +0 -2
  25. package/src/shared/DocsHeaderBar.module.scss +174 -0
  26. package/src/shared/DocsHeaderBar.tsx +149 -14
  27. package/src/shared/DocsSidebarNav.tsx +3 -3
  28. package/src/shared/index.ts +4 -1
  29. package/src/shared/types.ts +29 -3
  30. package/src/style-utils.ts +1 -1
  31. package/src/webmcp/runtime-tools.ts +1 -1
  32. package/tsconfig.json +2 -2
  33. package/src/assets/fragments-logo.ts +0 -4
  34. package/src/components/ActionsPanel.tsx +0 -332
  35. package/src/components/ComponentHeader.tsx +0 -88
  36. package/src/components/ContractPanel.tsx +0 -241
  37. package/src/components/FragmentEditor.tsx +0 -525
  38. package/src/components/HmrStatusIndicator.tsx +0 -61
  39. package/src/components/LandingPage.tsx +0 -420
  40. package/src/components/PropsTable.tsx +0 -111
  41. package/src/components/RelationsSection.tsx +0 -88
  42. package/src/components/ResizablePanel.tsx +0 -271
  43. package/src/components/RightSidebar.tsx +0 -102
  44. package/src/components/ScreenshotButton.tsx +0 -90
  45. package/src/components/Sidebar.tsx +0 -169
  46. package/src/components/UsageSection.tsx +0 -95
  47. package/src/components/VariantTabs.tsx +0 -40
  48. package/src/components/ViewportSelector.tsx +0 -172
  49. package/src/components/_future/CreatePage.tsx +0 -835
  50. package/src/composition-renderer.ts +0 -381
  51. package/src/constants/index.ts +0 -1
  52. package/src/hooks/index.ts +0 -2
  53. package/src/hooks/useHmrStatus.ts +0 -109
  54. package/src/hooks/useScrollSpy.ts +0 -78
  55. package/src/intelligence/healthReport.ts +0 -505
  56. package/src/intelligence/styleDrift.ts +0 -340
  57. package/src/intelligence/usageScanner.ts +0 -309
  58. package/src/utils/actionExport.ts +0 -372
  59. package/src/utils/colorSchemes.ts +0 -201
  60. package/src/webmcp/index.ts +0 -3
@@ -1,241 +0,0 @@
1
- /**
2
- * ContractPanel component - displays FragmentContract metadata for AI agents.
3
- * Shows propsSummary, scenarioTags, bans, and a11yRules.
4
- */
5
-
6
- import { memo } from 'react';
7
- import type { FragmentContract } from '@fragments-sdk/core';
8
- import { Stack, Text, Card, Chip, Alert, EmptyState, CodeBlock, Badge, Box } from '@fragments-sdk/ui';
9
-
10
- interface ContractPanelProps {
11
- contract?: FragmentContract;
12
- componentName: string;
13
- }
14
-
15
- export const ContractPanel = memo(function ContractPanel({
16
- contract,
17
- componentName,
18
- }: ContractPanelProps) {
19
- // Empty state when no contract metadata
20
- if (!contract || isContractEmpty(contract)) {
21
- return (
22
- <EmptyState>
23
- <EmptyState.Icon>
24
- <svg
25
- style={{ width: '48px', height: '48px', opacity: 0.5 }}
26
- fill="none"
27
- viewBox="0 0 24 24"
28
- stroke="currentColor"
29
- >
30
- <path
31
- strokeLinecap="round"
32
- strokeLinejoin="round"
33
- strokeWidth={1.5}
34
- d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"
35
- />
36
- </svg>
37
- </EmptyState.Icon>
38
- <EmptyState.Title>No contract metadata</EmptyState.Title>
39
- <EmptyState.Description>
40
- Add a <Box as="code" padding="xs" background="secondary" rounded="sm">contract</Box> field to the fragment definition to enable AI agent features.
41
- </EmptyState.Description>
42
- <EmptyState.Actions>
43
- <CodeBlock
44
- code={`contract: {
45
- propsSummary: ['variant: primary|secondary'],
46
- scenarioTags: ['form.submit', 'action.primary'],
47
- a11yRules: ['A11Y_BTN_LABEL'],
48
- }`}
49
- language="typescript"
50
- compact
51
- />
52
- </EmptyState.Actions>
53
- </EmptyState>
54
- );
55
- }
56
-
57
- return (
58
- <Box padding="md" style={{ fontSize: '14px' }}>
59
- <Stack gap="lg">
60
- {/* Props Summary */}
61
- {contract.propsSummary && contract.propsSummary.length > 0 && (
62
- <Section title="Props Summary">
63
- <Card>
64
- <Card.Body>
65
- <table style={{ width: '100%', fontSize: '12px', borderCollapse: 'collapse' }}>
66
- <thead>
67
- <tr style={{ borderBottom: '1px solid var(--border)' }}>
68
- <th style={{ textAlign: 'left', padding: '8px 16px 8px 0', fontWeight: 500, color: 'var(--text-tertiary)' }}>Name</th>
69
- <th style={{ textAlign: 'left', padding: '8px 16px 8px 0', fontWeight: 500, color: 'var(--text-tertiary)' }}>Type</th>
70
- <th style={{ textAlign: 'left', padding: '8px 0', fontWeight: 500, color: 'var(--text-tertiary)' }}>Description</th>
71
- </tr>
72
- </thead>
73
- <tbody>
74
- {contract.propsSummary.map((prop, i) => {
75
- const parsed = parsePropSummary(prop);
76
- return (
77
- <tr key={i} style={{ borderBottom: i < contract.propsSummary!.length - 1 ? '1px solid var(--border)' : undefined }}>
78
- <td style={{ padding: '8px 16px 8px 0', verticalAlign: 'top' }}>
79
- <Text font="mono" size="xs" weight="medium">{parsed.name}</Text>
80
- </td>
81
- <td style={{ padding: '8px 16px 8px 0', verticalAlign: 'top' }}>
82
- <Badge size="sm">{parsed.type}</Badge>
83
- </td>
84
- <td style={{ padding: '8px 0', verticalAlign: 'top' }}>
85
- <Text size="xs" color="secondary">{parsed.description}</Text>
86
- </td>
87
- </tr>
88
- );
89
- })}
90
- </tbody>
91
- </table>
92
- </Card.Body>
93
- </Card>
94
- </Section>
95
- )}
96
-
97
- {/* Scenario Tags */}
98
- {contract.scenarioTags && contract.scenarioTags.length > 0 && (
99
- <Section title="Scenario Tags" subtitle="Used by fragments_suggest for AI queries">
100
- <Stack direction="row" gap="sm" style={{ flexWrap: 'wrap' }}>
101
- {contract.scenarioTags.map((tag, i) => (
102
- <Chip key={i}>{tag}</Chip>
103
- ))}
104
- </Stack>
105
- </Section>
106
- )}
107
-
108
- {/* Accessibility Rules */}
109
- {contract.a11yRules && contract.a11yRules.length > 0 && (
110
- <Section title="Accessibility Rules">
111
- <Stack gap="sm">
112
- {contract.a11yRules.map((rule, i) => (
113
- <Box key={i} padding="sm" background="secondary" rounded="sm">
114
- <Stack
115
- direction="row"
116
- align="center"
117
- gap="sm"
118
- >
119
- <span style={{ color: '#22c55e' }}>
120
- <svg style={{ width: '16px', height: '16px' }} fill="none" viewBox="0 0 24 24" stroke="currentColor">
121
- <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
122
- </svg>
123
- </span>
124
- <Text font="mono" size="xs" color="secondary">{rule}</Text>
125
- </Stack>
126
- </Box>
127
- ))}
128
- </Stack>
129
- </Section>
130
- )}
131
-
132
- {/* Bans */}
133
- {contract.bans && contract.bans.length > 0 && (
134
- <Section title="Usage Bans" subtitle="Patterns to avoid">
135
- <Stack gap="sm">
136
- {contract.bans.map((ban, i) => (
137
- <Alert key={i} severity="warning">
138
- <Alert.Body>
139
- <Alert.Title>
140
- <Text font="mono" size="xs">{ban.pattern}</Text>
141
- </Alert.Title>
142
- <Alert.Content>
143
- <Text size="xs" color="tertiary">{ban.message}</Text>
144
- </Alert.Content>
145
- </Alert.Body>
146
- </Alert>
147
- ))}
148
- </Stack>
149
- </Section>
150
- )}
151
-
152
- {/* Empty sections message */}
153
- {isPartialContract(contract) && (
154
- <Alert severity="info">
155
- <Alert.Body>
156
- <Alert.Content>
157
- Tip: Add more contract fields to help AI agents better understand this component.
158
- </Alert.Content>
159
- </Alert.Body>
160
- </Alert>
161
- )}
162
- </Stack>
163
- </Box>
164
- );
165
- });
166
-
167
- // Helper component for consistent section styling
168
- interface SectionProps {
169
- title: string;
170
- subtitle?: string;
171
- children: React.ReactNode;
172
- }
173
-
174
- function Section({ title, subtitle, children }: SectionProps) {
175
- return (
176
- <div>
177
- <Stack direction="row" align="center" gap="sm" style={{ marginBottom: '8px' }}>
178
- <Text as="h3" size="xs" weight="semibold">{title}</Text>
179
- {subtitle && (
180
- <Text size="xs" color="tertiary">({subtitle})</Text>
181
- )}
182
- </Stack>
183
- {children}
184
- </div>
185
- );
186
- }
187
-
188
- // Check if contract is empty or has no meaningful content
189
- function isContractEmpty(contract: FragmentContract): boolean {
190
- return (
191
- (!contract.propsSummary || contract.propsSummary.length === 0) &&
192
- (!contract.scenarioTags || contract.scenarioTags.length === 0) &&
193
- (!contract.a11yRules || contract.a11yRules.length === 0) &&
194
- (!contract.bans || contract.bans.length === 0)
195
- );
196
- }
197
-
198
- // Check if contract has some but not all fields
199
- function isPartialContract(contract: FragmentContract): boolean {
200
- const fieldCount = [
201
- contract.propsSummary?.length ?? 0,
202
- contract.scenarioTags?.length ?? 0,
203
- contract.a11yRules?.length ?? 0,
204
- contract.bans?.length ?? 0,
205
- ].filter(n => n > 0).length;
206
-
207
- return fieldCount > 0 && fieldCount < 3;
208
- }
209
-
210
- // Parse a prop summary string like "name: type - description" or "name: type (default: value)"
211
- function parsePropSummary(prop: string): { name: string; type: string; description: string } {
212
- // Try to match "name: type - description" format
213
- const colonIndex = prop.indexOf(':');
214
- if (colonIndex === -1) {
215
- return { name: prop, type: '', description: '' };
216
- }
217
-
218
- const name = prop.slice(0, colonIndex).trim();
219
- const rest = prop.slice(colonIndex + 1).trim();
220
-
221
- // Check for " - description" pattern
222
- const dashIndex = rest.indexOf(' - ');
223
- if (dashIndex !== -1) {
224
- const type = rest.slice(0, dashIndex).trim();
225
- const description = rest.slice(dashIndex + 3).trim();
226
- return { name, type, description };
227
- }
228
-
229
- // Check for "(default: value)" or "(default: value) description" pattern
230
- const defaultMatch = rest.match(/^([^(]+)(\(default:\s*[^)]+\))(.*)$/);
231
- if (defaultMatch) {
232
- const type = defaultMatch[1].trim();
233
- const defaultInfo = defaultMatch[2];
234
- const extraDesc = defaultMatch[3].trim();
235
- const description = extraDesc ? `${defaultInfo} ${extraDesc}` : defaultInfo;
236
- return { name, type, description };
237
- }
238
-
239
- // Just type, no description
240
- return { name, type: rest, description: '' };
241
- }