@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.
Files changed (141) hide show
  1. package/LICENSE +84 -0
  2. package/index.html +28 -0
  3. package/package.json +71 -0
  4. package/src/__tests__/a11y-fixes.test.ts +358 -0
  5. package/src/__tests__/jsx-parser.test.ts +502 -0
  6. package/src/__tests__/render-utils.test.ts +232 -0
  7. package/src/__tests__/style-utils.test.ts +404 -0
  8. package/src/app/index.ts +1 -0
  9. package/src/assets/fragments-logo.ts +4 -0
  10. package/src/assets/fragments_logo.png +0 -0
  11. package/src/components/AccessibilityPanel.tsx +1457 -0
  12. package/src/components/ActionCapture.tsx +172 -0
  13. package/src/components/ActionsPanel.tsx +332 -0
  14. package/src/components/AllVariantsPreview.tsx +78 -0
  15. package/src/components/App.tsx +604 -0
  16. package/src/components/BottomPanel.tsx +288 -0
  17. package/src/components/CodePanel.naming.test.tsx +59 -0
  18. package/src/components/CodePanel.tsx +118 -0
  19. package/src/components/CommandPalette.tsx +392 -0
  20. package/src/components/ComponentDocView.tsx +164 -0
  21. package/src/components/ComponentGraph.tsx +380 -0
  22. package/src/components/ComponentHeader.tsx +88 -0
  23. package/src/components/ContractPanel.tsx +241 -0
  24. package/src/components/DeviceMockup.tsx +156 -0
  25. package/src/components/EmptyVariantMessage.tsx +54 -0
  26. package/src/components/ErrorBoundary.tsx +97 -0
  27. package/src/components/FigmaEmbed.tsx +238 -0
  28. package/src/components/FragmentEditor.tsx +525 -0
  29. package/src/components/FragmentRenderer.tsx +61 -0
  30. package/src/components/HeaderSearch.tsx +24 -0
  31. package/src/components/HealthDashboard.tsx +441 -0
  32. package/src/components/HmrStatusIndicator.tsx +61 -0
  33. package/src/components/Icons.tsx +479 -0
  34. package/src/components/InteractionsPanel.tsx +757 -0
  35. package/src/components/IsolatedPreviewFrame.tsx +390 -0
  36. package/src/components/IsolatedRender.tsx +113 -0
  37. package/src/components/KeyboardShortcutsHelp.tsx +53 -0
  38. package/src/components/LandingPage.tsx +420 -0
  39. package/src/components/Layout.tsx +27 -0
  40. package/src/components/LeftSidebar.tsx +472 -0
  41. package/src/components/LoadErrorMessage.tsx +102 -0
  42. package/src/components/MultiViewportPreview.tsx +527 -0
  43. package/src/components/NoVariantsMessage.tsx +59 -0
  44. package/src/components/PanelShell.tsx +161 -0
  45. package/src/components/PerformancePanel.tsx +304 -0
  46. package/src/components/PreviewArea.tsx +254 -0
  47. package/src/components/PreviewAside.tsx +168 -0
  48. package/src/components/PreviewFrameHost.tsx +304 -0
  49. package/src/components/PreviewToolbar.tsx +80 -0
  50. package/src/components/PropsEditor.tsx +506 -0
  51. package/src/components/PropsTable.tsx +111 -0
  52. package/src/components/RelationsSection.tsx +88 -0
  53. package/src/components/ResizablePanel.tsx +271 -0
  54. package/src/components/RightSidebar.tsx +102 -0
  55. package/src/components/RuntimeToolsRegistrar.tsx +17 -0
  56. package/src/components/ScreenshotButton.tsx +90 -0
  57. package/src/components/ShadowPreview.tsx +204 -0
  58. package/src/components/Sidebar.tsx +169 -0
  59. package/src/components/SkeletonLoader.tsx +161 -0
  60. package/src/components/ThemeProvider.tsx +42 -0
  61. package/src/components/Toast.tsx +3 -0
  62. package/src/components/TokenStylePanel.tsx +699 -0
  63. package/src/components/TopToolbar.tsx +159 -0
  64. package/src/components/Untitled +1 -0
  65. package/src/components/UsageSection.tsx +95 -0
  66. package/src/components/VariantMatrix.tsx +391 -0
  67. package/src/components/VariantRenderer.tsx +131 -0
  68. package/src/components/VariantTabs.tsx +40 -0
  69. package/src/components/ViewerHeader.tsx +69 -0
  70. package/src/components/ViewerStateSync.tsx +52 -0
  71. package/src/components/ViewportSelector.tsx +172 -0
  72. package/src/components/WebMCPDevTools.tsx +503 -0
  73. package/src/components/WebMCPIntegration.tsx +47 -0
  74. package/src/components/WebMCPStatusIndicator.tsx +60 -0
  75. package/src/components/_future/CreatePage.tsx +835 -0
  76. package/src/components/viewer-utils.ts +16 -0
  77. package/src/composition-renderer.ts +381 -0
  78. package/src/constants/index.ts +1 -0
  79. package/src/constants/ui.ts +166 -0
  80. package/src/entry.tsx +335 -0
  81. package/src/hooks/index.ts +2 -0
  82. package/src/hooks/useA11yCache.ts +383 -0
  83. package/src/hooks/useA11yService.ts +364 -0
  84. package/src/hooks/useActions.ts +138 -0
  85. package/src/hooks/useAppState.ts +147 -0
  86. package/src/hooks/useCompiledFragments.ts +42 -0
  87. package/src/hooks/useFigmaIntegration.ts +132 -0
  88. package/src/hooks/useHmrStatus.ts +109 -0
  89. package/src/hooks/useKeyboardShortcuts.ts +270 -0
  90. package/src/hooks/usePreviewBridge.ts +347 -0
  91. package/src/hooks/useScrollSpy.ts +78 -0
  92. package/src/hooks/useShadowStyles.ts +221 -0
  93. package/src/hooks/useUrlState.ts +318 -0
  94. package/src/hooks/useViewSettings.ts +111 -0
  95. package/src/intelligence/healthReport.ts +505 -0
  96. package/src/intelligence/styleDrift.ts +340 -0
  97. package/src/intelligence/usageScanner.ts +309 -0
  98. package/src/jsx-parser.ts +486 -0
  99. package/src/preview-frame-entry.tsx +25 -0
  100. package/src/preview-frame.html +148 -0
  101. package/src/render-template.html +68 -0
  102. package/src/render-utils.ts +311 -0
  103. package/src/shared/ComponentDocContent.module.scss +10 -0
  104. package/src/shared/ComponentDocContent.module.scss.d.ts +2 -0
  105. package/src/shared/ComponentDocContent.tsx +274 -0
  106. package/src/shared/DocsHeaderBar.tsx +129 -0
  107. package/src/shared/DocsPageAsideHost.tsx +89 -0
  108. package/src/shared/DocsPageShell.tsx +124 -0
  109. package/src/shared/DocsSearchCommand.tsx +99 -0
  110. package/src/shared/DocsSidebarNav.tsx +66 -0
  111. package/src/shared/PropsTable.module.scss +68 -0
  112. package/src/shared/PropsTable.module.scss.d.ts +2 -0
  113. package/src/shared/PropsTable.tsx +76 -0
  114. package/src/shared/VariantPreviewCard.module.scss +114 -0
  115. package/src/shared/VariantPreviewCard.module.scss.d.ts +2 -0
  116. package/src/shared/VariantPreviewCard.tsx +137 -0
  117. package/src/shared/docs-data/index.ts +32 -0
  118. package/src/shared/docs-data/mcp-configs.ts +72 -0
  119. package/src/shared/docs-data/palettes.ts +75 -0
  120. package/src/shared/docs-data/setup-examples.ts +55 -0
  121. package/src/shared/docs-layout.scss +28 -0
  122. package/src/shared/docs-layout.scss.d.ts +2 -0
  123. package/src/shared/index.ts +34 -0
  124. package/src/shared/types.ts +53 -0
  125. package/src/style-utils.ts +414 -0
  126. package/src/styles/globals.css +278 -0
  127. package/src/types/a11y.ts +197 -0
  128. package/src/utils/a11y-fixes.ts +509 -0
  129. package/src/utils/actionExport.ts +372 -0
  130. package/src/utils/colorSchemes.ts +201 -0
  131. package/src/utils/contrast.ts +246 -0
  132. package/src/utils/detectRelationships.ts +256 -0
  133. package/src/webmcp/__tests__/analytics.test.ts +108 -0
  134. package/src/webmcp/analytics.ts +165 -0
  135. package/src/webmcp/index.ts +3 -0
  136. package/src/webmcp/posthog-bridge.ts +39 -0
  137. package/src/webmcp/runtime-tools.ts +152 -0
  138. package/src/webmcp/scan-utils.ts +135 -0
  139. package/src/webmcp/use-tool-analytics.ts +69 -0
  140. package/src/webmcp/viewer-state.ts +45 -0
  141. package/tsconfig.json +20 -0
@@ -0,0 +1,525 @@
1
+ import { useState, useCallback } from "react";
2
+ import { useForm, useFieldArray, Controller } from "react-hook-form";
3
+ import type { Fragment, FragmentUsage, FragmentMeta } from '@fragments-sdk/core';
4
+ import { Box, Text, Button, Stack } from "@fragments-sdk/ui";
5
+ import { ChevronDownIcon } from "./Icons.js";
6
+
7
+ interface FragmentEditorProps {
8
+ /** Component name */
9
+ componentName: string;
10
+ /** Initial fragment data (if exists) */
11
+ fragment?: Fragment;
12
+ /** Called when the user saves changes */
13
+ onSave: (fragment: Fragment) => Promise<void>;
14
+ /** Whether save is in progress */
15
+ saving?: boolean;
16
+ }
17
+
18
+ interface FormData {
19
+ name: string;
20
+ description: string;
21
+ usage: {
22
+ when: string[];
23
+ doNot: Array<{ text: string; instead?: string }>;
24
+ };
25
+ accessibility: {
26
+ role: string;
27
+ requirements: string[];
28
+ };
29
+ related: {
30
+ similar: string[];
31
+ composedWith: string[];
32
+ usedIn: string[];
33
+ };
34
+ meta: {
35
+ owner: string;
36
+ status: "draft" | "experimental" | "beta" | "stable" | "deprecated";
37
+ since: string;
38
+ tags: string[];
39
+ };
40
+ }
41
+
42
+ const inputStyle: React.CSSProperties = {
43
+ width: '100%',
44
+ padding: '6px 12px',
45
+ fontSize: '14px',
46
+ background: 'var(--bg-elevated)',
47
+ border: '1px solid var(--border)',
48
+ borderRadius: '8px',
49
+ outline: 'none',
50
+ color: 'var(--text-primary)',
51
+ boxSizing: 'border-box',
52
+ };
53
+
54
+ export function FragmentEditor({
55
+ componentName,
56
+ fragment,
57
+ onSave,
58
+ saving = false,
59
+ }: FragmentEditorProps) {
60
+ const [expandedSections, setExpandedSections] = useState<Set<string>>(
61
+ new Set(["usage", "meta"])
62
+ );
63
+
64
+ const toggleSection = (section: string) => {
65
+ setExpandedSections((prev) => {
66
+ const next = new Set(prev);
67
+ if (next.has(section)) {
68
+ next.delete(section);
69
+ } else {
70
+ next.add(section);
71
+ }
72
+ return next;
73
+ });
74
+ };
75
+
76
+ const defaultValues: FormData = {
77
+ name: fragment?.name || componentName,
78
+ description: fragment?.description || "",
79
+ usage: {
80
+ when: fragment?.usage?.when || [],
81
+ doNot:
82
+ fragment?.usage?.doNot?.map((item) =>
83
+ typeof item === "string" ? { text: item } : item
84
+ ) || [],
85
+ },
86
+ accessibility: {
87
+ role: fragment?.accessibility?.role || "",
88
+ requirements: fragment?.accessibility?.requirements || [],
89
+ },
90
+ related: {
91
+ similar: fragment?.related?.similar || [],
92
+ composedWith: fragment?.related?.composedWith || [],
93
+ usedIn: fragment?.related?.usedIn || [],
94
+ },
95
+ meta: {
96
+ owner: fragment?.meta?.owner || "",
97
+ status: fragment?.meta?.status || "stable",
98
+ since: fragment?.meta?.since || "",
99
+ tags: fragment?.meta?.tags || [],
100
+ },
101
+ };
102
+
103
+ const {
104
+ register,
105
+ control,
106
+ handleSubmit,
107
+ formState: { isDirty },
108
+ } = useForm<FormData>({ defaultValues });
109
+
110
+ const {
111
+ fields: whenFields,
112
+ append: appendWhen,
113
+ remove: removeWhen,
114
+ } = useFieldArray({ control, name: "usage.when" as const });
115
+
116
+ const {
117
+ fields: doNotFields,
118
+ append: appendDoNot,
119
+ remove: removeDoNot,
120
+ } = useFieldArray({ control, name: "usage.doNot" });
121
+
122
+ const {
123
+ fields: requirementsFields,
124
+ append: appendRequirement,
125
+ remove: removeRequirement,
126
+ } = useFieldArray({ control, name: "accessibility.requirements" as const });
127
+
128
+ const onSubmit = useCallback(
129
+ async (data: FormData) => {
130
+ const fragment: Fragment = {
131
+ $schema: "https://fragments.dev/schema/v1.json",
132
+ name: data.name,
133
+ description: data.description || undefined,
134
+ usage: {
135
+ when: data.usage.when.filter(Boolean),
136
+ doNot: data.usage.doNot.filter((d) => d.text),
137
+ },
138
+ accessibility:
139
+ data.accessibility.role || data.accessibility.requirements.length > 0
140
+ ? {
141
+ role: data.accessibility.role || undefined,
142
+ requirements: data.accessibility.requirements.filter(Boolean),
143
+ }
144
+ : undefined,
145
+ related:
146
+ data.related.similar.length > 0 ||
147
+ data.related.composedWith.length > 0 ||
148
+ data.related.usedIn.length > 0
149
+ ? {
150
+ similar: data.related.similar.filter(Boolean),
151
+ composedWith: data.related.composedWith.filter(Boolean),
152
+ usedIn: data.related.usedIn.filter(Boolean),
153
+ }
154
+ : undefined,
155
+ meta: {
156
+ status: data.meta.status,
157
+ owner: data.meta.owner || undefined,
158
+ since: data.meta.since || undefined,
159
+ tags: data.meta.tags.filter(Boolean),
160
+ },
161
+ };
162
+
163
+ await onSave(fragment);
164
+ },
165
+ [onSave]
166
+ );
167
+
168
+ return (
169
+ <form
170
+ onSubmit={handleSubmit(onSubmit)}
171
+ style={{ height: '100%', display: 'flex', flexDirection: 'column', background: 'var(--bg-primary)' }}
172
+ >
173
+ {/* Header */}
174
+ <Box paddingX="md" paddingY="sm" borderBottom background="secondary">
175
+ <Text as="h3" size="sm" weight="semibold" style={{ margin: 0 }}>Fragment Editor</Text>
176
+ <Text size="xs" color="secondary" style={{ marginTop: '2px' }}>
177
+ Enrich {componentName} with metadata
178
+ </Text>
179
+ </Box>
180
+
181
+ {/* Scrollable content */}
182
+ <Box overflow="auto" style={{ flex: 1 }}>
183
+ {/* Basic Info */}
184
+ <Box padding="md" borderBottom>
185
+ <Text as="label" size="xs" weight="medium" color="secondary" style={{ display: 'block', marginBottom: '6px' }}>
186
+ Description
187
+ </Text>
188
+ <textarea
189
+ {...register("description")}
190
+ rows={3}
191
+ style={{
192
+ ...inputStyle,
193
+ resize: 'none',
194
+ }}
195
+ placeholder="Brief description of the component's purpose..."
196
+ />
197
+ </Box>
198
+
199
+ {/* Usage Section */}
200
+ <Section
201
+ title="Usage Guidelines"
202
+ expanded={expandedSections.has("usage")}
203
+ onToggle={() => toggleSection("usage")}
204
+ >
205
+ {/* When to Use */}
206
+ <div style={{ marginBottom: '16px' }}>
207
+ <Text as="label" size="xs" weight="medium" color="secondary" style={{ display: 'block', marginBottom: '8px' }}>
208
+ When to Use
209
+ </Text>
210
+ <Stack gap="sm">
211
+ {whenFields.map((field, index) => (
212
+ <Stack key={field.id} direction="row" gap="sm">
213
+ <input
214
+ {...register(`usage.when.${index}` as const)}
215
+ style={{ ...inputStyle, flex: 1 }}
216
+ placeholder="Scenario..."
217
+ />
218
+ <Button
219
+ type="button"
220
+ variant="ghost"
221
+ size="sm"
222
+ onClick={() => removeWhen(index)}
223
+ >
224
+ &times;
225
+ </Button>
226
+ </Stack>
227
+ ))}
228
+ <Button
229
+ type="button"
230
+ variant="ghost"
231
+ size="sm"
232
+ onClick={() => appendWhen("")}
233
+ style={{ padding: 0, alignSelf: 'flex-start' }}
234
+ >
235
+ + Add scenario
236
+ </Button>
237
+ </Stack>
238
+ </div>
239
+
240
+ {/* Do Not */}
241
+ <div>
242
+ <Text as="label" size="xs" weight="medium" color="secondary" style={{ display: 'block', marginBottom: '8px' }}>
243
+ Do Not
244
+ </Text>
245
+ <Stack gap="sm">
246
+ {doNotFields.map((field, index) => (
247
+ <Stack key={field.id} direction="row" gap="sm">
248
+ <input
249
+ {...register(`usage.doNot.${index}.text` as const)}
250
+ style={{ ...inputStyle, flex: 1 }}
251
+ placeholder="What not to do..."
252
+ />
253
+ <input
254
+ {...register(`usage.doNot.${index}.instead` as const)}
255
+ style={{ ...inputStyle, width: '128px' }}
256
+ placeholder="Instead..."
257
+ />
258
+ <Button
259
+ type="button"
260
+ variant="ghost"
261
+ size="sm"
262
+ onClick={() => removeDoNot(index)}
263
+ >
264
+ &times;
265
+ </Button>
266
+ </Stack>
267
+ ))}
268
+ <Button
269
+ type="button"
270
+ variant="ghost"
271
+ size="sm"
272
+ onClick={() => appendDoNot({ text: "", instead: "" })}
273
+ style={{ padding: 0, alignSelf: 'flex-start' }}
274
+ >
275
+ + Add anti-pattern
276
+ </Button>
277
+ </Stack>
278
+ </div>
279
+ </Section>
280
+
281
+ {/* Accessibility Section */}
282
+ <Section
283
+ title="Accessibility"
284
+ expanded={expandedSections.has("accessibility")}
285
+ onToggle={() => toggleSection("accessibility")}
286
+ >
287
+ <div style={{ marginBottom: '16px' }}>
288
+ <Text as="label" size="xs" weight="medium" color="secondary" style={{ display: 'block', marginBottom: '6px' }}>
289
+ ARIA Role
290
+ </Text>
291
+ <input
292
+ {...register("accessibility.role")}
293
+ style={inputStyle}
294
+ placeholder="button, dialog, etc."
295
+ />
296
+ </div>
297
+
298
+ <div>
299
+ <Text as="label" size="xs" weight="medium" color="secondary" style={{ display: 'block', marginBottom: '8px' }}>
300
+ Requirements
301
+ </Text>
302
+ <Stack gap="sm">
303
+ {requirementsFields.map((field, index) => (
304
+ <Stack key={field.id} direction="row" gap="sm">
305
+ <input
306
+ {...register(
307
+ `accessibility.requirements.${index}` as const
308
+ )}
309
+ style={{ ...inputStyle, flex: 1 }}
310
+ placeholder="Requirement..."
311
+ />
312
+ <Button
313
+ type="button"
314
+ variant="ghost"
315
+ size="sm"
316
+ onClick={() => removeRequirement(index)}
317
+ >
318
+ &times;
319
+ </Button>
320
+ </Stack>
321
+ ))}
322
+ <Button
323
+ type="button"
324
+ variant="ghost"
325
+ size="sm"
326
+ onClick={() => appendRequirement("")}
327
+ style={{ padding: 0, alignSelf: 'flex-start' }}
328
+ >
329
+ + Add requirement
330
+ </Button>
331
+ </Stack>
332
+ </div>
333
+ </Section>
334
+
335
+ {/* Related Components Section */}
336
+ <Section
337
+ title="Related Components"
338
+ expanded={expandedSections.has("related")}
339
+ onToggle={() => toggleSection("related")}
340
+ >
341
+ <RelatedField
342
+ label="Similar"
343
+ description="Alternative components"
344
+ name="related.similar"
345
+ control={control}
346
+ register={register}
347
+ />
348
+ <RelatedField
349
+ label="Composed With"
350
+ description="Often used together"
351
+ name="related.composedWith"
352
+ control={control}
353
+ register={register}
354
+ />
355
+ <RelatedField
356
+ label="Used In"
357
+ description="Parent components"
358
+ name="related.usedIn"
359
+ control={control}
360
+ register={register}
361
+ />
362
+ </Section>
363
+
364
+ {/* Meta Section */}
365
+ <Section
366
+ title="Metadata"
367
+ expanded={expandedSections.has("meta")}
368
+ onToggle={() => toggleSection("meta")}
369
+ >
370
+ <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '16px', marginBottom: '16px' }}>
371
+ <div>
372
+ <Text as="label" size="xs" weight="medium" color="secondary" style={{ display: 'block', marginBottom: '6px' }}>
373
+ Status
374
+ </Text>
375
+ <select
376
+ {...register("meta.status")}
377
+ style={inputStyle}
378
+ >
379
+ <option value="draft">Draft</option>
380
+ <option value="experimental">Experimental</option>
381
+ <option value="beta">Beta</option>
382
+ <option value="stable">Stable</option>
383
+ <option value="deprecated">Deprecated</option>
384
+ </select>
385
+ </div>
386
+ <div>
387
+ <Text as="label" size="xs" weight="medium" color="secondary" style={{ display: 'block', marginBottom: '6px' }}>
388
+ Since Version
389
+ </Text>
390
+ <input
391
+ {...register("meta.since")}
392
+ style={inputStyle}
393
+ placeholder="1.0.0"
394
+ />
395
+ </div>
396
+ </div>
397
+ <div style={{ marginBottom: '16px' }}>
398
+ <Text as="label" size="xs" weight="medium" color="secondary" style={{ display: 'block', marginBottom: '6px' }}>
399
+ Owner
400
+ </Text>
401
+ <input
402
+ {...register("meta.owner")}
403
+ style={inputStyle}
404
+ placeholder="@team-name or email"
405
+ />
406
+ </div>
407
+ </Section>
408
+ </Box>
409
+
410
+ {/* Footer with save button */}
411
+ <Box paddingX="md" paddingY="sm" borderTop background="secondary">
412
+ <Button
413
+ type="submit"
414
+ variant="primary"
415
+ fullWidth
416
+ disabled={!isDirty || saving}
417
+ >
418
+ {saving ? "Saving..." : "Save Fragment"}
419
+ </Button>
420
+ </Box>
421
+ </form>
422
+ );
423
+ }
424
+
425
+ interface SectionProps {
426
+ title: string;
427
+ expanded: boolean;
428
+ onToggle: () => void;
429
+ children: React.ReactNode;
430
+ }
431
+
432
+ function Section({ title, expanded, onToggle, children }: SectionProps) {
433
+ const [hovered, setHovered] = useState(false);
434
+
435
+ return (
436
+ <Box borderBottom>
437
+ <button
438
+ type="button"
439
+ onClick={onToggle}
440
+ onMouseEnter={() => setHovered(true)}
441
+ onMouseLeave={() => setHovered(false)}
442
+ style={{
443
+ width: '100%',
444
+ padding: '12px 16px',
445
+ display: 'flex',
446
+ alignItems: 'center',
447
+ justifyContent: 'space-between',
448
+ background: hovered ? 'var(--bg-hover)' : 'var(--bg-secondary)',
449
+ transition: 'background-color 150ms',
450
+ border: 'none',
451
+ cursor: 'pointer',
452
+ }}
453
+ >
454
+ <Text size="xs" weight="semibold" style={{ textTransform: 'uppercase', letterSpacing: '0.05em' }}>
455
+ {title}
456
+ </Text>
457
+ <ChevronDownIcon
458
+ style={{
459
+ width: '16px',
460
+ height: '16px',
461
+ color: 'var(--text-tertiary)',
462
+ transition: 'transform 150ms',
463
+ transform: expanded ? 'rotate(0deg)' : 'rotate(-90deg)',
464
+ }}
465
+ />
466
+ </button>
467
+ {expanded && <Box padding="md">{children}</Box>}
468
+ </Box>
469
+ );
470
+ }
471
+
472
+ interface RelatedFieldProps {
473
+ label: string;
474
+ description: string;
475
+ name: string;
476
+ control: any;
477
+ register: any;
478
+ }
479
+
480
+ function RelatedField({
481
+ label,
482
+ description,
483
+ name,
484
+ control,
485
+ register,
486
+ }: RelatedFieldProps) {
487
+ const { fields, append, remove } = useFieldArray({ control, name });
488
+
489
+ return (
490
+ <div style={{ marginBottom: '16px' }}>
491
+ <Text as="label" size="xs" weight="medium" color="secondary" style={{ display: 'block', marginBottom: '2px' }}>
492
+ {label}
493
+ </Text>
494
+ <Text size="xs" color="tertiary" style={{ marginBottom: '8px', marginTop: 0, fontSize: '10px' }}>{description}</Text>
495
+ <Stack gap="sm">
496
+ {fields.map((field, index) => (
497
+ <Stack key={field.id} direction="row" gap="sm">
498
+ <input
499
+ {...register(`${name}.${index}` as const)}
500
+ style={{ ...inputStyle, flex: 1 }}
501
+ placeholder="ComponentName"
502
+ />
503
+ <Button
504
+ type="button"
505
+ variant="ghost"
506
+ size="sm"
507
+ onClick={() => remove(index)}
508
+ >
509
+ &times;
510
+ </Button>
511
+ </Stack>
512
+ ))}
513
+ <Button
514
+ type="button"
515
+ variant="ghost"
516
+ size="sm"
517
+ onClick={() => append("")}
518
+ style={{ padding: 0, alignSelf: 'flex-start' }}
519
+ >
520
+ + Add component
521
+ </Button>
522
+ </Stack>
523
+ </div>
524
+ );
525
+ }
@@ -0,0 +1,61 @@
1
+ import type { ReactNode } from "react";
2
+ import {
3
+ PreviewVariantRuntime,
4
+ type FragmentVariant,
5
+ } from '@fragments-sdk/core';
6
+
7
+ interface FragmentRendererProps {
8
+ /** The variant to render */
9
+ variant: FragmentVariant;
10
+ /** Children render function - receives rendered content */
11
+ children: (content: ReactNode | null, isLoading: boolean, error: Error | null) => ReactNode;
12
+ }
13
+
14
+ /**
15
+ * Component that handles async loader execution before rendering a fragment variant.
16
+ *
17
+ * If the variant has loaders:
18
+ * 1. Shows loading state while loaders execute
19
+ * 2. Merges all loaded data
20
+ * 3. Passes loaded data to render function
21
+ *
22
+ * If no loaders, renders immediately.
23
+ */
24
+ export function FragmentRenderer({ variant, children }: FragmentRendererProps) {
25
+ return (
26
+ <PreviewVariantRuntime variant={variant}>
27
+ {({ content, isLoading, error }) => children(content, isLoading, error)}
28
+ </PreviewVariantRuntime>
29
+ );
30
+ }
31
+
32
+ /**
33
+ * Loading indicator for fragment variants with loaders
34
+ */
35
+ export function LoaderIndicator() {
36
+ return (
37
+ <div style={{ display: 'flex', alignItems: 'center', gap: '8px', color: 'var(--text-secondary)', fontSize: '14px' }}>
38
+ <svg
39
+ style={{ animation: 'spin 1s linear infinite', width: '16px', height: '16px' }}
40
+ xmlns="http://www.w3.org/2000/svg"
41
+ fill="none"
42
+ viewBox="0 0 24 24"
43
+ >
44
+ <circle
45
+ style={{ opacity: 0.25 }}
46
+ cx="12"
47
+ cy="12"
48
+ r="10"
49
+ stroke="currentColor"
50
+ strokeWidth="4"
51
+ />
52
+ <path
53
+ style={{ opacity: 0.75 }}
54
+ fill="currentColor"
55
+ d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
56
+ />
57
+ </svg>
58
+ <span>Running loaders...</span>
59
+ </div>
60
+ );
61
+ }
@@ -0,0 +1,24 @@
1
+ import type { RefObject } from "react";
2
+ import { Header, Input } from "@fragments-sdk/ui";
3
+
4
+ interface HeaderSearchProps {
5
+ value: string;
6
+ onChange: (value: string) => void;
7
+ inputRef: RefObject<HTMLInputElement>;
8
+ }
9
+
10
+ export function HeaderSearch({ value, onChange, inputRef }: HeaderSearchProps) {
11
+ return (
12
+ <Header.Search expandable>
13
+ <Input
14
+ ref={inputRef}
15
+ value={value}
16
+ onChange={onChange}
17
+ placeholder="Search components"
18
+ aria-label="Search components"
19
+ size="sm"
20
+ style={{ width: "240px" }}
21
+ />
22
+ </Header.Search>
23
+ );
24
+ }