@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.
- package/.github/CODEOWNERS +1 -0
- package/.github/workflows/bun-formatcheck.yml +26 -0
- package/.github/workflows/bun-test.yml +28 -0
- package/.github/workflows/bun-typecheck.yml +26 -0
- package/.github/workflows/bundle-size-analysis.yml +79 -0
- package/.github/workflows/playwright-test.yml +37 -0
- package/.github/workflows/stale.yml +40 -0
- package/.github/workflows/update-snapshots.yml +49 -0
- package/CONTRIBUTING.md +59 -0
- package/LICENSE +21 -0
- package/README.md +113 -0
- package/biome.json +60 -0
- package/bun-tests/fake-snippets-api/fixtures/get-circuit-json.ts +148 -0
- package/bun-tests/fake-snippets-api/fixtures/get-test-server.ts +96 -0
- package/bun-tests/fake-snippets-api/fixtures/start-server.ts +44 -0
- package/bun-tests/fake-snippets-api/routes/accounts/get_account_balance.test.ts +18 -0
- package/bun-tests/fake-snippets-api/routes/health.test.ts +9 -0
- package/bun-tests/fake-snippets-api/routes/order_files/get.test.ts +48 -0
- package/bun-tests/fake-snippets-api/routes/order_files/upload.test.ts +77 -0
- package/bun-tests/fake-snippets-api/routes/orders/create.test.ts +19 -0
- package/bun-tests/fake-snippets-api/routes/orders/get.test.ts +38 -0
- package/bun-tests/fake-snippets-api/routes/orders/list.test.ts +30 -0
- package/bun-tests/fake-snippets-api/routes/orders/update.test.ts +46 -0
- package/bun-tests/fake-snippets-api/routes/snippets/add_star.test.ts +114 -0
- package/bun-tests/fake-snippets-api/routes/snippets/create.test.ts +28 -0
- package/bun-tests/fake-snippets-api/routes/snippets/delete.test.ts +106 -0
- package/bun-tests/fake-snippets-api/routes/snippets/download.test.ts +90 -0
- package/bun-tests/fake-snippets-api/routes/snippets/generate_from_jlcpcb.test.ts +25 -0
- package/bun-tests/fake-snippets-api/routes/snippets/get_image.test.ts +113 -0
- package/bun-tests/fake-snippets-api/routes/snippets/images.test.ts +112 -0
- package/bun-tests/fake-snippets-api/routes/snippets/list.test.ts +62 -0
- package/bun-tests/fake-snippets-api/routes/snippets/list_newest.test.ts +48 -0
- package/bun-tests/fake-snippets-api/routes/snippets/list_trending.test.ts +69 -0
- package/bun-tests/fake-snippets-api/routes/snippets/remove_star.test.ts +110 -0
- package/bun-tests/fake-snippets-api/routes/snippets/search.test.ts +75 -0
- package/bun-tests/fake-snippets-api/routes/snippets/star-count.test.ts +44 -0
- package/bun-tests/fake-snippets-api/routes/snippets/update.test.ts +116 -0
- package/bun-tests/parts-engine.test.ts +18 -0
- package/bun.lockb +0 -0
- package/bunfig.toml +2 -0
- package/components.json +20 -0
- package/dist/assets/editor_example_1-1000w.webp +0 -0
- package/dist/assets/editor_example_1-1200w.webp +0 -0
- package/dist/assets/editor_example_1-1600w.webp +0 -0
- package/dist/assets/editor_example_1-2000w.webp +0 -0
- package/dist/assets/editor_example_1-400w.webp +0 -0
- package/dist/assets/editor_example_1-600w.webp +0 -0
- package/dist/assets/editor_example_1-800w.webp +0 -0
- package/dist/assets/editor_example_1_more_square-1000w.webp +0 -0
- package/dist/assets/editor_example_1_more_square-1200w.webp +0 -0
- package/dist/assets/editor_example_1_more_square-1600w.webp +0 -0
- package/dist/assets/editor_example_1_more_square-2000w.webp +0 -0
- package/dist/assets/editor_example_1_more_square-400w.webp +0 -0
- package/dist/assets/editor_example_1_more_square-600w.webp +0 -0
- package/dist/assets/editor_example_1_more_square-800w.webp +0 -0
- package/dist/assets/editor_example_2-1000w.webp +0 -0
- package/dist/assets/editor_example_2-1200w.webp +0 -0
- package/dist/assets/editor_example_2-1600w.webp +0 -0
- package/dist/assets/editor_example_2-2000w.webp +0 -0
- package/dist/assets/editor_example_2-400w.webp +0 -0
- package/dist/assets/editor_example_2-600w.webp +0 -0
- package/dist/assets/editor_example_2-800w.webp +0 -0
- package/dist/assets/example_schematic-1000w.webp +0 -0
- package/dist/assets/example_schematic-1200w.webp +0 -0
- package/dist/assets/example_schematic-1600w.webp +0 -0
- package/dist/assets/example_schematic-2000w.webp +0 -0
- package/dist/assets/example_schematic-400w.webp +0 -0
- package/dist/assets/example_schematic-600w.webp +0 -0
- package/dist/assets/example_schematic-800w.webp +0 -0
- package/dist/bundle.js +3270 -0
- package/dist/robots.txt +9 -0
- package/dist/sitemap.xml +118 -0
- package/docs/CIRCUIT_JSON_SOURCE_COMPONENT_OVERVIEW.md +151 -0
- package/fake-snippets-api/README.md +6 -0
- package/fake-snippets-api/biome.json +47 -0
- package/fake-snippets-api/bun.lockb +0 -0
- package/fake-snippets-api/lib/db/autoload-dev-snippets.ts +84 -0
- package/fake-snippets-api/lib/db/autoload-snippets.json +24 -0
- package/fake-snippets-api/lib/db/db-client.ts +343 -0
- package/fake-snippets-api/lib/db/schema.ts +112 -0
- package/fake-snippets-api/lib/db/seed.ts +1608 -0
- package/fake-snippets-api/lib/middleware/with-ctx-error.ts +26 -0
- package/fake-snippets-api/lib/middleware/with-db.ts +15 -0
- package/fake-snippets-api/lib/middleware/with-error-handling.ts +24 -0
- package/fake-snippets-api/lib/middleware/with-optional-session-auth.ts +34 -0
- package/fake-snippets-api/lib/middleware/with-request-logging.ts +54 -0
- package/fake-snippets-api/lib/middleware/with-session-auth.ts +39 -0
- package/fake-snippets-api/lib/middleware/with-winter-spec.ts +24 -0
- package/fake-snippets-api/next-env.d.ts +5 -0
- package/fake-snippets-api/routes/api/accounts/get.ts +21 -0
- package/fake-snippets-api/routes/api/accounts/get_account_balance.ts +22 -0
- package/fake-snippets-api/routes/api/accounts/update.ts +32 -0
- package/fake-snippets-api/routes/api/ai/[...anyroute].ts +31 -0
- package/fake-snippets-api/routes/api/ai.ts +2 -0
- package/fake-snippets-api/routes/api/aistream/[...anyroute].ts +65 -0
- package/fake-snippets-api/routes/api/health.ts +9 -0
- package/fake-snippets-api/routes/api/internal/sessions/create_without_auth.ts +63 -0
- package/fake-snippets-api/routes/api/order_files/get.ts +28 -0
- package/fake-snippets-api/routes/api/order_files/upload.ts +43 -0
- package/fake-snippets-api/routes/api/orders/create.ts +41 -0
- package/fake-snippets-api/routes/api/orders/get.ts +28 -0
- package/fake-snippets-api/routes/api/orders/list.ts +15 -0
- package/fake-snippets-api/routes/api/orders/update.ts +50 -0
- package/fake-snippets-api/routes/api/snippets/add_star.ts +42 -0
- package/fake-snippets-api/routes/api/snippets/create.ts +55 -0
- package/fake-snippets-api/routes/api/snippets/delete.ts +41 -0
- package/fake-snippets-api/routes/api/snippets/download.ts +148 -0
- package/fake-snippets-api/routes/api/snippets/generate_from_jlcpcb.ts +55 -0
- package/fake-snippets-api/routes/api/snippets/get.ts +50 -0
- package/fake-snippets-api/routes/api/snippets/get_image.ts +65 -0
- package/fake-snippets-api/routes/api/snippets/images/[author]/[snippet_name]/[typeFormat].ts +74 -0
- package/fake-snippets-api/routes/api/snippets/list.ts +28 -0
- package/fake-snippets-api/routes/api/snippets/list_newest.ts +13 -0
- package/fake-snippets-api/routes/api/snippets/list_trending.ts +21 -0
- package/fake-snippets-api/routes/api/snippets/remove_star.ts +42 -0
- package/fake-snippets-api/routes/api/snippets/search.ts +18 -0
- package/fake-snippets-api/routes/api/snippets/update.ts +86 -0
- package/favicon.ico +0 -0
- package/index.html +23 -0
- package/landing.html +23 -0
- package/package.json +164 -0
- package/playwright-tests/ai-page.spec.ts +19 -0
- package/playwright-tests/cmd-click.spec.ts +43 -0
- package/playwright-tests/dashboard-page.spec.ts +10 -0
- package/playwright-tests/editor-page.spec.ts +15 -0
- package/playwright-tests/files-dialog.spec.ts +19 -0
- package/playwright-tests/footprint-dialog/footprint-dialog.spec.ts +27 -0
- package/playwright-tests/footprint-dialog/footprint-insertion.spec.ts +38 -0
- package/playwright-tests/footprint-dialog/footprint-preview.spec.ts +34 -0
- package/playwright-tests/footprint-dialog/footprint-selection.spec.ts +29 -0
- package/playwright-tests/handle-manual-edits.spec.ts +55 -0
- package/playwright-tests/home-page.spec.ts +10 -0
- package/playwright-tests/images.spec.ts +17 -0
- package/playwright-tests/manual-edits.spec.ts +89 -0
- package/playwright-tests/preview-page.spec.ts +14 -0
- package/playwright-tests/quickstart-page.spec.ts +10 -0
- package/playwright-tests/search-links.spec.ts +21 -0
- package/playwright-tests/search.spec.ts +27 -0
- package/playwright-tests/snapshots/ai-page.spec.ts-AI-Page-lg.png +0 -0
- package/playwright-tests/snapshots/ai-page.spec.ts-AI-Page-md.png +0 -0
- package/playwright-tests/snapshots/ai-page.spec.ts-AI-Page-xs.png +0 -0
- package/playwright-tests/snapshots/cmd-click.spec.ts-underlined-imports.png +0 -0
- package/playwright-tests/snapshots/dashboard-page.spec.ts-Dashboard-page-lg.png +0 -0
- package/playwright-tests/snapshots/dashboard-page.spec.ts-Dashboard-page-md.png +0 -0
- package/playwright-tests/snapshots/dashboard-page.spec.ts-Dashboard-page-xs.png +0 -0
- package/playwright-tests/snapshots/editor-page.spec.ts-editor-with-snippet.png +0 -0
- package/playwright-tests/snapshots/error-fallback.spec.ts-error-fallback-lg.png +0 -0
- package/playwright-tests/snapshots/error-fallback.spec.ts-error-fallback-md.png +0 -0
- package/playwright-tests/snapshots/error-fallback.spec.ts-error-fallback-xs.png +0 -0
- package/playwright-tests/snapshots/files-dialog.spec.ts-view-snippet-files.png +0 -0
- package/playwright-tests/snapshots/footprint-dialog/footprint-dialog.spec.ts-footprint-preview-lg.png +0 -0
- package/playwright-tests/snapshots/footprint-dialog/footprint-dialog.spec.ts-footprint-preview-md.png +0 -0
- package/playwright-tests/snapshots/footprint-dialog/footprint-dialog.spec.ts-footprint-preview-xs.png +0 -0
- package/playwright-tests/snapshots/footprint-dialog/footprint-insertion.spec.ts-footprint-insertion-lg.png +0 -0
- package/playwright-tests/snapshots/footprint-dialog/footprint-insertion.spec.ts-footprint-insertion-md.png +0 -0
- package/playwright-tests/snapshots/footprint-dialog/footprint-insertion.spec.ts-footprint-insertion-xs.png +0 -0
- package/playwright-tests/snapshots/footprint-dialog/footprint-preview.spec.ts-footprint-preview-lg.png +0 -0
- package/playwright-tests/snapshots/footprint-dialog/footprint-preview.spec.ts-footprint-preview-md.png +0 -0
- package/playwright-tests/snapshots/footprint-dialog/footprint-preview.spec.ts-footprint-preview-xs.png +0 -0
- package/playwright-tests/snapshots/footprint-dialog/footprint-selection.spec.ts-footprint-preview-lg.png +0 -0
- package/playwright-tests/snapshots/footprint-dialog/footprint-selection.spec.ts-footprint-preview-md.png +0 -0
- package/playwright-tests/snapshots/footprint-dialog/footprint-selection.spec.ts-footprint-preview-xs.png +0 -0
- package/playwright-tests/snapshots/handle-manual-edits.spec.ts-handle-manual-edits.png +0 -0
- package/playwright-tests/snapshots/home-page.spec.ts-Home-page-lg.png +0 -0
- package/playwright-tests/snapshots/home-page.spec.ts-Home-page-md.png +0 -0
- package/playwright-tests/snapshots/home-page.spec.ts-Home-page-xs.png +0 -0
- package/playwright-tests/snapshots/images.spec.ts-pcb-image.png +0 -0
- package/playwright-tests/snapshots/images.spec.ts-schematic-image.png +0 -0
- package/playwright-tests/snapshots/manual-edits.spec.ts-editor-manual-edits.png +0 -0
- package/playwright-tests/snapshots/manual-edits.spec.ts-manual-edits-view.png +0 -0
- package/playwright-tests/snapshots/preview-page.spec.ts-preview-snippet-pcb.png +0 -0
- package/playwright-tests/snapshots/preview-page.spec.ts-preview-snippet-schematic.png +0 -0
- package/playwright-tests/snapshots/quickstart-page.spec.ts-Quickstart-Pagelg.png +0 -0
- package/playwright-tests/snapshots/quickstart-page.spec.ts-Quickstart-Pagemd.png +0 -0
- package/playwright-tests/snapshots/quickstart-page.spec.ts-Quickstart-Pagexs.png +0 -0
- package/playwright-tests/snapshots/search-links.spec.ts-search-links.png +0 -0
- package/playwright-tests/snapshots/search.spec.ts-search-lg.png +0 -0
- package/playwright-tests/snapshots/search.spec.ts-search-md.png +0 -0
- package/playwright-tests/snapshots/search.spec.ts-search-xs.png +0 -0
- package/playwright-tests/snapshots/star.spec.ts-remove-star-button.png +0 -0
- package/playwright-tests/snapshots/star.spec.ts-star-button.png +0 -0
- package/playwright-tests/snapshots/update-description.spec.ts-update-description.png +0 -0
- package/playwright-tests/snapshots/view-snippet.spec.ts-view-snippet-after-lg.png +0 -0
- package/playwright-tests/snapshots/view-snippet.spec.ts-view-snippet-after-md.png +0 -0
- package/playwright-tests/snapshots/view-snippet.spec.ts-view-snippet-after-xs.png +0 -0
- package/playwright-tests/snapshots/view-snippet.spec.ts-view-snippet-before-lg.png +0 -0
- package/playwright-tests/snapshots/view-snippet.spec.ts-view-snippet-before-md.png +0 -0
- package/playwright-tests/snapshots/view-snippet.spec.ts-view-snippet-before-xs.png +0 -0
- package/playwright-tests/snapshots/view-snippet.spec.ts-view-snippet-files.png +0 -0
- package/playwright-tests/star.spec.ts +40 -0
- package/playwright-tests/update-description.spec.ts +18 -0
- package/playwright-tests/view-snippet.spec.ts +35 -0
- package/playwright-tests/viewports.ts +5 -0
- package/playwright.config.ts +27 -0
- package/postcss.config.js +6 -0
- package/public/robots.txt +9 -0
- package/renovate.json +24 -0
- package/scripts/generate-image-sizes.ts +58 -0
- package/scripts/generate-sitemap.ts +103 -0
- package/scripts/generate_bundle_stats.js +192 -0
- package/scripts/snapshot.ts +35 -0
- package/src/App.tsx +113 -0
- package/src/ContextProviders.tsx +9 -0
- package/src/assets/originals/editor_example_1.webp +0 -0
- package/src/assets/originals/editor_example_1_more_square.webp +0 -0
- package/src/assets/originals/editor_example_2.webp +0 -0
- package/src/assets/originals/example_schematic.webp +0 -0
- package/src/components/AiChatInterface.tsx +221 -0
- package/src/components/AiChatMessage.tsx +86 -0
- package/src/components/Analytics.tsx +30 -0
- package/src/components/BomTable.tsx +69 -0
- package/src/components/ChatInput.tsx +53 -0
- package/src/components/CircuitToSvgWithMouseControl.tsx +78 -0
- package/src/components/CmdKMenu.tsx +301 -0
- package/src/components/CodeAndPreview.tsx +258 -0
- package/src/components/CodeEditor.tsx +460 -0
- package/src/components/CodeEditorHeader.tsx +160 -0
- package/src/components/CreateNewSnippetWithAiHero.tsx +77 -0
- package/src/components/DownloadButtonAndMenu.tsx +212 -0
- package/src/components/EditorNav.tsx +428 -0
- package/src/components/ErrorFallback.tsx +25 -0
- package/src/components/ErrorTabContent.tsx +122 -0
- package/src/components/FAQ.tsx +113 -0
- package/src/components/Footer.tsx +134 -0
- package/src/components/Footer2.tsx +100 -0
- package/src/components/FootprintDialog.tsx +342 -0
- package/src/components/Header.tsx +187 -0
- package/src/components/Header2.tsx +135 -0
- package/src/components/HeaderDropdown.tsx +83 -0
- package/src/components/HeaderLogin.tsx +94 -0
- package/src/components/JLCPCBImportDialog.tsx +155 -0
- package/src/components/LandingHero.tsx +175 -0
- package/src/components/LatestSnippets.tsx +39 -0
- package/src/components/OptimizedImage.tsx +96 -0
- package/src/components/OrderPreviewContent.tsx +61 -0
- package/src/components/ParametersEditor.tsx +140 -0
- package/src/components/PcbViewerWithContainerHeight.tsx +47 -0
- package/src/components/PrefetchPageLink.tsx +45 -0
- package/src/components/PreviewContent.tsx +375 -0
- package/src/components/PreviewEmptyState.tsx +16 -0
- package/src/components/RunButton.tsx +27 -0
- package/src/components/SearchComponent.tsx +163 -0
- package/src/components/ShippingInformationForm.tsx +423 -0
- package/src/components/SnippetLink.tsx +37 -0
- package/src/components/StaticPreviewContent.tsx +89 -0
- package/src/components/StaticViewSnippetHeader.tsx +70 -0
- package/src/components/StaticViewSnippetSidebar.tsx +100 -0
- package/src/components/TableViewer/CircuitJsonTableViewer.tsx +316 -0
- package/src/components/TableViewer/ClickableText.tsx +21 -0
- package/src/components/TableViewer/HeaderCell.tsx +27 -0
- package/src/components/TableViewer/Modal.tsx +39 -0
- package/src/components/TrendingSnippetCarousel.tsx +77 -0
- package/src/components/TypeBadge.tsx +31 -0
- package/src/components/ViewSnippetHeader.tsx +144 -0
- package/src/components/ViewSnippetSidebar.tsx +162 -0
- package/src/components/dialogs/confirm-delete-snippet-dialog.tsx +80 -0
- package/src/components/dialogs/create-order-dialog.tsx +146 -0
- package/src/components/dialogs/create-use-dialog.tsx +34 -0
- package/src/components/dialogs/edit-description-dialog.tsx +96 -0
- package/src/components/dialogs/files-dialog.tsx +70 -0
- package/src/components/dialogs/import-snippet-dialog.tsx +84 -0
- package/src/components/dialogs/rename-snippet-dialog.tsx +81 -0
- package/src/components/dialogs/view-ts-files-dialog.tsx +89 -0
- package/src/components/ui/accordion.tsx +55 -0
- package/src/components/ui/alert-dialog.tsx +139 -0
- package/src/components/ui/alert.tsx +59 -0
- package/src/components/ui/aspect-ratio.tsx +5 -0
- package/src/components/ui/avatar.tsx +48 -0
- package/src/components/ui/badge.tsx +36 -0
- package/src/components/ui/breadcrumb.tsx +118 -0
- package/src/components/ui/button.tsx +58 -0
- package/src/components/ui/calendar.tsx +73 -0
- package/src/components/ui/card.tsx +76 -0
- package/src/components/ui/carousel.tsx +260 -0
- package/src/components/ui/chart.tsx +363 -0
- package/src/components/ui/checkbox.tsx +28 -0
- package/src/components/ui/collapsible.tsx +9 -0
- package/src/components/ui/combobox.tsx +178 -0
- package/src/components/ui/command.tsx +151 -0
- package/src/components/ui/context-menu.tsx +202 -0
- package/src/components/ui/dialog.tsx +120 -0
- package/src/components/ui/drawer.tsx +116 -0
- package/src/components/ui/dropdown-menu.tsx +203 -0
- package/src/components/ui/form.tsx +182 -0
- package/src/components/ui/hover-card.tsx +27 -0
- package/src/components/ui/input-otp.tsx +69 -0
- package/src/components/ui/input.tsx +25 -0
- package/src/components/ui/label.tsx +24 -0
- package/src/components/ui/menubar.tsx +238 -0
- package/src/components/ui/navigation-menu.tsx +129 -0
- package/src/components/ui/pagination.tsx +121 -0
- package/src/components/ui/popover.tsx +31 -0
- package/src/components/ui/progress.tsx +26 -0
- package/src/components/ui/radio-group.tsx +42 -0
- package/src/components/ui/resizable.tsx +43 -0
- package/src/components/ui/scroll-area.tsx +46 -0
- package/src/components/ui/searchable-select.tsx +94 -0
- package/src/components/ui/select.tsx +162 -0
- package/src/components/ui/separator.tsx +29 -0
- package/src/components/ui/sheet.tsx +141 -0
- package/src/components/ui/skeleton.tsx +18 -0
- package/src/components/ui/slider.tsx +26 -0
- package/src/components/ui/sonner.tsx +30 -0
- package/src/components/ui/switch.tsx +27 -0
- package/src/components/ui/table.tsx +120 -0
- package/src/components/ui/tabs.tsx +53 -0
- package/src/components/ui/textarea.tsx +24 -0
- package/src/components/ui/toast.tsx +128 -0
- package/src/components/ui/toaster.tsx +33 -0
- package/src/components/ui/toggle-group.tsx +59 -0
- package/src/components/ui/toggle.tsx +43 -0
- package/src/components/ui/tooltip.tsx +28 -0
- package/src/entry-server.tsx +12 -0
- package/src/hooks/use-account-balance.ts +24 -0
- package/src/hooks/use-ai-api.ts +35 -0
- package/src/hooks/use-axios.ts +20 -0
- package/src/hooks/use-code-completion-ai-api.ts +11 -0
- package/src/hooks/use-compiled-tsx.ts +37 -0
- package/src/hooks/use-copy-to-clipboard.ts +26 -0
- package/src/hooks/use-create-snippet-mutation.ts +62 -0
- package/src/hooks/use-current-snippet-id.ts +75 -0
- package/src/hooks/use-current-snippet.ts +24 -0
- package/src/hooks/use-global-store.ts +33 -0
- package/src/hooks/use-is-using-fake-api.ts +3 -0
- package/src/hooks/use-run-tsx/construct-circuit.tsx +64 -0
- package/src/hooks/use-run-tsx/eval-compiled-js.ts +9 -0
- package/src/hooks/use-run-tsx/index.tsx +251 -0
- package/src/hooks/use-save-snippet.ts +66 -0
- package/src/hooks/use-sign-in.ts +22 -0
- package/src/hooks/use-snippet-by-name.ts +25 -0
- package/src/hooks/use-snippet.ts +23 -0
- package/src/hooks/use-snippets-base-api-url.ts +3 -0
- package/src/hooks/use-toast.tsx +208 -0
- package/src/hooks/use-typecheck.ts +54 -0
- package/src/hooks/use-url-params.ts +31 -0
- package/src/hooks/use-warn-user-on-page-change.ts +23 -0
- package/src/hooks/useForkSnippetMutation.ts +52 -0
- package/src/index.css +21 -0
- package/src/lib/__tests__/constants.test.ts +66 -0
- package/src/lib/base64ToBytes.ts +5 -0
- package/src/lib/bytesToBase64.ts +4 -0
- package/src/lib/codemirror/basic-setup.ts +51 -0
- package/src/lib/constants.ts +12 -0
- package/src/lib/decodeUrlHashToText.ts +15 -0
- package/src/lib/defaultCodeForBlankCode.tsx +7 -0
- package/src/lib/download-fns/createBlobURL.ts +4 -0
- package/src/lib/download-fns/download-assembly-svg.ts +12 -0
- package/src/lib/download-fns/download-circuit-json-fn.ts +12 -0
- package/src/lib/download-fns/download-dsn-file-fn.ts +12 -0
- package/src/lib/download-fns/download-fabrication-files.ts +233 -0
- package/src/lib/download-fns/download-gltf.ts +49 -0
- package/src/lib/download-fns/download-kicad-files.ts +27 -0
- package/src/lib/download-fns/download-readable-netlist.ts +12 -0
- package/src/lib/download-fns/download-schematic-svg.ts +12 -0
- package/src/lib/download-fns/download-simple-route-json.ts +17 -0
- package/src/lib/encodeTextToUrlHash.ts +17 -0
- package/src/lib/get-snippet-template.ts +26 -0
- package/src/lib/handleManualEditsImport.tsx +65 -0
- package/src/lib/jlc-parts-engine.ts +69 -0
- package/src/lib/templates/blank-3d-model-template.ts +12 -0
- package/src/lib/templates/blank-circuit-board-template.ts +24 -0
- package/src/lib/templates/blank-footprint-template.ts +29 -0
- package/src/lib/templates/blank-package-template.ts +22 -0
- package/src/lib/templates/blinking-led-board-template.ts +63 -0
- package/src/lib/templates/manual-edits-template.ts +5 -0
- package/src/lib/templates/usb-c-led-flashlight-template.ts +22 -0
- package/src/lib/utils/checkIfManualEditsImported.ts +6 -0
- package/src/lib/utils/getSyntaxError.ts +13 -0
- package/src/lib/utils/index.ts +6 -0
- package/src/lib/utils/load-prettier.ts +18 -0
- package/src/lib/utils/parseFootprintParams.ts +52 -0
- package/src/lib/utils/parseJsonOrNull.ts +8 -0
- package/src/lib/utils/pcbManualEditEventHandler.ts +156 -0
- package/src/main.tsx +10 -0
- package/src/pages/ai.tsx +92 -0
- package/src/pages/authorize.tsx +54 -0
- package/src/pages/dashboard.tsx +165 -0
- package/src/pages/dev-login.tsx +68 -0
- package/src/pages/editor.tsx +28 -0
- package/src/pages/landing.tsx +236 -0
- package/src/pages/my-orders.tsx +54 -0
- package/src/pages/newest.tsx +16 -0
- package/src/pages/preview.tsx +70 -0
- package/src/pages/quickstart.tsx +198 -0
- package/src/pages/search.tsx +26 -0
- package/src/pages/settings.tsx +25 -0
- package/src/pages/user-profile.tsx +97 -0
- package/src/pages/view-order.tsx +123 -0
- package/src/pages/view-snippet.tsx +149 -0
- package/src/prettier.ts +9 -0
- package/src/vite-env.d.ts +1 -0
- package/tailwind.config.js +47 -0
- package/tsconfig.json +30 -0
- package/vercel.json +50 -0
- package/vite.config.ts +146 -0
- package/winterspec.config.ts +6 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import * as TabsPrimitive from "@radix-ui/react-tabs"
|
|
3
|
+
|
|
4
|
+
import { cn } from "@/lib/utils"
|
|
5
|
+
|
|
6
|
+
const Tabs = TabsPrimitive.Root
|
|
7
|
+
|
|
8
|
+
const TabsList = React.forwardRef<
|
|
9
|
+
React.ElementRef<typeof TabsPrimitive.List>,
|
|
10
|
+
React.ComponentPropsWithoutRef<typeof TabsPrimitive.List>
|
|
11
|
+
>(({ className, ...props }, ref) => (
|
|
12
|
+
<TabsPrimitive.List
|
|
13
|
+
ref={ref}
|
|
14
|
+
className={cn(
|
|
15
|
+
"inline-flex h-9 items-center justify-center rounded-lg bg-slate-100 p-1 text-slate-500 dark:bg-slate-800 dark:text-slate-400",
|
|
16
|
+
className,
|
|
17
|
+
)}
|
|
18
|
+
{...props}
|
|
19
|
+
/>
|
|
20
|
+
))
|
|
21
|
+
TabsList.displayName = TabsPrimitive.List.displayName
|
|
22
|
+
|
|
23
|
+
const TabsTrigger = React.forwardRef<
|
|
24
|
+
React.ElementRef<typeof TabsPrimitive.Trigger>,
|
|
25
|
+
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger>
|
|
26
|
+
>(({ className, ...props }, ref) => (
|
|
27
|
+
<TabsPrimitive.Trigger
|
|
28
|
+
ref={ref}
|
|
29
|
+
className={cn(
|
|
30
|
+
"inline-flex items-center justify-center whitespace-nowrap rounded-md px-3 py-1 text-sm font-medium ring-offset-white transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-slate-950 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-white data-[state=active]:text-slate-950 data-[state=active]:shadow dark:ring-offset-slate-950 dark:focus-visible:ring-slate-300 dark:data-[state=active]:bg-slate-950 dark:data-[state=active]:text-slate-50",
|
|
31
|
+
className,
|
|
32
|
+
)}
|
|
33
|
+
{...props}
|
|
34
|
+
/>
|
|
35
|
+
))
|
|
36
|
+
TabsTrigger.displayName = TabsPrimitive.Trigger.displayName
|
|
37
|
+
|
|
38
|
+
const TabsContent = React.forwardRef<
|
|
39
|
+
React.ElementRef<typeof TabsPrimitive.Content>,
|
|
40
|
+
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Content>
|
|
41
|
+
>(({ className, ...props }, ref) => (
|
|
42
|
+
<TabsPrimitive.Content
|
|
43
|
+
ref={ref}
|
|
44
|
+
className={cn(
|
|
45
|
+
"mt-2 ring-offset-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-slate-950 focus-visible:ring-offset-2 dark:ring-offset-slate-950 dark:focus-visible:ring-slate-300",
|
|
46
|
+
className,
|
|
47
|
+
)}
|
|
48
|
+
{...props}
|
|
49
|
+
/>
|
|
50
|
+
))
|
|
51
|
+
TabsContent.displayName = TabsPrimitive.Content.displayName
|
|
52
|
+
|
|
53
|
+
export { Tabs, TabsList, TabsTrigger, TabsContent }
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
|
|
3
|
+
import { cn } from "@/lib/utils"
|
|
4
|
+
|
|
5
|
+
export interface TextareaProps
|
|
6
|
+
extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {}
|
|
7
|
+
|
|
8
|
+
const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
|
|
9
|
+
({ className, ...props }, ref) => {
|
|
10
|
+
return (
|
|
11
|
+
<textarea
|
|
12
|
+
className={cn(
|
|
13
|
+
"flex min-h-[60px] w-full rounded-md border border-slate-200 bg-transparent px-3 py-2 text-sm shadow-sm placeholder:text-slate-500 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-slate-950 disabled:cursor-not-allowed disabled:opacity-50 dark:border-slate-800 dark:placeholder:text-slate-400 dark:focus-visible:ring-slate-300",
|
|
14
|
+
className,
|
|
15
|
+
)}
|
|
16
|
+
ref={ref}
|
|
17
|
+
{...props}
|
|
18
|
+
/>
|
|
19
|
+
)
|
|
20
|
+
},
|
|
21
|
+
)
|
|
22
|
+
Textarea.displayName = "Textarea"
|
|
23
|
+
|
|
24
|
+
export { Textarea }
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { Cross2Icon } from "@radix-ui/react-icons"
|
|
3
|
+
import * as ToastPrimitives from "@radix-ui/react-toast"
|
|
4
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
5
|
+
|
|
6
|
+
import { cn } from "@/lib/utils"
|
|
7
|
+
|
|
8
|
+
const ToastProvider = ToastPrimitives.Provider
|
|
9
|
+
|
|
10
|
+
const ToastViewport = React.forwardRef<
|
|
11
|
+
React.ElementRef<typeof ToastPrimitives.Viewport>,
|
|
12
|
+
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Viewport>
|
|
13
|
+
>(({ className, ...props }, ref) => (
|
|
14
|
+
<ToastPrimitives.Viewport
|
|
15
|
+
ref={ref}
|
|
16
|
+
className={cn(
|
|
17
|
+
"fixed top-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:top-auto sm:right-0 sm:flex-col md:max-w-[420px]",
|
|
18
|
+
className,
|
|
19
|
+
)}
|
|
20
|
+
{...props}
|
|
21
|
+
/>
|
|
22
|
+
))
|
|
23
|
+
ToastViewport.displayName = ToastPrimitives.Viewport.displayName
|
|
24
|
+
|
|
25
|
+
const toastVariants = cva(
|
|
26
|
+
"group pointer-events-auto relative flex w-full items-center justify-between space-x-2 overflow-hidden rounded-md border border-slate-200 p-4 pr-6 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full dark:border-slate-800",
|
|
27
|
+
{
|
|
28
|
+
variants: {
|
|
29
|
+
variant: {
|
|
30
|
+
default:
|
|
31
|
+
"border bg-white text-slate-950 dark:bg-slate-950 dark:text-slate-50",
|
|
32
|
+
destructive:
|
|
33
|
+
"destructive group border-red-500 bg-red-500 text-slate-50 dark:border-red-900 dark:bg-red-900 dark:text-slate-50",
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
defaultVariants: {
|
|
37
|
+
variant: "default",
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
const Toast = React.forwardRef<
|
|
43
|
+
React.ElementRef<typeof ToastPrimitives.Root>,
|
|
44
|
+
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> &
|
|
45
|
+
VariantProps<typeof toastVariants>
|
|
46
|
+
>(({ className, variant, ...props }, ref) => {
|
|
47
|
+
return (
|
|
48
|
+
<ToastPrimitives.Root
|
|
49
|
+
ref={ref}
|
|
50
|
+
className={cn(toastVariants({ variant }), className)}
|
|
51
|
+
{...props}
|
|
52
|
+
/>
|
|
53
|
+
)
|
|
54
|
+
})
|
|
55
|
+
Toast.displayName = ToastPrimitives.Root.displayName
|
|
56
|
+
|
|
57
|
+
const ToastAction = React.forwardRef<
|
|
58
|
+
React.ElementRef<typeof ToastPrimitives.Action>,
|
|
59
|
+
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Action>
|
|
60
|
+
>(({ className, ...props }, ref) => (
|
|
61
|
+
<ToastPrimitives.Action
|
|
62
|
+
ref={ref}
|
|
63
|
+
className={cn(
|
|
64
|
+
"inline-flex h-8 shrink-0 items-center justify-center rounded-md border border-slate-200 bg-transparent px-3 text-sm font-medium transition-colors hover:bg-slate-100 focus:outline-none focus:ring-1 focus:ring-slate-950 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-slate-100/40 group-[.destructive]:hover:border-red-500/30 group-[.destructive]:hover:bg-red-500 group-[.destructive]:hover:text-slate-50 group-[.destructive]:focus:ring-red-500 dark:border-slate-800 dark:hover:bg-slate-800 dark:focus:ring-slate-300 dark:group-[.destructive]:border-slate-800/40 dark:group-[.destructive]:hover:border-red-900/30 dark:group-[.destructive]:hover:bg-red-900 dark:group-[.destructive]:hover:text-slate-50 dark:group-[.destructive]:focus:ring-red-900",
|
|
65
|
+
className,
|
|
66
|
+
)}
|
|
67
|
+
{...props}
|
|
68
|
+
/>
|
|
69
|
+
))
|
|
70
|
+
ToastAction.displayName = ToastPrimitives.Action.displayName
|
|
71
|
+
|
|
72
|
+
const ToastClose = React.forwardRef<
|
|
73
|
+
React.ElementRef<typeof ToastPrimitives.Close>,
|
|
74
|
+
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Close>
|
|
75
|
+
>(({ className, ...props }, ref) => (
|
|
76
|
+
<ToastPrimitives.Close
|
|
77
|
+
ref={ref}
|
|
78
|
+
className={cn(
|
|
79
|
+
"absolute right-1 top-1 rounded-md p-1 text-slate-950/50 opacity-0 transition-opacity hover:text-slate-950 focus:opacity-100 focus:outline-none focus:ring-1 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600 dark:text-slate-50/50 dark:hover:text-slate-50",
|
|
80
|
+
className,
|
|
81
|
+
)}
|
|
82
|
+
toast-close=""
|
|
83
|
+
{...props}
|
|
84
|
+
>
|
|
85
|
+
<Cross2Icon className="h-4 w-4" />
|
|
86
|
+
</ToastPrimitives.Close>
|
|
87
|
+
))
|
|
88
|
+
ToastClose.displayName = ToastPrimitives.Close.displayName
|
|
89
|
+
|
|
90
|
+
const ToastTitle = React.forwardRef<
|
|
91
|
+
React.ElementRef<typeof ToastPrimitives.Title>,
|
|
92
|
+
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Title>
|
|
93
|
+
>(({ className, ...props }, ref) => (
|
|
94
|
+
<ToastPrimitives.Title
|
|
95
|
+
ref={ref}
|
|
96
|
+
className={cn("text-sm font-semibold [&+div]:text-xs", className)}
|
|
97
|
+
{...props}
|
|
98
|
+
/>
|
|
99
|
+
))
|
|
100
|
+
ToastTitle.displayName = ToastPrimitives.Title.displayName
|
|
101
|
+
|
|
102
|
+
const ToastDescription = React.forwardRef<
|
|
103
|
+
React.ElementRef<typeof ToastPrimitives.Description>,
|
|
104
|
+
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Description>
|
|
105
|
+
>(({ className, ...props }, ref) => (
|
|
106
|
+
<ToastPrimitives.Description
|
|
107
|
+
ref={ref}
|
|
108
|
+
className={cn("text-sm opacity-90", className)}
|
|
109
|
+
{...props}
|
|
110
|
+
/>
|
|
111
|
+
))
|
|
112
|
+
ToastDescription.displayName = ToastPrimitives.Description.displayName
|
|
113
|
+
|
|
114
|
+
type ToastProps = React.ComponentPropsWithoutRef<typeof Toast>
|
|
115
|
+
|
|
116
|
+
type ToastActionElement = React.ReactElement<typeof ToastAction>
|
|
117
|
+
|
|
118
|
+
export {
|
|
119
|
+
type ToastProps,
|
|
120
|
+
type ToastActionElement,
|
|
121
|
+
ToastProvider,
|
|
122
|
+
ToastViewport,
|
|
123
|
+
Toast,
|
|
124
|
+
ToastTitle,
|
|
125
|
+
ToastDescription,
|
|
126
|
+
ToastClose,
|
|
127
|
+
ToastAction,
|
|
128
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useToast } from "@/hooks/use-toast"
|
|
2
|
+
import {
|
|
3
|
+
Toast,
|
|
4
|
+
ToastClose,
|
|
5
|
+
ToastDescription,
|
|
6
|
+
ToastProvider,
|
|
7
|
+
ToastTitle,
|
|
8
|
+
ToastViewport,
|
|
9
|
+
} from "@/components/ui/toast"
|
|
10
|
+
|
|
11
|
+
export function Toaster() {
|
|
12
|
+
const { toasts } = useToast()
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<ToastProvider>
|
|
16
|
+
{toasts.map(function ({ id, title, description, action, ...props }) {
|
|
17
|
+
return (
|
|
18
|
+
<Toast key={id} {...props}>
|
|
19
|
+
<div className="grid gap-1">
|
|
20
|
+
{title && <ToastTitle>{title}</ToastTitle>}
|
|
21
|
+
{description && (
|
|
22
|
+
<ToastDescription>{description}</ToastDescription>
|
|
23
|
+
)}
|
|
24
|
+
</div>
|
|
25
|
+
{action}
|
|
26
|
+
<ToastClose />
|
|
27
|
+
</Toast>
|
|
28
|
+
)
|
|
29
|
+
})}
|
|
30
|
+
<ToastViewport />
|
|
31
|
+
</ToastProvider>
|
|
32
|
+
)
|
|
33
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import * as ToggleGroupPrimitive from "@radix-ui/react-toggle-group"
|
|
3
|
+
import { type VariantProps } from "class-variance-authority"
|
|
4
|
+
|
|
5
|
+
import { cn } from "@/lib/utils"
|
|
6
|
+
import { toggleVariants } from "@/components/ui/toggle"
|
|
7
|
+
|
|
8
|
+
const ToggleGroupContext = React.createContext<
|
|
9
|
+
VariantProps<typeof toggleVariants>
|
|
10
|
+
>({
|
|
11
|
+
size: "default",
|
|
12
|
+
variant: "default",
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
const ToggleGroup = React.forwardRef<
|
|
16
|
+
React.ElementRef<typeof ToggleGroupPrimitive.Root>,
|
|
17
|
+
React.ComponentPropsWithoutRef<typeof ToggleGroupPrimitive.Root> &
|
|
18
|
+
VariantProps<typeof toggleVariants>
|
|
19
|
+
>(({ className, variant, size, children, ...props }, ref) => (
|
|
20
|
+
<ToggleGroupPrimitive.Root
|
|
21
|
+
ref={ref}
|
|
22
|
+
className={cn("flex items-center justify-center gap-1", className)}
|
|
23
|
+
{...props}
|
|
24
|
+
>
|
|
25
|
+
<ToggleGroupContext.Provider value={{ variant, size }}>
|
|
26
|
+
{children}
|
|
27
|
+
</ToggleGroupContext.Provider>
|
|
28
|
+
</ToggleGroupPrimitive.Root>
|
|
29
|
+
))
|
|
30
|
+
|
|
31
|
+
ToggleGroup.displayName = ToggleGroupPrimitive.Root.displayName
|
|
32
|
+
|
|
33
|
+
const ToggleGroupItem = React.forwardRef<
|
|
34
|
+
React.ElementRef<typeof ToggleGroupPrimitive.Item>,
|
|
35
|
+
React.ComponentPropsWithoutRef<typeof ToggleGroupPrimitive.Item> &
|
|
36
|
+
VariantProps<typeof toggleVariants>
|
|
37
|
+
>(({ className, children, variant, size, ...props }, ref) => {
|
|
38
|
+
const context = React.useContext(ToggleGroupContext)
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<ToggleGroupPrimitive.Item
|
|
42
|
+
ref={ref}
|
|
43
|
+
className={cn(
|
|
44
|
+
toggleVariants({
|
|
45
|
+
variant: context.variant || variant,
|
|
46
|
+
size: context.size || size,
|
|
47
|
+
}),
|
|
48
|
+
className,
|
|
49
|
+
)}
|
|
50
|
+
{...props}
|
|
51
|
+
>
|
|
52
|
+
{children}
|
|
53
|
+
</ToggleGroupPrimitive.Item>
|
|
54
|
+
)
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
ToggleGroupItem.displayName = ToggleGroupPrimitive.Item.displayName
|
|
58
|
+
|
|
59
|
+
export { ToggleGroup, ToggleGroupItem }
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import * as TogglePrimitive from "@radix-ui/react-toggle"
|
|
3
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
4
|
+
|
|
5
|
+
import { cn } from "@/lib/utils"
|
|
6
|
+
|
|
7
|
+
const toggleVariants = cva(
|
|
8
|
+
"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors hover:bg-slate-100 hover:text-slate-500 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-slate-950 disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-slate-100 data-[state=on]:text-slate-900 dark:hover:bg-slate-800 dark:hover:text-slate-400 dark:focus-visible:ring-slate-300 dark:data-[state=on]:bg-slate-800 dark:data-[state=on]:text-slate-50",
|
|
9
|
+
{
|
|
10
|
+
variants: {
|
|
11
|
+
variant: {
|
|
12
|
+
default: "bg-transparent",
|
|
13
|
+
outline:
|
|
14
|
+
"border border-slate-200 bg-transparent shadow-sm hover:bg-slate-100 hover:text-slate-900 dark:border-slate-800 dark:hover:bg-slate-800 dark:hover:text-slate-50",
|
|
15
|
+
},
|
|
16
|
+
size: {
|
|
17
|
+
default: "h-9 px-3",
|
|
18
|
+
sm: "h-8 px-2",
|
|
19
|
+
lg: "h-10 px-3",
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
defaultVariants: {
|
|
23
|
+
variant: "default",
|
|
24
|
+
size: "default",
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
const Toggle = React.forwardRef<
|
|
30
|
+
React.ElementRef<typeof TogglePrimitive.Root>,
|
|
31
|
+
React.ComponentPropsWithoutRef<typeof TogglePrimitive.Root> &
|
|
32
|
+
VariantProps<typeof toggleVariants>
|
|
33
|
+
>(({ className, variant, size, ...props }, ref) => (
|
|
34
|
+
<TogglePrimitive.Root
|
|
35
|
+
ref={ref}
|
|
36
|
+
className={cn(toggleVariants({ variant, size, className }))}
|
|
37
|
+
{...props}
|
|
38
|
+
/>
|
|
39
|
+
))
|
|
40
|
+
|
|
41
|
+
Toggle.displayName = TogglePrimitive.Root.displayName
|
|
42
|
+
|
|
43
|
+
export { Toggle, toggleVariants }
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import * as TooltipPrimitive from "@radix-ui/react-tooltip"
|
|
3
|
+
|
|
4
|
+
import { cn } from "@/lib/utils"
|
|
5
|
+
|
|
6
|
+
const TooltipProvider = TooltipPrimitive.Provider
|
|
7
|
+
|
|
8
|
+
const Tooltip = TooltipPrimitive.Root
|
|
9
|
+
|
|
10
|
+
const TooltipTrigger = TooltipPrimitive.Trigger
|
|
11
|
+
|
|
12
|
+
const TooltipContent = React.forwardRef<
|
|
13
|
+
React.ElementRef<typeof TooltipPrimitive.Content>,
|
|
14
|
+
React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>
|
|
15
|
+
>(({ className, sideOffset = 4, ...props }, ref) => (
|
|
16
|
+
<TooltipPrimitive.Content
|
|
17
|
+
ref={ref}
|
|
18
|
+
sideOffset={sideOffset}
|
|
19
|
+
className={cn(
|
|
20
|
+
"z-50 overflow-hidden rounded-md bg-slate-900 px-3 py-1.5 text-xs text-slate-50 animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 dark:bg-slate-50 dark:text-slate-900",
|
|
21
|
+
className,
|
|
22
|
+
)}
|
|
23
|
+
{...props}
|
|
24
|
+
/>
|
|
25
|
+
))
|
|
26
|
+
TooltipContent.displayName = TooltipPrimitive.Content.displayName
|
|
27
|
+
|
|
28
|
+
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider }
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from "react"
|
|
2
|
+
import ReactDOMServer from "react-dom/server"
|
|
3
|
+
import App from "./App"
|
|
4
|
+
|
|
5
|
+
export function render() {
|
|
6
|
+
const html = ReactDOMServer.renderToString(
|
|
7
|
+
<React.StrictMode>
|
|
8
|
+
<App />
|
|
9
|
+
</React.StrictMode>,
|
|
10
|
+
)
|
|
11
|
+
return { html }
|
|
12
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useQuery } from "react-query"
|
|
2
|
+
import { useAxios } from "./use-axios"
|
|
3
|
+
import { useGlobalStore } from "./use-global-store"
|
|
4
|
+
|
|
5
|
+
interface AccountBalance {
|
|
6
|
+
monthly_ai_budget_used_usd: number
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const useAccountBalance = () => {
|
|
10
|
+
const axios = useAxios()
|
|
11
|
+
const isLoggedIn = useGlobalStore((s) => Boolean(s.session))
|
|
12
|
+
|
|
13
|
+
return useQuery<AccountBalance, Error>(
|
|
14
|
+
"accountBalance",
|
|
15
|
+
async () => {
|
|
16
|
+
const { data } = await axios.get("/accounts/get_account_balance")
|
|
17
|
+
return data.account_balance
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
refetchInterval: 60000, // Refetch every minute
|
|
21
|
+
enabled: isLoggedIn,
|
|
22
|
+
},
|
|
23
|
+
)
|
|
24
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Anthropic } from "@anthropic-ai/sdk"
|
|
2
|
+
import { useMemo } from "react"
|
|
3
|
+
import { useGlobalStore } from "./use-global-store"
|
|
4
|
+
|
|
5
|
+
export const useAiApi = ({
|
|
6
|
+
streaming = false,
|
|
7
|
+
}: { streaming?: boolean } = {}) => {
|
|
8
|
+
const sessionToken = useGlobalStore((state) => state.session?.token)
|
|
9
|
+
const anthropic = useMemo(() => {
|
|
10
|
+
if (import.meta.env.VITE_USE_DIRECT_AI_REQUESTS === "true") {
|
|
11
|
+
console.warn(
|
|
12
|
+
"Direct AI requests are enabled. Do not use this in production.",
|
|
13
|
+
)
|
|
14
|
+
}
|
|
15
|
+
return new Anthropic(
|
|
16
|
+
import.meta.env.VITE_USE_DIRECT_AI_REQUESTS === "true"
|
|
17
|
+
? {
|
|
18
|
+
apiKey: import.meta.env.VITE_ANTHROPIC_API_KEY,
|
|
19
|
+
dangerouslyAllowBrowser: true,
|
|
20
|
+
}
|
|
21
|
+
: {
|
|
22
|
+
apiKey: "{REPLACE_ON_SERVER}",
|
|
23
|
+
baseURL: import.meta.env.VITE_SNIPPETS_API_URL
|
|
24
|
+
? `${import.meta.env.VITE_SNIPPETS_API_URL}/anthropic`
|
|
25
|
+
: "/api/anthropic",
|
|
26
|
+
defaultHeaders: {
|
|
27
|
+
Authorization: `Bearer ${sessionToken}`,
|
|
28
|
+
},
|
|
29
|
+
dangerouslyAllowBrowser: true,
|
|
30
|
+
},
|
|
31
|
+
)
|
|
32
|
+
}, [])
|
|
33
|
+
|
|
34
|
+
return anthropic
|
|
35
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import axios from "redaxios"
|
|
2
|
+
import { useMemo } from "react"
|
|
3
|
+
import { useSnippetsBaseApiUrl } from "./use-snippets-base-api-url"
|
|
4
|
+
import { useGlobalStore } from "./use-global-store"
|
|
5
|
+
|
|
6
|
+
export const useAxios = () => {
|
|
7
|
+
const snippetsBaseApiUrl = useSnippetsBaseApiUrl()
|
|
8
|
+
const session = useGlobalStore((s) => s.session)
|
|
9
|
+
return useMemo(() => {
|
|
10
|
+
const instance = axios.create({
|
|
11
|
+
baseURL: snippetsBaseApiUrl,
|
|
12
|
+
headers: session
|
|
13
|
+
? {
|
|
14
|
+
Authorization: `Bearer ${session?.token}`,
|
|
15
|
+
}
|
|
16
|
+
: {},
|
|
17
|
+
})
|
|
18
|
+
return instance
|
|
19
|
+
}, [session?.token])
|
|
20
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useMemo } from "react"
|
|
2
|
+
import * as Babel from "@babel/standalone"
|
|
3
|
+
|
|
4
|
+
export const safeCompileTsx = (
|
|
5
|
+
code: string,
|
|
6
|
+
):
|
|
7
|
+
| { success: true; compiledTsx: string; error?: undefined }
|
|
8
|
+
| { success: false; error: Error; compiledTsx?: undefined } => {
|
|
9
|
+
try {
|
|
10
|
+
return {
|
|
11
|
+
success: true,
|
|
12
|
+
compiledTsx:
|
|
13
|
+
Babel.transform(code, {
|
|
14
|
+
presets: ["react", "typescript"],
|
|
15
|
+
plugins: ["transform-modules-commonjs"],
|
|
16
|
+
filename: "virtual.tsx",
|
|
17
|
+
}).code || "",
|
|
18
|
+
}
|
|
19
|
+
} catch (error: any) {
|
|
20
|
+
return { success: false, error }
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const useCompiledTsx = (
|
|
25
|
+
code?: string,
|
|
26
|
+
{ isStreaming = false }: { isStreaming?: boolean } = {},
|
|
27
|
+
) => {
|
|
28
|
+
return useMemo(() => {
|
|
29
|
+
if (!code) return ""
|
|
30
|
+
if (isStreaming) return ""
|
|
31
|
+
const result = safeCompileTsx(code)
|
|
32
|
+
if (result.success) {
|
|
33
|
+
return result.compiledTsx
|
|
34
|
+
}
|
|
35
|
+
return `Error: ${result.error.message}`
|
|
36
|
+
}, [code, isStreaming])
|
|
37
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useToast } from "@/hooks/use-toast"
|
|
2
|
+
import { useCallback } from "react"
|
|
3
|
+
|
|
4
|
+
export const useCopyToClipboard = () => {
|
|
5
|
+
const { toast } = useToast()
|
|
6
|
+
|
|
7
|
+
const copyToClipboard = useCallback(
|
|
8
|
+
async (text: string) => {
|
|
9
|
+
try {
|
|
10
|
+
await navigator.clipboard.writeText(text)
|
|
11
|
+
toast({
|
|
12
|
+
title: "Copied to clipboard!",
|
|
13
|
+
description: "The text has been copied successfully.",
|
|
14
|
+
})
|
|
15
|
+
} catch (error) {
|
|
16
|
+
toast({
|
|
17
|
+
title: "Failed to copy",
|
|
18
|
+
description: "There was an error copying the text.",
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
[toast],
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
return { copyToClipboard }
|
|
26
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { getSnippetTemplate } from "@/lib/get-snippet-template"
|
|
2
|
+
import { Snippet } from "fake-snippets-api/lib/db/schema"
|
|
3
|
+
import { useMutation } from "react-query"
|
|
4
|
+
import { useAxios } from "./use-axios"
|
|
5
|
+
import { useGlobalStore } from "./use-global-store"
|
|
6
|
+
import { useUrlParams } from "./use-url-params"
|
|
7
|
+
|
|
8
|
+
export const useCreateSnippetMutation = ({
|
|
9
|
+
onSuccess,
|
|
10
|
+
}: { onSuccess?: (snippet: Snippet) => void } = {}) => {
|
|
11
|
+
const urlParams = useUrlParams()
|
|
12
|
+
const templateName = urlParams.template
|
|
13
|
+
const axios = useAxios()
|
|
14
|
+
const session = useGlobalStore((s) => s.session)
|
|
15
|
+
return useMutation(
|
|
16
|
+
["createSnippet"],
|
|
17
|
+
async ({
|
|
18
|
+
code,
|
|
19
|
+
circuit_json,
|
|
20
|
+
manual_edits_json_content,
|
|
21
|
+
}: {
|
|
22
|
+
code?: string
|
|
23
|
+
circuit_json?: any[]
|
|
24
|
+
manual_edits_json_content?: string
|
|
25
|
+
} = {}) => {
|
|
26
|
+
if (!session) throw new Error("No session")
|
|
27
|
+
const template =
|
|
28
|
+
typeof code === "string"
|
|
29
|
+
? {
|
|
30
|
+
code,
|
|
31
|
+
type:
|
|
32
|
+
urlParams.type ||
|
|
33
|
+
(code.includes("<board") ? "board" : "package"),
|
|
34
|
+
}
|
|
35
|
+
: getSnippetTemplate(templateName)
|
|
36
|
+
const {
|
|
37
|
+
data: { snippet },
|
|
38
|
+
} = await axios.post("/snippets/create", {
|
|
39
|
+
code: template.code,
|
|
40
|
+
snippet_type: template.type ?? "board",
|
|
41
|
+
manual_edits_json_content,
|
|
42
|
+
owner_name: session?.github_username,
|
|
43
|
+
circuit_json,
|
|
44
|
+
})
|
|
45
|
+
return snippet
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
onSuccess: (snippet: any) => {
|
|
49
|
+
const url = new URL(window.location.href)
|
|
50
|
+
url.searchParams.set("snippet_id", snippet.snippet_id)
|
|
51
|
+
url.searchParams.delete("template")
|
|
52
|
+
url.searchParams.delete("should_create_snippet")
|
|
53
|
+
window.history.pushState({}, "", url.toString())
|
|
54
|
+
onSuccess?.(snippet)
|
|
55
|
+
window.dispatchEvent(new Event("popstate"))
|
|
56
|
+
},
|
|
57
|
+
onError: (error: any) => {
|
|
58
|
+
console.error("Error creating snippet:", error)
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
)
|
|
62
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from "react"
|
|
2
|
+
import { useUrlParams } from "./use-url-params"
|
|
3
|
+
import { useAxios } from "./use-axios"
|
|
4
|
+
import { useLocation, useParams } from "wouter"
|
|
5
|
+
import { useMutation } from "react-query"
|
|
6
|
+
import { useSnippetByName } from "./use-snippet-by-name"
|
|
7
|
+
import { getSnippetTemplate } from "@/lib/get-snippet-template"
|
|
8
|
+
import { useGlobalStore } from "./use-global-store"
|
|
9
|
+
import { useCreateSnippetMutation } from "./use-create-snippet-mutation"
|
|
10
|
+
|
|
11
|
+
export const useCurrentSnippetId = (): {
|
|
12
|
+
snippetId: string | null
|
|
13
|
+
isLoading: boolean
|
|
14
|
+
error: (Error & { status: number }) | null
|
|
15
|
+
} => {
|
|
16
|
+
const urlParams = useUrlParams()
|
|
17
|
+
const urlSnippetId = urlParams.snippet_id
|
|
18
|
+
const templateName = urlParams.template
|
|
19
|
+
const isLoggedIn = useGlobalStore((s) => Boolean(s.session))
|
|
20
|
+
const wouter = useParams()
|
|
21
|
+
const [location] = useLocation()
|
|
22
|
+
const [snippetIdFromUrl, setSnippetId] = useState<string | null>(urlSnippetId)
|
|
23
|
+
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (urlSnippetId) {
|
|
26
|
+
setSnippetId(urlSnippetId)
|
|
27
|
+
}
|
|
28
|
+
}, [urlSnippetId])
|
|
29
|
+
|
|
30
|
+
const {
|
|
31
|
+
data: snippetByName,
|
|
32
|
+
isLoading: isLoadingSnippetByName,
|
|
33
|
+
error: errorSnippetByName,
|
|
34
|
+
} = useSnippetByName(
|
|
35
|
+
wouter.author && wouter.snippetName
|
|
36
|
+
? `${wouter.author}/${wouter.snippetName}`
|
|
37
|
+
: null,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
const createSnippetMutation = useCreateSnippetMutation({
|
|
41
|
+
onSuccess: (snippet) => {
|
|
42
|
+
setSnippetId(snippet.snippet_id)
|
|
43
|
+
},
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (snippetIdFromUrl) return
|
|
48
|
+
if (location !== "/editor") return
|
|
49
|
+
if (wouter?.author && wouter?.snippetName) return
|
|
50
|
+
if ((window as any).AUTO_CREATED_SNIPPET) return
|
|
51
|
+
if (!isLoggedIn) return
|
|
52
|
+
if (!urlParams.should_create_snippet) return
|
|
53
|
+
;(window as any).AUTO_CREATED_SNIPPET = true
|
|
54
|
+
createSnippetMutation.mutate({})
|
|
55
|
+
return () => {
|
|
56
|
+
setTimeout(() => {
|
|
57
|
+
;(window as any).AUTO_CREATED_SNIPPET = false
|
|
58
|
+
}, 1000)
|
|
59
|
+
}
|
|
60
|
+
}, [])
|
|
61
|
+
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
if (templateName) {
|
|
64
|
+
const url = new URL(window.location.href)
|
|
65
|
+
url.searchParams.delete("should_create_snippet")
|
|
66
|
+
window.history.replaceState({}, "", url.toString())
|
|
67
|
+
}
|
|
68
|
+
}, [templateName])
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
snippetId: snippetIdFromUrl ?? snippetByName?.snippet_id ?? null,
|
|
72
|
+
isLoading: isLoadingSnippetByName,
|
|
73
|
+
error: errorSnippetByName,
|
|
74
|
+
}
|
|
75
|
+
}
|