@tscircuit/fake-snippets 0.0.90 → 0.0.92
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 +73 -97
- package/dist/bundle.js +4 -3
- package/dist/index.js +2 -1
- package/fake-snippets-api/lib/db/autoload-dev-packages.ts +1 -0
- package/fake-snippets-api/routes/api/packages/list_trending.ts +1 -1
- package/package.json +4 -8
- package/src/ContextProviders.tsx +0 -2
- package/src/components/PageSearchComponent.tsx +2 -2
- package/src/components/SearchComponent.tsx +2 -2
- package/src/components/TrendingPackagesCarousel.tsx +2 -2
- package/src/components/dialogs/import-component-dialog.tsx +25 -0
- package/src/components/package-port/CodeEditor.tsx +103 -21
- package/src/components/package-port/CodeEditorHeader.tsx +67 -10
- package/src/components/package-port/EditorNav.tsx +56 -50
- package/src/components/package-port/GlobalFindReplace.tsx +2 -2
- package/src/hooks/use-axios.ts +2 -2
- package/src/hooks/use-packages-base-api-url.ts +3 -0
- package/src/hooks/use-request-ai-review-mutation.ts +1 -1
- package/src/hooks/use-sign-in.ts +2 -2
- package/src/hooks/use-toast.tsx +1 -0
- package/src/hooks/useFileManagement.ts +8 -3
- package/src/main.tsx +0 -3
- package/src/pages/dashboard.tsx +2 -2
- package/src/pages/dev-login.tsx +2 -2
- package/src/pages/latest.tsx +2 -2
- package/src/pages/search.tsx +2 -2
- package/src/pages/trending.tsx +2 -2
- package/src/pages/user-profile.tsx +2 -2
- package/vite.config.ts +0 -19
- package/src/build-watcher.ts +0 -52
- package/src/global.d.ts +0 -3
|
@@ -44,7 +44,7 @@ interface FileMatch {
|
|
|
44
44
|
interface GlobalFindReplaceProps {
|
|
45
45
|
files: PackageFile[]
|
|
46
46
|
currentFile: string | null
|
|
47
|
-
onFileSelect: (path: string) => void
|
|
47
|
+
onFileSelect: (path: string, lineNumber?: number) => void
|
|
48
48
|
onFileContentChanged?: (path: string, content: string) => void
|
|
49
49
|
onClose: () => void
|
|
50
50
|
}
|
|
@@ -217,7 +217,7 @@ const GlobalFindReplace = ({
|
|
|
217
217
|
|
|
218
218
|
const goToMatch = useCallback(
|
|
219
219
|
(fileMatch: FileMatch, match: Match) => {
|
|
220
|
-
onFileSelect(fileMatch.file.path)
|
|
220
|
+
onFileSelect(fileMatch.file.path, match.line)
|
|
221
221
|
onClose()
|
|
222
222
|
},
|
|
223
223
|
[onFileSelect, onClose],
|
package/src/hooks/use-axios.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import axios from "redaxios"
|
|
2
2
|
import { useMemo } from "react"
|
|
3
|
-
import { useSnippetsBaseApiUrl } from "./use-snippets-base-api-url"
|
|
4
3
|
import { useGlobalStore } from "./use-global-store"
|
|
4
|
+
import { usePackagesBaseApiUrl } from "./use-packages-base-api-url"
|
|
5
5
|
|
|
6
6
|
export const useAxios = () => {
|
|
7
|
-
const snippetsBaseApiUrl =
|
|
7
|
+
const snippetsBaseApiUrl = usePackagesBaseApiUrl()
|
|
8
8
|
const session = useGlobalStore((s) => s.session)
|
|
9
9
|
return useMemo(() => {
|
|
10
10
|
const instance = axios.create({
|
|
@@ -34,7 +34,7 @@ export const useRequestAiReviewMutation = ({
|
|
|
34
34
|
onSuccess: ({ package_release, ai_review }) => {
|
|
35
35
|
toast({
|
|
36
36
|
title: "AI review requested",
|
|
37
|
-
description: "An AI review has been
|
|
37
|
+
description: "An AI review has been requested.",
|
|
38
38
|
})
|
|
39
39
|
queryClient.invalidateQueries(["packageRelease"])
|
|
40
40
|
onSuccess?.(package_release, ai_review)
|
package/src/hooks/use-sign-in.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { useGlobalStore } from "./use-global-store"
|
|
2
2
|
import { useIsUsingFakeApi } from "./use-is-using-fake-api"
|
|
3
|
-
import {
|
|
3
|
+
import { usePackagesBaseApiUrl } from "./use-packages-base-api-url"
|
|
4
4
|
|
|
5
5
|
export const useSignIn = () => {
|
|
6
|
-
const snippetsBaseApiUrl =
|
|
6
|
+
const snippetsBaseApiUrl = usePackagesBaseApiUrl()
|
|
7
7
|
const isUsingFakeApi = useIsUsingFakeApi()
|
|
8
8
|
const setSession = useGlobalStore((s) => s.setSession)
|
|
9
9
|
return () => {
|
package/src/hooks/use-toast.tsx
CHANGED
|
@@ -20,7 +20,9 @@ import { encodeFsMapToUrlHash } from "@/lib/encodeFsMapToUrlHash"
|
|
|
20
20
|
|
|
21
21
|
export interface ICreateFileProps {
|
|
22
22
|
newFileName: string
|
|
23
|
+
content?: string
|
|
23
24
|
onError: (error: Error) => void
|
|
25
|
+
openFile?: boolean
|
|
24
26
|
}
|
|
25
27
|
export interface ICreateFileResult {
|
|
26
28
|
newFileCreated: boolean
|
|
@@ -182,6 +184,8 @@ export function useFileManagement({
|
|
|
182
184
|
const createFile = ({
|
|
183
185
|
newFileName,
|
|
184
186
|
onError,
|
|
187
|
+
content,
|
|
188
|
+
openFile = true,
|
|
185
189
|
}: ICreateFileProps): ICreateFileResult => {
|
|
186
190
|
newFileName = newFileName.trim()
|
|
187
191
|
if (!newFileName) {
|
|
@@ -206,11 +210,12 @@ export function useFileManagement({
|
|
|
206
210
|
}
|
|
207
211
|
const updatedFiles = [
|
|
208
212
|
...(localFiles || []),
|
|
209
|
-
{ path: newFileName, content: "" },
|
|
213
|
+
{ path: newFileName, content: content || "" },
|
|
210
214
|
]
|
|
211
215
|
setLocalFiles(updatedFiles)
|
|
212
|
-
|
|
213
|
-
|
|
216
|
+
if (openFile) {
|
|
217
|
+
setCurrentFile(newFileName)
|
|
218
|
+
}
|
|
214
219
|
return {
|
|
215
220
|
newFileCreated: true,
|
|
216
221
|
}
|
package/src/main.tsx
CHANGED
|
@@ -6,9 +6,6 @@ if (typeof window !== "undefined" && !window.__APP_LOADED_AT) {
|
|
|
6
6
|
window.__APP_LOADED_AT = Date.now()
|
|
7
7
|
}
|
|
8
8
|
import "./index.css"
|
|
9
|
-
import { setupBuildWatcher } from "./build-watcher"
|
|
10
|
-
|
|
11
|
-
setupBuildWatcher()
|
|
12
9
|
|
|
13
10
|
createRoot(document.getElementById("root")!).render(
|
|
14
11
|
<StrictMode>
|
package/src/pages/dashboard.tsx
CHANGED
|
@@ -12,7 +12,7 @@ import { PrefetchPageLink } from "@/components/PrefetchPageLink"
|
|
|
12
12
|
import { PackagesList } from "@/components/PackagesList"
|
|
13
13
|
import { Helmet } from "react-helmet-async"
|
|
14
14
|
import { useSignIn } from "@/hooks/use-sign-in"
|
|
15
|
-
import {
|
|
15
|
+
import { usePackagesBaseApiUrl } from "@/hooks/use-packages-base-api-url"
|
|
16
16
|
import { useConfirmDeletePackageDialog } from "@/components/dialogs/confirm-delete-package-dialog"
|
|
17
17
|
import { PackageCardSkeleton } from "@/components/PackageCardSkeleton"
|
|
18
18
|
import { PackageCard } from "@/components/PackageCard"
|
|
@@ -81,7 +81,7 @@ export const DashboardPage = () => {
|
|
|
81
81
|
},
|
|
82
82
|
)
|
|
83
83
|
|
|
84
|
-
const baseUrl =
|
|
84
|
+
const baseUrl = usePackagesBaseApiUrl()
|
|
85
85
|
|
|
86
86
|
const handleDeleteClick = (e: React.MouseEvent, pkg: Package) => {
|
|
87
87
|
e.preventDefault() // Prevent navigation
|
package/src/pages/dev-login.tsx
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { useGlobalStore } from "@/hooks/use-global-store"
|
|
2
|
-
import {
|
|
2
|
+
import { usePackagesBaseApiUrl } from "@/hooks/use-packages-base-api-url"
|
|
3
3
|
import { useState } from "react"
|
|
4
4
|
import { useLocation } from "wouter"
|
|
5
5
|
|
|
6
6
|
export const DevLoginPage = () => {
|
|
7
|
-
const snippetsBaseApiUrl =
|
|
7
|
+
const snippetsBaseApiUrl = usePackagesBaseApiUrl()
|
|
8
8
|
const [username, setUsername] = useState("")
|
|
9
9
|
const setSession = useGlobalStore((s) => s.setSession)
|
|
10
10
|
const [, setLocation] = useLocation()
|
package/src/pages/latest.tsx
CHANGED
|
@@ -6,7 +6,7 @@ import Header from "@/components/Header"
|
|
|
6
6
|
import Footer from "@/components/Footer"
|
|
7
7
|
import { Search, Keyboard, Cpu, Layers, LucideBellElectric } from "lucide-react"
|
|
8
8
|
import { Input } from "@/components/ui/input"
|
|
9
|
-
import {
|
|
9
|
+
import { usePackagesBaseApiUrl } from "@/hooks/use-packages-base-api-url"
|
|
10
10
|
import {
|
|
11
11
|
Select,
|
|
12
12
|
SelectContent,
|
|
@@ -18,7 +18,7 @@ import PackageSearchResults from "@/components/PackageSearchResults"
|
|
|
18
18
|
|
|
19
19
|
const LatestPage: React.FC = () => {
|
|
20
20
|
const axios = useAxios()
|
|
21
|
-
const apiBaseUrl =
|
|
21
|
+
const apiBaseUrl = usePackagesBaseApiUrl()
|
|
22
22
|
const [searchQuery, setSearchQuery] = useState("")
|
|
23
23
|
const [category, setCategory] = useState("all")
|
|
24
24
|
|
package/src/pages/search.tsx
CHANGED
|
@@ -7,7 +7,7 @@ import Footer from "@/components/Footer"
|
|
|
7
7
|
import { Input } from "@/components/ui/input"
|
|
8
8
|
import { Search } from "lucide-react"
|
|
9
9
|
import PackageSearchResults from "@/components/PackageSearchResults"
|
|
10
|
-
import {
|
|
10
|
+
import { usePackagesBaseApiUrl } from "@/hooks/use-packages-base-api-url"
|
|
11
11
|
import {
|
|
12
12
|
Select,
|
|
13
13
|
SelectContent,
|
|
@@ -19,7 +19,7 @@ import { Package } from "fake-snippets-api/lib/db/schema"
|
|
|
19
19
|
|
|
20
20
|
export const SearchPage = () => {
|
|
21
21
|
const axios = useAxios()
|
|
22
|
-
const apiBaseUrl =
|
|
22
|
+
const apiBaseUrl = usePackagesBaseApiUrl()
|
|
23
23
|
const [searchParams, setSearchParams] = useSearchParams()
|
|
24
24
|
|
|
25
25
|
const [searchQuery, setSearchQuery] = useState(searchParams.get("q") || "")
|
package/src/pages/trending.tsx
CHANGED
|
@@ -4,7 +4,7 @@ import { useAxios } from "@/hooks/use-axios"
|
|
|
4
4
|
import Header from "@/components/Header"
|
|
5
5
|
import Footer from "@/components/Footer"
|
|
6
6
|
import { useSearchParams } from "wouter"
|
|
7
|
-
import {
|
|
7
|
+
import { usePackagesBaseApiUrl } from "@/hooks/use-packages-base-api-url"
|
|
8
8
|
import { Search, Keyboard, Cpu, Layers, LucideBellElectric } from "lucide-react"
|
|
9
9
|
import { Input } from "@/components/ui/input"
|
|
10
10
|
import {
|
|
@@ -19,7 +19,7 @@ import PackageSearchResults from "@/components/PackageSearchResults"
|
|
|
19
19
|
|
|
20
20
|
const TrendingPage: React.FC = () => {
|
|
21
21
|
const axios = useAxios()
|
|
22
|
-
const apiBaseUrl =
|
|
22
|
+
const apiBaseUrl = usePackagesBaseApiUrl()
|
|
23
23
|
const [searchParams, setSearchParams] = useSearchParams()
|
|
24
24
|
|
|
25
25
|
const [searchQuery, setSearchQuery] = useState(searchParams.get("q") || "")
|
|
@@ -8,7 +8,7 @@ import { Input } from "@/components/ui/input"
|
|
|
8
8
|
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs"
|
|
9
9
|
import { useAxios } from "@/hooks/use-axios"
|
|
10
10
|
import { useGlobalStore } from "@/hooks/use-global-store"
|
|
11
|
-
import {
|
|
11
|
+
import { usePackagesBaseApiUrl } from "@/hooks/use-packages-base-api-url"
|
|
12
12
|
import { GitHubLogoIcon } from "@radix-ui/react-icons"
|
|
13
13
|
import type { Package } from "fake-snippets-api/lib/db/schema"
|
|
14
14
|
import type React from "react"
|
|
@@ -95,7 +95,7 @@ export const UserProfilePage = () => {
|
|
|
95
95
|
},
|
|
96
96
|
)
|
|
97
97
|
|
|
98
|
-
const baseUrl =
|
|
98
|
+
const baseUrl = usePackagesBaseApiUrl()
|
|
99
99
|
|
|
100
100
|
if (accountError) {
|
|
101
101
|
return <NotFoundPage heading="User Not Found" />
|
package/vite.config.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { defineConfig, Plugin, UserConfig } from "vite"
|
|
|
3
3
|
import type { PluginOption } from "vite"
|
|
4
4
|
import path, { extname } from "path"
|
|
5
5
|
import { readFileSync } from "fs"
|
|
6
|
-
import { execSync } from "child_process"
|
|
7
6
|
import react from "@vitejs/plugin-react"
|
|
8
7
|
import { ViteImageOptimizer } from "vite-plugin-image-optimizer"
|
|
9
8
|
import { getNodeHandler } from "winterspec/adapters/node"
|
|
@@ -119,23 +118,6 @@ function vercelSsrDevPlugin(): Plugin {
|
|
|
119
118
|
}
|
|
120
119
|
}
|
|
121
120
|
|
|
122
|
-
function buildIdPlugin(): Plugin {
|
|
123
|
-
return {
|
|
124
|
-
name: "build-id",
|
|
125
|
-
transformIndexHtml(html) {
|
|
126
|
-
try {
|
|
127
|
-
const hash = execSync("git rev-parse --short HEAD").toString().trim()
|
|
128
|
-
return html.replace(
|
|
129
|
-
/<\/head>/i,
|
|
130
|
-
` <meta name="tscircuit-build" content="${hash}"></head>`,
|
|
131
|
-
)
|
|
132
|
-
} catch {
|
|
133
|
-
return html
|
|
134
|
-
}
|
|
135
|
-
},
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
121
|
export default defineConfig(async (): Promise<UserConfig> => {
|
|
140
122
|
let proxyConfig: Record<string, any> | undefined
|
|
141
123
|
|
|
@@ -169,7 +151,6 @@ export default defineConfig(async (): Promise<UserConfig> => {
|
|
|
169
151
|
},
|
|
170
152
|
}),
|
|
171
153
|
vercelSsrDevPlugin(),
|
|
172
|
-
buildIdPlugin(),
|
|
173
154
|
]
|
|
174
155
|
|
|
175
156
|
if (process.env.VITE_BUNDLE_ANALYZE === "true" || 1) {
|
package/src/build-watcher.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { toast } from "sonner"
|
|
2
|
-
|
|
3
|
-
export function setupBuildWatcher() {
|
|
4
|
-
const meta = document.querySelector<HTMLMetaElement>(
|
|
5
|
-
'meta[name="tscircuit-build"]',
|
|
6
|
-
)
|
|
7
|
-
const currentId = meta?.content || ""
|
|
8
|
-
;(window as any).TSC_BUILD_ID = currentId
|
|
9
|
-
|
|
10
|
-
async function fetchBuildId(): Promise<string | null> {
|
|
11
|
-
try {
|
|
12
|
-
const res = await fetch("/api/generated-index", { cache: "no-store" })
|
|
13
|
-
const text = await res.text()
|
|
14
|
-
const match = text.match(
|
|
15
|
-
/<meta name="tscircuit-build" content="([^"]+)"/i,
|
|
16
|
-
)
|
|
17
|
-
return match ? match[1] : null
|
|
18
|
-
} catch (err) {
|
|
19
|
-
console.error("Failed to fetch build identifier", err)
|
|
20
|
-
return null
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
let updateToastShown = false
|
|
25
|
-
|
|
26
|
-
async function checkForUpdate() {
|
|
27
|
-
const serverId = await fetchBuildId()
|
|
28
|
-
if (
|
|
29
|
-
serverId &&
|
|
30
|
-
serverId !== (window as any).TSC_BUILD_ID &&
|
|
31
|
-
!updateToastShown
|
|
32
|
-
) {
|
|
33
|
-
updateToastShown = true
|
|
34
|
-
toast("A new version of tscircuit.com is available.", {
|
|
35
|
-
action: {
|
|
36
|
-
label: "Reload",
|
|
37
|
-
onClick: () => window.location.reload(),
|
|
38
|
-
},
|
|
39
|
-
duration: Infinity,
|
|
40
|
-
position: "bottom-left",
|
|
41
|
-
})
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
document.addEventListener("visibilitychange", () => {
|
|
46
|
-
if (document.visibilityState === "visible") {
|
|
47
|
-
checkForUpdate()
|
|
48
|
-
}
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
setInterval(checkForUpdate, 5 * 60 * 1000)
|
|
52
|
-
}
|
package/src/global.d.ts
DELETED