@tscircuit/fake-snippets 0.0.107 → 0.0.108

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 (35) hide show
  1. package/api/generated-index.js +82 -22
  2. package/biome.json +7 -1
  3. package/bun-tests/fake-snippets-api/routes/package_builds/get.test.ts +0 -15
  4. package/bun-tests/fake-snippets-api/routes/package_builds/list.test.ts +0 -12
  5. package/dist/bundle.js +23 -23
  6. package/dist/index.d.ts +21 -15
  7. package/dist/index.js +17 -17
  8. package/dist/schema.d.ts +24 -24
  9. package/dist/schema.js +5 -5
  10. package/fake-snippets-api/lib/db/db-client.ts +10 -1
  11. package/fake-snippets-api/lib/db/schema.ts +3 -3
  12. package/fake-snippets-api/lib/db/seed.ts +6 -9
  13. package/fake-snippets-api/lib/public-mapping/public-map-package-build.ts +0 -3
  14. package/fake-snippets-api/lib/public-mapping/public-map-package-release.ts +3 -0
  15. package/package.json +1 -1
  16. package/src/App.tsx +12 -9
  17. package/src/components/FileSidebar.tsx +14 -159
  18. package/src/components/PackageBreadcrumb.tsx +1 -1
  19. package/src/components/ViewPackagePage/components/mobile-sidebar.tsx +1 -1
  20. package/src/components/ViewPackagePage/components/sidebar-about-section.tsx +18 -2
  21. package/src/components/ViewPackagePage/components/sidebar-releases-section.tsx +1 -1
  22. package/src/components/preview/BuildsList.tsx +20 -9
  23. package/src/components/preview/ConnectedPackagesList.tsx +73 -60
  24. package/src/components/preview/ConnectedRepoOverview.tsx +160 -154
  25. package/src/components/preview/PackageReleasesDashboard.tsx +11 -5
  26. package/src/components/preview/index.tsx +16 -153
  27. package/src/index.css +24 -0
  28. package/src/lib/utils/transformFilesToTreeData.tsx +195 -0
  29. package/src/pages/404.tsx +3 -5
  30. package/src/pages/preview-release.tsx +269 -0
  31. package/src/pages/release-builds.tsx +0 -8
  32. package/src/pages/release-detail.tsx +17 -15
  33. package/src/pages/releases.tsx +5 -1
  34. package/src/hooks/use-snippets-base-api-url.ts +0 -3
  35. package/src/pages/preview-build.tsx +0 -380
@@ -1,380 +0,0 @@
1
- import { useState } from "react"
2
- import { useParams } from "wouter"
3
- import { Loader2, ChevronLeft, ChevronRight, File, Folder } from "lucide-react"
4
- import Header from "@/components/Header"
5
- import { SuspenseRunFrame } from "@/components/SuspenseRunFrame"
6
- import { TreeView, TreeDataItem } from "@/components/ui/tree-view"
7
- import { cn } from "@/lib/utils"
8
- import { PrefetchPageLink } from "@/components/PrefetchPageLink"
9
- import NotFoundPage from "./404"
10
- import { getBuildStatus, MOCK_PACKAGE_BUILDS } from "@/components/preview"
11
-
12
- const MOCK_DEPLOYMENT_FILES: Record<
13
- string,
14
- Array<{ path: string; content: string }>
15
- > = {
16
- pb_1a2b3c4d: [
17
- {
18
- path: "index.tsx",
19
- content: `export default () => (
20
- <board width="10mm" height="10mm">
21
- <resistor
22
- resistance="1k"
23
- footprint="0402"
24
- name="R1"
25
- schX={3}
26
- pcbX={3}
27
- />
28
- <capacitor
29
- capacitance="1000pF"
30
- footprint="0402"
31
- name="C1"
32
- schX={-3}
33
- pcbX={-3}
34
- />
35
- <trace from=".R1 > .pin1" to=".C1 > .pin1" />
36
- </board>
37
- )`,
38
- },
39
- {
40
- path: "components/Button.tsx",
41
- content: `export default () => (
42
- <board width="10mm" height="10mm">
43
- <resistor
44
- resistance="1k"
45
- footprint="0402"
46
- name="R1"
47
- schX={3}
48
- pcbX={3}
49
- />
50
- <capacitor
51
- capacitance="1000pF"
52
- footprint="0402"
53
- name="C1"
54
- schX={-3}
55
- pcbX={-3}
56
- />
57
- <trace from=".R1 > .pin1" to=".C1 > .pin1" />
58
- </board>
59
- )`,
60
- },
61
- ],
62
- pb_9i8j7k6l: [
63
- {
64
- path: "index.tsx",
65
- content: `export default () => (
66
- <board width="10mm" height="10mm">
67
- <resistor
68
- resistance="1k"
69
- footprint="0402"
70
- name="R1"
71
- schX={3}
72
- pcbX={3}
73
- />
74
- <capacitor
75
- capacitance="1000pF"
76
- footprint="0402"
77
- name="C1"
78
- schX={-3}
79
- pcbX={-3}
80
- />
81
- <trace from=".R1 > .pin1" to=".C1 > .pin1" />
82
- </board>
83
- )`,
84
- },
85
- {
86
- path: "utils/helpers.ts",
87
- content: `export default () => (
88
- <board width="10mm" height="10mm">
89
- <resistor
90
- resistance="1k"
91
- footprint="0402"
92
- name="R1"
93
- schX={3}
94
- pcbX={3}
95
- />
96
- <capacitor
97
- capacitance="1000pF"
98
- footprint="0402"
99
- name="C1"
100
- schX={-3}
101
- pcbX={-3}
102
- />
103
- <trace from=".R1 > .pin1" to=".C1 > .pin1" />
104
- </board>
105
- )`,
106
- },
107
- ],
108
- pb_1q2w3e4r: [
109
- {
110
- path: "index.tsx",
111
- content: `export default () => (
112
- <board width="10mm" height="10mm">
113
- <resistor
114
- resistance="1k"
115
- footprint="0402"
116
- name="R1"
117
- schX={3}
118
- pcbX={3}
119
- />
120
- <capacitor
121
- capacitance="1000pF"
122
- footprint="0402"
123
- name="C1"
124
- schX={-3}
125
- pcbX={-3}
126
- />
127
- <trace from=".R1 > .pin1" to=".C1 > .pin1" />
128
- </board>
129
- )`,
130
- },
131
- ],
132
- pb_9o8i7u6y: [
133
- {
134
- path: "index.tsx",
135
- content: `export default () => (
136
- <board width="10mm" height="10mm">
137
- <resistor
138
- resistance="1k"
139
- footprint="0402"
140
- name="R1"
141
- schX={3}
142
- pcbX={3}
143
- />
144
- <capacitor
145
- capacitance="1000pF"
146
- footprint="0402"
147
- name="C1"
148
- schX={-3}
149
- pcbX={-3}
150
- />
151
- <trace from=".R1 > .pin1" to=".C1 > .pin1" />
152
- </board>
153
- )`,
154
- },
155
- ],
156
- }
157
-
158
- const getBuildFiles = (buildId: string | null) => {
159
- if (!buildId) return []
160
- return MOCK_DEPLOYMENT_FILES[buildId] || []
161
- }
162
-
163
- const getBuildFsMap = (buildId: string | null) => {
164
- const files = getBuildFiles(buildId)
165
- return Object.fromEntries(files.map((f) => [f.path, f.content]))
166
- }
167
-
168
- const StatusPill = ({ status }: { status: string }) => {
169
- const color =
170
- status === "success"
171
- ? "bg-emerald-600"
172
- : status === "failed"
173
- ? "bg-red-600"
174
- : status === "building"
175
- ? "bg-blue-600 animate-pulse"
176
- : "bg-gray-500"
177
- return <span className={cn("inline-block w-2 h-2 rounded-full", color)} />
178
- }
179
-
180
- export default function PreviewBuildPage() {
181
- const params = useParams<{ buildId: string }>()
182
- const buildId = params?.buildId || null
183
-
184
- const [sidebarCollapsed, setSidebarCollapsed] = useState(false)
185
- const [selectedFile, setSelectedFile] = useState<string | null>("index.tsx")
186
- const [selectedItemId, setSelectedItemId] = useState<string>("")
187
-
188
- const buildFiles = getBuildFiles(buildId)
189
- const buildFsMap = getBuildFsMap(buildId)
190
-
191
- const build = buildId
192
- ? MOCK_PACKAGE_BUILDS.find((d) => d.package_build_id === buildId)
193
- : MOCK_PACKAGE_BUILDS[0]
194
-
195
- if (!build) {
196
- return <NotFoundPage heading="Build Not Found" />
197
- }
198
- const { status, label } = getBuildStatus(build)
199
- const convertFilesToTreeData = (
200
- files: Array<{ path: string; content: string }>,
201
- ): TreeDataItem[] => {
202
- const tree: TreeDataItem[] = []
203
- const pathMap = new Map<string, TreeDataItem>()
204
-
205
- files.forEach((file) => {
206
- const parts = file.path.split("/")
207
- let currentPath = ""
208
-
209
- parts.forEach((part, index) => {
210
- const isLast = index === parts.length - 1
211
- currentPath = currentPath ? `${currentPath}/${part}` : part
212
-
213
- if (!pathMap.has(currentPath)) {
214
- const item: TreeDataItem = {
215
- id: currentPath,
216
- name: part,
217
- icon: isLast ? File : Folder,
218
- children: isLast ? undefined : [],
219
- }
220
-
221
- pathMap.set(currentPath, item)
222
-
223
- if (index === 0) {
224
- tree.push(item)
225
- } else {
226
- const parentPath = parts.slice(0, index).join("/")
227
- const parent = pathMap.get(parentPath)
228
- if (parent && parent.children) {
229
- parent.children.push(item)
230
- }
231
- }
232
- }
233
- })
234
- })
235
-
236
- return tree
237
- }
238
-
239
- const treeData = convertFilesToTreeData(buildFiles)
240
-
241
- return (
242
- <>
243
- <Header />
244
- <div className="flex flex-col h-screen overflow-hidden !-mt-1">
245
- <div className="flex flex-1 overflow-hidden">
246
- <aside
247
- className={cn(
248
- "relative border-r border-gray-200 rounded-r-lg z-[5] h-full transition-all duration-300 ease-in-out bg-white",
249
- sidebarCollapsed ? "w-3" : "w-80",
250
- )}
251
- >
252
- <button
253
- onClick={() => setSidebarCollapsed(!sidebarCollapsed)}
254
- className="absolute top-4 -right-3 z-10 bg-white border border-gray-200 rounded-full p-1 hover:bg-gray-50"
255
- >
256
- {sidebarCollapsed ? (
257
- <ChevronRight size={20} />
258
- ) : (
259
- <ChevronLeft size={20} />
260
- )}
261
- </button>
262
-
263
- {!sidebarCollapsed && (
264
- <>
265
- <div className="p-4 border-b border-gray-200">
266
- <div className="space-y-3">
267
- <div className="flex items-center justify-between">
268
- <h2 className="text-lg font-semibold text-gray-900">
269
- Deployment
270
- </h2>
271
- <StatusPill status={status} />
272
- </div>
273
-
274
- <div className="space-y-2">
275
- <div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2">
276
- <span className="text-xs text-gray-500 uppercase tracking-wide">
277
- ID
278
- </span>
279
- <PrefetchPageLink
280
- href={`/build/${build.package_build_id}`}
281
- className="font-mono text-sm text-gray-900 bg-gray-100 px-2 py-1 rounded"
282
- >
283
- {build.package_build_id}
284
- </PrefetchPageLink>
285
- </div>
286
-
287
- <div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2">
288
- <span className="text-xs text-gray-500 uppercase tracking-wide">
289
- Commit
290
- </span>
291
- <PrefetchPageLink
292
- href={`https://github.com/${build.commit_author}/tscircuit.com/commit/${build.commit_message}`}
293
- className="font-mono text-xs text-gray-600 bg-gray-50 px-2 text-right py-1 rounded line-clamp-1"
294
- >
295
- {build.commit_message}
296
- </PrefetchPageLink>
297
- </div>
298
-
299
- <div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2">
300
- <span className="text-xs text-gray-500 uppercase tracking-wide">
301
- Status
302
- </span>
303
- <span
304
- className={`text-xs font-medium px-2 py-1 rounded-full capitalize ${
305
- status === "success"
306
- ? "bg-emerald-100 text-emerald-800"
307
- : status === "failed"
308
- ? "bg-red-100 text-red-800"
309
- : status === "building"
310
- ? "bg-blue-100 text-blue-800"
311
- : "bg-gray-100 text-gray-800"
312
- }`}
313
- >
314
- {status}
315
- </span>
316
- </div>
317
- </div>
318
- </div>
319
- </div>
320
-
321
- <div className="flex-1 overflow-hidden">
322
- <div className="px-4 py-3 border-b border-gray-200">
323
- <h3 className="text-sm font-semibold text-gray-900">
324
- Files
325
- </h3>
326
- <p className="text-xs text-gray-500 mt-1">
327
- {buildFiles.length} file
328
- {buildFiles.length !== 1 ? "s" : ""}
329
- </p>
330
- </div>
331
- <div className="px-2 py-2 overflow-y-auto select-none">
332
- <TreeView
333
- selectedItemId={selectedItemId || ""}
334
- setSelectedItemId={(v) => setSelectedItemId(v || "")}
335
- data={treeData}
336
- className="w-full"
337
- onSelectChange={(item) => {
338
- if (item && !item.children) {
339
- setSelectedFile(item.id)
340
- }
341
- }}
342
- />
343
- </div>
344
- </div>
345
- </>
346
- )}
347
- </aside>
348
-
349
- <main className="flex-1 overflow-y-auto">
350
- <div className="flex flex-col h-full overflow-h-hidden">
351
- {status === "success" ? (
352
- <SuspenseRunFrame
353
- fsMap={buildFsMap}
354
- mainComponentPath={selectedFile ?? "index.tsx"}
355
- showRunButton={false}
356
- className="[&>div]:overflow-y-hidden"
357
- />
358
- ) : (
359
- <div className="flex-1 flex items-center justify-center">
360
- {status === "building" ? (
361
- <div className="flex flex-col items-center gap-3 text-gray-500">
362
- <Loader2 className="w-6 h-6 animate-spin" />
363
- <p>Building…</p>
364
- </div>
365
- ) : status === "failed" ? (
366
- <div className="text-center">
367
- <p className="text-red-600 font-medium mb-2">
368
- Build Failed
369
- </p>
370
- </div>
371
- ) : null}
372
- </div>
373
- )}
374
- </div>
375
- </main>
376
- </div>
377
- </div>
378
- </>
379
- )
380
- }