@fragments-sdk/cli 0.10.1 → 0.12.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 (223) hide show
  1. package/dist/ai-client-I6MDWNYA.js +21 -0
  2. package/dist/bin.js +292 -367
  3. package/dist/bin.js.map +1 -1
  4. package/dist/{chunk-PW7QTQA6.js → chunk-4OC7FTJB.js} +2 -2
  5. package/dist/{chunk-HRFUSSZI.js → chunk-AM4MRTMN.js} +2 -2
  6. package/dist/{chunk-5G3VZH43.js → chunk-GVDSFQ4E.js} +281 -351
  7. package/dist/chunk-GVDSFQ4E.js.map +1 -0
  8. package/dist/chunk-JJ2VRTBU.js +626 -0
  9. package/dist/chunk-JJ2VRTBU.js.map +1 -0
  10. package/dist/{chunk-D5PYOXEI.js → chunk-LVWFOLUZ.js} +148 -13
  11. package/dist/{chunk-D5PYOXEI.js.map → chunk-LVWFOLUZ.js.map} +1 -1
  12. package/dist/{chunk-WXSR2II7.js → chunk-OQKMEFOS.js} +58 -6
  13. package/dist/chunk-OQKMEFOS.js.map +1 -0
  14. package/dist/chunk-SXTKFDCR.js +104 -0
  15. package/dist/chunk-SXTKFDCR.js.map +1 -0
  16. package/dist/chunk-T5OMVL7E.js +443 -0
  17. package/dist/chunk-T5OMVL7E.js.map +1 -0
  18. package/dist/{chunk-ZM4ZQZWZ.js → chunk-TPWGL2XS.js} +39 -37
  19. package/dist/chunk-TPWGL2XS.js.map +1 -0
  20. package/dist/{chunk-OQO55NKV.js → chunk-WFS63PCW.js} +85 -11
  21. package/dist/chunk-WFS63PCW.js.map +1 -0
  22. package/dist/core/index.js +9 -1
  23. package/dist/{discovery-NEOY4MPN.js → discovery-ZJQSXF56.js} +3 -3
  24. package/dist/{generate-FBHSXR3D.js → generate-RJFS2JWA.js} +4 -4
  25. package/dist/index.js +7 -6
  26. package/dist/index.js.map +1 -1
  27. package/dist/init-ZSX3NRCZ.js +636 -0
  28. package/dist/init-ZSX3NRCZ.js.map +1 -0
  29. package/dist/mcp-bin.js +2 -2
  30. package/dist/{scan-CJF2DOQW.js → scan-3PMCJ4RB.js} +6 -6
  31. package/dist/scan-generate-SYU4PYZD.js +1115 -0
  32. package/dist/scan-generate-SYU4PYZD.js.map +1 -0
  33. package/dist/{service-TQYWY65E.js → service-VMGNJZ42.js} +3 -3
  34. package/dist/snapshot-XOISO2IS.js +139 -0
  35. package/dist/snapshot-XOISO2IS.js.map +1 -0
  36. package/dist/{static-viewer-NUBFPKWH.js → static-viewer-5GXH2MGE.js} +3 -3
  37. package/dist/static-viewer-5GXH2MGE.js.map +1 -0
  38. package/dist/{test-Z5LVO724.js → test-SI4NSHQX.js} +4 -4
  39. package/dist/{tokens-CE46OTMD.js → tokens-T6SIVUT5.js} +5 -5
  40. package/dist/{viewer-DNMNC5VS.js → viewer-7ZEAFBVN.js} +80 -58
  41. package/dist/viewer-7ZEAFBVN.js.map +1 -0
  42. package/package.json +6 -14
  43. package/src/ai-client.ts +156 -0
  44. package/src/bin.ts +74 -2
  45. package/src/build.ts +95 -33
  46. package/src/commands/__tests__/drift-sync.test.ts +252 -0
  47. package/src/commands/__tests__/scan-generate.test.ts +497 -45
  48. package/src/commands/enhance.ts +11 -35
  49. package/src/commands/init.ts +296 -193
  50. package/src/commands/scan-generate.ts +740 -139
  51. package/src/commands/scan.ts +37 -32
  52. package/src/commands/setup.ts +143 -52
  53. package/src/commands/snapshot.ts +197 -0
  54. package/src/commands/sync.ts +357 -0
  55. package/src/commands/validate.ts +43 -1
  56. package/src/core/component-extractor.test.ts +282 -0
  57. package/src/core/component-extractor.ts +1030 -0
  58. package/src/core/discovery.ts +93 -7
  59. package/src/service/enhance/props-extractor.ts +235 -13
  60. package/src/validators.ts +236 -0
  61. package/src/viewer/__tests__/viewer-integration.test.ts +85 -74
  62. package/src/viewer/server.ts +37 -22
  63. package/src/viewer/vite-plugin.ts +25 -9
  64. package/dist/chunk-5G3VZH43.js.map +0 -1
  65. package/dist/chunk-OQO55NKV.js.map +0 -1
  66. package/dist/chunk-WXSR2II7.js.map +0 -1
  67. package/dist/chunk-ZM4ZQZWZ.js.map +0 -1
  68. package/dist/init-NDQXUWDU.js +0 -796
  69. package/dist/init-NDQXUWDU.js.map +0 -1
  70. package/dist/scan-generate-SJAN5MVI.js +0 -691
  71. package/dist/scan-generate-SJAN5MVI.js.map +0 -1
  72. package/dist/viewer-DNMNC5VS.js.map +0 -1
  73. package/src/ai.ts +0 -266
  74. package/src/commands/init-framework.ts +0 -414
  75. package/src/mcp/bin.ts +0 -36
  76. package/src/migrate/bin.ts +0 -114
  77. package/src/theme/index.ts +0 -77
  78. package/src/viewer/__tests__/a11y-fixes.test.ts +0 -358
  79. package/src/viewer/__tests__/jsx-parser.test.ts +0 -502
  80. package/src/viewer/__tests__/render-utils.test.ts +0 -232
  81. package/src/viewer/__tests__/style-utils.test.ts +0 -404
  82. package/src/viewer/assets/fragments-logo.ts +0 -4
  83. package/src/viewer/assets/fragments_logo.png +0 -0
  84. package/src/viewer/bin.ts +0 -86
  85. package/src/viewer/cli/health.ts +0 -256
  86. package/src/viewer/cli/index.ts +0 -33
  87. package/src/viewer/cli/scan.ts +0 -124
  88. package/src/viewer/cli/utils.ts +0 -174
  89. package/src/viewer/components/AccessibilityPanel.tsx +0 -1457
  90. package/src/viewer/components/ActionCapture.tsx +0 -172
  91. package/src/viewer/components/ActionsPanel.tsx +0 -332
  92. package/src/viewer/components/AllVariantsPreview.tsx +0 -78
  93. package/src/viewer/components/App.tsx +0 -582
  94. package/src/viewer/components/BottomPanel.tsx +0 -288
  95. package/src/viewer/components/CodePanel.naming.test.tsx +0 -59
  96. package/src/viewer/components/CodePanel.tsx +0 -118
  97. package/src/viewer/components/CommandPalette.tsx +0 -392
  98. package/src/viewer/components/ComponentDocView.tsx +0 -164
  99. package/src/viewer/components/ComponentGraph.tsx +0 -380
  100. package/src/viewer/components/ComponentHeader.tsx +0 -88
  101. package/src/viewer/components/ContractPanel.tsx +0 -241
  102. package/src/viewer/components/EmptyVariantMessage.tsx +0 -54
  103. package/src/viewer/components/ErrorBoundary.tsx +0 -97
  104. package/src/viewer/components/FigmaEmbed.tsx +0 -238
  105. package/src/viewer/components/FragmentEditor.tsx +0 -525
  106. package/src/viewer/components/FragmentRenderer.tsx +0 -61
  107. package/src/viewer/components/HeaderSearch.tsx +0 -24
  108. package/src/viewer/components/HealthDashboard.tsx +0 -441
  109. package/src/viewer/components/HmrStatusIndicator.tsx +0 -61
  110. package/src/viewer/components/Icons.tsx +0 -479
  111. package/src/viewer/components/InteractionsPanel.tsx +0 -757
  112. package/src/viewer/components/IsolatedPreviewFrame.tsx +0 -346
  113. package/src/viewer/components/IsolatedRender.tsx +0 -113
  114. package/src/viewer/components/KeyboardShortcutsHelp.tsx +0 -53
  115. package/src/viewer/components/LandingPage.tsx +0 -421
  116. package/src/viewer/components/Layout.tsx +0 -27
  117. package/src/viewer/components/LeftSidebar.tsx +0 -472
  118. package/src/viewer/components/LoadErrorMessage.tsx +0 -102
  119. package/src/viewer/components/MultiViewportPreview.tsx +0 -522
  120. package/src/viewer/components/NoVariantsMessage.tsx +0 -59
  121. package/src/viewer/components/PanelShell.tsx +0 -161
  122. package/src/viewer/components/PerformancePanel.tsx +0 -304
  123. package/src/viewer/components/PreviewArea.tsx +0 -472
  124. package/src/viewer/components/PreviewAside.tsx +0 -168
  125. package/src/viewer/components/PreviewFrameHost.tsx +0 -303
  126. package/src/viewer/components/PreviewPane.tsx +0 -149
  127. package/src/viewer/components/PreviewToolbar.tsx +0 -80
  128. package/src/viewer/components/PropsEditor.tsx +0 -506
  129. package/src/viewer/components/PropsTable.tsx +0 -111
  130. package/src/viewer/components/RelationsSection.tsx +0 -88
  131. package/src/viewer/components/ResizablePanel.tsx +0 -271
  132. package/src/viewer/components/RightSidebar.tsx +0 -102
  133. package/src/viewer/components/RuntimeToolsRegistrar.tsx +0 -17
  134. package/src/viewer/components/ScreenshotButton.tsx +0 -90
  135. package/src/viewer/components/Sidebar.tsx +0 -169
  136. package/src/viewer/components/SkeletonLoader.tsx +0 -161
  137. package/src/viewer/components/ThemeProvider.tsx +0 -42
  138. package/src/viewer/components/Toast.tsx +0 -3
  139. package/src/viewer/components/TokenStylePanel.tsx +0 -699
  140. package/src/viewer/components/TopToolbar.tsx +0 -159
  141. package/src/viewer/components/UsageSection.tsx +0 -95
  142. package/src/viewer/components/VariantMatrix.tsx +0 -388
  143. package/src/viewer/components/VariantRenderer.tsx +0 -131
  144. package/src/viewer/components/VariantTabs.tsx +0 -40
  145. package/src/viewer/components/ViewerHeader.tsx +0 -69
  146. package/src/viewer/components/ViewerStateSync.tsx +0 -52
  147. package/src/viewer/components/ViewportSelector.tsx +0 -172
  148. package/src/viewer/components/WebMCPDevTools.tsx +0 -503
  149. package/src/viewer/components/WebMCPIntegration.tsx +0 -47
  150. package/src/viewer/components/WebMCPStatusIndicator.tsx +0 -60
  151. package/src/viewer/components/_future/CreatePage.tsx +0 -836
  152. package/src/viewer/components/viewer-utils.ts +0 -16
  153. package/src/viewer/composition-renderer.ts +0 -381
  154. package/src/viewer/constants/index.ts +0 -1
  155. package/src/viewer/constants/ui.ts +0 -166
  156. package/src/viewer/entry.tsx +0 -335
  157. package/src/viewer/hooks/index.ts +0 -2
  158. package/src/viewer/hooks/useA11yCache.ts +0 -383
  159. package/src/viewer/hooks/useA11yService.ts +0 -364
  160. package/src/viewer/hooks/useActions.ts +0 -138
  161. package/src/viewer/hooks/useAppState.ts +0 -147
  162. package/src/viewer/hooks/useCompiledFragments.ts +0 -42
  163. package/src/viewer/hooks/useFigmaIntegration.ts +0 -132
  164. package/src/viewer/hooks/useHmrStatus.ts +0 -109
  165. package/src/viewer/hooks/useKeyboardShortcuts.ts +0 -270
  166. package/src/viewer/hooks/usePreviewBridge.ts +0 -347
  167. package/src/viewer/hooks/useScrollSpy.ts +0 -78
  168. package/src/viewer/hooks/useUrlState.ts +0 -318
  169. package/src/viewer/hooks/useViewSettings.ts +0 -111
  170. package/src/viewer/index.html +0 -28
  171. package/src/viewer/intelligence/healthReport.ts +0 -505
  172. package/src/viewer/intelligence/styleDrift.ts +0 -340
  173. package/src/viewer/intelligence/usageScanner.ts +0 -309
  174. package/src/viewer/jsx-parser.ts +0 -486
  175. package/src/viewer/preview-frame-entry.tsx +0 -25
  176. package/src/viewer/preview-frame.html +0 -125
  177. package/src/viewer/public/favicon.ico +0 -0
  178. package/src/viewer/render-template.html +0 -68
  179. package/src/viewer/styles/globals.css +0 -278
  180. package/src/viewer/types/a11y.ts +0 -197
  181. package/src/viewer/utils/a11y-fixes.ts +0 -509
  182. package/src/viewer/utils/actionExport.ts +0 -372
  183. package/src/viewer/utils/colorSchemes.ts +0 -201
  184. package/src/viewer/utils/detectRelationships.ts +0 -256
  185. package/src/viewer/vendor/shared/src/ComponentDocContent.module.scss +0 -10
  186. package/src/viewer/vendor/shared/src/ComponentDocContent.module.scss.d.ts +0 -2
  187. package/src/viewer/vendor/shared/src/ComponentDocContent.tsx +0 -274
  188. package/src/viewer/vendor/shared/src/DocsHeaderBar.tsx +0 -129
  189. package/src/viewer/vendor/shared/src/DocsPageAsideHost.tsx +0 -89
  190. package/src/viewer/vendor/shared/src/DocsPageShell.tsx +0 -124
  191. package/src/viewer/vendor/shared/src/DocsSearchCommand.tsx +0 -99
  192. package/src/viewer/vendor/shared/src/DocsSidebarNav.tsx +0 -66
  193. package/src/viewer/vendor/shared/src/PropsTable.module.scss +0 -68
  194. package/src/viewer/vendor/shared/src/PropsTable.module.scss.d.ts +0 -2
  195. package/src/viewer/vendor/shared/src/PropsTable.tsx +0 -76
  196. package/src/viewer/vendor/shared/src/VariantPreviewCard.module.scss +0 -114
  197. package/src/viewer/vendor/shared/src/VariantPreviewCard.module.scss.d.ts +0 -2
  198. package/src/viewer/vendor/shared/src/VariantPreviewCard.tsx +0 -137
  199. package/src/viewer/vendor/shared/src/docs-data/index.ts +0 -32
  200. package/src/viewer/vendor/shared/src/docs-data/mcp-configs.ts +0 -72
  201. package/src/viewer/vendor/shared/src/docs-data/palettes.ts +0 -75
  202. package/src/viewer/vendor/shared/src/docs-data/setup-examples.ts +0 -55
  203. package/src/viewer/vendor/shared/src/docs-layout.scss +0 -28
  204. package/src/viewer/vendor/shared/src/docs-layout.scss.d.ts +0 -2
  205. package/src/viewer/vendor/shared/src/index.ts +0 -34
  206. package/src/viewer/vendor/shared/src/types.ts +0 -53
  207. package/src/viewer/webmcp/__tests__/analytics.test.ts +0 -108
  208. package/src/viewer/webmcp/analytics.ts +0 -165
  209. package/src/viewer/webmcp/index.ts +0 -3
  210. package/src/viewer/webmcp/posthog-bridge.ts +0 -39
  211. package/src/viewer/webmcp/runtime-tools.ts +0 -152
  212. package/src/viewer/webmcp/scan-utils.ts +0 -135
  213. package/src/viewer/webmcp/use-tool-analytics.ts +0 -69
  214. package/src/viewer/webmcp/viewer-state.ts +0 -45
  215. /package/dist/{discovery-NEOY4MPN.js.map → ai-client-I6MDWNYA.js.map} +0 -0
  216. /package/dist/{chunk-PW7QTQA6.js.map → chunk-4OC7FTJB.js.map} +0 -0
  217. /package/dist/{chunk-HRFUSSZI.js.map → chunk-AM4MRTMN.js.map} +0 -0
  218. /package/dist/{scan-CJF2DOQW.js.map → discovery-ZJQSXF56.js.map} +0 -0
  219. /package/dist/{generate-FBHSXR3D.js.map → generate-RJFS2JWA.js.map} +0 -0
  220. /package/dist/{service-TQYWY65E.js.map → scan-3PMCJ4RB.js.map} +0 -0
  221. /package/dist/{static-viewer-NUBFPKWH.js.map → service-VMGNJZ42.js.map} +0 -0
  222. /package/dist/{test-Z5LVO724.js.map → test-SI4NSHQX.js.map} +0 -0
  223. /package/dist/{tokens-CE46OTMD.js.map → tokens-T6SIVUT5.js.map} +0 -0
@@ -1,506 +0,0 @@
1
- import { useState } from "react";
2
- import type { PropDefinition } from "../../core/index.js";
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
- }
@@ -1,111 +0,0 @@
1
- import { useMemo } from 'react';
2
- import type { PropDefinition } from '../../core/index.js';
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">&mdash;</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
- }
@@ -1,88 +0,0 @@
1
- import { useState } from 'react';
2
- import type { ComponentRelation } from '../../core/index.js';
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
- }