@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,363 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import * as RechartsPrimitive from "recharts"
|
|
3
|
+
|
|
4
|
+
import { cn } from "@/lib/utils"
|
|
5
|
+
|
|
6
|
+
// Format: { THEME_NAME: CSS_SELECTOR }
|
|
7
|
+
const THEMES = { light: "", dark: ".dark" } as const
|
|
8
|
+
|
|
9
|
+
export type ChartConfig = {
|
|
10
|
+
[k in string]: {
|
|
11
|
+
label?: React.ReactNode
|
|
12
|
+
icon?: React.ComponentType
|
|
13
|
+
} & (
|
|
14
|
+
| { color?: string; theme?: never }
|
|
15
|
+
| { color?: never; theme: Record<keyof typeof THEMES, string> }
|
|
16
|
+
)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type ChartContextProps = {
|
|
20
|
+
config: ChartConfig
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const ChartContext = React.createContext<ChartContextProps | null>(null)
|
|
24
|
+
|
|
25
|
+
function useChart() {
|
|
26
|
+
const context = React.useContext(ChartContext)
|
|
27
|
+
|
|
28
|
+
if (!context) {
|
|
29
|
+
throw new Error("useChart must be used within a <ChartContainer />")
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return context
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const ChartContainer = React.forwardRef<
|
|
36
|
+
HTMLDivElement,
|
|
37
|
+
React.ComponentProps<"div"> & {
|
|
38
|
+
config: ChartConfig
|
|
39
|
+
children: React.ComponentProps<
|
|
40
|
+
typeof RechartsPrimitive.ResponsiveContainer
|
|
41
|
+
>["children"]
|
|
42
|
+
}
|
|
43
|
+
>(({ id, className, children, config, ...props }, ref) => {
|
|
44
|
+
const uniqueId = React.useId()
|
|
45
|
+
const chartId = `chart-${id || uniqueId.replace(/:/g, "")}`
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<ChartContext.Provider value={{ config }}>
|
|
49
|
+
<div
|
|
50
|
+
data-chart={chartId}
|
|
51
|
+
ref={ref}
|
|
52
|
+
className={cn(
|
|
53
|
+
"flex aspect-video justify-center text-xs [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-none [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-sector]:outline-none [&_.recharts-surface]:outline-none",
|
|
54
|
+
className,
|
|
55
|
+
)}
|
|
56
|
+
{...props}
|
|
57
|
+
>
|
|
58
|
+
<ChartStyle id={chartId} config={config} />
|
|
59
|
+
<RechartsPrimitive.ResponsiveContainer>
|
|
60
|
+
{children}
|
|
61
|
+
</RechartsPrimitive.ResponsiveContainer>
|
|
62
|
+
</div>
|
|
63
|
+
</ChartContext.Provider>
|
|
64
|
+
)
|
|
65
|
+
})
|
|
66
|
+
ChartContainer.displayName = "Chart"
|
|
67
|
+
|
|
68
|
+
const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
|
|
69
|
+
const colorConfig = Object.entries(config).filter(
|
|
70
|
+
([_, config]) => config.theme || config.color,
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
if (!colorConfig.length) {
|
|
74
|
+
return null
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<style
|
|
79
|
+
dangerouslySetInnerHTML={{
|
|
80
|
+
__html: Object.entries(THEMES)
|
|
81
|
+
.map(
|
|
82
|
+
([theme, prefix]) => `
|
|
83
|
+
${prefix} [data-chart=${id}] {
|
|
84
|
+
${colorConfig
|
|
85
|
+
.map(([key, itemConfig]) => {
|
|
86
|
+
const color =
|
|
87
|
+
itemConfig.theme?.[theme as keyof typeof itemConfig.theme] ||
|
|
88
|
+
itemConfig.color
|
|
89
|
+
return color ? ` --color-${key}: ${color};` : null
|
|
90
|
+
})
|
|
91
|
+
.join("\n")}
|
|
92
|
+
}
|
|
93
|
+
`,
|
|
94
|
+
)
|
|
95
|
+
.join("\n"),
|
|
96
|
+
}}
|
|
97
|
+
/>
|
|
98
|
+
)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const ChartTooltip = RechartsPrimitive.Tooltip
|
|
102
|
+
|
|
103
|
+
const ChartTooltipContent = React.forwardRef<
|
|
104
|
+
HTMLDivElement,
|
|
105
|
+
React.ComponentProps<typeof RechartsPrimitive.Tooltip> &
|
|
106
|
+
React.ComponentProps<"div"> & {
|
|
107
|
+
hideLabel?: boolean
|
|
108
|
+
hideIndicator?: boolean
|
|
109
|
+
indicator?: "line" | "dot" | "dashed"
|
|
110
|
+
nameKey?: string
|
|
111
|
+
labelKey?: string
|
|
112
|
+
}
|
|
113
|
+
>(
|
|
114
|
+
(
|
|
115
|
+
{
|
|
116
|
+
active,
|
|
117
|
+
payload,
|
|
118
|
+
className,
|
|
119
|
+
indicator = "dot",
|
|
120
|
+
hideLabel = false,
|
|
121
|
+
hideIndicator = false,
|
|
122
|
+
label,
|
|
123
|
+
labelFormatter,
|
|
124
|
+
labelClassName,
|
|
125
|
+
formatter,
|
|
126
|
+
color,
|
|
127
|
+
nameKey,
|
|
128
|
+
labelKey,
|
|
129
|
+
},
|
|
130
|
+
ref,
|
|
131
|
+
) => {
|
|
132
|
+
const { config } = useChart()
|
|
133
|
+
|
|
134
|
+
const tooltipLabel = React.useMemo(() => {
|
|
135
|
+
if (hideLabel || !payload?.length) {
|
|
136
|
+
return null
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const [item] = payload
|
|
140
|
+
const key = `${labelKey || item.dataKey || item.name || "value"}`
|
|
141
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key)
|
|
142
|
+
const value =
|
|
143
|
+
!labelKey && typeof label === "string"
|
|
144
|
+
? config[label as keyof typeof config]?.label || label
|
|
145
|
+
: itemConfig?.label
|
|
146
|
+
|
|
147
|
+
if (labelFormatter) {
|
|
148
|
+
return (
|
|
149
|
+
<div className={cn("font-medium", labelClassName)}>
|
|
150
|
+
{labelFormatter(value, payload)}
|
|
151
|
+
</div>
|
|
152
|
+
)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (!value) {
|
|
156
|
+
return null
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return <div className={cn("font-medium", labelClassName)}>{value}</div>
|
|
160
|
+
}, [
|
|
161
|
+
label,
|
|
162
|
+
labelFormatter,
|
|
163
|
+
payload,
|
|
164
|
+
hideLabel,
|
|
165
|
+
labelClassName,
|
|
166
|
+
config,
|
|
167
|
+
labelKey,
|
|
168
|
+
])
|
|
169
|
+
|
|
170
|
+
if (!active || !payload?.length) {
|
|
171
|
+
return null
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const nestLabel = payload.length === 1 && indicator !== "dot"
|
|
175
|
+
|
|
176
|
+
return (
|
|
177
|
+
<div
|
|
178
|
+
ref={ref}
|
|
179
|
+
className={cn(
|
|
180
|
+
"grid min-w-[8rem] items-start gap-1.5 rounded-lg border border-slate-200 border-slate-200/50 bg-white px-2.5 py-1.5 text-xs shadow-xl dark:border-slate-800 dark:border-slate-800/50 dark:bg-slate-950",
|
|
181
|
+
className,
|
|
182
|
+
)}
|
|
183
|
+
>
|
|
184
|
+
{!nestLabel ? tooltipLabel : null}
|
|
185
|
+
<div className="grid gap-1.5">
|
|
186
|
+
{payload.map((item, index) => {
|
|
187
|
+
const key = `${nameKey || item.name || item.dataKey || "value"}`
|
|
188
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key)
|
|
189
|
+
const indicatorColor = color || item.payload.fill || item.color
|
|
190
|
+
|
|
191
|
+
return (
|
|
192
|
+
<div
|
|
193
|
+
key={item.dataKey}
|
|
194
|
+
className={cn(
|
|
195
|
+
"flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-slate-500 dark:[&>svg]:text-slate-400",
|
|
196
|
+
indicator === "dot" && "items-center",
|
|
197
|
+
)}
|
|
198
|
+
>
|
|
199
|
+
{formatter && item?.value !== undefined && item.name ? (
|
|
200
|
+
formatter(item.value, item.name, item, index, item.payload)
|
|
201
|
+
) : (
|
|
202
|
+
<>
|
|
203
|
+
{itemConfig?.icon ? (
|
|
204
|
+
<itemConfig.icon />
|
|
205
|
+
) : (
|
|
206
|
+
!hideIndicator && (
|
|
207
|
+
<div
|
|
208
|
+
className={cn(
|
|
209
|
+
"shrink-0 rounded-[2px] border-[--color-border] bg-[--color-bg]",
|
|
210
|
+
{
|
|
211
|
+
"h-2.5 w-2.5": indicator === "dot",
|
|
212
|
+
"w-1": indicator === "line",
|
|
213
|
+
"w-0 border-[1.5px] border-dashed bg-transparent":
|
|
214
|
+
indicator === "dashed",
|
|
215
|
+
"my-0.5": nestLabel && indicator === "dashed",
|
|
216
|
+
},
|
|
217
|
+
)}
|
|
218
|
+
style={
|
|
219
|
+
{
|
|
220
|
+
"--color-bg": indicatorColor,
|
|
221
|
+
"--color-border": indicatorColor,
|
|
222
|
+
} as React.CSSProperties
|
|
223
|
+
}
|
|
224
|
+
/>
|
|
225
|
+
)
|
|
226
|
+
)}
|
|
227
|
+
<div
|
|
228
|
+
className={cn(
|
|
229
|
+
"flex flex-1 justify-between leading-none",
|
|
230
|
+
nestLabel ? "items-end" : "items-center",
|
|
231
|
+
)}
|
|
232
|
+
>
|
|
233
|
+
<div className="grid gap-1.5">
|
|
234
|
+
{nestLabel ? tooltipLabel : null}
|
|
235
|
+
<span className="text-slate-500 dark:text-slate-400">
|
|
236
|
+
{itemConfig?.label || item.name}
|
|
237
|
+
</span>
|
|
238
|
+
</div>
|
|
239
|
+
{item.value && (
|
|
240
|
+
<span className="font-mono font-medium tabular-nums text-slate-950 dark:text-slate-50">
|
|
241
|
+
{item.value.toLocaleString()}
|
|
242
|
+
</span>
|
|
243
|
+
)}
|
|
244
|
+
</div>
|
|
245
|
+
</>
|
|
246
|
+
)}
|
|
247
|
+
</div>
|
|
248
|
+
)
|
|
249
|
+
})}
|
|
250
|
+
</div>
|
|
251
|
+
</div>
|
|
252
|
+
)
|
|
253
|
+
},
|
|
254
|
+
)
|
|
255
|
+
ChartTooltipContent.displayName = "ChartTooltip"
|
|
256
|
+
|
|
257
|
+
const ChartLegend = RechartsPrimitive.Legend
|
|
258
|
+
|
|
259
|
+
const ChartLegendContent = React.forwardRef<
|
|
260
|
+
HTMLDivElement,
|
|
261
|
+
React.ComponentProps<"div"> &
|
|
262
|
+
Pick<RechartsPrimitive.LegendProps, "payload" | "verticalAlign"> & {
|
|
263
|
+
hideIcon?: boolean
|
|
264
|
+
nameKey?: string
|
|
265
|
+
}
|
|
266
|
+
>(
|
|
267
|
+
(
|
|
268
|
+
{ className, hideIcon = false, payload, verticalAlign = "bottom", nameKey },
|
|
269
|
+
ref,
|
|
270
|
+
) => {
|
|
271
|
+
const { config } = useChart()
|
|
272
|
+
|
|
273
|
+
if (!payload?.length) {
|
|
274
|
+
return null
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
return (
|
|
278
|
+
<div
|
|
279
|
+
ref={ref}
|
|
280
|
+
className={cn(
|
|
281
|
+
"flex items-center justify-center gap-4",
|
|
282
|
+
verticalAlign === "top" ? "pb-3" : "pt-3",
|
|
283
|
+
className,
|
|
284
|
+
)}
|
|
285
|
+
>
|
|
286
|
+
{payload.map((item) => {
|
|
287
|
+
const key = `${nameKey || item.dataKey || "value"}`
|
|
288
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key)
|
|
289
|
+
|
|
290
|
+
return (
|
|
291
|
+
<div
|
|
292
|
+
key={item.value}
|
|
293
|
+
className={cn(
|
|
294
|
+
"flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-slate-500 dark:[&>svg]:text-slate-400",
|
|
295
|
+
)}
|
|
296
|
+
>
|
|
297
|
+
{itemConfig?.icon && !hideIcon ? (
|
|
298
|
+
<itemConfig.icon />
|
|
299
|
+
) : (
|
|
300
|
+
<div
|
|
301
|
+
className="h-2 w-2 shrink-0 rounded-[2px]"
|
|
302
|
+
style={{
|
|
303
|
+
backgroundColor: item.color,
|
|
304
|
+
}}
|
|
305
|
+
/>
|
|
306
|
+
)}
|
|
307
|
+
{itemConfig?.label}
|
|
308
|
+
</div>
|
|
309
|
+
)
|
|
310
|
+
})}
|
|
311
|
+
</div>
|
|
312
|
+
)
|
|
313
|
+
},
|
|
314
|
+
)
|
|
315
|
+
ChartLegendContent.displayName = "ChartLegend"
|
|
316
|
+
|
|
317
|
+
// Helper to extract item config from a payload.
|
|
318
|
+
function getPayloadConfigFromPayload(
|
|
319
|
+
config: ChartConfig,
|
|
320
|
+
payload: unknown,
|
|
321
|
+
key: string,
|
|
322
|
+
) {
|
|
323
|
+
if (typeof payload !== "object" || payload === null) {
|
|
324
|
+
return undefined
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const payloadPayload =
|
|
328
|
+
"payload" in payload &&
|
|
329
|
+
typeof payload.payload === "object" &&
|
|
330
|
+
payload.payload !== null
|
|
331
|
+
? payload.payload
|
|
332
|
+
: undefined
|
|
333
|
+
|
|
334
|
+
let configLabelKey: string = key
|
|
335
|
+
|
|
336
|
+
if (
|
|
337
|
+
key in payload &&
|
|
338
|
+
typeof payload[key as keyof typeof payload] === "string"
|
|
339
|
+
) {
|
|
340
|
+
configLabelKey = payload[key as keyof typeof payload] as string
|
|
341
|
+
} else if (
|
|
342
|
+
payloadPayload &&
|
|
343
|
+
key in payloadPayload &&
|
|
344
|
+
typeof payloadPayload[key as keyof typeof payloadPayload] === "string"
|
|
345
|
+
) {
|
|
346
|
+
configLabelKey = payloadPayload[
|
|
347
|
+
key as keyof typeof payloadPayload
|
|
348
|
+
] as string
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
return configLabelKey in config
|
|
352
|
+
? config[configLabelKey]
|
|
353
|
+
: config[key as keyof typeof config]
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
export {
|
|
357
|
+
ChartContainer,
|
|
358
|
+
ChartTooltip,
|
|
359
|
+
ChartTooltipContent,
|
|
360
|
+
ChartLegend,
|
|
361
|
+
ChartLegendContent,
|
|
362
|
+
ChartStyle,
|
|
363
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import * as CheckboxPrimitive from "@radix-ui/react-checkbox"
|
|
3
|
+
import { CheckIcon } from "@radix-ui/react-icons"
|
|
4
|
+
|
|
5
|
+
import { cn } from "@/lib/utils"
|
|
6
|
+
|
|
7
|
+
const Checkbox = React.forwardRef<
|
|
8
|
+
React.ElementRef<typeof CheckboxPrimitive.Root>,
|
|
9
|
+
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
|
|
10
|
+
>(({ className, ...props }, ref) => (
|
|
11
|
+
<CheckboxPrimitive.Root
|
|
12
|
+
ref={ref}
|
|
13
|
+
className={cn(
|
|
14
|
+
"peer h-4 w-4 shrink-0 rounded-sm border border-slate-200 border-slate-900 shadow focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-slate-950 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-slate-900 data-[state=checked]:text-slate-50 dark:border-slate-800 dark:border-slate-50 dark:focus-visible:ring-slate-300 dark:data-[state=checked]:bg-slate-50 dark:data-[state=checked]:text-slate-900",
|
|
15
|
+
className,
|
|
16
|
+
)}
|
|
17
|
+
{...props}
|
|
18
|
+
>
|
|
19
|
+
<CheckboxPrimitive.Indicator
|
|
20
|
+
className={cn("flex items-center justify-center text-current")}
|
|
21
|
+
>
|
|
22
|
+
<CheckIcon className="h-4 w-4" />
|
|
23
|
+
</CheckboxPrimitive.Indicator>
|
|
24
|
+
</CheckboxPrimitive.Root>
|
|
25
|
+
))
|
|
26
|
+
Checkbox.displayName = CheckboxPrimitive.Root.displayName
|
|
27
|
+
|
|
28
|
+
export { Checkbox }
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as CollapsiblePrimitive from "@radix-ui/react-collapsible"
|
|
2
|
+
|
|
3
|
+
const Collapsible = CollapsiblePrimitive.Root
|
|
4
|
+
|
|
5
|
+
const CollapsibleTrigger = CollapsiblePrimitive.CollapsibleTrigger
|
|
6
|
+
|
|
7
|
+
const CollapsibleContent = CollapsiblePrimitive.CollapsibleContent
|
|
8
|
+
|
|
9
|
+
export { Collapsible, CollapsibleTrigger, CollapsibleContent }
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { Check, ChevronsUpDown } from "lucide-react"
|
|
3
|
+
import { cn } from "../../lib/utils"
|
|
4
|
+
import { Button } from "../../components/ui/button"
|
|
5
|
+
import {
|
|
6
|
+
Command,
|
|
7
|
+
CommandEmpty,
|
|
8
|
+
CommandGroup,
|
|
9
|
+
CommandInput,
|
|
10
|
+
CommandItem,
|
|
11
|
+
} from "../../components/ui/command"
|
|
12
|
+
import {
|
|
13
|
+
Popover,
|
|
14
|
+
PopoverContent,
|
|
15
|
+
PopoverTrigger,
|
|
16
|
+
} from "../../components/ui/popover"
|
|
17
|
+
|
|
18
|
+
interface ComboboxProps {
|
|
19
|
+
value: string
|
|
20
|
+
onChange: (value: string) => void
|
|
21
|
+
options: string[]
|
|
22
|
+
placeholder?: string
|
|
23
|
+
searchPlaceholder?: string
|
|
24
|
+
emptyText?: string
|
|
25
|
+
className?: string
|
|
26
|
+
name?: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function Combobox({
|
|
30
|
+
value,
|
|
31
|
+
onChange,
|
|
32
|
+
options,
|
|
33
|
+
placeholder = "Select option...",
|
|
34
|
+
searchPlaceholder = "Search...",
|
|
35
|
+
emptyText = "No results found.",
|
|
36
|
+
className,
|
|
37
|
+
name,
|
|
38
|
+
}: ComboboxProps) {
|
|
39
|
+
const [open, setOpen] = React.useState(false)
|
|
40
|
+
const [searchValue, setSearchValue] = React.useState("")
|
|
41
|
+
const [highlightedIndex, setHighlightedIndex] = React.useState(0)
|
|
42
|
+
const filteredOptions = React.useMemo(
|
|
43
|
+
() =>
|
|
44
|
+
options.filter((option) =>
|
|
45
|
+
option.toLowerCase().includes(searchValue.toLowerCase()),
|
|
46
|
+
),
|
|
47
|
+
[options, searchValue],
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
const handleKeyDown = (e: React.KeyboardEvent) => {
|
|
51
|
+
switch (e.key) {
|
|
52
|
+
case "Tab":
|
|
53
|
+
case "ArrowDown":
|
|
54
|
+
e.preventDefault()
|
|
55
|
+
setHighlightedIndex((prev) =>
|
|
56
|
+
prev < filteredOptions.length - 1 ? prev + 1 : prev,
|
|
57
|
+
)
|
|
58
|
+
break
|
|
59
|
+
case "ArrowUp":
|
|
60
|
+
e.preventDefault()
|
|
61
|
+
setHighlightedIndex((prev) => (prev > 0 ? prev - 1 : prev))
|
|
62
|
+
break
|
|
63
|
+
case "Enter":
|
|
64
|
+
e.preventDefault()
|
|
65
|
+
if (filteredOptions.length > 0) {
|
|
66
|
+
const selectedOption = filteredOptions[highlightedIndex]
|
|
67
|
+
onChange(selectedOption)
|
|
68
|
+
setSearchValue("")
|
|
69
|
+
setOpen(false)
|
|
70
|
+
setHighlightedIndex(0)
|
|
71
|
+
}
|
|
72
|
+
break
|
|
73
|
+
case "Escape":
|
|
74
|
+
setOpen(false)
|
|
75
|
+
setHighlightedIndex(0)
|
|
76
|
+
break
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Reset highlighted index when filtered options change
|
|
81
|
+
React.useEffect(() => {
|
|
82
|
+
setHighlightedIndex(0)
|
|
83
|
+
}, [filteredOptions.length])
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
87
|
+
<PopoverTrigger asChild>
|
|
88
|
+
<Button
|
|
89
|
+
name={name}
|
|
90
|
+
variant="outline"
|
|
91
|
+
role="combobox"
|
|
92
|
+
aria-expanded={open}
|
|
93
|
+
className={cn("w-full justify-between", className)}
|
|
94
|
+
>
|
|
95
|
+
{value || placeholder}
|
|
96
|
+
<ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
|
97
|
+
</Button>
|
|
98
|
+
</PopoverTrigger>
|
|
99
|
+
<PopoverContent className="w-[280px] p-0 z-[100]">
|
|
100
|
+
<Command onKeyDown={handleKeyDown} shouldFilter={false}>
|
|
101
|
+
<CommandInput
|
|
102
|
+
value={searchValue}
|
|
103
|
+
onValueChange={setSearchValue}
|
|
104
|
+
placeholder={searchPlaceholder}
|
|
105
|
+
/>
|
|
106
|
+
<CommandEmpty
|
|
107
|
+
className="text-sm text-slate-500
|
|
108
|
+
py-6"
|
|
109
|
+
>
|
|
110
|
+
{emptyText}
|
|
111
|
+
</CommandEmpty>
|
|
112
|
+
<CommandGroup
|
|
113
|
+
className="max-h-[400px] overflow-y-auto overscroll-contain scroll-smooth"
|
|
114
|
+
onWheel={(e) => {
|
|
115
|
+
e.stopPropagation()
|
|
116
|
+
const target = e.currentTarget
|
|
117
|
+
target.scrollTop += e.deltaY
|
|
118
|
+
}}
|
|
119
|
+
onTouchStart={(e) => {
|
|
120
|
+
e.stopPropagation()
|
|
121
|
+
const target = e.currentTarget
|
|
122
|
+
target.dataset.touchStartY = e.touches[0].clientY.toString()
|
|
123
|
+
}}
|
|
124
|
+
onTouchMove={(e) => {
|
|
125
|
+
e.stopPropagation()
|
|
126
|
+
const target = e.currentTarget
|
|
127
|
+
const touchStartY = parseFloat(target.dataset.touchStartY || "0")
|
|
128
|
+
const touchCurrentY = e.touches[0].clientY
|
|
129
|
+
target.scrollTop += touchStartY - touchCurrentY
|
|
130
|
+
target.dataset.touchStartY = touchCurrentY.toString()
|
|
131
|
+
}}
|
|
132
|
+
ref={(ref) => {
|
|
133
|
+
if (ref && filteredOptions.length > 0) {
|
|
134
|
+
const items = ref.getElementsByClassName("cmd-item")
|
|
135
|
+
const highlighted = items[highlightedIndex] as HTMLElement
|
|
136
|
+
if (highlighted) {
|
|
137
|
+
highlighted.scrollIntoView({
|
|
138
|
+
block: "nearest",
|
|
139
|
+
behavior: "smooth",
|
|
140
|
+
})
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}}
|
|
144
|
+
>
|
|
145
|
+
{filteredOptions.map((option, index) => (
|
|
146
|
+
<CommandItem
|
|
147
|
+
key={option}
|
|
148
|
+
onSelect={(currentValue) => {
|
|
149
|
+
onChange(currentValue)
|
|
150
|
+
setSearchValue("")
|
|
151
|
+
setOpen(false)
|
|
152
|
+
setHighlightedIndex(0)
|
|
153
|
+
}}
|
|
154
|
+
className={cn(
|
|
155
|
+
"cmd-item cursor-pointer transition-all ease-in-out",
|
|
156
|
+
index === highlightedIndex
|
|
157
|
+
? "bg-indigo-500 text-white"
|
|
158
|
+
: "hover:bg-slate-100 dark:hover:bg-slate-800",
|
|
159
|
+
)}
|
|
160
|
+
>
|
|
161
|
+
<Check
|
|
162
|
+
className={cn(
|
|
163
|
+
"mr-2 h-4 w-4 transition-opacity",
|
|
164
|
+
value === option ? "opacity-100" : "opacity-0",
|
|
165
|
+
index === highlightedIndex
|
|
166
|
+
? "text-white"
|
|
167
|
+
: "text-indigo-500",
|
|
168
|
+
)}
|
|
169
|
+
/>
|
|
170
|
+
{option}
|
|
171
|
+
</CommandItem>
|
|
172
|
+
))}
|
|
173
|
+
</CommandGroup>
|
|
174
|
+
</Command>
|
|
175
|
+
</PopoverContent>
|
|
176
|
+
</Popover>
|
|
177
|
+
)
|
|
178
|
+
}
|