@tscircuit/fake-snippets 0.0.66 → 0.0.67

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 (73) hide show
  1. package/bun-tests/fake-snippets-api/fixtures/get-circuit-json.ts +5 -143
  2. package/bun-tests/fake-snippets-api/fixtures/get-test-server.ts +1 -4
  3. package/bun-tests/fake-snippets-api/fixtures/start-server.ts +7 -3
  4. package/bun-tests/fake-snippets-api/routes/order_quotes/create.test.ts +20 -56
  5. package/bun-tests/fake-snippets-api/routes/package_files/create_or_update.test.ts +2 -2
  6. package/bun-tests/fake-snippets-api/routes/package_releases/update.test.ts +1 -1
  7. package/bun-tests/fake-snippets-api/routes/packages/images.test.ts +0 -11
  8. package/bun.lock +15 -17
  9. package/dist/bundle.js +32 -39
  10. package/fake-snippets-api/routes/api/order_quotes/create.ts +30 -37
  11. package/fake-snippets-api/routes/api/order_quotes/get.ts +5 -8
  12. package/package.json +4 -3
  13. package/src/App.tsx +0 -7
  14. package/src/ContextProviders.tsx +2 -0
  15. package/src/components/DownloadButtonAndMenu.tsx +1 -4
  16. package/src/components/Footer.tsx +5 -2
  17. package/src/components/HeaderLogin.tsx +37 -54
  18. package/src/components/ImageWithFallback.tsx +37 -0
  19. package/src/components/JLCPCBImportDialog.tsx +43 -24
  20. package/src/components/PackageCard.tsx +2 -2
  21. package/src/components/{SnippetLink.tsx → PackageLink.tsx} +8 -16
  22. package/src/components/PackageSearchResults.tsx +87 -0
  23. package/src/components/PackagesList.tsx +3 -3
  24. package/src/components/PageSearchComponent.tsx +9 -9
  25. package/src/components/ViewPackagePage/components/ShikiCodeViewer.tsx +5 -28
  26. package/src/components/ViewPackagePage/components/main-content-header.tsx +8 -8
  27. package/src/components/ViewPackagePage/components/mobile-sidebar.tsx +24 -14
  28. package/src/components/ViewPackagePage/components/package-header.tsx +6 -1
  29. package/src/components/package-port/CodeEditor.tsx +13 -10
  30. package/src/components/package-port/CodeEditorHeader.tsx +1 -1
  31. package/src/components/package-port/EditorNav.tsx +2 -2
  32. package/src/hooks/use-global-store.ts +1 -0
  33. package/src/hooks/use-shiki-highlighter.ts +13 -6
  34. package/src/lib/download-fns/download-gltf.ts +3 -10
  35. package/src/lib/handleManualEditsImport.tsx +1 -1
  36. package/src/lib/types.ts +4 -2
  37. package/src/pages/dashboard.tsx +3 -4
  38. package/src/pages/editor.tsx +20 -14
  39. package/src/pages/latest.tsx +25 -26
  40. package/src/pages/search.tsx +120 -19
  41. package/src/pages/trending.tsx +14 -58
  42. package/src/pages/user-profile.tsx +13 -8
  43. package/bun-tests/fake-snippets-api/routes/snippets/add_star.test.ts +0 -84
  44. package/bun-tests/fake-snippets-api/routes/snippets/create.test.ts +0 -53
  45. package/bun-tests/fake-snippets-api/routes/snippets/delete.test.ts +0 -82
  46. package/bun-tests/fake-snippets-api/routes/snippets/download.test.ts +0 -90
  47. package/bun-tests/fake-snippets-api/routes/snippets/generate_from_jlcpcb.test.ts +0 -16
  48. package/bun-tests/fake-snippets-api/routes/snippets/get.test.ts +0 -163
  49. package/bun-tests/fake-snippets-api/routes/snippets/get_image.test.ts +0 -117
  50. package/bun-tests/fake-snippets-api/routes/snippets/images.test.ts +0 -114
  51. package/bun-tests/fake-snippets-api/routes/snippets/list.test.ts +0 -169
  52. package/bun-tests/fake-snippets-api/routes/snippets/list_newest.test.ts +0 -50
  53. package/bun-tests/fake-snippets-api/routes/snippets/list_trending.test.ts +0 -72
  54. package/bun-tests/fake-snippets-api/routes/snippets/remove_star.test.ts +0 -80
  55. package/bun-tests/fake-snippets-api/routes/snippets/search.test.ts +0 -75
  56. package/bun-tests/fake-snippets-api/routes/snippets/star-count.test.ts +0 -51
  57. package/bun-tests/fake-snippets-api/routes/snippets/update.test.ts +0 -175
  58. package/src/components/AiChatInterface.tsx +0 -229
  59. package/src/components/CodeAndPreview.tsx +0 -289
  60. package/src/components/CodeEditor.tsx +0 -539
  61. package/src/components/CodeEditorHeader.tsx +0 -135
  62. package/src/components/EditorNav.tsx +0 -502
  63. package/src/components/PreviewContent.tsx +0 -372
  64. package/src/components/SnippetCard.tsx +0 -159
  65. package/src/components/SnippetList.tsx +0 -71
  66. package/src/hooks/use-compiled-tsx.ts +0 -37
  67. package/src/hooks/use-run-tsx/construct-circuit.tsx +0 -62
  68. package/src/hooks/use-run-tsx/index.tsx +0 -256
  69. package/src/hooks/use-save-snippet.ts +0 -66
  70. package/src/hooks/use-typecheck.ts +0 -54
  71. package/src/lib/utils/getSyntaxError.ts +0 -13
  72. package/src/pages/ai.tsx +0 -92
  73. package/src/pages/view-snippet.tsx +0 -166
@@ -1,166 +0,0 @@
1
- import { DownloadButtonAndMenu } from "@/components/DownloadButtonAndMenu"
2
- import Header from "@/components/Header"
3
- import { Button } from "@/components/ui/button"
4
- import ViewSnippetHeader from "@/components/ViewSnippetHeader"
5
- import ViewSnippetSidebar from "@/components/ViewSnippetSidebar"
6
- import { useCurrentSnippet } from "@/hooks/use-current-snippet"
7
- import { useRunTsx } from "@/hooks/use-run-tsx"
8
- import { encodeTextToUrlHash } from "@/lib/encodeTextToUrlHash"
9
- import { Share } from "lucide-react"
10
- import { useParams } from "wouter"
11
- import { PreviewContent } from "@/components/PreviewContent"
12
- import Footer from "@/components/Footer"
13
- import { Helmet } from "react-helmet-async"
14
- import type { AnyCircuitElement } from "circuit-json"
15
- import StaticViewSnippetHeader from "../components/StaticViewSnippetHeader"
16
- import StaticPreviewContent from "../components/StaticPreviewContent"
17
- import StaticViewSnippetSidebar from "../components/StaticViewSnippetSidebar"
18
- import { useEffect, useMemo, useState } from "react"
19
- import { parseJsonOrNull } from "@/lib/utils/parseJsonOrNull"
20
-
21
- export const ViewSnippetPage = () => {
22
- const { author, snippetName } = useParams()
23
- const { snippet, error: snippetError, isLoading } = useCurrentSnippet()
24
-
25
- const [manualEditsFileContent, setManualEditsFileContent] = useState<
26
- string | null
27
- >(null)
28
-
29
- useEffect(() => {
30
- if (snippet?.manual_edits_json_content) {
31
- setManualEditsFileContent(snippet.manual_edits_json_content ?? "")
32
- }
33
- }, [Boolean(snippet?.manual_edits_json_content)])
34
-
35
- const userImports = useMemo(
36
- () => ({
37
- "./manual-edits.json": parseJsonOrNull(manualEditsFileContent) ?? "",
38
- }),
39
- [manualEditsFileContent],
40
- )
41
-
42
- const {
43
- circuitJson: tsxResultCircuitJson,
44
- message,
45
- triggerRunTsx,
46
- isRunningCode,
47
- tsxRunTriggerCount,
48
- circuitJsonKey: tsxResultCircuitJsonKey,
49
- } = useRunTsx({
50
- code: snippet?.code ?? "",
51
- type: snippet?.snippet_type,
52
- userImports,
53
- circuitDisplayName: snippet?.name,
54
- })
55
-
56
- const circuitJsonForPreview = tsxResultCircuitJson ?? snippet?.circuit_json
57
- const circuitJsonKeyForPreview = tsxResultCircuitJson
58
- ? tsxResultCircuitJsonKey
59
- : snippet?.circuit_json
60
- ? "snippet"
61
- : ""
62
-
63
- return (
64
- <>
65
- <Helmet>
66
- <title>{`${author}/${snippetName} - tscircuit`}</title>
67
- {snippet && (
68
- <>
69
- <meta
70
- property="og:title"
71
- content={`${author}/${snippetName} - tscircuit`}
72
- />
73
- <meta
74
- property="og:image"
75
- content={`https://registry-api.tscircuit.com/snippets/images/${author}/${snippetName}/pcb.png`}
76
- />
77
- <meta name="twitter:card" content="summary_large_image" />
78
- <meta
79
- name="twitter:image"
80
- content={`https://registry-api.tscircuit.com/snippets/images/${author}/${snippetName}/pcb.png`}
81
- />
82
- </>
83
- )}
84
- </Helmet>
85
- <div>
86
- <Header />
87
- {isLoading && (
88
- <>
89
- <StaticViewSnippetHeader
90
- author={author as string}
91
- snippetName={snippetName as string}
92
- />
93
- <div className="flex flex-row min-h-full">
94
- <div className="flex-grow overflow-auto">
95
- <StaticPreviewContent />
96
- </div>
97
- <StaticViewSnippetSidebar />
98
- </div>
99
- </>
100
- )}
101
- {snippetError && snippetError.status === 404 && (
102
- <div className="text-gray-500 flex items-center justify-center h-64">
103
- Snippet not found: {author}/{snippetName}
104
- </div>
105
- )}
106
- {snippetError && snippetError.status !== 404 && (
107
- <div>Error: {snippetError.toString()}</div>
108
- )}
109
- {snippet && (
110
- <>
111
- <ViewSnippetHeader />
112
- <div className="flex flex-row min-h-full">
113
- <div className="flex-grow overflow-auto">
114
- <PreviewContent
115
- className="h-full"
116
- code={snippet?.code ?? ""}
117
- triggerRunTsx={triggerRunTsx}
118
- tsxRunTriggerCount={tsxRunTriggerCount}
119
- errorMessage={message}
120
- circuitJson={circuitJsonForPreview}
121
- circuitJsonKey={circuitJsonKeyForPreview}
122
- isRunningCode={isRunningCode}
123
- showCodeTab={true}
124
- showJsonTab={false}
125
- showImportAndFormatButtons={false}
126
- readOnly
127
- headerClassName="p-4 border-b border-gray-200"
128
- leftHeaderContent={
129
- <>
130
- <Button
131
- variant="outline"
132
- size="sm"
133
- className="h-6 px-2 text-xs"
134
- onClick={() => {
135
- if (!snippet) return
136
- const url = encodeTextToUrlHash(snippet.code)
137
- navigator.clipboard.writeText(url)
138
- alert("URL copied to clipboard!")
139
- }}
140
- >
141
- <Share className="mr-1 h-3 w-3" />
142
- Copy URL
143
- </Button>
144
- <DownloadButtonAndMenu
145
- snippetUnscopedName={snippet?.unscoped_name}
146
- circuitJson={
147
- circuitJsonForPreview as AnyCircuitElement[]
148
- }
149
- className="hidden md:flex"
150
- />
151
- </>
152
- }
153
- isStreaming={false}
154
- onCodeChange={() => {}}
155
- onDtsChange={() => {}}
156
- />
157
- </div>
158
- <ViewSnippetSidebar />
159
- </div>
160
- </>
161
- )}
162
- <Footer />
163
- </div>
164
- </>
165
- )
166
- }