@fragments-sdk/cli 0.9.0 → 0.9.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/dist/bin.js +83 -33
- package/dist/bin.js.map +1 -1
- package/dist/{chunk-WI6SLMSO.js → chunk-5GT62FCB.js} +2 -2
- package/dist/{chunk-CJEGT3WD.js → chunk-BW3ZATBW.js} +20 -3
- package/dist/chunk-BW3ZATBW.js.map +1 -0
- package/dist/{chunk-2JIKCJX3.js → chunk-D7372LQX.js} +13 -6
- package/dist/chunk-D7372LQX.js.map +1 -0
- package/dist/chunk-EZYXYWNF.js +131 -0
- package/dist/chunk-EZYXYWNF.js.map +1 -0
- package/dist/{chunk-NGIMCIK2.js → chunk-GF6OVPIN.js} +2 -2
- package/dist/{chunk-GOVI6COW.js → chunk-NVSPGSKB.js} +12 -4
- package/dist/chunk-NVSPGSKB.js.map +1 -0
- package/dist/core/index.d.ts +105 -3
- package/dist/core/index.js +12 -2
- package/dist/{defineFragment-D0UTve-I.d.ts → defineFragment-CBMS7Bab.d.ts} +21 -1
- package/dist/generate-LQA2R7FN.js +461 -0
- package/dist/generate-LQA2R7FN.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +5 -4
- package/dist/index.js.map +1 -1
- package/dist/{init-KSAAS7X3.js → init-2GEGVIUQ.js} +13 -75
- package/dist/init-2GEGVIUQ.js.map +1 -0
- package/dist/mcp-bin.js +4 -3
- package/dist/mcp-bin.js.map +1 -1
- package/dist/{scan-65RH3QMM.js → scan-JGS65S7P.js} +6 -5
- package/dist/{service-A5GIGGGK.js → service-XP2EAJXD.js} +4 -3
- package/dist/{static-viewer-NSODM5VX.js → static-viewer-XCS7UJTO.js} +4 -3
- package/dist/storyFilters-3LUYAFZF.js +15 -0
- package/dist/storyFilters-3LUYAFZF.js.map +1 -0
- package/dist/{test-RPWZAYSJ.js → test-TD6TJNVY.js} +3 -3
- package/dist/{tokens-NIXSZRX7.js → tokens-2EXPCVP3.js} +5 -4
- package/dist/{tokens-NIXSZRX7.js.map → tokens-2EXPCVP3.js.map} +1 -1
- package/dist/{viewer-SBTJDMP7.js → viewer-RFA2KVBG.js} +243 -18
- package/dist/viewer-RFA2KVBG.js.map +1 -0
- package/package.json +1 -1
- package/src/build.ts +12 -2
- package/src/commands/build.ts +16 -2
- package/src/commands/generate.ts +383 -68
- package/src/commands/init.ts +9 -51
- package/src/core/config.ts +15 -2
- package/src/core/generators/typescript-extractor.ts +10 -0
- package/src/core/index.ts +15 -0
- package/src/core/schema.ts +10 -2
- package/src/core/storyFilters.test.ts +350 -0
- package/src/core/storyFilters.ts +253 -0
- package/src/core/types.ts +22 -0
- package/src/migrate/converter.ts +9 -1
- package/src/migrate/parser.ts +2 -0
- package/src/migrate/types.ts +2 -0
- package/src/setup.ts +69 -24
- package/src/viewer/__tests__/viewer-integration.test.ts +1 -1
- package/src/viewer/components/AccessibilityPanel.tsx +305 -312
- package/src/viewer/components/ActionsPanel.tsx +31 -29
- package/src/viewer/components/AllVariantsPreview.tsx +78 -0
- package/src/viewer/components/App.tsx +187 -740
- package/src/viewer/components/BottomPanel.tsx +228 -132
- package/src/viewer/components/CodePanel.tsx +1 -1
- package/src/viewer/components/CommandPalette.tsx +7 -10
- package/src/viewer/components/ComponentDocView.tsx +164 -0
- package/src/viewer/components/ComponentGraph.tsx +111 -142
- package/src/viewer/components/ContractPanel.tsx +6 -6
- package/src/viewer/components/EmptyVariantMessage.tsx +54 -0
- package/src/viewer/components/FigmaEmbed.tsx +20 -18
- package/src/viewer/components/FragmentEditor.tsx +92 -115
- package/src/viewer/components/HeaderSearch.tsx +24 -0
- package/src/viewer/components/HealthDashboard.tsx +16 -2
- package/src/viewer/components/Icons.tsx +9 -0
- package/src/viewer/components/InteractionsPanel.tsx +101 -117
- package/src/viewer/components/IsolatedPreviewFrame.tsx +1 -0
- package/src/viewer/components/LandingPage.tsx +3 -3
- package/src/viewer/components/LeftSidebar.tsx +141 -63
- package/src/viewer/components/LoadErrorMessage.tsx +102 -0
- package/src/viewer/components/MultiViewportPreview.tsx +61 -142
- package/src/viewer/components/NoVariantsMessage.tsx +59 -0
- package/src/viewer/components/PanelShell.tsx +161 -0
- package/src/viewer/components/PerformancePanel.tsx +31 -28
- package/src/viewer/components/PreviewArea.tsx +1 -1
- package/src/viewer/components/PreviewAside.tsx +168 -0
- package/src/viewer/components/PreviewFrameHost.tsx +3 -3
- package/src/viewer/components/PropsEditor.tsx +70 -156
- package/src/viewer/components/ResizablePanel.tsx +103 -263
- package/src/viewer/components/RightSidebar.tsx +3 -9
- package/src/viewer/components/SkeletonLoader.tsx +13 -13
- package/src/viewer/components/TokenStylePanel.tsx +182 -209
- package/src/viewer/components/TopToolbar.tsx +159 -0
- package/src/viewer/components/VariantMatrix.tsx +42 -86
- package/src/viewer/components/VariantTabs.tsx +3 -3
- package/src/viewer/components/ViewerHeader.tsx +69 -0
- package/src/viewer/components/WebMCPDevTools.tsx +17 -23
- package/src/viewer/components/viewer-utils.ts +16 -0
- package/src/viewer/entry.tsx +5 -0
- package/src/viewer/hooks/useAppState.ts +27 -4
- package/src/viewer/hooks/usePreviewBridge.ts +2 -2
- package/src/viewer/preview-frame.html +6 -12
- package/src/viewer/server.ts +169 -2
- package/src/viewer/vendor/shared/src/ComponentDocContent.module.scss +10 -0
- package/src/viewer/vendor/shared/src/ComponentDocContent.module.scss.d.ts +2 -0
- package/src/viewer/vendor/shared/src/ComponentDocContent.tsx +274 -0
- package/src/viewer/vendor/shared/src/DocsHeaderBar.tsx +6 -18
- package/src/viewer/vendor/shared/src/DocsPageShell.tsx +5 -0
- package/src/viewer/vendor/shared/src/DocsSidebarNav.tsx +5 -16
- package/src/viewer/vendor/shared/src/PropsTable.module.scss +68 -0
- package/src/viewer/vendor/shared/src/PropsTable.module.scss.d.ts +2 -0
- package/src/viewer/vendor/shared/src/PropsTable.tsx +76 -0
- package/src/viewer/vendor/shared/src/VariantPreviewCard.module.scss +122 -0
- package/src/viewer/vendor/shared/src/VariantPreviewCard.module.scss.d.ts +2 -0
- package/src/viewer/vendor/shared/src/VariantPreviewCard.tsx +134 -0
- package/src/viewer/vendor/shared/src/index.ts +8 -0
- package/src/viewer/vendor/shared/src/types.ts +12 -0
- package/src/viewer/vite-plugin.ts +109 -4
- package/dist/chunk-2JIKCJX3.js.map +0 -1
- package/dist/chunk-CJEGT3WD.js.map +0 -1
- package/dist/chunk-GOVI6COW.js.map +0 -1
- package/dist/generate-35OIMW4Y.js +0 -252
- package/dist/generate-35OIMW4Y.js.map +0 -1
- package/dist/init-KSAAS7X3.js.map +0 -1
- package/dist/viewer-SBTJDMP7.js.map +0 -1
- /package/dist/{chunk-WI6SLMSO.js.map → chunk-5GT62FCB.js.map} +0 -0
- /package/dist/{chunk-NGIMCIK2.js.map → chunk-GF6OVPIN.js.map} +0 -0
- /package/dist/{scan-65RH3QMM.js.map → scan-JGS65S7P.js.map} +0 -0
- /package/dist/{service-A5GIGGGK.js.map → service-XP2EAJXD.js.map} +0 -0
- /package/dist/{static-viewer-NSODM5VX.js.map → static-viewer-XCS7UJTO.js.map} +0 -0
- /package/dist/{test-RPWZAYSJ.js.map → test-TD6TJNVY.js.map} +0 -0
|
@@ -1,22 +1,43 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* BottomPanel component - the tabbed panel at the bottom of the viewer.
|
|
3
|
-
*
|
|
3
|
+
* Uses the Drawer component from @fragments-sdk/ui as a non-modal bottom sheet.
|
|
4
|
+
* Contains Styles, Accessibility, Interactions, Graph, and Performance tabs.
|
|
4
5
|
*/
|
|
5
6
|
|
|
6
|
-
import { memo, useCallback } from
|
|
7
|
-
import type { FragmentDefinition, FragmentVariant } from
|
|
8
|
-
import { Tabs,
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { TokenStylePanel } from
|
|
12
|
-
import { AccessibilityPanel } from
|
|
13
|
-
import { InteractionsPanel } from
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
7
|
+
import { memo, useCallback, useState, useEffect, useRef } from "react";
|
|
8
|
+
import type { FragmentDefinition, FragmentVariant } from "../../core/index.js";
|
|
9
|
+
import { Drawer, Tabs, Button, Tooltip } from "@fragments-sdk/ui";
|
|
10
|
+
import { Terminal } from "@phosphor-icons/react";
|
|
11
|
+
import { BRAND } from "../../core/index.js";
|
|
12
|
+
import { TokenStylePanel } from "./TokenStylePanel.js";
|
|
13
|
+
import { AccessibilityPanel } from "./AccessibilityPanel.js";
|
|
14
|
+
import { InteractionsPanel } from "./InteractionsPanel.js";
|
|
15
|
+
import { ComponentGraph } from "./ComponentGraph.js";
|
|
16
|
+
import { PerformancePanel } from "./PerformancePanel.js";
|
|
17
|
+
import type { ActivePanel } from "../hooks/useAppState.js";
|
|
18
|
+
|
|
19
|
+
// Persist panel height to localStorage
|
|
20
|
+
const HEIGHT_KEY = `${BRAND.storagePrefix}panel-height`;
|
|
21
|
+
const MIN_HEIGHT = 120;
|
|
22
|
+
const MAX_HEIGHT = 600;
|
|
23
|
+
const DEFAULT_HEIGHT = 240;
|
|
24
|
+
|
|
25
|
+
function loadHeight(): number {
|
|
26
|
+
try {
|
|
27
|
+
const v = localStorage.getItem(HEIGHT_KEY);
|
|
28
|
+
return v ? Math.max(MIN_HEIGHT, Math.min(MAX_HEIGHT, Number(v))) : DEFAULT_HEIGHT;
|
|
29
|
+
} catch {
|
|
30
|
+
return DEFAULT_HEIGHT;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function saveHeight(h: number) {
|
|
35
|
+
try {
|
|
36
|
+
localStorage.setItem(HEIGHT_KEY, String(h));
|
|
37
|
+
} catch {
|
|
38
|
+
// Ignore storage errors
|
|
39
|
+
}
|
|
40
|
+
}
|
|
20
41
|
|
|
21
42
|
interface BottomPanelProps {
|
|
22
43
|
// Component data
|
|
@@ -25,6 +46,8 @@ interface BottomPanelProps {
|
|
|
25
46
|
fragments: Array<{ path: string; fragment: FragmentDefinition }>;
|
|
26
47
|
|
|
27
48
|
// Panel state
|
|
49
|
+
open: boolean;
|
|
50
|
+
onOpenChange: (open: boolean) => void;
|
|
28
51
|
activePanel: ActivePanel;
|
|
29
52
|
onPanelChange: (panel: ActivePanel) => void;
|
|
30
53
|
|
|
@@ -37,10 +60,6 @@ interface BottomPanelProps {
|
|
|
37
60
|
onFetchFigma: () => void;
|
|
38
61
|
onRefreshRendered: () => void;
|
|
39
62
|
|
|
40
|
-
// Actions
|
|
41
|
-
actionLogs: ActionLog[];
|
|
42
|
-
onClearActionLogs: () => void;
|
|
43
|
-
|
|
44
63
|
// Navigation
|
|
45
64
|
onNavigateToComponent: (name: string) => void;
|
|
46
65
|
|
|
@@ -53,6 +72,8 @@ export const BottomPanel = memo(function BottomPanel({
|
|
|
53
72
|
fragment,
|
|
54
73
|
variant,
|
|
55
74
|
fragments,
|
|
75
|
+
open,
|
|
76
|
+
onOpenChange,
|
|
56
77
|
activePanel,
|
|
57
78
|
onPanelChange,
|
|
58
79
|
figmaUrl,
|
|
@@ -62,131 +83,206 @@ export const BottomPanel = memo(function BottomPanel({
|
|
|
62
83
|
figmaError,
|
|
63
84
|
onFetchFigma,
|
|
64
85
|
onRefreshRendered,
|
|
65
|
-
actionLogs,
|
|
66
|
-
onClearActionLogs,
|
|
67
86
|
onNavigateToComponent,
|
|
68
87
|
previewKey,
|
|
69
88
|
fragmentKey,
|
|
70
89
|
}: BottomPanelProps) {
|
|
90
|
+
// Resize state
|
|
91
|
+
const [height, setHeight] = useState(loadHeight);
|
|
92
|
+
const [isResizing, setIsResizing] = useState(false);
|
|
93
|
+
const startYRef = useRef(0);
|
|
94
|
+
const startHeightRef = useRef(0);
|
|
95
|
+
|
|
96
|
+
// Save height changes
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
saveHeight(height);
|
|
99
|
+
}, [height]);
|
|
100
|
+
|
|
101
|
+
const handleMouseDown = useCallback(
|
|
102
|
+
(e: React.MouseEvent) => {
|
|
103
|
+
e.preventDefault();
|
|
104
|
+
setIsResizing(true);
|
|
105
|
+
startYRef.current = e.clientY;
|
|
106
|
+
startHeightRef.current = height;
|
|
107
|
+
},
|
|
108
|
+
[height]
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
if (!isResizing) return;
|
|
113
|
+
|
|
114
|
+
const handleMouseMove = (e: MouseEvent) => {
|
|
115
|
+
const deltaY = startYRef.current - e.clientY;
|
|
116
|
+
setHeight(Math.max(MIN_HEIGHT, Math.min(MAX_HEIGHT, startHeightRef.current + deltaY)));
|
|
117
|
+
};
|
|
118
|
+
const handleMouseUp = () => setIsResizing(false);
|
|
119
|
+
|
|
120
|
+
document.addEventListener("mousemove", handleMouseMove);
|
|
121
|
+
document.addEventListener("mouseup", handleMouseUp);
|
|
122
|
+
document.body.style.cursor = "ns-resize";
|
|
123
|
+
document.body.style.userSelect = "none";
|
|
124
|
+
|
|
125
|
+
return () => {
|
|
126
|
+
document.removeEventListener("mousemove", handleMouseMove);
|
|
127
|
+
document.removeEventListener("mouseup", handleMouseUp);
|
|
128
|
+
document.body.style.cursor = "";
|
|
129
|
+
document.body.style.userSelect = "";
|
|
130
|
+
};
|
|
131
|
+
}, [isResizing]);
|
|
132
|
+
|
|
133
|
+
// Tab change handler with Figma side effects
|
|
71
134
|
const handleStylesClick = useCallback(() => {
|
|
72
|
-
onPanelChange(
|
|
135
|
+
onPanelChange("styles");
|
|
73
136
|
onFetchFigma();
|
|
74
137
|
setTimeout(onRefreshRendered, 100);
|
|
75
138
|
}, [onPanelChange, onFetchFigma, onRefreshRendered]);
|
|
76
139
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
140
|
+
const handleTabChange = useCallback(
|
|
141
|
+
(value: string | number) => {
|
|
142
|
+
const panel = String(value);
|
|
143
|
+
if (panel === "styles") {
|
|
144
|
+
handleStylesClick();
|
|
145
|
+
} else {
|
|
146
|
+
onPanelChange(panel as ActivePanel);
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
[handleStylesClick, onPanelChange]
|
|
150
|
+
);
|
|
86
151
|
|
|
87
152
|
return (
|
|
88
|
-
<
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
<
|
|
92
|
-
<
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
{
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
153
|
+
<Drawer open={open} onOpenChange={onOpenChange} modal={false}>
|
|
154
|
+
{/* Floating trigger FAB — fixed bottom-right, moves up when drawer is open */}
|
|
155
|
+
<Tooltip content={open ? "Close dev tools" : "Open dev tools"} side="left">
|
|
156
|
+
<Drawer.Trigger asChild>
|
|
157
|
+
<Button
|
|
158
|
+
variant={open ? "secondary" : "primary"}
|
|
159
|
+
icon
|
|
160
|
+
size="md"
|
|
161
|
+
aria-label={open ? "Close dev tools" : "Open dev tools"}
|
|
162
|
+
style={{
|
|
163
|
+
position: "fixed",
|
|
164
|
+
bottom: open ? `${height + 16}px` : "16px",
|
|
165
|
+
right: "16px",
|
|
166
|
+
zIndex: 52,
|
|
167
|
+
borderRadius: "50%",
|
|
168
|
+
boxShadow: "0 4px 12px rgba(0, 0, 0, 0.15), 0 2px 4px rgba(0, 0, 0, 0.1)",
|
|
169
|
+
transition: "bottom 300ms ease, box-shadow 200ms ease",
|
|
170
|
+
width: "44px",
|
|
171
|
+
height: "44px",
|
|
172
|
+
}}
|
|
173
|
+
>
|
|
174
|
+
<Terminal size={20} weight={open ? "fill" : "regular"} />
|
|
175
|
+
</Button>
|
|
176
|
+
</Drawer.Trigger>
|
|
177
|
+
</Tooltip>
|
|
178
|
+
|
|
179
|
+
<Drawer.Content
|
|
180
|
+
side="bottom"
|
|
181
|
+
backdrop={false}
|
|
182
|
+
id="bottom-panel"
|
|
183
|
+
aria-label="Bottom panel"
|
|
184
|
+
style={{
|
|
185
|
+
height: `${height}px`,
|
|
186
|
+
transition: isResizing ? "none" : undefined,
|
|
187
|
+
}}
|
|
188
|
+
>
|
|
189
|
+
{/* Full-viewport overlay during resize — prevents iframes from capturing events */}
|
|
190
|
+
{isResizing && (
|
|
191
|
+
<div
|
|
192
|
+
style={{
|
|
193
|
+
position: "fixed",
|
|
194
|
+
inset: 0,
|
|
195
|
+
zIndex: 52,
|
|
196
|
+
cursor: "ns-resize",
|
|
197
|
+
}}
|
|
198
|
+
/>
|
|
199
|
+
)}
|
|
200
|
+
|
|
201
|
+
{/* Resize grab handle */}
|
|
202
|
+
<div
|
|
203
|
+
onMouseDown={handleMouseDown}
|
|
204
|
+
style={{
|
|
205
|
+
width: "100%",
|
|
206
|
+
display: "flex",
|
|
207
|
+
justifyContent: "center",
|
|
208
|
+
padding: "6px 0 2px",
|
|
209
|
+
cursor: "ns-resize",
|
|
210
|
+
flexShrink: 0,
|
|
211
|
+
}}
|
|
212
|
+
>
|
|
213
|
+
<div
|
|
214
|
+
style={{
|
|
215
|
+
width: "36px",
|
|
216
|
+
height: "4px",
|
|
217
|
+
borderRadius: "9999px",
|
|
218
|
+
backgroundColor: "var(--fui-text-muted, var(--text-muted))",
|
|
219
|
+
opacity: isResizing ? 0.8 : 0.3,
|
|
220
|
+
transition: "opacity 150ms ease",
|
|
221
|
+
}}
|
|
129
222
|
/>
|
|
130
223
|
</div>
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
224
|
+
|
|
225
|
+
{/* Header with tabs */}
|
|
226
|
+
<Drawer.Header
|
|
227
|
+
style={{
|
|
228
|
+
padding: "0 16px",
|
|
229
|
+
borderBottom: "1px solid var(--fui-border-subtle, var(--border-subtle))",
|
|
230
|
+
}}
|
|
231
|
+
>
|
|
232
|
+
<Tabs value={activePanel} onValueChange={handleTabChange}>
|
|
233
|
+
<Tabs.List variant="pills">
|
|
234
|
+
{figmaUrl && <Tabs.Tab value="styles">Styles</Tabs.Tab>}
|
|
235
|
+
<Tabs.Tab value="accessibility">Accessibility</Tabs.Tab>
|
|
236
|
+
{variant?.hasPlayFunction && (
|
|
237
|
+
<Tabs.Tab value="interactions">Interactions</Tabs.Tab>
|
|
238
|
+
)}
|
|
239
|
+
<Tabs.Tab value="graph">Graph</Tabs.Tab>
|
|
240
|
+
<Tabs.Tab value="performance">Performance</Tabs.Tab>
|
|
241
|
+
</Tabs.List>
|
|
242
|
+
</Tabs>
|
|
243
|
+
</Drawer.Header>
|
|
244
|
+
|
|
245
|
+
{/* Panel Content */}
|
|
246
|
+
<Drawer.Body style={{ padding: 0 }}>
|
|
247
|
+
{activePanel === "styles" && figmaUrl && (
|
|
248
|
+
<TokenStylePanel
|
|
249
|
+
figmaUrl={figmaUrl}
|
|
250
|
+
figmaStyles={figmaStyles}
|
|
251
|
+
renderedStyles={renderedStyles}
|
|
252
|
+
figmaLoading={figmaLoading}
|
|
253
|
+
figmaError={figmaError}
|
|
254
|
+
onFetchFigma={onFetchFigma}
|
|
255
|
+
onRefreshRendered={onRefreshRendered}
|
|
256
|
+
/>
|
|
257
|
+
)}
|
|
258
|
+
|
|
259
|
+
{activePanel === "accessibility" && (
|
|
260
|
+
<AccessibilityPanel
|
|
261
|
+
cacheKey={fragmentKey}
|
|
262
|
+
previewKey={previewKey}
|
|
263
|
+
autoScan={true}
|
|
264
|
+
componentName={fragment.meta.name}
|
|
265
|
+
variantName={variant.name}
|
|
266
|
+
/>
|
|
267
|
+
)}
|
|
268
|
+
|
|
269
|
+
{activePanel === "interactions" && (
|
|
270
|
+
<InteractionsPanel key={fragmentKey} variant={variant} previewKey={previewKey} />
|
|
271
|
+
)}
|
|
272
|
+
|
|
273
|
+
{activePanel === "graph" && (
|
|
274
|
+
<ComponentGraph
|
|
275
|
+
fragment={fragment}
|
|
276
|
+
allFragments={fragments}
|
|
277
|
+
onNavigate={onNavigateToComponent}
|
|
278
|
+
/>
|
|
279
|
+
)}
|
|
280
|
+
|
|
281
|
+
{activePanel === "performance" && (
|
|
282
|
+
<PerformancePanel componentName={fragment.meta.name} />
|
|
283
|
+
)}
|
|
284
|
+
</Drawer.Body>
|
|
285
|
+
</Drawer.Content>
|
|
286
|
+
</Drawer>
|
|
191
287
|
);
|
|
192
288
|
});
|
|
@@ -88,7 +88,7 @@ export function __buildFallbackSnippetForTest(componentName: string, variant: Fr
|
|
|
88
88
|
return buildFallbackSnippet(componentName, variant);
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
function resolveDisplayedCode(componentName: string, variant: FragmentVariant): string {
|
|
91
|
+
export function resolveDisplayedCode(componentName: string, variant: FragmentVariant): string {
|
|
92
92
|
if (typeof variant.code === 'string') {
|
|
93
93
|
const normalized = normalizeAuthoredSnippet(variant.code);
|
|
94
94
|
if (normalized.length > 0) {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { useState, useEffect, useRef, useMemo, useCallback } from "react";
|
|
13
|
-
import { Dialog, Stack, Text, Badge, Separator, Input } from '@fragments-sdk/ui';
|
|
13
|
+
import { Dialog, Stack, Text, Badge, Separator, Input, Box } from '@fragments-sdk/ui';
|
|
14
14
|
import type { FragmentDefinition } from "../../core/index.js";
|
|
15
15
|
import { SearchIcon, ChevronRightIcon } from "./Icons.js";
|
|
16
16
|
|
|
@@ -198,9 +198,9 @@ export function CommandPalette({
|
|
|
198
198
|
</Stack>
|
|
199
199
|
|
|
200
200
|
{/* Results */}
|
|
201
|
-
<
|
|
201
|
+
<Box ref={listRef} overflow="auto" style={{ maxHeight: '320px', padding: '8px 0' }}>
|
|
202
202
|
{results.length === 0 ? (
|
|
203
|
-
<
|
|
203
|
+
<Box padding="lg" style={{ textAlign: 'center' }}>
|
|
204
204
|
<Text color="tertiary">
|
|
205
205
|
{query ? (
|
|
206
206
|
<>No results for “{query}”</>
|
|
@@ -208,7 +208,7 @@ export function CommandPalette({
|
|
|
208
208
|
<>Start typing to search...</>
|
|
209
209
|
)}
|
|
210
210
|
</Text>
|
|
211
|
-
</
|
|
211
|
+
</Box>
|
|
212
212
|
) : (
|
|
213
213
|
results.map((result, index) => (
|
|
214
214
|
<button
|
|
@@ -300,13 +300,10 @@ export function CommandPalette({
|
|
|
300
300
|
</button>
|
|
301
301
|
))
|
|
302
302
|
)}
|
|
303
|
-
</
|
|
303
|
+
</Box>
|
|
304
304
|
|
|
305
305
|
{/* Footer */}
|
|
306
|
-
<
|
|
307
|
-
padding: '8px 16px',
|
|
308
|
-
borderTop: '1px solid var(--border)',
|
|
309
|
-
}}>
|
|
306
|
+
<Box paddingX="md" paddingY="sm" borderTop>
|
|
310
307
|
<Stack direction="row" align="center" justify="between">
|
|
311
308
|
<Stack direction="row" align="center" gap="md">
|
|
312
309
|
<Stack direction="row" align="center" gap="xs">
|
|
@@ -323,7 +320,7 @@ export function CommandPalette({
|
|
|
323
320
|
{results.length} result{results.length !== 1 ? "s" : ""}
|
|
324
321
|
</Text>
|
|
325
322
|
</Stack>
|
|
326
|
-
</
|
|
323
|
+
</Box>
|
|
327
324
|
</Dialog.Content>
|
|
328
325
|
</Dialog>
|
|
329
326
|
);
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type {
|
|
3
|
+
FragmentDefinition,
|
|
4
|
+
FragmentVariant,
|
|
5
|
+
PropDefinition,
|
|
6
|
+
} from "../../core/index.js";
|
|
7
|
+
import type { DocProp } from "@fragments-sdk/shared";
|
|
8
|
+
import { ComponentDocContent } from "@fragments-sdk/shared";
|
|
9
|
+
import { VariantPreviewCard } from "@fragments-sdk/shared";
|
|
10
|
+
import { Badge, Card, CardBody, Stack, Text } from "@fragments-sdk/ui";
|
|
11
|
+
import { PreviewArea } from "./PreviewArea.js";
|
|
12
|
+
import { resolveDisplayedCode } from "./CodePanel.js";
|
|
13
|
+
import { getVariantSectionId } from "./viewer-utils.js";
|
|
14
|
+
import type { ZoomLevel, ViewportPreset, ViewportSize } from "../constants/ui.js";
|
|
15
|
+
import type { PreviewTheme } from "../hooks/useViewSettings.js";
|
|
16
|
+
|
|
17
|
+
interface ComponentDocViewProps {
|
|
18
|
+
fragment: { path: string; fragment: FragmentDefinition };
|
|
19
|
+
fragments: Array<{ path: string; fragment: FragmentDefinition }>;
|
|
20
|
+
renderVariantContent: (variant: FragmentVariant) => ReactNode;
|
|
21
|
+
onNavigateToComponent: (name: string) => void;
|
|
22
|
+
zoom: ZoomLevel;
|
|
23
|
+
viewport: ViewportPreset;
|
|
24
|
+
customSize: ViewportSize;
|
|
25
|
+
previewTheme: PreviewTheme;
|
|
26
|
+
showComparison: boolean;
|
|
27
|
+
allFigmaUrls: string[];
|
|
28
|
+
onRetry: () => void;
|
|
29
|
+
previewKeyBase: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function mapPropsToDocProps(props: Record<string, PropDefinition>): Record<string, DocProp> {
|
|
33
|
+
const record: Record<string, DocProp> = {};
|
|
34
|
+
for (const [name, prop] of Object.entries(props)) {
|
|
35
|
+
record[name] = {
|
|
36
|
+
type: prop.type,
|
|
37
|
+
description: prop.description || "",
|
|
38
|
+
required: prop.required,
|
|
39
|
+
default: prop.default,
|
|
40
|
+
values: prop.values ? [...prop.values] : undefined,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return record;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function ComponentDocView({
|
|
47
|
+
fragment,
|
|
48
|
+
fragments,
|
|
49
|
+
renderVariantContent,
|
|
50
|
+
onNavigateToComponent,
|
|
51
|
+
zoom,
|
|
52
|
+
viewport,
|
|
53
|
+
customSize,
|
|
54
|
+
previewTheme,
|
|
55
|
+
showComparison,
|
|
56
|
+
allFigmaUrls,
|
|
57
|
+
onRetry,
|
|
58
|
+
previewKeyBase,
|
|
59
|
+
}: ComponentDocViewProps) {
|
|
60
|
+
const def = fragment.fragment;
|
|
61
|
+
const componentName = def.meta.name;
|
|
62
|
+
|
|
63
|
+
const propsRecord = mapPropsToDocProps(def.props);
|
|
64
|
+
const packageName = typeof window !== 'undefined' ? window.__FRAGMENTS_PACKAGE_NAME__ : null;
|
|
65
|
+
|
|
66
|
+
const usageData = {
|
|
67
|
+
when: def.usage?.when || [],
|
|
68
|
+
whenNot: def.usage?.whenNot || [],
|
|
69
|
+
guidelines: def.usage?.guidelines || [],
|
|
70
|
+
accessibility: def.usage?.accessibility || [],
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const relations = def.relations || [];
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<ComponentDocContent
|
|
77
|
+
name={componentName}
|
|
78
|
+
description={def.meta.description || ""}
|
|
79
|
+
componentId={componentName}
|
|
80
|
+
packageName={packageName || undefined}
|
|
81
|
+
props={propsRecord}
|
|
82
|
+
variants={def.variants.map((v) => ({
|
|
83
|
+
name: v.name,
|
|
84
|
+
description: v.description,
|
|
85
|
+
code: v.code,
|
|
86
|
+
}))}
|
|
87
|
+
usage={usageData}
|
|
88
|
+
relations={relations}
|
|
89
|
+
dependencies={def.meta.dependencies}
|
|
90
|
+
renderVariant={(variant, index) => {
|
|
91
|
+
const fragVariant = def.variants[index];
|
|
92
|
+
if (!fragVariant) return null;
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<VariantPreviewCard
|
|
96
|
+
key={variant.name}
|
|
97
|
+
name={variant.name}
|
|
98
|
+
description={variant.description}
|
|
99
|
+
code={resolveDisplayedCode(componentName, fragVariant)}
|
|
100
|
+
id={getVariantSectionId(componentName, variant.name)}
|
|
101
|
+
>
|
|
102
|
+
<PreviewArea
|
|
103
|
+
componentName={componentName}
|
|
104
|
+
fragmentPath={fragment.path}
|
|
105
|
+
variant={fragVariant}
|
|
106
|
+
variants={def.variants}
|
|
107
|
+
zoom={zoom}
|
|
108
|
+
viewport={viewport}
|
|
109
|
+
customSize={customSize}
|
|
110
|
+
previewTheme={previewTheme}
|
|
111
|
+
showMatrixView={false}
|
|
112
|
+
showMultiViewport={false}
|
|
113
|
+
showComparison={showComparison}
|
|
114
|
+
figmaUrl={fragVariant.figma || def.meta.figma}
|
|
115
|
+
allFigmaUrls={allFigmaUrls}
|
|
116
|
+
onSelectVariant={() => {}}
|
|
117
|
+
onRetry={onRetry}
|
|
118
|
+
renderContent={() => renderVariantContent(fragVariant)}
|
|
119
|
+
previewKey={`${previewKeyBase}-${index}`}
|
|
120
|
+
/>
|
|
121
|
+
</VariantPreviewCard>
|
|
122
|
+
);
|
|
123
|
+
}}
|
|
124
|
+
renderRelatedLink={(comp, relationship, note, key) => {
|
|
125
|
+
const target = fragments.find(
|
|
126
|
+
(s) => s.fragment.meta.name.toLowerCase() === comp.toLowerCase()
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
return (
|
|
130
|
+
<a
|
|
131
|
+
key={key}
|
|
132
|
+
onClick={(e) => {
|
|
133
|
+
e.preventDefault();
|
|
134
|
+
onNavigateToComponent(comp);
|
|
135
|
+
}}
|
|
136
|
+
href="#"
|
|
137
|
+
style={{
|
|
138
|
+
textDecoration: "none",
|
|
139
|
+
color: "inherit",
|
|
140
|
+
cursor: target ? "pointer" : "default",
|
|
141
|
+
opacity: target ? 1 : 0.6,
|
|
142
|
+
}}
|
|
143
|
+
>
|
|
144
|
+
<Card variant="outlined">
|
|
145
|
+
<CardBody>
|
|
146
|
+
<Stack gap="xs">
|
|
147
|
+
<Stack direction="row" align="center" justify="between">
|
|
148
|
+
<Text weight="semibold">{comp}</Text>
|
|
149
|
+
<Badge size="sm">{relationship}</Badge>
|
|
150
|
+
</Stack>
|
|
151
|
+
{note && (
|
|
152
|
+
<Text size="sm" color="secondary">
|
|
153
|
+
{note}
|
|
154
|
+
</Text>
|
|
155
|
+
)}
|
|
156
|
+
</Stack>
|
|
157
|
+
</CardBody>
|
|
158
|
+
</Card>
|
|
159
|
+
</a>
|
|
160
|
+
);
|
|
161
|
+
}}
|
|
162
|
+
/>
|
|
163
|
+
);
|
|
164
|
+
}
|