@tscircuit/fake-snippets 0.0.99 → 0.0.101
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/bun.lock +302 -808
- package/dist/bundle.js +466 -414
- package/dist/index.d.ts +4 -2
- package/dist/index.js +25 -0
- package/fake-snippets-api/lib/db/db-client.ts +32 -0
- package/fake-snippets-api/routes/api/accounts/search.ts +20 -0
- package/fake-snippets-api/routes/api/packages/create.ts +14 -3
- package/package.json +7 -5
- package/src/App.tsx +58 -2
- package/src/components/CircuitJsonImportDialog.tsx +10 -5
- package/src/components/CmdKMenu.tsx +154 -19
- package/src/components/Header2.tsx +106 -25
- package/src/components/PackageBuildsPage/package-build-header.tsx +19 -15
- package/src/components/ViewPackagePage/components/important-files-view.tsx +304 -172
- package/src/components/ViewPackagePage/components/main-content-header.tsx +2 -2
- package/src/components/ViewPackagePage/components/repo-page-content.tsx +9 -0
- package/src/components/ViewPackagePage/components/sidebar-about-section.tsx +10 -3
- package/src/components/ViewPackagePage/components/sidebar.tsx +3 -1
- package/src/components/dialogs/edit-package-details-dialog.tsx +3 -2
- package/src/components/package-port/CodeAndPreview.tsx +1 -1
- package/src/components/package-port/CodeEditor.tsx +2 -2
- package/src/components/package-port/CodeEditorHeader.tsx +20 -16
- package/src/hooks/use-create-package-mutation.ts +1 -1
- package/src/hooks/useFileManagement.ts +1 -5
- package/src/lib/utils/package-utils.ts +0 -3
- package/src/pages/landing.tsx +1 -1
|
@@ -13,9 +13,12 @@ import { PackageInfo } from "@/lib/types"
|
|
|
13
13
|
interface SidebarAboutSectionProps {
|
|
14
14
|
packageInfo?: PackageInfo
|
|
15
15
|
isLoading?: boolean
|
|
16
|
+
onLicenseClick?: () => void
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
export default function SidebarAboutSection(
|
|
19
|
+
export default function SidebarAboutSection({
|
|
20
|
+
onLicenseClick,
|
|
21
|
+
}: SidebarAboutSectionProps = {}) {
|
|
19
22
|
const { packageInfo, refetch: refetchPackageInfo } = useCurrentPackageInfo()
|
|
20
23
|
const { data: packageRelease } = usePackageReleaseById(
|
|
21
24
|
packageInfo?.latest_package_release_id,
|
|
@@ -137,7 +140,11 @@ export default function SidebarAboutSection() {
|
|
|
137
140
|
))}
|
|
138
141
|
</div>
|
|
139
142
|
<div className="space-y-2 text-sm">
|
|
140
|
-
<
|
|
143
|
+
<button
|
|
144
|
+
className="flex items-center hover:underline hover:underline-offset-2 cursor-pointer hover:decoration-gray-500"
|
|
145
|
+
onClick={onLicenseClick}
|
|
146
|
+
disabled={!onLicenseClick}
|
|
147
|
+
>
|
|
141
148
|
<svg
|
|
142
149
|
className="h-4 w-4 mr-2 text-gray-500 dark:text-[#8b949e]"
|
|
143
150
|
viewBox="0 0 16 16"
|
|
@@ -146,7 +153,7 @@ export default function SidebarAboutSection() {
|
|
|
146
153
|
<path d="M8.75.75V2h.985c.304 0 .603.08.867.231l1.29.736c.038.022.08.033.124.033h2.234a.75.75 0 0 1 0 1.5h-.427l2.111 4.692a.75.75 0 0 1-.154.838l-.53-.53.53.53-.001.002-.002.002-.006.006-.006.005-.01.01-.045.04c-.21.176-.441.327-.686.45C14.556 10.78 13.88 11 13 11a4.498 4.498 0 0 1-2.023-.454 3.544 3.544 0 0 1-.686-.45l-.045-.04-.016-.015-.006-.006-.004-.004v-.001a.75.75 0 0 1-.154-.838L12.178 4.5h-.162c-.305 0-.604-.079-.868-.231l-1.29-.736a.245.245 0 0 0-.124-.033H8.75V13h2.5a.75.75 0 0 1 0 1.5h-6.5a.75.75 0 0 1 0-1.5h2.5V3.5h-.984a.245.245 0 0 0-.124.033l-1.29.736c-.264.152-.563.231-.868.231h-.162l2.112 4.692a.75.75 0 0 1-.154.838l-.53-.53.53.53-.001.002-.002.002-.006.006-.016.015-.045.04c-.21.176-.441.327-.686.45C4.556 10.78 3.88 11 3 11a4.498 4.498 0 0 1-2.023-.454 3.544 3.544 0 0 1-.686-.45l-.045-.04-.016-.015-.006-.006-.004-.004v-.001a.75.75 0 0 1-.154-.838L2.178 4.5H1.75a.75.75 0 0 1 0-1.5h2.234a.249.249 0 0 0 .125-.033l1.29-.736c.263-.15.561-.231.865-.231H7.25V.75a.75.75 0 0 1 1.5 0Zm2.945 8.477c.285.135.718.273 1.305.273s1.02-.138 1.305-.273L13 6.327Zm-10 0c.285.135.718.273 1.305.273s1.02-.138 1.305-.273L3 6.327Z"></path>
|
|
147
154
|
</svg>
|
|
148
155
|
<span>{currentLicense ?? "Unset"} license</span>
|
|
149
|
-
</
|
|
156
|
+
</button>
|
|
150
157
|
|
|
151
158
|
<div className="flex items-center">
|
|
152
159
|
<Star className="h-4 w-4 mr-2 text-gray-500 dark:text-[#8b949e]" />
|
|
@@ -9,16 +9,18 @@ interface SidebarProps {
|
|
|
9
9
|
packageInfo?: Package
|
|
10
10
|
isLoading?: boolean
|
|
11
11
|
onViewChange?: (view: "3d" | "pcb" | "schematic") => void
|
|
12
|
+
onLicenseClick?: () => void
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
export default function Sidebar({
|
|
15
16
|
packageInfo,
|
|
16
17
|
isLoading = false,
|
|
17
18
|
onViewChange,
|
|
19
|
+
onLicenseClick,
|
|
18
20
|
}: SidebarProps) {
|
|
19
21
|
return (
|
|
20
22
|
<div className="h-full p-4 bg-white dark:bg-[#0d1117] overflow-y-auto">
|
|
21
|
-
<SidebarAboutSection />
|
|
23
|
+
<SidebarAboutSection onLicenseClick={onLicenseClick} />
|
|
22
24
|
<PreviewImageSquares
|
|
23
25
|
packageInfo={packageInfo}
|
|
24
26
|
onViewChange={onViewChange}
|
|
@@ -186,6 +186,7 @@ export const EditPackageDetailsDialog = ({
|
|
|
186
186
|
"packageFile",
|
|
187
187
|
{ package_release_id: packageReleaseId },
|
|
188
188
|
])
|
|
189
|
+
qc.invalidateQueries(["packageFiles", packageReleaseId])
|
|
189
190
|
toast({
|
|
190
191
|
title: "Package details updated",
|
|
191
192
|
description: "Successfully updated package details",
|
|
@@ -376,7 +377,7 @@ export const EditPackageDetailsDialog = ({
|
|
|
376
377
|
className="mt-2 rounded-md"
|
|
377
378
|
onToggle={(e) => setDangerOpen(e.currentTarget.open)}
|
|
378
379
|
>
|
|
379
|
-
<summary className="cursor-pointer p-2 font-medium text-sm text-black list-none flex justify-between items-center">
|
|
380
|
+
<summary className="select-none cursor-pointer p-2 font-medium text-sm text-black list-none flex justify-between items-center">
|
|
380
381
|
Danger Zone
|
|
381
382
|
<ChevronDown
|
|
382
383
|
className={`w-4 h-4 mr-1 transition-transform ${dangerOpen ? "rotate-180" : ""}`}
|
|
@@ -405,7 +406,7 @@ export const EditPackageDetailsDialog = ({
|
|
|
405
406
|
</div>
|
|
406
407
|
|
|
407
408
|
<DialogFooter className="mt-auto">
|
|
408
|
-
<div className="lg:px-2 flex flex-col sm:flex-row justify-end gap-2">
|
|
409
|
+
<div className="lg:px-2 select-none flex flex-col sm:flex-row justify-end gap-2">
|
|
409
410
|
<Button
|
|
410
411
|
variant="outline"
|
|
411
412
|
onClick={() => onOpenChange(false)}
|
|
@@ -172,7 +172,7 @@ export function CodeAndPreview({ pkg, projectUrl }: Props) {
|
|
|
172
172
|
|
|
173
173
|
if (urlParams.package_id && (!pkg || isLoading)) {
|
|
174
174
|
return (
|
|
175
|
-
<div className="flex items-center justify-center h-[
|
|
175
|
+
<div className="flex items-center justify-center h-[80vh]">
|
|
176
176
|
<div className="flex flex-col items-center justify-center">
|
|
177
177
|
<div className="text-lg text-gray-500 mb-4">Loading</div>
|
|
178
178
|
<Loader2 className="w-16 h-16 animate-spin text-gray-400" />
|
|
@@ -205,7 +205,7 @@ export const CodeEditor = ({
|
|
|
205
205
|
projectName: "my-project",
|
|
206
206
|
typescript: tsModule,
|
|
207
207
|
logger: console,
|
|
208
|
-
fetcher: async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
208
|
+
fetcher: (async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
209
209
|
const registryPrefixes = [
|
|
210
210
|
"https://data.jsdelivr.com/v1/package/resolve/npm/@tsci/",
|
|
211
211
|
"https://data.jsdelivr.com/v1/package/npm/@tsci/",
|
|
@@ -231,7 +231,7 @@ export const CodeEditor = ({
|
|
|
231
231
|
)
|
|
232
232
|
}
|
|
233
233
|
return fetch(input, init)
|
|
234
|
-
},
|
|
234
|
+
}) as typeof fetch,
|
|
235
235
|
delegate: {
|
|
236
236
|
started: () => {
|
|
237
237
|
const manualEditsTypeDeclaration = `
|
|
@@ -162,22 +162,26 @@ export const CodeEditorHeader: React.FC<CodeEditorHeaderProps> = ({
|
|
|
162
162
|
if (!session?.token) {
|
|
163
163
|
throw new Error("You need to be logged in to import jlcpcb component")
|
|
164
164
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
165
|
+
|
|
166
|
+
const jlcpcbComponent = await fetchEasyEDAComponent(
|
|
167
|
+
component.partNumber ?? component.name,
|
|
168
|
+
{
|
|
169
|
+
fetch: ((url, options: any) => {
|
|
170
|
+
return fetch(`${API_BASE}/proxy`, {
|
|
171
|
+
body: options.body,
|
|
172
|
+
method: options.method,
|
|
173
|
+
headers: {
|
|
174
|
+
authority: options.headers.authority,
|
|
175
|
+
Authorization: `Bearer ${session?.token}`,
|
|
176
|
+
"X-Target-Url": url.toString(),
|
|
177
|
+
"X-Sender-Host": options.headers.origin,
|
|
178
|
+
"X-Sender-Origin": options.headers.origin,
|
|
179
|
+
"content-type": options.headers["content-type"],
|
|
180
|
+
},
|
|
181
|
+
})
|
|
182
|
+
}) as typeof fetch,
|
|
183
|
+
},
|
|
184
|
+
)
|
|
181
185
|
const tsxComponent = await convertRawEasyToTsx(jlcpcbComponent)
|
|
182
186
|
let componentName = component.name.replace(/ /g, "-")
|
|
183
187
|
if (files[`${componentName}.tsx`] || files[`./${componentName}.tsx`]) {
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { useEffect, useMemo, useState, useCallback, useRef } from "react"
|
|
2
2
|
import { isValidFileName } from "@/lib/utils/isValidFileName"
|
|
3
3
|
import { PackageFile } from "@/types/package"
|
|
4
|
-
import {
|
|
5
|
-
DEFAULT_CODE,
|
|
6
|
-
generateRandomPackageName,
|
|
7
|
-
} from "@/lib/utils/package-utils"
|
|
4
|
+
import { DEFAULT_CODE } from "@/lib/utils/package-utils"
|
|
8
5
|
import { Package } from "fake-snippets-api/lib/db/schema"
|
|
9
6
|
import { usePackageFiles } from "./use-package-files"
|
|
10
7
|
import { decodeUrlHashToText } from "@/lib/decodeUrlHashToText"
|
|
@@ -318,7 +315,6 @@ export function useFileManagement({
|
|
|
318
315
|
}
|
|
319
316
|
|
|
320
317
|
await createPackageMutation.mutateAsync({
|
|
321
|
-
name: `${loggedInUser?.github_username}/${generateRandomPackageName()}`,
|
|
322
318
|
is_private: isPrivate,
|
|
323
319
|
})
|
|
324
320
|
}
|