@tscircuit/fake-snippets 0.0.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.
Files changed (396) hide show
  1. package/.github/CODEOWNERS +1 -0
  2. package/.github/workflows/bun-formatcheck.yml +26 -0
  3. package/.github/workflows/bun-test.yml +28 -0
  4. package/.github/workflows/bun-typecheck.yml +26 -0
  5. package/.github/workflows/bundle-size-analysis.yml +79 -0
  6. package/.github/workflows/playwright-test.yml +37 -0
  7. package/.github/workflows/stale.yml +40 -0
  8. package/.github/workflows/update-snapshots.yml +49 -0
  9. package/CONTRIBUTING.md +59 -0
  10. package/LICENSE +21 -0
  11. package/README.md +113 -0
  12. package/biome.json +60 -0
  13. package/bun-tests/fake-snippets-api/fixtures/get-circuit-json.ts +148 -0
  14. package/bun-tests/fake-snippets-api/fixtures/get-test-server.ts +96 -0
  15. package/bun-tests/fake-snippets-api/fixtures/start-server.ts +44 -0
  16. package/bun-tests/fake-snippets-api/routes/accounts/get_account_balance.test.ts +18 -0
  17. package/bun-tests/fake-snippets-api/routes/health.test.ts +9 -0
  18. package/bun-tests/fake-snippets-api/routes/order_files/get.test.ts +48 -0
  19. package/bun-tests/fake-snippets-api/routes/order_files/upload.test.ts +77 -0
  20. package/bun-tests/fake-snippets-api/routes/orders/create.test.ts +19 -0
  21. package/bun-tests/fake-snippets-api/routes/orders/get.test.ts +38 -0
  22. package/bun-tests/fake-snippets-api/routes/orders/list.test.ts +30 -0
  23. package/bun-tests/fake-snippets-api/routes/orders/update.test.ts +46 -0
  24. package/bun-tests/fake-snippets-api/routes/snippets/add_star.test.ts +114 -0
  25. package/bun-tests/fake-snippets-api/routes/snippets/create.test.ts +28 -0
  26. package/bun-tests/fake-snippets-api/routes/snippets/delete.test.ts +106 -0
  27. package/bun-tests/fake-snippets-api/routes/snippets/download.test.ts +90 -0
  28. package/bun-tests/fake-snippets-api/routes/snippets/generate_from_jlcpcb.test.ts +25 -0
  29. package/bun-tests/fake-snippets-api/routes/snippets/get_image.test.ts +113 -0
  30. package/bun-tests/fake-snippets-api/routes/snippets/images.test.ts +112 -0
  31. package/bun-tests/fake-snippets-api/routes/snippets/list.test.ts +62 -0
  32. package/bun-tests/fake-snippets-api/routes/snippets/list_newest.test.ts +48 -0
  33. package/bun-tests/fake-snippets-api/routes/snippets/list_trending.test.ts +69 -0
  34. package/bun-tests/fake-snippets-api/routes/snippets/remove_star.test.ts +110 -0
  35. package/bun-tests/fake-snippets-api/routes/snippets/search.test.ts +75 -0
  36. package/bun-tests/fake-snippets-api/routes/snippets/star-count.test.ts +44 -0
  37. package/bun-tests/fake-snippets-api/routes/snippets/update.test.ts +116 -0
  38. package/bun-tests/parts-engine.test.ts +18 -0
  39. package/bun.lockb +0 -0
  40. package/bunfig.toml +2 -0
  41. package/components.json +20 -0
  42. package/dist/assets/editor_example_1-1000w.webp +0 -0
  43. package/dist/assets/editor_example_1-1200w.webp +0 -0
  44. package/dist/assets/editor_example_1-1600w.webp +0 -0
  45. package/dist/assets/editor_example_1-2000w.webp +0 -0
  46. package/dist/assets/editor_example_1-400w.webp +0 -0
  47. package/dist/assets/editor_example_1-600w.webp +0 -0
  48. package/dist/assets/editor_example_1-800w.webp +0 -0
  49. package/dist/assets/editor_example_1_more_square-1000w.webp +0 -0
  50. package/dist/assets/editor_example_1_more_square-1200w.webp +0 -0
  51. package/dist/assets/editor_example_1_more_square-1600w.webp +0 -0
  52. package/dist/assets/editor_example_1_more_square-2000w.webp +0 -0
  53. package/dist/assets/editor_example_1_more_square-400w.webp +0 -0
  54. package/dist/assets/editor_example_1_more_square-600w.webp +0 -0
  55. package/dist/assets/editor_example_1_more_square-800w.webp +0 -0
  56. package/dist/assets/editor_example_2-1000w.webp +0 -0
  57. package/dist/assets/editor_example_2-1200w.webp +0 -0
  58. package/dist/assets/editor_example_2-1600w.webp +0 -0
  59. package/dist/assets/editor_example_2-2000w.webp +0 -0
  60. package/dist/assets/editor_example_2-400w.webp +0 -0
  61. package/dist/assets/editor_example_2-600w.webp +0 -0
  62. package/dist/assets/editor_example_2-800w.webp +0 -0
  63. package/dist/assets/example_schematic-1000w.webp +0 -0
  64. package/dist/assets/example_schematic-1200w.webp +0 -0
  65. package/dist/assets/example_schematic-1600w.webp +0 -0
  66. package/dist/assets/example_schematic-2000w.webp +0 -0
  67. package/dist/assets/example_schematic-400w.webp +0 -0
  68. package/dist/assets/example_schematic-600w.webp +0 -0
  69. package/dist/assets/example_schematic-800w.webp +0 -0
  70. package/dist/bundle.js +3270 -0
  71. package/dist/robots.txt +9 -0
  72. package/dist/sitemap.xml +118 -0
  73. package/docs/CIRCUIT_JSON_SOURCE_COMPONENT_OVERVIEW.md +151 -0
  74. package/fake-snippets-api/README.md +6 -0
  75. package/fake-snippets-api/biome.json +47 -0
  76. package/fake-snippets-api/bun.lockb +0 -0
  77. package/fake-snippets-api/lib/db/autoload-dev-snippets.ts +84 -0
  78. package/fake-snippets-api/lib/db/autoload-snippets.json +24 -0
  79. package/fake-snippets-api/lib/db/db-client.ts +343 -0
  80. package/fake-snippets-api/lib/db/schema.ts +112 -0
  81. package/fake-snippets-api/lib/db/seed.ts +1608 -0
  82. package/fake-snippets-api/lib/middleware/with-ctx-error.ts +26 -0
  83. package/fake-snippets-api/lib/middleware/with-db.ts +15 -0
  84. package/fake-snippets-api/lib/middleware/with-error-handling.ts +24 -0
  85. package/fake-snippets-api/lib/middleware/with-optional-session-auth.ts +34 -0
  86. package/fake-snippets-api/lib/middleware/with-request-logging.ts +54 -0
  87. package/fake-snippets-api/lib/middleware/with-session-auth.ts +39 -0
  88. package/fake-snippets-api/lib/middleware/with-winter-spec.ts +24 -0
  89. package/fake-snippets-api/next-env.d.ts +5 -0
  90. package/fake-snippets-api/routes/api/accounts/get.ts +21 -0
  91. package/fake-snippets-api/routes/api/accounts/get_account_balance.ts +22 -0
  92. package/fake-snippets-api/routes/api/accounts/update.ts +32 -0
  93. package/fake-snippets-api/routes/api/ai/[...anyroute].ts +31 -0
  94. package/fake-snippets-api/routes/api/ai.ts +2 -0
  95. package/fake-snippets-api/routes/api/aistream/[...anyroute].ts +65 -0
  96. package/fake-snippets-api/routes/api/health.ts +9 -0
  97. package/fake-snippets-api/routes/api/internal/sessions/create_without_auth.ts +63 -0
  98. package/fake-snippets-api/routes/api/order_files/get.ts +28 -0
  99. package/fake-snippets-api/routes/api/order_files/upload.ts +43 -0
  100. package/fake-snippets-api/routes/api/orders/create.ts +41 -0
  101. package/fake-snippets-api/routes/api/orders/get.ts +28 -0
  102. package/fake-snippets-api/routes/api/orders/list.ts +15 -0
  103. package/fake-snippets-api/routes/api/orders/update.ts +50 -0
  104. package/fake-snippets-api/routes/api/snippets/add_star.ts +42 -0
  105. package/fake-snippets-api/routes/api/snippets/create.ts +55 -0
  106. package/fake-snippets-api/routes/api/snippets/delete.ts +41 -0
  107. package/fake-snippets-api/routes/api/snippets/download.ts +148 -0
  108. package/fake-snippets-api/routes/api/snippets/generate_from_jlcpcb.ts +55 -0
  109. package/fake-snippets-api/routes/api/snippets/get.ts +50 -0
  110. package/fake-snippets-api/routes/api/snippets/get_image.ts +65 -0
  111. package/fake-snippets-api/routes/api/snippets/images/[author]/[snippet_name]/[typeFormat].ts +74 -0
  112. package/fake-snippets-api/routes/api/snippets/list.ts +28 -0
  113. package/fake-snippets-api/routes/api/snippets/list_newest.ts +13 -0
  114. package/fake-snippets-api/routes/api/snippets/list_trending.ts +21 -0
  115. package/fake-snippets-api/routes/api/snippets/remove_star.ts +42 -0
  116. package/fake-snippets-api/routes/api/snippets/search.ts +18 -0
  117. package/fake-snippets-api/routes/api/snippets/update.ts +86 -0
  118. package/favicon.ico +0 -0
  119. package/index.html +23 -0
  120. package/landing.html +23 -0
  121. package/package.json +164 -0
  122. package/playwright-tests/ai-page.spec.ts +19 -0
  123. package/playwright-tests/cmd-click.spec.ts +43 -0
  124. package/playwright-tests/dashboard-page.spec.ts +10 -0
  125. package/playwright-tests/editor-page.spec.ts +15 -0
  126. package/playwright-tests/files-dialog.spec.ts +19 -0
  127. package/playwright-tests/footprint-dialog/footprint-dialog.spec.ts +27 -0
  128. package/playwright-tests/footprint-dialog/footprint-insertion.spec.ts +38 -0
  129. package/playwright-tests/footprint-dialog/footprint-preview.spec.ts +34 -0
  130. package/playwright-tests/footprint-dialog/footprint-selection.spec.ts +29 -0
  131. package/playwright-tests/handle-manual-edits.spec.ts +55 -0
  132. package/playwright-tests/home-page.spec.ts +10 -0
  133. package/playwright-tests/images.spec.ts +17 -0
  134. package/playwright-tests/manual-edits.spec.ts +89 -0
  135. package/playwright-tests/preview-page.spec.ts +14 -0
  136. package/playwright-tests/quickstart-page.spec.ts +10 -0
  137. package/playwright-tests/search-links.spec.ts +21 -0
  138. package/playwright-tests/search.spec.ts +27 -0
  139. package/playwright-tests/snapshots/ai-page.spec.ts-AI-Page-lg.png +0 -0
  140. package/playwright-tests/snapshots/ai-page.spec.ts-AI-Page-md.png +0 -0
  141. package/playwright-tests/snapshots/ai-page.spec.ts-AI-Page-xs.png +0 -0
  142. package/playwright-tests/snapshots/cmd-click.spec.ts-underlined-imports.png +0 -0
  143. package/playwright-tests/snapshots/dashboard-page.spec.ts-Dashboard-page-lg.png +0 -0
  144. package/playwright-tests/snapshots/dashboard-page.spec.ts-Dashboard-page-md.png +0 -0
  145. package/playwright-tests/snapshots/dashboard-page.spec.ts-Dashboard-page-xs.png +0 -0
  146. package/playwright-tests/snapshots/editor-page.spec.ts-editor-with-snippet.png +0 -0
  147. package/playwright-tests/snapshots/error-fallback.spec.ts-error-fallback-lg.png +0 -0
  148. package/playwright-tests/snapshots/error-fallback.spec.ts-error-fallback-md.png +0 -0
  149. package/playwright-tests/snapshots/error-fallback.spec.ts-error-fallback-xs.png +0 -0
  150. package/playwright-tests/snapshots/files-dialog.spec.ts-view-snippet-files.png +0 -0
  151. package/playwright-tests/snapshots/footprint-dialog/footprint-dialog.spec.ts-footprint-preview-lg.png +0 -0
  152. package/playwright-tests/snapshots/footprint-dialog/footprint-dialog.spec.ts-footprint-preview-md.png +0 -0
  153. package/playwright-tests/snapshots/footprint-dialog/footprint-dialog.spec.ts-footprint-preview-xs.png +0 -0
  154. package/playwright-tests/snapshots/footprint-dialog/footprint-insertion.spec.ts-footprint-insertion-lg.png +0 -0
  155. package/playwright-tests/snapshots/footprint-dialog/footprint-insertion.spec.ts-footprint-insertion-md.png +0 -0
  156. package/playwright-tests/snapshots/footprint-dialog/footprint-insertion.spec.ts-footprint-insertion-xs.png +0 -0
  157. package/playwright-tests/snapshots/footprint-dialog/footprint-preview.spec.ts-footprint-preview-lg.png +0 -0
  158. package/playwright-tests/snapshots/footprint-dialog/footprint-preview.spec.ts-footprint-preview-md.png +0 -0
  159. package/playwright-tests/snapshots/footprint-dialog/footprint-preview.spec.ts-footprint-preview-xs.png +0 -0
  160. package/playwright-tests/snapshots/footprint-dialog/footprint-selection.spec.ts-footprint-preview-lg.png +0 -0
  161. package/playwright-tests/snapshots/footprint-dialog/footprint-selection.spec.ts-footprint-preview-md.png +0 -0
  162. package/playwright-tests/snapshots/footprint-dialog/footprint-selection.spec.ts-footprint-preview-xs.png +0 -0
  163. package/playwright-tests/snapshots/handle-manual-edits.spec.ts-handle-manual-edits.png +0 -0
  164. package/playwright-tests/snapshots/home-page.spec.ts-Home-page-lg.png +0 -0
  165. package/playwright-tests/snapshots/home-page.spec.ts-Home-page-md.png +0 -0
  166. package/playwright-tests/snapshots/home-page.spec.ts-Home-page-xs.png +0 -0
  167. package/playwright-tests/snapshots/images.spec.ts-pcb-image.png +0 -0
  168. package/playwright-tests/snapshots/images.spec.ts-schematic-image.png +0 -0
  169. package/playwright-tests/snapshots/manual-edits.spec.ts-editor-manual-edits.png +0 -0
  170. package/playwright-tests/snapshots/manual-edits.spec.ts-manual-edits-view.png +0 -0
  171. package/playwright-tests/snapshots/preview-page.spec.ts-preview-snippet-pcb.png +0 -0
  172. package/playwright-tests/snapshots/preview-page.spec.ts-preview-snippet-schematic.png +0 -0
  173. package/playwright-tests/snapshots/quickstart-page.spec.ts-Quickstart-Pagelg.png +0 -0
  174. package/playwright-tests/snapshots/quickstart-page.spec.ts-Quickstart-Pagemd.png +0 -0
  175. package/playwright-tests/snapshots/quickstart-page.spec.ts-Quickstart-Pagexs.png +0 -0
  176. package/playwright-tests/snapshots/search-links.spec.ts-search-links.png +0 -0
  177. package/playwright-tests/snapshots/search.spec.ts-search-lg.png +0 -0
  178. package/playwright-tests/snapshots/search.spec.ts-search-md.png +0 -0
  179. package/playwright-tests/snapshots/search.spec.ts-search-xs.png +0 -0
  180. package/playwright-tests/snapshots/star.spec.ts-remove-star-button.png +0 -0
  181. package/playwright-tests/snapshots/star.spec.ts-star-button.png +0 -0
  182. package/playwright-tests/snapshots/update-description.spec.ts-update-description.png +0 -0
  183. package/playwright-tests/snapshots/view-snippet.spec.ts-view-snippet-after-lg.png +0 -0
  184. package/playwright-tests/snapshots/view-snippet.spec.ts-view-snippet-after-md.png +0 -0
  185. package/playwright-tests/snapshots/view-snippet.spec.ts-view-snippet-after-xs.png +0 -0
  186. package/playwright-tests/snapshots/view-snippet.spec.ts-view-snippet-before-lg.png +0 -0
  187. package/playwright-tests/snapshots/view-snippet.spec.ts-view-snippet-before-md.png +0 -0
  188. package/playwright-tests/snapshots/view-snippet.spec.ts-view-snippet-before-xs.png +0 -0
  189. package/playwright-tests/snapshots/view-snippet.spec.ts-view-snippet-files.png +0 -0
  190. package/playwright-tests/star.spec.ts +40 -0
  191. package/playwright-tests/update-description.spec.ts +18 -0
  192. package/playwright-tests/view-snippet.spec.ts +35 -0
  193. package/playwright-tests/viewports.ts +5 -0
  194. package/playwright.config.ts +27 -0
  195. package/postcss.config.js +6 -0
  196. package/public/robots.txt +9 -0
  197. package/renovate.json +24 -0
  198. package/scripts/generate-image-sizes.ts +58 -0
  199. package/scripts/generate-sitemap.ts +103 -0
  200. package/scripts/generate_bundle_stats.js +192 -0
  201. package/scripts/snapshot.ts +35 -0
  202. package/src/App.tsx +113 -0
  203. package/src/ContextProviders.tsx +9 -0
  204. package/src/assets/originals/editor_example_1.webp +0 -0
  205. package/src/assets/originals/editor_example_1_more_square.webp +0 -0
  206. package/src/assets/originals/editor_example_2.webp +0 -0
  207. package/src/assets/originals/example_schematic.webp +0 -0
  208. package/src/components/AiChatInterface.tsx +221 -0
  209. package/src/components/AiChatMessage.tsx +86 -0
  210. package/src/components/Analytics.tsx +30 -0
  211. package/src/components/BomTable.tsx +69 -0
  212. package/src/components/ChatInput.tsx +53 -0
  213. package/src/components/CircuitToSvgWithMouseControl.tsx +78 -0
  214. package/src/components/CmdKMenu.tsx +301 -0
  215. package/src/components/CodeAndPreview.tsx +258 -0
  216. package/src/components/CodeEditor.tsx +460 -0
  217. package/src/components/CodeEditorHeader.tsx +160 -0
  218. package/src/components/CreateNewSnippetWithAiHero.tsx +77 -0
  219. package/src/components/DownloadButtonAndMenu.tsx +212 -0
  220. package/src/components/EditorNav.tsx +428 -0
  221. package/src/components/ErrorFallback.tsx +25 -0
  222. package/src/components/ErrorTabContent.tsx +122 -0
  223. package/src/components/FAQ.tsx +113 -0
  224. package/src/components/Footer.tsx +134 -0
  225. package/src/components/Footer2.tsx +100 -0
  226. package/src/components/FootprintDialog.tsx +342 -0
  227. package/src/components/Header.tsx +187 -0
  228. package/src/components/Header2.tsx +135 -0
  229. package/src/components/HeaderDropdown.tsx +83 -0
  230. package/src/components/HeaderLogin.tsx +94 -0
  231. package/src/components/JLCPCBImportDialog.tsx +155 -0
  232. package/src/components/LandingHero.tsx +175 -0
  233. package/src/components/LatestSnippets.tsx +39 -0
  234. package/src/components/OptimizedImage.tsx +96 -0
  235. package/src/components/OrderPreviewContent.tsx +61 -0
  236. package/src/components/ParametersEditor.tsx +140 -0
  237. package/src/components/PcbViewerWithContainerHeight.tsx +47 -0
  238. package/src/components/PrefetchPageLink.tsx +45 -0
  239. package/src/components/PreviewContent.tsx +375 -0
  240. package/src/components/PreviewEmptyState.tsx +16 -0
  241. package/src/components/RunButton.tsx +27 -0
  242. package/src/components/SearchComponent.tsx +163 -0
  243. package/src/components/ShippingInformationForm.tsx +423 -0
  244. package/src/components/SnippetLink.tsx +37 -0
  245. package/src/components/StaticPreviewContent.tsx +89 -0
  246. package/src/components/StaticViewSnippetHeader.tsx +70 -0
  247. package/src/components/StaticViewSnippetSidebar.tsx +100 -0
  248. package/src/components/TableViewer/CircuitJsonTableViewer.tsx +316 -0
  249. package/src/components/TableViewer/ClickableText.tsx +21 -0
  250. package/src/components/TableViewer/HeaderCell.tsx +27 -0
  251. package/src/components/TableViewer/Modal.tsx +39 -0
  252. package/src/components/TrendingSnippetCarousel.tsx +77 -0
  253. package/src/components/TypeBadge.tsx +31 -0
  254. package/src/components/ViewSnippetHeader.tsx +144 -0
  255. package/src/components/ViewSnippetSidebar.tsx +162 -0
  256. package/src/components/dialogs/confirm-delete-snippet-dialog.tsx +80 -0
  257. package/src/components/dialogs/create-order-dialog.tsx +146 -0
  258. package/src/components/dialogs/create-use-dialog.tsx +34 -0
  259. package/src/components/dialogs/edit-description-dialog.tsx +96 -0
  260. package/src/components/dialogs/files-dialog.tsx +70 -0
  261. package/src/components/dialogs/import-snippet-dialog.tsx +84 -0
  262. package/src/components/dialogs/rename-snippet-dialog.tsx +81 -0
  263. package/src/components/dialogs/view-ts-files-dialog.tsx +89 -0
  264. package/src/components/ui/accordion.tsx +55 -0
  265. package/src/components/ui/alert-dialog.tsx +139 -0
  266. package/src/components/ui/alert.tsx +59 -0
  267. package/src/components/ui/aspect-ratio.tsx +5 -0
  268. package/src/components/ui/avatar.tsx +48 -0
  269. package/src/components/ui/badge.tsx +36 -0
  270. package/src/components/ui/breadcrumb.tsx +118 -0
  271. package/src/components/ui/button.tsx +58 -0
  272. package/src/components/ui/calendar.tsx +73 -0
  273. package/src/components/ui/card.tsx +76 -0
  274. package/src/components/ui/carousel.tsx +260 -0
  275. package/src/components/ui/chart.tsx +363 -0
  276. package/src/components/ui/checkbox.tsx +28 -0
  277. package/src/components/ui/collapsible.tsx +9 -0
  278. package/src/components/ui/combobox.tsx +178 -0
  279. package/src/components/ui/command.tsx +151 -0
  280. package/src/components/ui/context-menu.tsx +202 -0
  281. package/src/components/ui/dialog.tsx +120 -0
  282. package/src/components/ui/drawer.tsx +116 -0
  283. package/src/components/ui/dropdown-menu.tsx +203 -0
  284. package/src/components/ui/form.tsx +182 -0
  285. package/src/components/ui/hover-card.tsx +27 -0
  286. package/src/components/ui/input-otp.tsx +69 -0
  287. package/src/components/ui/input.tsx +25 -0
  288. package/src/components/ui/label.tsx +24 -0
  289. package/src/components/ui/menubar.tsx +238 -0
  290. package/src/components/ui/navigation-menu.tsx +129 -0
  291. package/src/components/ui/pagination.tsx +121 -0
  292. package/src/components/ui/popover.tsx +31 -0
  293. package/src/components/ui/progress.tsx +26 -0
  294. package/src/components/ui/radio-group.tsx +42 -0
  295. package/src/components/ui/resizable.tsx +43 -0
  296. package/src/components/ui/scroll-area.tsx +46 -0
  297. package/src/components/ui/searchable-select.tsx +94 -0
  298. package/src/components/ui/select.tsx +162 -0
  299. package/src/components/ui/separator.tsx +29 -0
  300. package/src/components/ui/sheet.tsx +141 -0
  301. package/src/components/ui/skeleton.tsx +18 -0
  302. package/src/components/ui/slider.tsx +26 -0
  303. package/src/components/ui/sonner.tsx +30 -0
  304. package/src/components/ui/switch.tsx +27 -0
  305. package/src/components/ui/table.tsx +120 -0
  306. package/src/components/ui/tabs.tsx +53 -0
  307. package/src/components/ui/textarea.tsx +24 -0
  308. package/src/components/ui/toast.tsx +128 -0
  309. package/src/components/ui/toaster.tsx +33 -0
  310. package/src/components/ui/toggle-group.tsx +59 -0
  311. package/src/components/ui/toggle.tsx +43 -0
  312. package/src/components/ui/tooltip.tsx +28 -0
  313. package/src/entry-server.tsx +12 -0
  314. package/src/hooks/use-account-balance.ts +24 -0
  315. package/src/hooks/use-ai-api.ts +35 -0
  316. package/src/hooks/use-axios.ts +20 -0
  317. package/src/hooks/use-code-completion-ai-api.ts +11 -0
  318. package/src/hooks/use-compiled-tsx.ts +37 -0
  319. package/src/hooks/use-copy-to-clipboard.ts +26 -0
  320. package/src/hooks/use-create-snippet-mutation.ts +62 -0
  321. package/src/hooks/use-current-snippet-id.ts +75 -0
  322. package/src/hooks/use-current-snippet.ts +24 -0
  323. package/src/hooks/use-global-store.ts +33 -0
  324. package/src/hooks/use-is-using-fake-api.ts +3 -0
  325. package/src/hooks/use-run-tsx/construct-circuit.tsx +64 -0
  326. package/src/hooks/use-run-tsx/eval-compiled-js.ts +9 -0
  327. package/src/hooks/use-run-tsx/index.tsx +251 -0
  328. package/src/hooks/use-save-snippet.ts +66 -0
  329. package/src/hooks/use-sign-in.ts +22 -0
  330. package/src/hooks/use-snippet-by-name.ts +25 -0
  331. package/src/hooks/use-snippet.ts +23 -0
  332. package/src/hooks/use-snippets-base-api-url.ts +3 -0
  333. package/src/hooks/use-toast.tsx +208 -0
  334. package/src/hooks/use-typecheck.ts +54 -0
  335. package/src/hooks/use-url-params.ts +31 -0
  336. package/src/hooks/use-warn-user-on-page-change.ts +23 -0
  337. package/src/hooks/useForkSnippetMutation.ts +52 -0
  338. package/src/index.css +21 -0
  339. package/src/lib/__tests__/constants.test.ts +66 -0
  340. package/src/lib/base64ToBytes.ts +5 -0
  341. package/src/lib/bytesToBase64.ts +4 -0
  342. package/src/lib/codemirror/basic-setup.ts +51 -0
  343. package/src/lib/constants.ts +12 -0
  344. package/src/lib/decodeUrlHashToText.ts +15 -0
  345. package/src/lib/defaultCodeForBlankCode.tsx +7 -0
  346. package/src/lib/download-fns/createBlobURL.ts +4 -0
  347. package/src/lib/download-fns/download-assembly-svg.ts +12 -0
  348. package/src/lib/download-fns/download-circuit-json-fn.ts +12 -0
  349. package/src/lib/download-fns/download-dsn-file-fn.ts +12 -0
  350. package/src/lib/download-fns/download-fabrication-files.ts +233 -0
  351. package/src/lib/download-fns/download-gltf.ts +49 -0
  352. package/src/lib/download-fns/download-kicad-files.ts +27 -0
  353. package/src/lib/download-fns/download-readable-netlist.ts +12 -0
  354. package/src/lib/download-fns/download-schematic-svg.ts +12 -0
  355. package/src/lib/download-fns/download-simple-route-json.ts +17 -0
  356. package/src/lib/encodeTextToUrlHash.ts +17 -0
  357. package/src/lib/get-snippet-template.ts +26 -0
  358. package/src/lib/handleManualEditsImport.tsx +65 -0
  359. package/src/lib/jlc-parts-engine.ts +69 -0
  360. package/src/lib/templates/blank-3d-model-template.ts +12 -0
  361. package/src/lib/templates/blank-circuit-board-template.ts +24 -0
  362. package/src/lib/templates/blank-footprint-template.ts +29 -0
  363. package/src/lib/templates/blank-package-template.ts +22 -0
  364. package/src/lib/templates/blinking-led-board-template.ts +63 -0
  365. package/src/lib/templates/manual-edits-template.ts +5 -0
  366. package/src/lib/templates/usb-c-led-flashlight-template.ts +22 -0
  367. package/src/lib/utils/checkIfManualEditsImported.ts +6 -0
  368. package/src/lib/utils/getSyntaxError.ts +13 -0
  369. package/src/lib/utils/index.ts +6 -0
  370. package/src/lib/utils/load-prettier.ts +18 -0
  371. package/src/lib/utils/parseFootprintParams.ts +52 -0
  372. package/src/lib/utils/parseJsonOrNull.ts +8 -0
  373. package/src/lib/utils/pcbManualEditEventHandler.ts +156 -0
  374. package/src/main.tsx +10 -0
  375. package/src/pages/ai.tsx +92 -0
  376. package/src/pages/authorize.tsx +54 -0
  377. package/src/pages/dashboard.tsx +165 -0
  378. package/src/pages/dev-login.tsx +68 -0
  379. package/src/pages/editor.tsx +28 -0
  380. package/src/pages/landing.tsx +236 -0
  381. package/src/pages/my-orders.tsx +54 -0
  382. package/src/pages/newest.tsx +16 -0
  383. package/src/pages/preview.tsx +70 -0
  384. package/src/pages/quickstart.tsx +198 -0
  385. package/src/pages/search.tsx +26 -0
  386. package/src/pages/settings.tsx +25 -0
  387. package/src/pages/user-profile.tsx +97 -0
  388. package/src/pages/view-order.tsx +123 -0
  389. package/src/pages/view-snippet.tsx +149 -0
  390. package/src/prettier.ts +9 -0
  391. package/src/vite-env.d.ts +1 -0
  392. package/tailwind.config.js +47 -0
  393. package/tsconfig.json +30 -0
  394. package/vercel.json +50 -0
  395. package/vite.config.ts +146 -0
  396. package/winterspec.config.ts +6 -0
@@ -0,0 +1,24 @@
1
+ import { useCurrentSnippetId } from "./use-current-snippet-id"
2
+ import { useSnippet } from "./use-snippet"
3
+ import { Snippet } from "fake-snippets-api/lib/db/schema"
4
+ import { useAxios } from "./use-axios"
5
+
6
+ export const useCurrentSnippet = (): {
7
+ snippet: Snippet | null
8
+ isLoading: boolean
9
+ error: (Error & { status: number }) | null
10
+ } => {
11
+ const {
12
+ snippetId,
13
+ isLoading: isLoadingSnippetId,
14
+ error: errorSnippetId,
15
+ } = useCurrentSnippetId()
16
+ const axios = useAxios()
17
+ const { data: snippet, isLoading, error } = useSnippet(snippetId || "")
18
+
19
+ return {
20
+ snippet: snippet || null,
21
+ isLoading: isLoadingSnippetId || isLoading,
22
+ error: errorSnippetId || error || null,
23
+ }
24
+ }
@@ -0,0 +1,33 @@
1
+ import { create } from "zustand"
2
+ import { persist } from "zustand/middleware"
3
+
4
+ export type Store = {
5
+ session: {
6
+ token: string
7
+ account_id: string
8
+ session_id: string
9
+ github_username: string
10
+ } | null
11
+ setSession: (session: Store["session"]) => any
12
+ should_onboarding_tips_be_closed: boolean
13
+ setOnboardingTipsClosed: (closed: boolean) => any
14
+ }
15
+
16
+ export const useGlobalStore = create<Store>()(
17
+ persist(
18
+ (set) => ({
19
+ session: null,
20
+ setSession: (session) => set({ session }),
21
+ should_onboarding_tips_be_closed: false,
22
+ setOnboardingTipsClosed: (closed) =>
23
+ set({ should_onboarding_tips_be_closed: closed }),
24
+ }),
25
+ {
26
+ name: "session_store",
27
+ },
28
+ ),
29
+ )
30
+
31
+ useGlobalStore.subscribe((state, prevState) => {
32
+ ;(window as any).globalStore = state
33
+ })
@@ -0,0 +1,3 @@
1
+ export const useIsUsingFakeApi = () => {
2
+ return import.meta.env.VITE_USE_FAKE_API === "true"
3
+ }
@@ -0,0 +1,64 @@
1
+ import { Circuit } from "@tscircuit/core"
2
+ import { useEffect, useMemo, useState } from "react"
3
+ import * as React from "react"
4
+ import { useCompiledTsx } from "../use-compiled-tsx"
5
+ import { createJSCADRenderer } from "jscad-fiber"
6
+ import { jscadPlanner } from "jscad-planner"
7
+ import { jlcPartsEngine } from "@/lib/jlc-parts-engine"
8
+
9
+ export const constructCircuit = ({
10
+ UserElm,
11
+ type,
12
+ circuitDisplayName,
13
+ }: {
14
+ UserElm: any
15
+ type: "board" | "footprint" | "package" | "model"
16
+ circuitDisplayName?: string
17
+ }) => {
18
+ const circuit = new Circuit()
19
+
20
+ if (circuitDisplayName) {
21
+ circuit.name = circuitDisplayName
22
+ }
23
+
24
+ if (type === "board") {
25
+ circuit.add(<UserElm />)
26
+ // HACK: switch to selectOne when root fixes bug with selecting board
27
+ const board = circuit.root?.children[0]
28
+ // const board = circuit.selectOne("board")
29
+ if (board) {
30
+ board.setProps({
31
+ ...board.props,
32
+ partsEngine: jlcPartsEngine,
33
+ })
34
+ }
35
+ } else if (type === "package") {
36
+ circuit.add(
37
+ <board width="50mm" height="50mm">
38
+ <UserElm name="U1" />
39
+ </board>,
40
+ )
41
+ } else if (type === "footprint") {
42
+ circuit.add(
43
+ <board width="10mm" height="10mm">
44
+ <chip name="U1" footprint={<UserElm />} />
45
+ </board>,
46
+ )
47
+ } else if (type === "model") {
48
+ const jscadGeoms: any[] = []
49
+ const { createJSCADRoot } = createJSCADRenderer(jscadPlanner as any)
50
+ const jscadRoot = createJSCADRoot(jscadGeoms)
51
+ jscadRoot.render(<UserElm />)
52
+ circuit.add(
53
+ <board width="10mm" height="10mm">
54
+ <chip
55
+ name="U1"
56
+ cadModel={{
57
+ jscad: jscadGeoms[0],
58
+ }}
59
+ />
60
+ </board>,
61
+ )
62
+ }
63
+ return circuit
64
+ }
@@ -0,0 +1,9 @@
1
+ export const evalCompiledJs = (compiledCode: string) => {
2
+ const functionBody = `
3
+ var exports = {};
4
+ var require = globalThis.__tscircuit_require;
5
+ var module = { exports };
6
+ ${compiledCode};
7
+ return module;`.trim()
8
+ return Function(functionBody).call(globalThis)
9
+ }
@@ -0,0 +1,251 @@
1
+ import * as tscircuitCore from "@tscircuit/core"
2
+ import { getImportsFromCode } from "@tscircuit/prompt-benchmarks/code-runner-utils"
3
+ import type { AnyCircuitElement } from "circuit-json"
4
+ import * as jscadFiber from "jscad-fiber"
5
+ import * as React from "react"
6
+ import * as tscircuitMathUtils from "@tscircuit/math-utils"
7
+ import { useEffect, useMemo, useReducer, useRef, useState } from "react"
8
+ import { safeCompileTsx } from "../use-compiled-tsx"
9
+ import { useSnippetsBaseApiUrl } from "../use-snippets-base-api-url"
10
+ import { constructCircuit } from "./construct-circuit"
11
+ import { evalCompiledJs } from "./eval-compiled-js"
12
+ import { getSyntaxError } from "@/lib/utils/getSyntaxError"
13
+
14
+ type RunTsxResult = {
15
+ compiledModule: any
16
+ message: string
17
+ circuitJson: AnyCircuitElement[] | null
18
+ compiledJs?: string
19
+ isRunningCode: boolean
20
+ }
21
+
22
+ export const useRunTsx = ({
23
+ code,
24
+ userImports,
25
+ type,
26
+ isStreaming = false,
27
+ circuitDisplayName,
28
+ }: {
29
+ code?: string
30
+ userImports?: Record<string, object>
31
+ type?: "board" | "footprint" | "package" | "model"
32
+ isStreaming?: boolean
33
+ circuitDisplayName?: string
34
+ } = {}): RunTsxResult & {
35
+ circuitJsonKey: string
36
+ triggerRunTsx: () => void
37
+ tsxRunTriggerCount: number
38
+ } => {
39
+ type ??= "board"
40
+ const [tsxRunTriggerCount, incTsxRunTriggerCount] = useReducer(
41
+ (c) => c + 1,
42
+ 0,
43
+ )
44
+ const [tsxResult, setTsxResult] = useState<RunTsxResult>({
45
+ compiledModule: null,
46
+ message: "",
47
+ circuitJson: null,
48
+ isRunningCode: false,
49
+ })
50
+ const apiBaseUrl = useSnippetsBaseApiUrl()
51
+ const preSuppliedImportsRef = useRef<Record<string, any>>({})
52
+
53
+ useEffect(() => {
54
+ if (tsxRunTriggerCount === 0) return
55
+ if (isStreaming) {
56
+ setTsxResult({
57
+ compiledModule: null,
58
+ message: "",
59
+ circuitJson: null,
60
+ isRunningCode: false,
61
+ })
62
+ }
63
+ if (!code) return
64
+ const syntaxError = getSyntaxError(code)
65
+ if (syntaxError) {
66
+ setTsxResult({
67
+ compiledModule: null,
68
+ message: syntaxError,
69
+ circuitJson: null,
70
+ isRunningCode: false,
71
+ })
72
+ return
73
+ }
74
+ async function run() {
75
+ setTsxResult({
76
+ compiledModule: null,
77
+ message: "",
78
+ circuitJson: null,
79
+ isRunningCode: true,
80
+ })
81
+
82
+ const userCodeTsciImports = getImportsFromCode(code!).filter((imp) =>
83
+ imp.startsWith("@tsci/"),
84
+ )
85
+
86
+ const preSuppliedImports: Record<string, any> =
87
+ preSuppliedImportsRef.current
88
+
89
+ for (const [importName, importValue] of Object.entries(
90
+ userImports ?? {},
91
+ )) {
92
+ preSuppliedImports[importName] = importValue
93
+ }
94
+
95
+ const __tscircuit_require = (name: string) => {
96
+ if (
97
+ name === "./manual-edits.json" &&
98
+ preSuppliedImports["./manual-edits.json"] === ""
99
+ ) {
100
+ return preSuppliedImports["./manual-edits.json"]
101
+ }
102
+ if (!preSuppliedImports[name]) {
103
+ throw new Error(
104
+ `Import "${name}" not found (imports available: ${Object.keys(preSuppliedImports).join(",")})`,
105
+ )
106
+ }
107
+ return preSuppliedImports[name]
108
+ }
109
+ ;(globalThis as any).__tscircuit_require = __tscircuit_require
110
+ preSuppliedImports["@tscircuit/core"] = tscircuitCore
111
+ preSuppliedImports["@tscircuit/math-utils"] = tscircuitMathUtils
112
+ preSuppliedImports["react"] = React
113
+ preSuppliedImports["jscad-fiber"] = jscadFiber
114
+ globalThis.React = React
115
+
116
+ async function addImport(importName: string, depth = 0) {
117
+ if (!importName.startsWith("@tsci/")) return
118
+ if (preSuppliedImports[importName]) return
119
+ if (depth > 5) {
120
+ console.log("Max depth for imports reached")
121
+ return
122
+ }
123
+
124
+ const fullSnippetName = importName
125
+ .replace("@tsci/", "")
126
+ .replace(".", "/")
127
+ const { snippet: importedSnippet, error } = await fetch(
128
+ `${apiBaseUrl}/snippets/get?name=${fullSnippetName}`,
129
+ )
130
+ .then((res) => res.json())
131
+ .catch((e) => ({ error: e }))
132
+
133
+ if (error) {
134
+ console.error("Error fetching import", importName, error)
135
+ return
136
+ }
137
+
138
+ const { compiled_js, code } = importedSnippet
139
+
140
+ const importNames = getImportsFromCode(code!)
141
+
142
+ for (const importName of importNames) {
143
+ if (!preSuppliedImports[importName]) {
144
+ await addImport(importName, depth + 1)
145
+ }
146
+ }
147
+
148
+ try {
149
+ preSuppliedImports[importName] = evalCompiledJs(compiled_js).exports
150
+ } catch (e) {
151
+ console.error("Error importing snippet", e)
152
+ }
153
+ }
154
+
155
+ for (const userCodeTsciImport of userCodeTsciImports) {
156
+ await addImport(userCodeTsciImport)
157
+ }
158
+
159
+ const { success, compiledTsx: compiledJs, error } = safeCompileTsx(code!)
160
+
161
+ if (!success) {
162
+ setTsxResult({
163
+ compiledModule: null,
164
+ message: `Compile Error: ${error.message}`,
165
+ circuitJson: null,
166
+ isRunningCode: false,
167
+ })
168
+ }
169
+
170
+ try {
171
+ const module = evalCompiledJs(compiledJs!)
172
+
173
+ const componentExportKeys = Object.keys(module.exports).filter(
174
+ (key) => !key.startsWith("use"),
175
+ )
176
+
177
+ if (componentExportKeys.length > 1) {
178
+ throw new Error(
179
+ `Too many exports, only export one component. You exported: ${JSON.stringify(Object.keys(module.exports))}`,
180
+ )
181
+ }
182
+
183
+ const primaryKey = componentExportKeys[0]
184
+
185
+ const UserElm = (props: any) =>
186
+ React.createElement(module.exports[primaryKey], props)
187
+
188
+ try {
189
+ const circuit = constructCircuit({
190
+ UserElm,
191
+ type: type as any,
192
+ circuitDisplayName,
193
+ })
194
+ const renderPromise = circuit.renderUntilSettled()
195
+
196
+ // wait one tick to allow a single render pass
197
+ await new Promise((resolve) => setTimeout(resolve, 1))
198
+
199
+ let circuitJson = circuit.getCircuitJson()
200
+ setTsxResult({
201
+ compiledModule: module,
202
+ compiledJs,
203
+ message: "",
204
+ circuitJson: circuitJson as AnyCircuitElement[],
205
+ isRunningCode: true,
206
+ })
207
+
208
+ await renderPromise
209
+
210
+ circuitJson = circuit.getCircuitJson()
211
+ setTsxResult({
212
+ compiledModule: module,
213
+ compiledJs,
214
+ message: "",
215
+ circuitJson: circuitJson as AnyCircuitElement[],
216
+ isRunningCode: false,
217
+ })
218
+ } catch (error: any) {
219
+ console.error("Evaluation error:", error)
220
+ setTsxResult({
221
+ compiledModule: module,
222
+ message: `Render Error: ${error.message}`,
223
+ circuitJson: null,
224
+ isRunningCode: false,
225
+ })
226
+ }
227
+ } catch (error: any) {
228
+ console.error("Evaluation error:", error)
229
+ setTsxResult({
230
+ compiledModule: null,
231
+ message: `Eval Error: ${error.message}\n\n${error.stack}`,
232
+ circuitJson: null,
233
+ isRunningCode: false,
234
+ })
235
+ }
236
+ }
237
+ run()
238
+ }, [tsxRunTriggerCount])
239
+
240
+ const circuitJsonKey: string = useMemo(() => {
241
+ if (!tsxResult.circuitJson) return ""
242
+ return `cj-${Math.random().toString(36).substring(2, 15)}`
243
+ }, [tsxResult.circuitJson, tsxResult.circuitJson?.length])
244
+
245
+ return {
246
+ ...tsxResult,
247
+ circuitJsonKey: circuitJsonKey,
248
+ triggerRunTsx: incTsxRunTriggerCount,
249
+ tsxRunTriggerCount,
250
+ }
251
+ }
@@ -0,0 +1,66 @@
1
+ import { Snippet } from "fake-snippets-api/lib/db/schema"
2
+ import { useMutation } from "react-query"
3
+ import { useAxios } from "./use-axios"
4
+ import { safeCompileTsx } from "./use-compiled-tsx"
5
+ import { useCurrentSnippetId } from "./use-current-snippet-id"
6
+
7
+ export const useSaveSnippet = () => {
8
+ const axios = useAxios()
9
+
10
+ const { snippetId } = useCurrentSnippetId()
11
+
12
+ const saveSnippetMutation = useMutation<
13
+ Snippet,
14
+ Error,
15
+ { code: string; snippet_type: string; dts?: string; circuit_json?: any[] }
16
+ >({
17
+ mutationFn: async ({ code, snippet_type, dts, circuit_json }) => {
18
+ const compileResult = safeCompileTsx(code)
19
+
20
+ if (snippetId) {
21
+ const response = await axios.post("/snippets/update", {
22
+ snippet_id: snippetId,
23
+ code,
24
+ snippet_type,
25
+ compiled_js: compileResult.success
26
+ ? compileResult.compiledTsx
27
+ : undefined,
28
+ circuit_json: circuit_json,
29
+ dts,
30
+ })
31
+ return response.data.snippet
32
+ } else {
33
+ const response = await axios.post("/snippets/create", {
34
+ code,
35
+ snippet_type,
36
+ owner_name: "seveibar", // Replace with actual user name or fetch from user context
37
+ compiled_js: compileResult.success
38
+ ? compileResult.compiledTsx
39
+ : undefined,
40
+ dts,
41
+ })
42
+ return response.data.snippet
43
+ }
44
+ },
45
+ })
46
+
47
+ const saveSnippet = async (
48
+ code: string,
49
+ snippet_type: string,
50
+ dts?: string,
51
+ circuit_json?: any[],
52
+ ) => {
53
+ return saveSnippetMutation.mutateAsync({
54
+ code,
55
+ snippet_type,
56
+ dts,
57
+ circuit_json,
58
+ })
59
+ }
60
+
61
+ return {
62
+ saveSnippet,
63
+ isLoading: saveSnippetMutation.isLoading,
64
+ error: saveSnippetMutation.error,
65
+ }
66
+ }
@@ -0,0 +1,22 @@
1
+ import { useGlobalStore } from "./use-global-store"
2
+ import { useIsUsingFakeApi } from "./use-is-using-fake-api"
3
+ import { useSnippetsBaseApiUrl } from "./use-snippets-base-api-url"
4
+
5
+ export const useSignIn = () => {
6
+ const snippetsBaseApiUrl = useSnippetsBaseApiUrl()
7
+ const isUsingFakeApi = useIsUsingFakeApi()
8
+ const setSession = useGlobalStore((s) => s.setSession)
9
+ return () => {
10
+ if (!isUsingFakeApi) {
11
+ const nextUrl = window.location.origin.replace("127.0.0.1", "localhost")
12
+ window.location.href = `${snippetsBaseApiUrl}/internal/oauth/github/authorize?next=${nextUrl}/authorize`
13
+ } else {
14
+ setSession({
15
+ account_id: "account-1234",
16
+ github_username: "testuser",
17
+ token: "1234",
18
+ session_id: "session-1234",
19
+ })
20
+ }
21
+ }
22
+ }
@@ -0,0 +1,25 @@
1
+ import { useQuery } from "react-query"
2
+ import { useAxios } from "@/hooks/use-axios"
3
+ import type { Snippet } from "fake-snippets-api/lib/db/schema"
4
+
5
+ export const useSnippetByName = (fullSnippetName: string | null) => {
6
+ const axios = useAxios()
7
+ return useQuery<Snippet, Error & { status: number }>(
8
+ ["snippet", fullSnippetName],
9
+ async () => {
10
+ if (!fullSnippetName) return
11
+ const [owner_name, unscoped_name] = fullSnippetName.split("/")
12
+ const { data } = await axios.get("/snippets/get", {
13
+ params: {
14
+ owner_name,
15
+ unscoped_name,
16
+ },
17
+ })
18
+ return data.snippet
19
+ },
20
+ {
21
+ retry: false,
22
+ enabled: Boolean(fullSnippetName),
23
+ },
24
+ )
25
+ }
@@ -0,0 +1,23 @@
1
+ import { useQuery } from "react-query"
2
+ import { useAxios } from "@/hooks/use-axios"
3
+ import type { Snippet } from "fake-snippets-api/lib/db/schema"
4
+
5
+ export const useSnippet = (snippetId: string | null) => {
6
+ const axios = useAxios()
7
+ return useQuery<Snippet, Error & { status: number }>(
8
+ ["snippets", snippetId],
9
+ async () => {
10
+ if (!snippetId) {
11
+ throw new Error("Snippet ID is required")
12
+ }
13
+ const { data } = await axios.get("/snippets/get", {
14
+ params: { snippet_id: snippetId },
15
+ })
16
+ return data.snippet
17
+ },
18
+ {
19
+ enabled: Boolean(snippetId),
20
+ retry: false,
21
+ },
22
+ )
23
+ }
@@ -0,0 +1,3 @@
1
+ export const useSnippetsBaseApiUrl = () => {
2
+ return import.meta.env.VITE_SNIPPETS_API_URL ?? "/api"
3
+ }