@tscircuit/fake-snippets 0.0.73 → 0.0.75

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 (34) hide show
  1. package/dist/bundle.js +250 -202
  2. package/dist/index.d.ts +72 -2
  3. package/dist/index.js +24 -7
  4. package/dist/schema.d.ts +112 -0
  5. package/dist/schema.js +18 -1
  6. package/fake-snippets-api/lib/db/db-client.ts +11 -7
  7. package/fake-snippets-api/lib/db/schema.ts +25 -0
  8. package/fake-snippets-api/routes/api/package_releases/rebuild.ts +32 -0
  9. package/fake-snippets-api/routes/api/package_releases/update.ts +4 -1
  10. package/package.json +1 -1
  11. package/src/components/DownloadButtonAndMenu.tsx +26 -8
  12. package/src/components/Header.tsx +7 -7
  13. package/src/components/PackageBuildsPage/ErrorObject.ts +12 -0
  14. package/src/components/PackageBuildsPage/LogContent.tsx +32 -0
  15. package/src/components/PackageBuildsPage/PackageBuildDetailsPage.tsx +114 -0
  16. package/src/components/PackageBuildsPage/build-preview-content.tsx +21 -5
  17. package/src/components/PackageBuildsPage/capitalCase.ts +4 -0
  18. package/src/components/PackageBuildsPage/collapsible-section.tsx +34 -9
  19. package/src/components/PackageBuildsPage/getColorForDisplayStatus.ts +17 -0
  20. package/src/components/PackageBuildsPage/package-build-details-panel.tsx +147 -0
  21. package/src/components/PackageBuildsPage/{deployment-header.tsx → package-build-header.tsx} +16 -31
  22. package/src/components/ViewPackagePage/components/main-content-header.tsx +1 -1
  23. package/src/components/ViewPackagePage/components/package-header.tsx +0 -1
  24. package/src/components/dialogs/pcb-download-dialog.tsx +113 -0
  25. package/src/components/package-port/CodeAndPreview.tsx +3 -2
  26. package/src/components/package-port/CodeEditor.tsx +4 -2
  27. package/src/hooks/use-create-package-mutation.ts +0 -7
  28. package/src/hooks/use-current-package-release.ts +28 -0
  29. package/src/hooks/useFileManagement.ts +26 -21
  30. package/src/lib/download-fns/download-pcb-svg.ts +35 -0
  31. package/src/lib/utils/timeAgo.ts +14 -3
  32. package/src/pages/package-builds.tsx +2 -2
  33. package/src/components/PackageBuildsPage/DeploymentDetailsPage.tsx +0 -56
  34. package/src/components/PackageBuildsPage/deployment-details-panel.tsx +0 -84
@@ -164,9 +164,9 @@ export function CodeAndPreview({ pkg }: Props) {
164
164
  )
165
165
  }
166
166
 
167
- if ((!pkg && urlParams.package_id) || isLoading) {
167
+ if (urlParams.package_id && (!pkg || isLoading)) {
168
168
  return (
169
- <div className="flex items-center justify-center h-64">
169
+ <div className="flex items-center justify-center h-[60vh]">
170
170
  <div className="flex flex-col items-center justify-center">
171
171
  <div className="text-lg text-gray-500 mb-4">Loading</div>
172
172
  <Loader2 className="w-16 h-16 animate-spin text-gray-400" />
@@ -200,6 +200,7 @@ export function CodeAndPreview({ pkg }: Props) {
200
200
  )}
201
201
  >
202
202
  <CodeEditor
203
+ isSaving={isSaving}
203
204
  handleCreateFile={createFile}
204
205
  handleDeleteFile={deleteFile}
205
206
  currentFile={currentFile}
@@ -49,6 +49,7 @@ export const CodeEditor = ({
49
49
  onCodeChange,
50
50
  readOnly = false,
51
51
  files = [],
52
+ isSaving = false,
52
53
  isStreaming = false,
53
54
  showImportAndFormatButtons = true,
54
55
  onFileContentChanged,
@@ -60,6 +61,7 @@ export const CodeEditor = ({
60
61
  }: {
61
62
  onCodeChange: (code: string, filename?: string) => void
62
63
  files: PackageFile[]
64
+ isSaving?: boolean
63
65
  handleCreateFile: (props: ICreateFileProps) => ICreateFileResult
64
66
  handleDeleteFile: (props: IDeleteFileProps) => IDeleteFileResult
65
67
  readOnly?: boolean
@@ -242,7 +244,7 @@ export const CodeEditor = ({
242
244
  ? json()
243
245
  : javascript({ typescript: true, jsx: true }),
244
246
  keymap.of([indentWithTab]),
245
- EditorState.readOnly.of(readOnly),
247
+ EditorState.readOnly.of(readOnly || isSaving),
246
248
  EditorView.updateListener.of((update) => {
247
249
  if (update.docChanged) {
248
250
  const newContent = update.state.doc.toString()
@@ -448,7 +450,7 @@ export const CodeEditor = ({
448
450
  return () => {
449
451
  view.destroy()
450
452
  }
451
- }, [!isStreaming, currentFile, code !== "", Boolean(highlighter)])
453
+ }, [!isStreaming, currentFile, code !== "", Boolean(highlighter), isSaving])
452
454
 
453
455
  const updateCurrentEditorContent = (newContent: string) => {
454
456
  if (viewRef.current) {
@@ -2,7 +2,6 @@ import type { Package } from "fake-snippets-api/lib/db/schema"
2
2
  import { useMutation } from "react-query"
3
3
  import { useAxios } from "./use-axios"
4
4
  import { useGlobalStore } from "./use-global-store"
5
- import { useUrlParams } from "./use-url-params"
6
5
 
7
6
  export const useCreatePackageMutation = ({
8
7
  onSuccess,
@@ -42,13 +41,7 @@ export const useCreatePackageMutation = ({
42
41
  },
43
42
  {
44
43
  onSuccess: (pkg: Package) => {
45
- const url = new URL(window.location.href)
46
- url.searchParams.set("package_id", pkg.package_id)
47
- url.searchParams.delete("template")
48
- url.searchParams.delete("should_create_package")
49
- window.history.pushState({}, "", url.toString())
50
44
  onSuccess?.(pkg)
51
- window.dispatchEvent(new Event("popstate"))
52
45
  },
53
46
  onError: (error: any) => {
54
47
  console.error("Error creating package:", error)
@@ -0,0 +1,28 @@
1
+ import { useParams } from "wouter"
2
+ import { useCurrentPackageId } from "./use-current-package-id"
3
+ import { useUrlParams } from "./use-url-params"
4
+ import { usePackageRelease } from "./use-package-release"
5
+
6
+ export const useCurrentPackageRelease = () => {
7
+ const { packageId } = useCurrentPackageId()
8
+ const urlParams = useUrlParams()
9
+ const { author, packageName } = useParams()
10
+
11
+ const version = urlParams.version
12
+ const releaseId = urlParams.package_release_id
13
+
14
+ let query: Parameters<typeof usePackageRelease>[0] | null = null
15
+
16
+ if (releaseId) {
17
+ query = { package_release_id: releaseId }
18
+ } else if (version && author && packageName) {
19
+ query = { package_name_with_version: `${author}/${packageName}@${version}` }
20
+ } else if (author && packageName) {
21
+ query = { package_name: `${author}/${packageName}`, is_latest: true }
22
+ } else if (packageId) {
23
+ query = { package_id: packageId, is_latest: true }
24
+ }
25
+
26
+ const { data: packageRelease, ...rest } = usePackageRelease(query)
27
+ return { packageRelease, ...rest }
28
+ }
@@ -91,7 +91,31 @@ export function useFileManagement({
91
91
  })
92
92
  },
93
93
  })
94
- const createPackageMutation = useCreatePackageMutation()
94
+ const createPackageMutation = useCreatePackageMutation({
95
+ onSuccess: (newPackage) => {
96
+ createRelease(
97
+ {
98
+ package_name_with_version: `${newPackage.name}@latest`,
99
+ },
100
+ {
101
+ onSuccess: () => {
102
+ updatePackageFilesMutation.mutate({
103
+ package_name_with_version: `${newPackage.name}@latest`,
104
+ ...newPackage,
105
+ })
106
+ const url = new URL(window.location.href)
107
+ url.searchParams.set("package_id", newPackage.package_id)
108
+ url.searchParams.delete("template")
109
+ url.searchParams.delete("should_create_package")
110
+ window.history.pushState({}, "", url.toString())
111
+ window.dispatchEvent(new Event("popstate"))
112
+ updateLastUpdated()
113
+ setInitialFiles([...localFiles])
114
+ },
115
+ },
116
+ )
117
+ },
118
+ })
95
119
 
96
120
  useEffect(() => {
97
121
  if (!currentPackage || isLoadingPackageFilesWithContent) {
@@ -204,29 +228,10 @@ export function useFileManagement({
204
228
  return
205
229
  }
206
230
 
207
- const newPackage = await createPackageMutation.mutateAsync({
231
+ await createPackageMutation.mutateAsync({
208
232
  name: `${loggedInUser?.github_username}/${generateRandomPackageName()}`,
209
233
  is_private: isPrivate,
210
234
  })
211
-
212
- if (newPackage) {
213
- createRelease(
214
- {
215
- package_name_with_version: `${newPackage.name}@latest`,
216
- },
217
- {
218
- onSuccess: () => {
219
- updatePackageFilesMutation.mutate({
220
- package_name_with_version: `${newPackage.name}@latest`,
221
- ...newPackage,
222
- })
223
- updateLastUpdated()
224
- setInitialFiles([...localFiles])
225
- },
226
- },
227
- )
228
- }
229
- updateLastUpdated()
230
235
  }
231
236
 
232
237
  const saveFiles = () => {
@@ -0,0 +1,35 @@
1
+ import { AnyCircuitElement } from "circuit-json"
2
+ import { convertCircuitJsonToPcbSvg } from "circuit-to-svg"
3
+ import { saveAs } from "file-saver"
4
+
5
+ export interface DownloadPcbSvgOptions {
6
+ layer?: "all" | "top" | "bottom"
7
+ drawPaddingOutsideBoard?: boolean
8
+ backgroundColor?: string
9
+ matchAspectRatio?: boolean
10
+ }
11
+
12
+ export const downloadPcbSvg = (
13
+ circuitJson: AnyCircuitElement[],
14
+ fileName: string,
15
+ options: DownloadPcbSvgOptions = {},
16
+ ) => {
17
+ const convertOptions: any = {}
18
+ if (options.layer && options.layer !== "all") {
19
+ convertOptions.layer = options.layer
20
+ }
21
+ if (options.matchAspectRatio) {
22
+ convertOptions.matchBoardAspectRatio = true
23
+ }
24
+ if (typeof options.drawPaddingOutsideBoard === "boolean") {
25
+ convertOptions.drawPaddingOutsideBoard = options.drawPaddingOutsideBoard
26
+ }
27
+ if (options.backgroundColor) {
28
+ convertOptions.backgroundColor = options.backgroundColor
29
+ }
30
+
31
+ const svg = convertCircuitJsonToPcbSvg(circuitJson, convertOptions)
32
+
33
+ const blob = new Blob([svg], { type: "image/svg+xml" })
34
+ saveAs(blob, fileName + ".svg")
35
+ }
@@ -3,7 +3,18 @@ import en from "javascript-time-ago/locale/en"
3
3
 
4
4
  TimeAgo.addDefaultLocale(en)
5
5
 
6
- export const timeAgo = (date: Date) => {
7
- const timeAgo = new TimeAgo("en-US")
8
- return timeAgo.format(date)
6
+ export const timeAgo = (
7
+ date: Date | string | null | undefined,
8
+ fallback = "???",
9
+ ) => {
10
+ if (!date) return fallback
11
+ if (typeof date === "string") {
12
+ date = new Date(date)
13
+ }
14
+ try {
15
+ const timeAgo = new TimeAgo("en-US")
16
+ return timeAgo.format(date)
17
+ } catch (error) {
18
+ return fallback
19
+ }
9
20
  }
@@ -6,7 +6,7 @@ import { Helmet } from "react-helmet-async"
6
6
  import { useCurrentPackageId } from "@/hooks/use-current-package-id"
7
7
  import { NotFound } from "@/components/NotFound"
8
8
  import { ErrorOutline } from "@/components/ErrorOutline"
9
- import { DeploymentDetailsPage } from "@/components/PackageBuildsPage/DeploymentDetailsPage"
9
+ import { PackageBuildDetailsPage } from "@/components/PackageBuildsPage/PackageBuildDetailsPage"
10
10
 
11
11
  export const EditorPage = () => {
12
12
  const { packageId } = useCurrentPackageId()
@@ -26,7 +26,7 @@ export const EditorPage = () => {
26
26
  )}
27
27
  </Helmet>
28
28
  <Header />
29
- <DeploymentDetailsPage />
29
+ <PackageBuildDetailsPage />
30
30
  <Footer />
31
31
  </div>
32
32
  )
@@ -1,56 +0,0 @@
1
- "use client"
2
-
3
- import { useState } from "react"
4
- import { BuildPreviewContent } from "./build-preview-content"
5
- import { DeploymentDetailsPanel } from "./deployment-details-panel"
6
- import { DeploymentHeader } from "./deployment-header"
7
- import { CollapsibleSection } from "./collapsible-section"
8
-
9
- export const DeploymentDetailsPage = () => {
10
- const [openSections, setOpenSections] = useState<Record<string, boolean>>({})
11
-
12
- const toggleSection = (section: string) => {
13
- setOpenSections((prev) => ({
14
- ...prev,
15
- [section]: !prev[section],
16
- }))
17
- }
18
-
19
- return (
20
- <div className="min-h-screen bg-gray-50 text-gray-900">
21
- <DeploymentHeader />
22
-
23
- <div className="px-6 py-6 container mx-auto">
24
- {/* Main Content */}
25
- <div className="grid grid-cols-1 lg:grid-cols-3 gap-6 mb-8 items-start">
26
- {/* Preview Section */}
27
- <div className="lg:col-span-2">
28
- <div className="bg-white border border-gray-200 rounded-lg p-4 flex items-center justify-center max-h-[420px]">
29
- <BuildPreviewContent />
30
- </div>
31
- </div>
32
-
33
- {/* Details Panel */}
34
- <DeploymentDetailsPanel />
35
- </div>
36
-
37
- {/* Collapsible Sections */}
38
- <div className="space-y-4 mb-8">
39
- <CollapsibleSection
40
- title="Transpilation Logs"
41
- duration="1m 15s"
42
- isOpen={openSections.summary}
43
- onToggle={() => toggleSection("summary")}
44
- />
45
-
46
- <CollapsibleSection
47
- title="Circuit JSON Build Logs"
48
- duration="2m 29s"
49
- isOpen={openSections.logs}
50
- onToggle={() => toggleSection("logs")}
51
- />
52
- </div>
53
- </div>
54
- </div>
55
- )
56
- }
@@ -1,84 +0,0 @@
1
- import { Globe, GitBranch, GitCommit, Clock } from "lucide-react"
2
- import { Badge } from "@/components/ui/badge"
3
-
4
- export function DeploymentDetailsPanel() {
5
- return (
6
- <div className="space-y-6 bg-white p-4 border border-gray-200 rounded-lg">
7
- {/* Created */}
8
- <div>
9
- <h3 className="text-sm font-medium text-gray-600 mb-2">Created</h3>
10
- <div className="flex items-center gap-2">
11
- <div className="w-6 h-6 bg-orange-500 rounded-full flex items-center justify-center text-xs font-bold">
12
- I
13
- </div>
14
- <span className="text-sm">imrishabh18</span>
15
- <span className="text-sm text-gray-500">48m ago</span>
16
- </div>
17
- </div>
18
-
19
- {/* Status */}
20
- <div>
21
- <h3 className="text-sm font-medium text-gray-600 mb-2">Status</h3>
22
- <div className="flex items-center gap-2">
23
- <div className="w-2 h-2 bg-green-500 rounded-full"></div>
24
- <span className="text-sm">Ready</span>
25
- <Badge
26
- variant="secondary"
27
- className="bg-gray-200 text-gray-700 text-xs"
28
- >
29
- Latest
30
- </Badge>
31
- </div>
32
- </div>
33
-
34
- {/* Time to Ready */}
35
- <div>
36
- <h3 className="text-sm font-medium text-gray-600 mb-2">
37
- Time to Ready
38
- </h3>
39
- <div className="flex items-center gap-2">
40
- <Clock className="w-4 h-4 text-gray-500" />
41
- <span className="text-sm">1m 3s</span>
42
- <span className="text-sm text-gray-500">47m ago</span>
43
- </div>
44
- </div>
45
-
46
- {/* Version */}
47
- <div>
48
- <h3 className="text-sm font-medium text-gray-600 mb-2">Version</h3>
49
- <div className="flex items-center gap-2">
50
- <Globe className="w-4 h-4 text-gray-500" />
51
- <span className="text-sm">v1.0.3</span>
52
- <Badge variant="default" className="bg-blue-600 text-white text-xs">
53
- Current
54
- </Badge>
55
- </div>
56
- </div>
57
-
58
- {/* Outputs */}
59
- <div>
60
- <h3 className="text-sm font-medium text-gray-600 mb-2">Outputs</h3>
61
- <div>
62
- <span className="text-sm text-gray-400">None</span>
63
- </div>
64
- </div>
65
-
66
- {/* Source */}
67
- <div>
68
- <h3 className="text-sm font-medium text-gray-600 mb-2">Source</h3>
69
- <div className="space-y-2">
70
- <div className="flex items-center gap-2">
71
- <GitBranch className="w-4 h-4 text-gray-500" />
72
- <span className="text-sm">main</span>
73
- </div>
74
- <div className="flex items-center gap-2">
75
- <GitCommit className="w-4 h-4 text-gray-500" />
76
- <span className="text-sm text-gray-500">
77
- edfdc67 support empty file creation (#356)
78
- </span>
79
- </div>
80
- </div>
81
- </div>
82
- </div>
83
- )
84
- }