@fragments-sdk/viewer 0.2.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.
- package/LICENSE +84 -0
- package/index.html +28 -0
- package/package.json +71 -0
- package/src/__tests__/a11y-fixes.test.ts +358 -0
- package/src/__tests__/jsx-parser.test.ts +502 -0
- package/src/__tests__/render-utils.test.ts +232 -0
- package/src/__tests__/style-utils.test.ts +404 -0
- package/src/app/index.ts +1 -0
- package/src/assets/fragments-logo.ts +4 -0
- package/src/assets/fragments_logo.png +0 -0
- package/src/components/AccessibilityPanel.tsx +1457 -0
- package/src/components/ActionCapture.tsx +172 -0
- package/src/components/ActionsPanel.tsx +332 -0
- package/src/components/AllVariantsPreview.tsx +78 -0
- package/src/components/App.tsx +604 -0
- package/src/components/BottomPanel.tsx +288 -0
- package/src/components/CodePanel.naming.test.tsx +59 -0
- package/src/components/CodePanel.tsx +118 -0
- package/src/components/CommandPalette.tsx +392 -0
- package/src/components/ComponentDocView.tsx +164 -0
- package/src/components/ComponentGraph.tsx +380 -0
- package/src/components/ComponentHeader.tsx +88 -0
- package/src/components/ContractPanel.tsx +241 -0
- package/src/components/DeviceMockup.tsx +156 -0
- package/src/components/EmptyVariantMessage.tsx +54 -0
- package/src/components/ErrorBoundary.tsx +97 -0
- package/src/components/FigmaEmbed.tsx +238 -0
- package/src/components/FragmentEditor.tsx +525 -0
- package/src/components/FragmentRenderer.tsx +61 -0
- package/src/components/HeaderSearch.tsx +24 -0
- package/src/components/HealthDashboard.tsx +441 -0
- package/src/components/HmrStatusIndicator.tsx +61 -0
- package/src/components/Icons.tsx +479 -0
- package/src/components/InteractionsPanel.tsx +757 -0
- package/src/components/IsolatedPreviewFrame.tsx +390 -0
- package/src/components/IsolatedRender.tsx +113 -0
- package/src/components/KeyboardShortcutsHelp.tsx +53 -0
- package/src/components/LandingPage.tsx +420 -0
- package/src/components/Layout.tsx +27 -0
- package/src/components/LeftSidebar.tsx +472 -0
- package/src/components/LoadErrorMessage.tsx +102 -0
- package/src/components/MultiViewportPreview.tsx +527 -0
- package/src/components/NoVariantsMessage.tsx +59 -0
- package/src/components/PanelShell.tsx +161 -0
- package/src/components/PerformancePanel.tsx +304 -0
- package/src/components/PreviewArea.tsx +254 -0
- package/src/components/PreviewAside.tsx +168 -0
- package/src/components/PreviewFrameHost.tsx +304 -0
- package/src/components/PreviewToolbar.tsx +80 -0
- package/src/components/PropsEditor.tsx +506 -0
- package/src/components/PropsTable.tsx +111 -0
- package/src/components/RelationsSection.tsx +88 -0
- package/src/components/ResizablePanel.tsx +271 -0
- package/src/components/RightSidebar.tsx +102 -0
- package/src/components/RuntimeToolsRegistrar.tsx +17 -0
- package/src/components/ScreenshotButton.tsx +90 -0
- package/src/components/ShadowPreview.tsx +204 -0
- package/src/components/Sidebar.tsx +169 -0
- package/src/components/SkeletonLoader.tsx +161 -0
- package/src/components/ThemeProvider.tsx +42 -0
- package/src/components/Toast.tsx +3 -0
- package/src/components/TokenStylePanel.tsx +699 -0
- package/src/components/TopToolbar.tsx +159 -0
- package/src/components/Untitled +1 -0
- package/src/components/UsageSection.tsx +95 -0
- package/src/components/VariantMatrix.tsx +391 -0
- package/src/components/VariantRenderer.tsx +131 -0
- package/src/components/VariantTabs.tsx +40 -0
- package/src/components/ViewerHeader.tsx +69 -0
- package/src/components/ViewerStateSync.tsx +52 -0
- package/src/components/ViewportSelector.tsx +172 -0
- package/src/components/WebMCPDevTools.tsx +503 -0
- package/src/components/WebMCPIntegration.tsx +47 -0
- package/src/components/WebMCPStatusIndicator.tsx +60 -0
- package/src/components/_future/CreatePage.tsx +835 -0
- package/src/components/viewer-utils.ts +16 -0
- package/src/composition-renderer.ts +381 -0
- package/src/constants/index.ts +1 -0
- package/src/constants/ui.ts +166 -0
- package/src/entry.tsx +335 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/useA11yCache.ts +383 -0
- package/src/hooks/useA11yService.ts +364 -0
- package/src/hooks/useActions.ts +138 -0
- package/src/hooks/useAppState.ts +147 -0
- package/src/hooks/useCompiledFragments.ts +42 -0
- package/src/hooks/useFigmaIntegration.ts +132 -0
- package/src/hooks/useHmrStatus.ts +109 -0
- package/src/hooks/useKeyboardShortcuts.ts +270 -0
- package/src/hooks/usePreviewBridge.ts +347 -0
- package/src/hooks/useScrollSpy.ts +78 -0
- package/src/hooks/useShadowStyles.ts +221 -0
- package/src/hooks/useUrlState.ts +318 -0
- package/src/hooks/useViewSettings.ts +111 -0
- package/src/intelligence/healthReport.ts +505 -0
- package/src/intelligence/styleDrift.ts +340 -0
- package/src/intelligence/usageScanner.ts +309 -0
- package/src/jsx-parser.ts +486 -0
- package/src/preview-frame-entry.tsx +25 -0
- package/src/preview-frame.html +148 -0
- package/src/render-template.html +68 -0
- package/src/render-utils.ts +311 -0
- package/src/shared/ComponentDocContent.module.scss +10 -0
- package/src/shared/ComponentDocContent.module.scss.d.ts +2 -0
- package/src/shared/ComponentDocContent.tsx +274 -0
- package/src/shared/DocsHeaderBar.tsx +129 -0
- package/src/shared/DocsPageAsideHost.tsx +89 -0
- package/src/shared/DocsPageShell.tsx +124 -0
- package/src/shared/DocsSearchCommand.tsx +99 -0
- package/src/shared/DocsSidebarNav.tsx +66 -0
- package/src/shared/PropsTable.module.scss +68 -0
- package/src/shared/PropsTable.module.scss.d.ts +2 -0
- package/src/shared/PropsTable.tsx +76 -0
- package/src/shared/VariantPreviewCard.module.scss +114 -0
- package/src/shared/VariantPreviewCard.module.scss.d.ts +2 -0
- package/src/shared/VariantPreviewCard.tsx +137 -0
- package/src/shared/docs-data/index.ts +32 -0
- package/src/shared/docs-data/mcp-configs.ts +72 -0
- package/src/shared/docs-data/palettes.ts +75 -0
- package/src/shared/docs-data/setup-examples.ts +55 -0
- package/src/shared/docs-layout.scss +28 -0
- package/src/shared/docs-layout.scss.d.ts +2 -0
- package/src/shared/index.ts +34 -0
- package/src/shared/types.ts +53 -0
- package/src/style-utils.ts +414 -0
- package/src/styles/globals.css +278 -0
- package/src/types/a11y.ts +197 -0
- package/src/utils/a11y-fixes.ts +509 -0
- package/src/utils/actionExport.ts +372 -0
- package/src/utils/colorSchemes.ts +201 -0
- package/src/utils/contrast.ts +246 -0
- package/src/utils/detectRelationships.ts +256 -0
- package/src/webmcp/__tests__/analytics.test.ts +108 -0
- package/src/webmcp/analytics.ts +165 -0
- package/src/webmcp/index.ts +3 -0
- package/src/webmcp/posthog-bridge.ts +39 -0
- package/src/webmcp/runtime-tools.ts +152 -0
- package/src/webmcp/scan-utils.ts +135 -0
- package/src/webmcp/use-tool-analytics.ts +69 -0
- package/src/webmcp/viewer-state.ts +45 -0
- package/tsconfig.json +20 -0
|
@@ -0,0 +1,506 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import type { PropDefinition } from '@fragments-sdk/core';
|
|
3
|
+
import { Box, Stack, Text, Button, Badge, Card, Input, Select, Toggle } from "@fragments-sdk/ui";
|
|
4
|
+
import { ControlsIcon, ChevronDownIcon, RefreshIcon } from "./Icons.js";
|
|
5
|
+
|
|
6
|
+
interface PropsEditorProps {
|
|
7
|
+
props: Record<string, PropDefinition>;
|
|
8
|
+
values: Record<string, unknown>;
|
|
9
|
+
onChange: (name: string, value: unknown) => void;
|
|
10
|
+
onReset: () => void;
|
|
11
|
+
hasChanges: boolean;
|
|
12
|
+
compact?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function PropsEditor({
|
|
16
|
+
props,
|
|
17
|
+
values,
|
|
18
|
+
onChange,
|
|
19
|
+
onReset,
|
|
20
|
+
hasChanges,
|
|
21
|
+
compact = false,
|
|
22
|
+
}: PropsEditorProps) {
|
|
23
|
+
const [isCollapsed, setIsCollapsed] = useState(false);
|
|
24
|
+
const propEntries = Object.entries(props);
|
|
25
|
+
|
|
26
|
+
if (propEntries.length === 0) return null;
|
|
27
|
+
|
|
28
|
+
// Compact mode - show controls in a single horizontal line
|
|
29
|
+
if (compact) {
|
|
30
|
+
return (
|
|
31
|
+
<Stack gap="lg">
|
|
32
|
+
{propEntries.map(([name, prop]) => (
|
|
33
|
+
<PropControl
|
|
34
|
+
key={name}
|
|
35
|
+
name={name}
|
|
36
|
+
prop={prop}
|
|
37
|
+
value={values[name]}
|
|
38
|
+
onChange={(value) => onChange(name, value)}
|
|
39
|
+
compact
|
|
40
|
+
/>
|
|
41
|
+
))}
|
|
42
|
+
{hasChanges && (
|
|
43
|
+
<Button variant="ghost" size="sm" onClick={onReset}>
|
|
44
|
+
<RefreshIcon style={{ width: 12, height: 12 }} />
|
|
45
|
+
Reset
|
|
46
|
+
</Button>
|
|
47
|
+
)}
|
|
48
|
+
</Stack>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<Card>
|
|
54
|
+
{/* Header */}
|
|
55
|
+
<Button
|
|
56
|
+
variant="ghost"
|
|
57
|
+
fullWidth
|
|
58
|
+
onClick={() => setIsCollapsed(!isCollapsed)}
|
|
59
|
+
style={{ justifyContent: 'space-between', padding: '12px 16px', borderRadius: 0, borderBottom: '1px solid var(--border)' }}
|
|
60
|
+
>
|
|
61
|
+
<Stack direction="row" align="center" gap="sm">
|
|
62
|
+
<ControlsIcon style={{ width: 16, height: 16 }} />
|
|
63
|
+
<Text size="sm" weight="medium">Props Editor</Text>
|
|
64
|
+
{hasChanges && <Badge variant="info" size="sm">Modified</Badge>}
|
|
65
|
+
</Stack>
|
|
66
|
+
<ChevronDownIcon style={{ width: 16, height: 16, transition: 'transform 0.15s', transform: isCollapsed ? 'rotate(-90deg)' : 'rotate(0deg)' }} />
|
|
67
|
+
</Button>
|
|
68
|
+
|
|
69
|
+
{/* Content */}
|
|
70
|
+
{!isCollapsed && (
|
|
71
|
+
<Box padding="md">
|
|
72
|
+
<Stack gap="md">
|
|
73
|
+
{/* Reset button */}
|
|
74
|
+
{hasChanges && (
|
|
75
|
+
<Button variant="ghost" size="sm" onClick={onReset}>
|
|
76
|
+
<RefreshIcon style={{ width: 14, height: 14 }} />
|
|
77
|
+
Reset to defaults
|
|
78
|
+
</Button>
|
|
79
|
+
)}
|
|
80
|
+
|
|
81
|
+
{/* Prop controls */}
|
|
82
|
+
<Stack gap="sm">
|
|
83
|
+
{propEntries.map(([name, prop]) => (
|
|
84
|
+
<PropControl
|
|
85
|
+
key={name}
|
|
86
|
+
name={name}
|
|
87
|
+
prop={prop}
|
|
88
|
+
value={values[name]}
|
|
89
|
+
onChange={(value) => onChange(name, value)}
|
|
90
|
+
/>
|
|
91
|
+
))}
|
|
92
|
+
</Stack>
|
|
93
|
+
</Stack>
|
|
94
|
+
</Box>
|
|
95
|
+
)}
|
|
96
|
+
</Card>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
interface PropControlProps {
|
|
101
|
+
name: string;
|
|
102
|
+
prop: PropDefinition;
|
|
103
|
+
value: unknown;
|
|
104
|
+
onChange: (value: unknown) => void;
|
|
105
|
+
compact?: boolean;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Determine which control to render based on prop type and controlType
|
|
110
|
+
*/
|
|
111
|
+
function getControlForProp(
|
|
112
|
+
prop: PropDefinition,
|
|
113
|
+
displayValue: unknown,
|
|
114
|
+
onChange: (value: unknown) => void,
|
|
115
|
+
compact: boolean = false
|
|
116
|
+
) {
|
|
117
|
+
// Check controlType first for special controls (color, date, range)
|
|
118
|
+
if (prop.controlType === "color") {
|
|
119
|
+
return (
|
|
120
|
+
<ColorControl
|
|
121
|
+
value={displayValue as string}
|
|
122
|
+
onChange={onChange}
|
|
123
|
+
presetColors={prop.controlOptions?.presetColors}
|
|
124
|
+
/>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (prop.controlType === "date") {
|
|
129
|
+
return <DateControl value={displayValue as string} onChange={onChange} />;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (prop.controlType === "range") {
|
|
133
|
+
return (
|
|
134
|
+
<RangeControl
|
|
135
|
+
value={displayValue as number}
|
|
136
|
+
onChange={onChange}
|
|
137
|
+
min={prop.controlOptions?.min}
|
|
138
|
+
max={prop.controlOptions?.max}
|
|
139
|
+
step={prop.controlOptions?.step}
|
|
140
|
+
/>
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Fall back to type-based controls
|
|
145
|
+
if (prop.type === "boolean") {
|
|
146
|
+
return <BooleanControl value={displayValue as boolean} onChange={onChange} />;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (prop.type === "enum" && prop.values) {
|
|
150
|
+
return (
|
|
151
|
+
<EnumControl
|
|
152
|
+
value={displayValue as string}
|
|
153
|
+
values={prop.values as string[]}
|
|
154
|
+
onChange={onChange}
|
|
155
|
+
/>
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (prop.type === "number") {
|
|
160
|
+
return <NumberControl value={displayValue as number} onChange={onChange} />;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (prop.type === "string") {
|
|
164
|
+
return <StringControl value={displayValue as string} onChange={onChange} compact={compact} />;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (prop.type === "function") {
|
|
168
|
+
return <FunctionControl value={displayValue} onChange={onChange} />;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return <StringControl value={String(displayValue)} onChange={onChange} compact={compact} />;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function PropControl({
|
|
175
|
+
name,
|
|
176
|
+
prop,
|
|
177
|
+
value,
|
|
178
|
+
onChange,
|
|
179
|
+
compact = false,
|
|
180
|
+
}: PropControlProps) {
|
|
181
|
+
const displayValue = value ?? prop.default ?? "";
|
|
182
|
+
|
|
183
|
+
if (compact) {
|
|
184
|
+
return (
|
|
185
|
+
<Stack direction="row" gap="sm">
|
|
186
|
+
<Text as="label" size="xs" weight="medium" font="mono" style={{ whiteSpace: 'nowrap', minWidth: '100px' }} color="secondary">
|
|
187
|
+
{name}
|
|
188
|
+
</Text>
|
|
189
|
+
{getControlForProp(prop, displayValue, onChange, true)}
|
|
190
|
+
</Stack>
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return (
|
|
195
|
+
<Stack gap="sm">
|
|
196
|
+
<Stack direction="row" align="center" gap="sm">
|
|
197
|
+
<Text as="label" size="xs" weight="medium" font="mono">
|
|
198
|
+
{name}
|
|
199
|
+
{prop.required && (
|
|
200
|
+
<span style={{ color: 'var(--color-danger, #ef4444)', marginLeft: '2px' }}>*</span>
|
|
201
|
+
)}
|
|
202
|
+
</Text>
|
|
203
|
+
<Text size="xs" color="tertiary">{prop.type}</Text>
|
|
204
|
+
{prop.controlType && prop.controlType !== prop.type && (
|
|
205
|
+
<Badge size="sm">{prop.controlType}</Badge>
|
|
206
|
+
)}
|
|
207
|
+
</Stack>
|
|
208
|
+
|
|
209
|
+
{getControlForProp(prop, displayValue, onChange, false)}
|
|
210
|
+
|
|
211
|
+
{prop.description && (
|
|
212
|
+
<Text as="p" size="xs" color="tertiary" style={{ lineHeight: 1.6 }}>
|
|
213
|
+
{prop.description}
|
|
214
|
+
</Text>
|
|
215
|
+
)}
|
|
216
|
+
</Stack>
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function BooleanControl({
|
|
221
|
+
value,
|
|
222
|
+
onChange,
|
|
223
|
+
}: {
|
|
224
|
+
value: boolean;
|
|
225
|
+
onChange: (v: boolean) => void;
|
|
226
|
+
}) {
|
|
227
|
+
return (
|
|
228
|
+
<Toggle
|
|
229
|
+
checked={value}
|
|
230
|
+
onChange={() => onChange(!value)}
|
|
231
|
+
/>
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function EnumControl({
|
|
236
|
+
value,
|
|
237
|
+
values,
|
|
238
|
+
onChange,
|
|
239
|
+
}: {
|
|
240
|
+
value: string;
|
|
241
|
+
values: string[];
|
|
242
|
+
onChange: (v: string) => void;
|
|
243
|
+
}) {
|
|
244
|
+
return (
|
|
245
|
+
<Select
|
|
246
|
+
value={value}
|
|
247
|
+
onChange={(e: React.ChangeEvent<HTMLSelectElement>) => onChange(e.target.value)}
|
|
248
|
+
>
|
|
249
|
+
{values.map((v) => (
|
|
250
|
+
<option key={v} value={v}>
|
|
251
|
+
{v}
|
|
252
|
+
</option>
|
|
253
|
+
))}
|
|
254
|
+
</Select>
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function NumberControl({
|
|
259
|
+
value,
|
|
260
|
+
onChange,
|
|
261
|
+
}: {
|
|
262
|
+
value: number;
|
|
263
|
+
onChange: (v: number) => void;
|
|
264
|
+
}) {
|
|
265
|
+
return (
|
|
266
|
+
<Input
|
|
267
|
+
type="number"
|
|
268
|
+
value={value ?? ""}
|
|
269
|
+
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
|
|
270
|
+
onChange(
|
|
271
|
+
e.target.value
|
|
272
|
+
? Number(e.target.value)
|
|
273
|
+
: (undefined as unknown as number)
|
|
274
|
+
)
|
|
275
|
+
}
|
|
276
|
+
style={{ width: '128px', fontFamily: 'monospace' }}
|
|
277
|
+
/>
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function StringControl({
|
|
282
|
+
value,
|
|
283
|
+
onChange,
|
|
284
|
+
compact = false,
|
|
285
|
+
}: {
|
|
286
|
+
value: string;
|
|
287
|
+
onChange: (v: string) => void;
|
|
288
|
+
compact?: boolean;
|
|
289
|
+
}) {
|
|
290
|
+
return (
|
|
291
|
+
<Input
|
|
292
|
+
type="text"
|
|
293
|
+
value={value ?? ""}
|
|
294
|
+
onChange={(e: React.ChangeEvent<HTMLInputElement>) => onChange(e.target.value)}
|
|
295
|
+
style={compact
|
|
296
|
+
? { width: '96px', fontSize: '11px', fontFamily: 'monospace' }
|
|
297
|
+
: { width: '100%', maxWidth: '320px', fontFamily: 'monospace' }
|
|
298
|
+
}
|
|
299
|
+
/>
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function FunctionControl({
|
|
304
|
+
value,
|
|
305
|
+
onChange,
|
|
306
|
+
}: {
|
|
307
|
+
value: unknown;
|
|
308
|
+
onChange: (v: unknown) => void;
|
|
309
|
+
}) {
|
|
310
|
+
const [isEditing, setIsEditing] = useState(false);
|
|
311
|
+
const [inputValue, setInputValue] = useState('');
|
|
312
|
+
|
|
313
|
+
// Get a display string for the function
|
|
314
|
+
const getDisplayValue = () => {
|
|
315
|
+
if (typeof value === 'function') {
|
|
316
|
+
const fnStr = value.toString();
|
|
317
|
+
// Truncate if too long
|
|
318
|
+
if (fnStr.length > 50) {
|
|
319
|
+
return fnStr.slice(0, 47) + '...';
|
|
320
|
+
}
|
|
321
|
+
return fnStr;
|
|
322
|
+
}
|
|
323
|
+
if (typeof value === 'string' && value.trim()) {
|
|
324
|
+
return value;
|
|
325
|
+
}
|
|
326
|
+
return '() => {}';
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
const handleStartEdit = () => {
|
|
330
|
+
// Convert function to string for editing
|
|
331
|
+
if (typeof value === 'function') {
|
|
332
|
+
setInputValue(value.toString());
|
|
333
|
+
} else if (typeof value === 'string') {
|
|
334
|
+
setInputValue(value);
|
|
335
|
+
} else {
|
|
336
|
+
setInputValue('() => {}');
|
|
337
|
+
}
|
|
338
|
+
setIsEditing(true);
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
const handleSave = () => {
|
|
342
|
+
// Save as string - the parent will handle conversion
|
|
343
|
+
onChange(inputValue);
|
|
344
|
+
setIsEditing(false);
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
const handleCancel = () => {
|
|
348
|
+
setIsEditing(false);
|
|
349
|
+
setInputValue('');
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
if (isEditing) {
|
|
353
|
+
return (
|
|
354
|
+
<Stack gap="sm" style={{ flex: 1 }}>
|
|
355
|
+
<textarea
|
|
356
|
+
value={inputValue}
|
|
357
|
+
onChange={(e) => setInputValue(e.target.value)}
|
|
358
|
+
style={{
|
|
359
|
+
width: '100%',
|
|
360
|
+
padding: '6px 8px',
|
|
361
|
+
fontSize: '11px',
|
|
362
|
+
fontFamily: 'monospace',
|
|
363
|
+
background: 'var(--bg-primary)',
|
|
364
|
+
border: '1px solid var(--border)',
|
|
365
|
+
borderRadius: '4px',
|
|
366
|
+
color: 'var(--text-primary)',
|
|
367
|
+
outline: 'none',
|
|
368
|
+
resize: 'vertical',
|
|
369
|
+
minHeight: '60px',
|
|
370
|
+
}}
|
|
371
|
+
placeholder="() => console.log('clicked')"
|
|
372
|
+
autoFocus
|
|
373
|
+
/>
|
|
374
|
+
<Stack direction="row" gap="sm">
|
|
375
|
+
<Button variant="primary" size="sm" onClick={handleSave}>Apply</Button>
|
|
376
|
+
<Button variant="ghost" size="sm" onClick={handleCancel}>Cancel</Button>
|
|
377
|
+
</Stack>
|
|
378
|
+
</Stack>
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
return (
|
|
383
|
+
<button
|
|
384
|
+
onClick={handleStartEdit}
|
|
385
|
+
style={{
|
|
386
|
+
padding: '6px 10px',
|
|
387
|
+
fontSize: '11px',
|
|
388
|
+
fontFamily: 'monospace',
|
|
389
|
+
color: 'var(--text-tertiary)',
|
|
390
|
+
background: 'var(--bg-secondary)',
|
|
391
|
+
borderRadius: '6px',
|
|
392
|
+
width: 'fit-content',
|
|
393
|
+
textAlign: 'left',
|
|
394
|
+
transition: 'background 0.15s',
|
|
395
|
+
cursor: 'pointer',
|
|
396
|
+
border: 'none',
|
|
397
|
+
}}
|
|
398
|
+
title="Click to edit function"
|
|
399
|
+
>
|
|
400
|
+
{getDisplayValue()}
|
|
401
|
+
</button>
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function ColorControl({
|
|
406
|
+
value,
|
|
407
|
+
onChange,
|
|
408
|
+
presetColors,
|
|
409
|
+
}: {
|
|
410
|
+
value: string;
|
|
411
|
+
onChange: (v: string) => void;
|
|
412
|
+
presetColors?: string[];
|
|
413
|
+
}) {
|
|
414
|
+
return (
|
|
415
|
+
<Stack direction="row" align="center" gap="sm">
|
|
416
|
+
<input
|
|
417
|
+
type="color"
|
|
418
|
+
value={value || "#000000"}
|
|
419
|
+
onChange={(e) => onChange(e.target.value)}
|
|
420
|
+
style={{ width: '32px', height: '32px', borderRadius: '4px', border: '1px solid var(--border)', cursor: 'pointer', background: 'transparent' }}
|
|
421
|
+
/>
|
|
422
|
+
<Input
|
|
423
|
+
type="text"
|
|
424
|
+
value={value ?? ""}
|
|
425
|
+
onChange={(e: React.ChangeEvent<HTMLInputElement>) => onChange(e.target.value)}
|
|
426
|
+
placeholder="#000000"
|
|
427
|
+
style={{ width: '96px', fontSize: '11px', fontFamily: 'monospace' }}
|
|
428
|
+
/>
|
|
429
|
+
{presetColors && presetColors.length > 0 && (
|
|
430
|
+
<Stack direction="row" gap="xs" wrap>
|
|
431
|
+
{presetColors.slice(0, 6).map((color) => (
|
|
432
|
+
<button
|
|
433
|
+
key={color}
|
|
434
|
+
onClick={() => onChange(color)}
|
|
435
|
+
style={{
|
|
436
|
+
width: '20px',
|
|
437
|
+
height: '20px',
|
|
438
|
+
borderRadius: '4px',
|
|
439
|
+
border: '1px solid var(--border)',
|
|
440
|
+
backgroundColor: color,
|
|
441
|
+
cursor: 'pointer',
|
|
442
|
+
padding: 0,
|
|
443
|
+
}}
|
|
444
|
+
title={color}
|
|
445
|
+
/>
|
|
446
|
+
))}
|
|
447
|
+
</Stack>
|
|
448
|
+
)}
|
|
449
|
+
</Stack>
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
function DateControl({
|
|
454
|
+
value,
|
|
455
|
+
onChange,
|
|
456
|
+
}: {
|
|
457
|
+
value: string;
|
|
458
|
+
onChange: (v: string) => void;
|
|
459
|
+
}) {
|
|
460
|
+
// Convert ISO string to datetime-local format for input
|
|
461
|
+
const inputValue = value
|
|
462
|
+
? new Date(value).toISOString().slice(0, 16)
|
|
463
|
+
: "";
|
|
464
|
+
|
|
465
|
+
return (
|
|
466
|
+
<Input
|
|
467
|
+
type="datetime-local"
|
|
468
|
+
value={inputValue}
|
|
469
|
+
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
|
|
470
|
+
const date = e.target.value ? new Date(e.target.value).toISOString() : "";
|
|
471
|
+
onChange(date);
|
|
472
|
+
}}
|
|
473
|
+
/>
|
|
474
|
+
);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
function RangeControl({
|
|
478
|
+
value,
|
|
479
|
+
onChange,
|
|
480
|
+
min = 0,
|
|
481
|
+
max = 100,
|
|
482
|
+
step = 1,
|
|
483
|
+
}: {
|
|
484
|
+
value: number;
|
|
485
|
+
onChange: (v: number) => void;
|
|
486
|
+
min?: number;
|
|
487
|
+
max?: number;
|
|
488
|
+
step?: number;
|
|
489
|
+
}) {
|
|
490
|
+
return (
|
|
491
|
+
<Stack direction="row" align="center" gap="sm">
|
|
492
|
+
<input
|
|
493
|
+
type="range"
|
|
494
|
+
value={value ?? min}
|
|
495
|
+
min={min}
|
|
496
|
+
max={max}
|
|
497
|
+
step={step}
|
|
498
|
+
onChange={(e) => onChange(Number(e.target.value))}
|
|
499
|
+
style={{ flex: 1, height: '8px', background: 'var(--bg-secondary)', borderRadius: '8px', cursor: 'pointer', accentColor: 'var(--color-accent)' }}
|
|
500
|
+
/>
|
|
501
|
+
<Text size="xs" font="mono" color="secondary" style={{ minWidth: '3rem', textAlign: 'right' }}>
|
|
502
|
+
{value ?? min}
|
|
503
|
+
</Text>
|
|
504
|
+
</Stack>
|
|
505
|
+
);
|
|
506
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import type { PropDefinition } from '@fragments-sdk/core';
|
|
3
|
+
import { DataTable, createColumns, Badge, Text, Stack } from '@fragments-sdk/ui';
|
|
4
|
+
import { WarningIcon } from './Icons.js';
|
|
5
|
+
|
|
6
|
+
interface PropsTableProps {
|
|
7
|
+
props: Record<string, PropDefinition>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface PropRow {
|
|
11
|
+
name: string;
|
|
12
|
+
required: boolean;
|
|
13
|
+
type: string;
|
|
14
|
+
values?: string[];
|
|
15
|
+
default: unknown;
|
|
16
|
+
description: string;
|
|
17
|
+
constraints?: string[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function PropsTable({ props }: PropsTableProps) {
|
|
21
|
+
const propEntries = Object.entries(props);
|
|
22
|
+
|
|
23
|
+
const data = useMemo<PropRow[]>(() =>
|
|
24
|
+
propEntries.map(([name, prop]) => ({
|
|
25
|
+
name,
|
|
26
|
+
required: !!prop.required,
|
|
27
|
+
type: prop.type,
|
|
28
|
+
values: prop.values,
|
|
29
|
+
default: prop.default,
|
|
30
|
+
description: prop.description,
|
|
31
|
+
constraints: prop.constraints,
|
|
32
|
+
})),
|
|
33
|
+
[propEntries]
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const columns = useMemo(() => createColumns<PropRow>([
|
|
37
|
+
{
|
|
38
|
+
key: 'name',
|
|
39
|
+
header: 'Prop',
|
|
40
|
+
cell: (row) => (
|
|
41
|
+
<Text font="mono" size="sm" weight="medium">
|
|
42
|
+
{row.name}
|
|
43
|
+
{row.required && <span style={{ color: 'var(--color-danger, #ef4444)', marginLeft: '2px' }}>*</span>}
|
|
44
|
+
</Text>
|
|
45
|
+
),
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
key: 'type',
|
|
49
|
+
header: 'Type',
|
|
50
|
+
cell: (row) => {
|
|
51
|
+
if (row.type === 'enum' && row.values && row.values.length > 0) {
|
|
52
|
+
return (
|
|
53
|
+
<Stack direction="row" gap="xs" style={{ flexWrap: 'wrap' }}>
|
|
54
|
+
{row.values.map((value, index) => (
|
|
55
|
+
<span key={value} style={{ display: 'inline-flex', alignItems: 'center' }}>
|
|
56
|
+
<Badge size="sm">{value}</Badge>
|
|
57
|
+
{index < row.values!.length - 1 && <Text size="xs" color="tertiary" style={{ margin: '0 4px' }}>|</Text>}
|
|
58
|
+
</span>
|
|
59
|
+
))}
|
|
60
|
+
</Stack>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
return <Text font="mono" size="xs" color="secondary">{row.type}</Text>;
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
key: 'default',
|
|
68
|
+
header: 'Default',
|
|
69
|
+
cell: (row) => {
|
|
70
|
+
if (row.default !== undefined) {
|
|
71
|
+
return <Text font="mono" size="xs" color="secondary">{String(row.default)}</Text>;
|
|
72
|
+
}
|
|
73
|
+
return <Text color="tertiary">—</Text>;
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
key: 'description',
|
|
78
|
+
header: 'Description',
|
|
79
|
+
cell: (row) => (
|
|
80
|
+
<Stack gap="xs">
|
|
81
|
+
<Text size="sm" color="secondary">{row.description}</Text>
|
|
82
|
+
{row.constraints && row.constraints.length > 0 && (
|
|
83
|
+
<Stack gap="xs">
|
|
84
|
+
{row.constraints.map((constraint, index) => (
|
|
85
|
+
<Stack key={index} direction="row" gap="xs" align="start" style={{ fontSize: '12px', color: 'var(--color-warning, #f59e0b)' }}>
|
|
86
|
+
<WarningIcon style={{ width: 12, height: 12, marginTop: '2px', flexShrink: 0 }} />
|
|
87
|
+
<span>{constraint}</span>
|
|
88
|
+
</Stack>
|
|
89
|
+
))}
|
|
90
|
+
</Stack>
|
|
91
|
+
)}
|
|
92
|
+
</Stack>
|
|
93
|
+
),
|
|
94
|
+
},
|
|
95
|
+
]), []);
|
|
96
|
+
|
|
97
|
+
if (propEntries.length === 0) return null;
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<section id="props" style={{ scrollMarginTop: '96px' }}>
|
|
101
|
+
<Text as="h2" size="md" weight="semibold" style={{ marginBottom: '16px' }}>Props</Text>
|
|
102
|
+
<DataTable
|
|
103
|
+
columns={columns}
|
|
104
|
+
data={data}
|
|
105
|
+
size="sm"
|
|
106
|
+
bordered
|
|
107
|
+
getRowId={(row) => row.name}
|
|
108
|
+
/>
|
|
109
|
+
</section>
|
|
110
|
+
);
|
|
111
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import type { ComponentRelation } from '@fragments-sdk/core';
|
|
3
|
+
import { getRelationshipConfig } from '../constants/ui.js';
|
|
4
|
+
import { ChevronRightIcon } from './Icons.js';
|
|
5
|
+
|
|
6
|
+
interface RelationsSectionProps {
|
|
7
|
+
relations: ComponentRelation[];
|
|
8
|
+
onNavigate?: (componentName: string) => void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function RelationsSection({ relations, onNavigate }: RelationsSectionProps) {
|
|
12
|
+
if (relations.length === 0) return null;
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<section id="relations" style={{ scrollMarginTop: '96px' }}>
|
|
16
|
+
<h2 style={{ fontSize: '16px', fontWeight: 600, color: 'var(--text-primary)', marginBottom: '16px' }}>Related Components</h2>
|
|
17
|
+
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(280px, 1fr))', gap: '12px' }}>
|
|
18
|
+
{relations.map((relation, index) => (
|
|
19
|
+
<RelationButton key={index} relation={relation} onNavigate={onNavigate} />
|
|
20
|
+
))}
|
|
21
|
+
</div>
|
|
22
|
+
</section>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function RelationButton({ relation, onNavigate }: { relation: ComponentRelation; onNavigate?: (componentName: string) => void }) {
|
|
27
|
+
const config = getRelationshipConfig(relation.relationship);
|
|
28
|
+
const [hovered, setHovered] = useState(false);
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<button
|
|
32
|
+
onClick={() => onNavigate?.(relation.component)}
|
|
33
|
+
onMouseEnter={() => setHovered(true)}
|
|
34
|
+
onMouseLeave={() => setHovered(false)}
|
|
35
|
+
style={{
|
|
36
|
+
textAlign: 'left',
|
|
37
|
+
padding: '16px',
|
|
38
|
+
borderRadius: '12px',
|
|
39
|
+
border: `1px solid ${hovered ? 'var(--border-strong)' : 'var(--border)'}`,
|
|
40
|
+
background: 'var(--bg-elevated)',
|
|
41
|
+
transition: 'all 150ms',
|
|
42
|
+
cursor: 'pointer',
|
|
43
|
+
outline: 'none',
|
|
44
|
+
}}
|
|
45
|
+
>
|
|
46
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: '8px', marginBottom: '6px' }}>
|
|
47
|
+
<span style={{
|
|
48
|
+
fontSize: '13px',
|
|
49
|
+
fontWeight: 500,
|
|
50
|
+
color: hovered ? 'var(--color-accent)' : 'var(--text-primary)',
|
|
51
|
+
transition: 'color 150ms',
|
|
52
|
+
}}>
|
|
53
|
+
{relation.component}
|
|
54
|
+
</span>
|
|
55
|
+
<span style={{
|
|
56
|
+
fontSize: '10px',
|
|
57
|
+
fontWeight: 500,
|
|
58
|
+
padding: '2px 6px',
|
|
59
|
+
borderRadius: '4px',
|
|
60
|
+
background: config.bgColor ?? 'var(--bg-tertiary)',
|
|
61
|
+
color: config.textColor ?? 'var(--text-secondary)',
|
|
62
|
+
}}>
|
|
63
|
+
{config.label}
|
|
64
|
+
</span>
|
|
65
|
+
</div>
|
|
66
|
+
{relation.note && (
|
|
67
|
+
<p style={{ fontSize: '13px', color: 'var(--text-secondary)', lineHeight: 1.6, margin: 0 }}>{relation.note}</p>
|
|
68
|
+
)}
|
|
69
|
+
<div style={{
|
|
70
|
+
marginTop: '8px',
|
|
71
|
+
display: 'flex',
|
|
72
|
+
alignItems: 'center',
|
|
73
|
+
fontSize: '12px',
|
|
74
|
+
color: hovered ? 'var(--text-secondary)' : 'var(--text-tertiary)',
|
|
75
|
+
transition: 'color 150ms',
|
|
76
|
+
}}>
|
|
77
|
+
<span>View component</span>
|
|
78
|
+
<ChevronRightIcon style={{
|
|
79
|
+
width: '12px',
|
|
80
|
+
height: '12px',
|
|
81
|
+
marginLeft: '4px',
|
|
82
|
+
transform: hovered ? 'translateX(2px)' : 'translateX(0)',
|
|
83
|
+
transition: 'transform 150ms',
|
|
84
|
+
}} />
|
|
85
|
+
</div>
|
|
86
|
+
</button>
|
|
87
|
+
);
|
|
88
|
+
}
|