@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,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ActionCapture component - captures DOM events for action logging.
|
|
3
|
+
*
|
|
4
|
+
* Uses event delegation to capture interactions at the DOM level,
|
|
5
|
+
* which works even when component render functions don't pass callbacks.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { useRef, useEffect, type ReactNode } from 'react';
|
|
9
|
+
|
|
10
|
+
interface ActionCaptureProps {
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
onAction: (name: string, args: unknown[]) => void;
|
|
13
|
+
enabled?: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Events to capture
|
|
17
|
+
const CAPTURE_EVENTS = [
|
|
18
|
+
'click',
|
|
19
|
+
'dblclick',
|
|
20
|
+
'change',
|
|
21
|
+
'input',
|
|
22
|
+
'submit',
|
|
23
|
+
'focus',
|
|
24
|
+
'blur',
|
|
25
|
+
'keydown',
|
|
26
|
+
'keyup',
|
|
27
|
+
] as const;
|
|
28
|
+
|
|
29
|
+
// Map event types to action names
|
|
30
|
+
function getActionName(event: Event): string {
|
|
31
|
+
const type = event.type;
|
|
32
|
+
// Convert to React-style naming
|
|
33
|
+
switch (type) {
|
|
34
|
+
case 'click': return 'onClick';
|
|
35
|
+
case 'dblclick': return 'onDoubleClick';
|
|
36
|
+
case 'change': return 'onChange';
|
|
37
|
+
case 'input': return 'onInput';
|
|
38
|
+
case 'submit': return 'onSubmit';
|
|
39
|
+
case 'focus': return 'onFocus';
|
|
40
|
+
case 'blur': return 'onBlur';
|
|
41
|
+
case 'keydown': return 'onKeyDown';
|
|
42
|
+
case 'keyup': return 'onKeyUp';
|
|
43
|
+
default: return `on${type.charAt(0).toUpperCase() + type.slice(1)}`;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Extract useful information about the target element
|
|
48
|
+
function getElementInfo(element: Element): Record<string, unknown> {
|
|
49
|
+
const tag = element.tagName.toLowerCase();
|
|
50
|
+
const info: Record<string, unknown> = { element: tag };
|
|
51
|
+
|
|
52
|
+
// Get identifying attributes
|
|
53
|
+
if (element.id) info.id = element.id;
|
|
54
|
+
if (element.className && typeof element.className === 'string') {
|
|
55
|
+
const classes = element.className.trim().split(/\s+/).slice(0, 3);
|
|
56
|
+
if (classes.length > 0 && classes[0]) info.className = classes.join(' ');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Get accessibility info
|
|
60
|
+
const role = element.getAttribute('role');
|
|
61
|
+
if (role) info.role = role;
|
|
62
|
+
|
|
63
|
+
const ariaLabel = element.getAttribute('aria-label');
|
|
64
|
+
if (ariaLabel) info['aria-label'] = ariaLabel;
|
|
65
|
+
|
|
66
|
+
// Get text content (truncated)
|
|
67
|
+
const text = element.textContent?.trim();
|
|
68
|
+
if (text && text.length > 0 && text.length <= 50) {
|
|
69
|
+
info.text = text;
|
|
70
|
+
} else if (text && text.length > 50) {
|
|
71
|
+
info.text = text.slice(0, 47) + '...';
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Get input-specific info
|
|
75
|
+
if (element instanceof HTMLInputElement) {
|
|
76
|
+
info.type = element.type;
|
|
77
|
+
info.name = element.name || undefined;
|
|
78
|
+
if (element.type === 'checkbox' || element.type === 'radio') {
|
|
79
|
+
info.checked = element.checked;
|
|
80
|
+
} else if (element.type !== 'password') {
|
|
81
|
+
info.value = element.value;
|
|
82
|
+
}
|
|
83
|
+
} else if (element instanceof HTMLSelectElement) {
|
|
84
|
+
info.name = element.name || undefined;
|
|
85
|
+
info.value = element.value;
|
|
86
|
+
info.selectedText = element.options[element.selectedIndex]?.text;
|
|
87
|
+
} else if (element instanceof HTMLTextAreaElement) {
|
|
88
|
+
info.name = element.name || undefined;
|
|
89
|
+
info.value = element.value.length > 100 ? element.value.slice(0, 97) + '...' : element.value;
|
|
90
|
+
} else if (element instanceof HTMLButtonElement) {
|
|
91
|
+
info.type = element.type;
|
|
92
|
+
if (element.name) info.name = element.name;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Clean up undefined values
|
|
96
|
+
return Object.fromEntries(Object.entries(info).filter(([, v]) => v !== undefined));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Extract keyboard event info
|
|
100
|
+
function getKeyboardInfo(event: KeyboardEvent): Record<string, unknown> {
|
|
101
|
+
return {
|
|
102
|
+
key: event.key,
|
|
103
|
+
code: event.code,
|
|
104
|
+
...(event.ctrlKey && { ctrlKey: true }),
|
|
105
|
+
...(event.shiftKey && { shiftKey: true }),
|
|
106
|
+
...(event.altKey && { altKey: true }),
|
|
107
|
+
...(event.metaKey && { metaKey: true }),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function ActionCapture({ children, onAction, enabled = true }: ActionCaptureProps) {
|
|
112
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
113
|
+
|
|
114
|
+
useEffect(() => {
|
|
115
|
+
if (!enabled) return;
|
|
116
|
+
|
|
117
|
+
const container = containerRef.current;
|
|
118
|
+
if (!container) return;
|
|
119
|
+
|
|
120
|
+
const handleEvent = (event: Event) => {
|
|
121
|
+
const target = event.target;
|
|
122
|
+
if (!(target instanceof Element)) return;
|
|
123
|
+
|
|
124
|
+
// Skip if the event is from the container itself
|
|
125
|
+
if (target === container) return;
|
|
126
|
+
|
|
127
|
+
// Get action name
|
|
128
|
+
const actionName = getActionName(event);
|
|
129
|
+
|
|
130
|
+
// Build args array with useful info
|
|
131
|
+
const args: unknown[] = [];
|
|
132
|
+
|
|
133
|
+
// Add element info
|
|
134
|
+
const elementInfo = getElementInfo(target);
|
|
135
|
+
args.push(elementInfo);
|
|
136
|
+
|
|
137
|
+
// Add keyboard-specific info for key events
|
|
138
|
+
if (event instanceof KeyboardEvent) {
|
|
139
|
+
args.push(getKeyboardInfo(event));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Add mouse position for click events
|
|
143
|
+
if (event instanceof MouseEvent && (event.type === 'click' || event.type === 'dblclick')) {
|
|
144
|
+
args.push({
|
|
145
|
+
clientX: event.clientX,
|
|
146
|
+
clientY: event.clientY,
|
|
147
|
+
button: event.button,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
onAction(actionName, args);
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
// Attach event listeners with capture phase
|
|
155
|
+
// This ensures we catch events even if stopPropagation is called
|
|
156
|
+
CAPTURE_EVENTS.forEach(eventType => {
|
|
157
|
+
container.addEventListener(eventType, handleEvent, { capture: true });
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
return () => {
|
|
161
|
+
CAPTURE_EVENTS.forEach(eventType => {
|
|
162
|
+
container.removeEventListener(eventType, handleEvent, { capture: true });
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
}, [onAction, enabled]);
|
|
166
|
+
|
|
167
|
+
return (
|
|
168
|
+
<div ref={containerRef} style={{ display: 'contents' }}>
|
|
169
|
+
{children}
|
|
170
|
+
</div>
|
|
171
|
+
);
|
|
172
|
+
}
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Actions Panel - Storybook-style event logging
|
|
3
|
+
*
|
|
4
|
+
* Displays a log of callback invocations (onClick, onChange, etc.)
|
|
5
|
+
* with expandable argument details and timestamps.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { useState, useMemo } from "react";
|
|
9
|
+
import type { ActionLog } from "../hooks/useActions.js";
|
|
10
|
+
import { formatActionArg } from "../hooks/useActions.js";
|
|
11
|
+
import { Button, Stack, Text, Badge, Input, Menu, Separator, Box } from "@fragments-sdk/ui";
|
|
12
|
+
import {
|
|
13
|
+
TrashIcon,
|
|
14
|
+
ChevronDownIcon,
|
|
15
|
+
ChevronRightIcon,
|
|
16
|
+
PlayIcon,
|
|
17
|
+
ExportIcon,
|
|
18
|
+
DownloadIcon,
|
|
19
|
+
CopyIcon,
|
|
20
|
+
CheckIcon,
|
|
21
|
+
} from "./Icons.js";
|
|
22
|
+
import {
|
|
23
|
+
exportActions,
|
|
24
|
+
copyToClipboard,
|
|
25
|
+
downloadAsFile,
|
|
26
|
+
getFileExtension,
|
|
27
|
+
type ExportFormat,
|
|
28
|
+
} from "../utils/actionExport.js";
|
|
29
|
+
|
|
30
|
+
interface ActionsPanelProps {
|
|
31
|
+
/** List of action logs */
|
|
32
|
+
logs: ActionLog[];
|
|
33
|
+
/** Callback to clear all logs */
|
|
34
|
+
onClear: () => void;
|
|
35
|
+
/** Component name for export context */
|
|
36
|
+
componentName?: string;
|
|
37
|
+
/** Variant name for export context */
|
|
38
|
+
variantName?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function ActionsPanel({ logs, onClear, componentName = 'Component', variantName = 'Default' }: ActionsPanelProps) {
|
|
42
|
+
const [expandedLogs, setExpandedLogs] = useState<Set<string>>(new Set());
|
|
43
|
+
const [filter, setFilter] = useState("");
|
|
44
|
+
const [copyFeedback, setCopyFeedback] = useState<string | null>(null);
|
|
45
|
+
|
|
46
|
+
const filteredLogs = useMemo(() => {
|
|
47
|
+
if (!filter) return logs;
|
|
48
|
+
const lowerFilter = filter.toLowerCase();
|
|
49
|
+
return logs.filter((log) => log.name.toLowerCase().includes(lowerFilter));
|
|
50
|
+
}, [logs, filter]);
|
|
51
|
+
|
|
52
|
+
const toggleExpanded = (id: string) => {
|
|
53
|
+
setExpandedLogs((prev) => {
|
|
54
|
+
const next = new Set(prev);
|
|
55
|
+
if (next.has(id)) {
|
|
56
|
+
next.delete(id);
|
|
57
|
+
} else {
|
|
58
|
+
next.add(id);
|
|
59
|
+
}
|
|
60
|
+
return next;
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const formatTime = (timestamp: number) => {
|
|
65
|
+
const date = new Date(timestamp);
|
|
66
|
+
return date.toLocaleTimeString("en-US", {
|
|
67
|
+
hour12: false,
|
|
68
|
+
hour: "2-digit",
|
|
69
|
+
minute: "2-digit",
|
|
70
|
+
second: "2-digit",
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const handleExport = async (format: ExportFormat, action: 'copy' | 'download') => {
|
|
75
|
+
const content = exportActions(logs, format, {
|
|
76
|
+
componentName,
|
|
77
|
+
variantName,
|
|
78
|
+
includeComments: true,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
if (action === 'copy') {
|
|
82
|
+
const success = await copyToClipboard(content);
|
|
83
|
+
if (success) {
|
|
84
|
+
setCopyFeedback(format);
|
|
85
|
+
setTimeout(() => setCopyFeedback(null), 2000);
|
|
86
|
+
}
|
|
87
|
+
} else {
|
|
88
|
+
const filename = `${componentName}-${variantName}-actions${getFileExtension(format)}`;
|
|
89
|
+
downloadAsFile(content, filename.toLowerCase().replace(/\s+/g, '-'));
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
// No logs state
|
|
94
|
+
if (logs.length === 0) {
|
|
95
|
+
return (
|
|
96
|
+
<Stack style={{ height: '100%' }}>
|
|
97
|
+
<Box padding="md" borderBottom>
|
|
98
|
+
<Stack direction="row" align="center" gap="sm">
|
|
99
|
+
<PlayIcon style={{ width: 16, height: 16 }} />
|
|
100
|
+
<Text weight="medium">Actions</Text>
|
|
101
|
+
</Stack>
|
|
102
|
+
</Box>
|
|
103
|
+
<Stack align="center" justify="center" style={{ flex: 1, padding: '32px', textAlign: 'center' }}>
|
|
104
|
+
<div style={{ maxWidth: '28rem' }}>
|
|
105
|
+
<div style={{ width: '48px', height: '48px', borderRadius: '9999px', background: 'var(--bg-secondary)', display: 'flex', alignItems: 'center', justifyContent: 'center', margin: '0 auto 16px' }}>
|
|
106
|
+
<PlayIcon style={{ width: 24, height: 24, color: 'var(--text-tertiary)' }} />
|
|
107
|
+
</div>
|
|
108
|
+
<Text weight="medium" color="secondary" style={{ marginBottom: '8px' }}>
|
|
109
|
+
No actions logged yet
|
|
110
|
+
</Text>
|
|
111
|
+
<Text size="sm" color="tertiary">
|
|
112
|
+
Interact with the component to see callback invocations here.
|
|
113
|
+
Actions like <Box as="code" padding="xs" background="secondary" rounded="sm" style={{ fontSize: '12px', display: 'inline' }}>onClick</Box>, <Box as="code" padding="xs" background="secondary" rounded="sm" style={{ fontSize: '12px', display: 'inline' }}>onChange</Box>, etc. will be logged automatically.
|
|
114
|
+
</Text>
|
|
115
|
+
</div>
|
|
116
|
+
</Stack>
|
|
117
|
+
</Stack>
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return (
|
|
122
|
+
<Stack style={{ height: '100%' }}>
|
|
123
|
+
{/* Header */}
|
|
124
|
+
<Box padding="sm" borderBottom>
|
|
125
|
+
<Stack direction="row" align="center" justify="between" gap="sm">
|
|
126
|
+
<Stack direction="row" align="center" gap="sm" style={{ flex: 1 }}>
|
|
127
|
+
<Stack direction="row" align="center" gap="sm">
|
|
128
|
+
<PlayIcon style={{ width: 16, height: 16 }} />
|
|
129
|
+
<Text weight="medium" size="sm">Actions</Text>
|
|
130
|
+
</Stack>
|
|
131
|
+
<Badge size="sm">{logs.length}</Badge>
|
|
132
|
+
</Stack>
|
|
133
|
+
<Stack direction="row" align="center" gap="sm">
|
|
134
|
+
<Input
|
|
135
|
+
size="sm"
|
|
136
|
+
placeholder="Filter..."
|
|
137
|
+
value={filter}
|
|
138
|
+
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setFilter(e.target.value)}
|
|
139
|
+
style={{ width: '96px' }}
|
|
140
|
+
/>
|
|
141
|
+
|
|
142
|
+
{/* Export dropdown */}
|
|
143
|
+
<Menu>
|
|
144
|
+
<Menu.Trigger>
|
|
145
|
+
<Button variant="ghost" size="sm" title="Export actions">
|
|
146
|
+
<ExportIcon style={{ width: 16, height: 16 }} />
|
|
147
|
+
</Button>
|
|
148
|
+
</Menu.Trigger>
|
|
149
|
+
<Menu.Content>
|
|
150
|
+
<Box paddingX="sm" paddingY="xs">
|
|
151
|
+
<Text size="xs" weight="medium" color="tertiary" style={{ textTransform: 'uppercase', letterSpacing: '0.05em' }}>
|
|
152
|
+
Export as
|
|
153
|
+
</Text>
|
|
154
|
+
</Box>
|
|
155
|
+
|
|
156
|
+
{/* JSON */}
|
|
157
|
+
<Stack direction="row" align="center" justify="between" style={{ padding: '6px 12px' }}>
|
|
158
|
+
<Text size="sm" color="secondary">JSON</Text>
|
|
159
|
+
<Stack direction="row" gap="xs">
|
|
160
|
+
<Menu.Item onSelect={() => handleExport('json', 'copy')}>
|
|
161
|
+
{copyFeedback === 'json' ? <CheckIcon style={{ width: 14, height: 14, color: '#22c55e' }} /> : <CopyIcon style={{ width: 14, height: 14 }} />}
|
|
162
|
+
</Menu.Item>
|
|
163
|
+
<Menu.Item onSelect={() => handleExport('json', 'download')}>
|
|
164
|
+
<DownloadIcon style={{ width: 14, height: 14 }} />
|
|
165
|
+
</Menu.Item>
|
|
166
|
+
</Stack>
|
|
167
|
+
</Stack>
|
|
168
|
+
|
|
169
|
+
{/* Jest */}
|
|
170
|
+
<Stack direction="row" align="center" justify="between" style={{ padding: '6px 12px' }}>
|
|
171
|
+
<Text size="sm" color="secondary">Jest Assertions</Text>
|
|
172
|
+
<Stack direction="row" gap="xs">
|
|
173
|
+
<Menu.Item onSelect={() => handleExport('jest', 'copy')}>
|
|
174
|
+
{copyFeedback === 'jest' ? <CheckIcon style={{ width: 14, height: 14, color: '#22c55e' }} /> : <CopyIcon style={{ width: 14, height: 14 }} />}
|
|
175
|
+
</Menu.Item>
|
|
176
|
+
<Menu.Item onSelect={() => handleExport('jest', 'download')}>
|
|
177
|
+
<DownloadIcon style={{ width: 14, height: 14 }} />
|
|
178
|
+
</Menu.Item>
|
|
179
|
+
</Stack>
|
|
180
|
+
</Stack>
|
|
181
|
+
|
|
182
|
+
{/* Playwright */}
|
|
183
|
+
<Stack direction="row" align="center" justify="between" style={{ padding: '6px 12px' }}>
|
|
184
|
+
<Text size="sm" color="secondary">Playwright Test</Text>
|
|
185
|
+
<Stack direction="row" gap="xs">
|
|
186
|
+
<Menu.Item onSelect={() => handleExport('playwright', 'copy')}>
|
|
187
|
+
{copyFeedback === 'playwright' ? <CheckIcon style={{ width: 14, height: 14, color: '#22c55e' }} /> : <CopyIcon style={{ width: 14, height: 14 }} />}
|
|
188
|
+
</Menu.Item>
|
|
189
|
+
<Menu.Item onSelect={() => handleExport('playwright', 'download')}>
|
|
190
|
+
<DownloadIcon style={{ width: 14, height: 14 }} />
|
|
191
|
+
</Menu.Item>
|
|
192
|
+
</Stack>
|
|
193
|
+
</Stack>
|
|
194
|
+
|
|
195
|
+
<Separator />
|
|
196
|
+
<Box paddingX="sm" paddingY="xs">
|
|
197
|
+
<Text size="xs" color="tertiary">
|
|
198
|
+
{logs.length} action{logs.length !== 1 ? 's' : ''} recorded
|
|
199
|
+
</Text>
|
|
200
|
+
</Box>
|
|
201
|
+
</Menu.Content>
|
|
202
|
+
</Menu>
|
|
203
|
+
|
|
204
|
+
<Button
|
|
205
|
+
onClick={onClear}
|
|
206
|
+
variant="ghost"
|
|
207
|
+
size="sm"
|
|
208
|
+
title="Clear all actions"
|
|
209
|
+
>
|
|
210
|
+
<TrashIcon style={{ width: 16, height: 16 }} />
|
|
211
|
+
</Button>
|
|
212
|
+
</Stack>
|
|
213
|
+
</Stack>
|
|
214
|
+
</Box>
|
|
215
|
+
|
|
216
|
+
{/* Log list */}
|
|
217
|
+
<Box overflow="auto" style={{ flex: 1 }}>
|
|
218
|
+
{filteredLogs.length === 0 ? (
|
|
219
|
+
<Box padding="md" style={{ textAlign: 'center' }}>
|
|
220
|
+
<Text size="sm" color="tertiary">No actions match "{filter}"</Text>
|
|
221
|
+
</Box>
|
|
222
|
+
) : (
|
|
223
|
+
<div>
|
|
224
|
+
{filteredLogs.map((log, index) => (
|
|
225
|
+
<div key={log.id} style={{ borderBottom: index < filteredLogs.length - 1 ? '1px solid var(--border)' : undefined }}>
|
|
226
|
+
<ActionLogItem
|
|
227
|
+
log={log}
|
|
228
|
+
isExpanded={expandedLogs.has(log.id)}
|
|
229
|
+
onToggle={() => toggleExpanded(log.id)}
|
|
230
|
+
formatTime={formatTime}
|
|
231
|
+
/>
|
|
232
|
+
</div>
|
|
233
|
+
))}
|
|
234
|
+
</div>
|
|
235
|
+
)}
|
|
236
|
+
</Box>
|
|
237
|
+
</Stack>
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
interface ActionLogItemProps {
|
|
242
|
+
log: ActionLog;
|
|
243
|
+
isExpanded: boolean;
|
|
244
|
+
onToggle: () => void;
|
|
245
|
+
formatTime: (timestamp: number) => string;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function ActionLogItem({ log, isExpanded, onToggle, formatTime }: ActionLogItemProps) {
|
|
249
|
+
const [hovered, setHovered] = useState(false);
|
|
250
|
+
const hasArgs = log.args.length > 0;
|
|
251
|
+
const argsPreview = hasArgs
|
|
252
|
+
? log.args.map((arg) => formatActionArg(arg, 50)).join(", ")
|
|
253
|
+
: "";
|
|
254
|
+
|
|
255
|
+
return (
|
|
256
|
+
<div
|
|
257
|
+
style={{ background: hovered ? 'var(--bg-secondary)' : 'transparent', transition: 'background 0.15s' }}
|
|
258
|
+
onMouseEnter={() => setHovered(true)}
|
|
259
|
+
onMouseLeave={() => setHovered(false)}
|
|
260
|
+
>
|
|
261
|
+
<button
|
|
262
|
+
onClick={onToggle}
|
|
263
|
+
disabled={!hasArgs}
|
|
264
|
+
style={{
|
|
265
|
+
width: '100%',
|
|
266
|
+
padding: '8px 12px',
|
|
267
|
+
display: 'flex',
|
|
268
|
+
alignItems: 'flex-start',
|
|
269
|
+
gap: '8px',
|
|
270
|
+
textAlign: 'left',
|
|
271
|
+
cursor: hasArgs ? 'pointer' : 'default',
|
|
272
|
+
border: 'none',
|
|
273
|
+
background: 'transparent',
|
|
274
|
+
color: 'inherit',
|
|
275
|
+
}}
|
|
276
|
+
>
|
|
277
|
+
{/* Expand icon */}
|
|
278
|
+
<div style={{ flexShrink: 0, width: '16px', height: '16px', marginTop: '2px' }}>
|
|
279
|
+
{hasArgs ? (
|
|
280
|
+
isExpanded ? (
|
|
281
|
+
<ChevronDownIcon style={{ width: 16, height: 16, color: 'var(--text-tertiary)' }} />
|
|
282
|
+
) : (
|
|
283
|
+
<ChevronRightIcon style={{ width: 16, height: 16, color: 'var(--text-tertiary)' }} />
|
|
284
|
+
)
|
|
285
|
+
) : (
|
|
286
|
+
<div style={{ width: '16px', height: '16px' }} />
|
|
287
|
+
)}
|
|
288
|
+
</div>
|
|
289
|
+
|
|
290
|
+
{/* Action name */}
|
|
291
|
+
<div style={{ flex: 1, minWidth: 0 }}>
|
|
292
|
+
<Stack direction="row" align="center" gap="sm">
|
|
293
|
+
<Text font="mono" size="sm" style={{ color: 'var(--color-accent)' }}>
|
|
294
|
+
{log.name}
|
|
295
|
+
</Text>
|
|
296
|
+
{log.count > 1 && (
|
|
297
|
+
<Badge size="sm">x{log.count}</Badge>
|
|
298
|
+
)}
|
|
299
|
+
</Stack>
|
|
300
|
+
{!isExpanded && hasArgs && (
|
|
301
|
+
<Text size="xs" color="tertiary" font="mono" style={{ overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', marginTop: '2px' }}>
|
|
302
|
+
({argsPreview})
|
|
303
|
+
</Text>
|
|
304
|
+
)}
|
|
305
|
+
</div>
|
|
306
|
+
|
|
307
|
+
{/* Timestamp */}
|
|
308
|
+
<Text size="xs" color="tertiary" font="mono" style={{ flexShrink: 0 }}>
|
|
309
|
+
{formatTime(log.timestamp)}
|
|
310
|
+
</Text>
|
|
311
|
+
</button>
|
|
312
|
+
|
|
313
|
+
{/* Expanded args */}
|
|
314
|
+
{isExpanded && hasArgs && (
|
|
315
|
+
<div style={{ padding: '0 12px 12px 36px' }}>
|
|
316
|
+
<Box padding="sm" background="secondary" rounded="lg" overflow="auto">
|
|
317
|
+
{log.args.map((arg, index) => (
|
|
318
|
+
<div key={index} style={{ marginBottom: index < log.args.length - 1 ? '4px' : 0 }}>
|
|
319
|
+
<Text size="xs" color="tertiary" as="span">
|
|
320
|
+
{log.args.length > 1 ? `[${index}] ` : ""}
|
|
321
|
+
</Text>
|
|
322
|
+
<pre style={{ display: 'inline', fontSize: '12px', fontFamily: 'monospace', color: 'var(--text-secondary)', whiteSpace: 'pre-wrap' }}>
|
|
323
|
+
{formatActionArg(arg, 500)}
|
|
324
|
+
</pre>
|
|
325
|
+
</div>
|
|
326
|
+
))}
|
|
327
|
+
</Box>
|
|
328
|
+
</div>
|
|
329
|
+
)}
|
|
330
|
+
</div>
|
|
331
|
+
);
|
|
332
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { FragmentVariant } from '@fragments-sdk/core';
|
|
3
|
+
import type { useViewSettings } from "../hooks/useViewSettings.js";
|
|
4
|
+
import type { useTheme } from "./ThemeProvider.js";
|
|
5
|
+
import { Stack } from "@fragments-sdk/ui";
|
|
6
|
+
import { VariantPreviewCard } from "../shared/VariantPreviewCard";
|
|
7
|
+
import { PreviewArea } from "./PreviewArea.js";
|
|
8
|
+
import { resolveDisplayedCode } from "./CodePanel.js";
|
|
9
|
+
import { getVariantSectionId } from "./viewer-utils.js";
|
|
10
|
+
|
|
11
|
+
interface AllVariantsPreviewProps {
|
|
12
|
+
componentName: string;
|
|
13
|
+
fragmentPath: string;
|
|
14
|
+
variants: FragmentVariant[];
|
|
15
|
+
focusedVariantIndex: number;
|
|
16
|
+
zoom: ReturnType<typeof useViewSettings>["zoom"];
|
|
17
|
+
viewport: ReturnType<typeof useViewSettings>["viewport"];
|
|
18
|
+
customSize: ReturnType<typeof useViewSettings>["customSize"];
|
|
19
|
+
previewTheme: ReturnType<typeof useTheme>["resolvedTheme"];
|
|
20
|
+
showComparison: boolean;
|
|
21
|
+
allFigmaUrls: string[];
|
|
22
|
+
fallbackFigmaUrl?: string;
|
|
23
|
+
onRetry: () => void;
|
|
24
|
+
renderVariantContent: (variant: FragmentVariant) => ReactNode;
|
|
25
|
+
previewKeyBase: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function AllVariantsPreview({
|
|
29
|
+
componentName,
|
|
30
|
+
fragmentPath,
|
|
31
|
+
variants,
|
|
32
|
+
focusedVariantIndex,
|
|
33
|
+
zoom,
|
|
34
|
+
viewport,
|
|
35
|
+
customSize,
|
|
36
|
+
previewTheme,
|
|
37
|
+
showComparison,
|
|
38
|
+
allFigmaUrls,
|
|
39
|
+
fallbackFigmaUrl,
|
|
40
|
+
onRetry,
|
|
41
|
+
renderVariantContent,
|
|
42
|
+
previewKeyBase,
|
|
43
|
+
}: AllVariantsPreviewProps) {
|
|
44
|
+
return (
|
|
45
|
+
<Stack gap="lg" style={{ padding: "20px" }}>
|
|
46
|
+
{variants.map((variant, index) => (
|
|
47
|
+
<VariantPreviewCard
|
|
48
|
+
key={variant.name}
|
|
49
|
+
name={variant.name}
|
|
50
|
+
description={variant.description}
|
|
51
|
+
code={resolveDisplayedCode(componentName, variant)}
|
|
52
|
+
id={getVariantSectionId(componentName, variant.name)}
|
|
53
|
+
highlight={index === focusedVariantIndex}
|
|
54
|
+
>
|
|
55
|
+
<PreviewArea
|
|
56
|
+
componentName={componentName}
|
|
57
|
+
fragmentPath={fragmentPath}
|
|
58
|
+
variant={variant}
|
|
59
|
+
variants={variants}
|
|
60
|
+
zoom={zoom}
|
|
61
|
+
viewport={viewport}
|
|
62
|
+
customSize={customSize}
|
|
63
|
+
previewTheme={previewTheme}
|
|
64
|
+
showMatrixView={false}
|
|
65
|
+
showMultiViewport={false}
|
|
66
|
+
showComparison={showComparison}
|
|
67
|
+
figmaUrl={variant.figma || fallbackFigmaUrl}
|
|
68
|
+
allFigmaUrls={allFigmaUrls}
|
|
69
|
+
onSelectVariant={() => {}}
|
|
70
|
+
onRetry={onRetry}
|
|
71
|
+
renderContent={() => renderVariantContent(variant)}
|
|
72
|
+
previewKey={`${previewKeyBase}-${index}`}
|
|
73
|
+
/>
|
|
74
|
+
</VariantPreviewCard>
|
|
75
|
+
))}
|
|
76
|
+
</Stack>
|
|
77
|
+
);
|
|
78
|
+
}
|