@tscircuit/fake-snippets 0.0.88 → 0.0.90
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/api/generated-index.js +96 -14
- package/bun-tests/fake-snippets-api/routes/proxy.test.ts +42 -0
- package/bun.lock +196 -215
- package/dist/bundle.js +596 -370
- package/fake-snippets-api/routes/api/autocomplete/create_autocomplete.ts +134 -0
- package/fake-snippets-api/routes/api/proxy.ts +128 -0
- package/package.json +59 -48
- package/renovate.json +2 -1
- package/src/App.tsx +67 -3
- package/src/ContextProviders.tsx +2 -0
- package/src/build-watcher.ts +52 -0
- package/src/components/CircuitJsonImportDialog.tsx +1 -1
- package/src/components/CmdKMenu.tsx +533 -197
- package/src/components/DownloadButtonAndMenu.tsx +104 -26
- package/src/components/FileSidebar.tsx +11 -1
- package/src/components/Header2.tsx +7 -2
- package/src/components/PackageBuildsPage/LogContent.tsx +25 -22
- package/src/components/PackageBuildsPage/PackageBuildDetailsPage.tsx +6 -6
- package/src/components/PackageBuildsPage/build-preview-content.tsx +5 -5
- package/src/components/PackageBuildsPage/package-build-details-panel.tsx +15 -13
- package/src/components/PackageBuildsPage/package-build-header.tsx +19 -28
- package/src/components/PackageCard.tsx +66 -16
- package/src/components/SearchComponent.tsx +2 -2
- package/src/components/SuspenseRunFrame.tsx +14 -2
- package/src/components/ViewPackagePage/components/important-files-view.tsx +90 -17
- package/src/components/ViewPackagePage/components/main-content-header.tsx +26 -2
- package/src/components/ViewPackagePage/components/mobile-sidebar.tsx +2 -2
- package/src/components/ViewPackagePage/components/repo-page-content.tsx +35 -30
- package/src/components/ViewPackagePage/components/sidebar-about-section.tsx +2 -2
- package/src/components/ViewPackagePage/components/sidebar-releases-section.tsx +20 -12
- package/src/components/ViewPackagePage/components/tab-views/files-view.tsx +0 -7
- package/src/components/ViewPackagePage/utils/fuzz-search.ts +121 -0
- package/src/components/ViewPackagePage/utils/is-hidden-file.ts +4 -0
- package/src/components/dialogs/confirm-delete-package-dialog.tsx +1 -1
- package/src/components/dialogs/confirm-discard-changes-dialog.tsx +73 -0
- package/src/components/dialogs/edit-package-details-dialog.tsx +2 -2
- package/src/components/dialogs/view-ts-files-dialog.tsx +478 -42
- package/src/components/package-port/CodeAndPreview.tsx +17 -16
- package/src/components/package-port/CodeEditor.tsx +138 -17
- package/src/components/package-port/CodeEditorHeader.tsx +44 -4
- package/src/components/package-port/EditorNav.tsx +42 -29
- package/src/components/package-port/GlobalFindReplace.tsx +681 -0
- package/src/components/package-port/QuickOpen.tsx +241 -0
- package/src/components/ui/dialog.tsx +1 -1
- package/src/components/ui/tree-view.tsx +1 -1
- package/src/global.d.ts +3 -0
- package/src/hooks/use-ai-review.ts +31 -0
- package/src/hooks/use-code-completion-ai-api.ts +3 -3
- package/src/hooks/use-current-package-release.ts +5 -1
- package/src/hooks/use-delete-package.ts +6 -2
- package/src/hooks/use-download-zip.ts +50 -0
- package/src/hooks/use-hotkey.ts +116 -0
- package/src/hooks/use-package-by-package-id.ts +1 -0
- package/src/hooks/use-package-by-package-name.ts +1 -0
- package/src/hooks/use-package-files.ts +3 -0
- package/src/hooks/use-package-release.ts +5 -1
- package/src/hooks/use-package.ts +1 -0
- package/src/hooks/use-request-ai-review-mutation.ts +14 -6
- package/src/hooks/use-snippet.ts +1 -0
- package/src/hooks/useFileManagement.ts +28 -10
- package/src/hooks/usePackageFilesLoader.ts +3 -1
- package/src/index.css +11 -0
- package/src/lib/decodeUrlHashToFsMap.ts +17 -0
- package/src/lib/download-fns/download-circuit-png.ts +88 -0
- package/src/lib/download-fns/download-png-utils.ts +31 -0
- package/src/lib/encodeFsMapToUrlHash.ts +13 -0
- package/src/lib/populate-query-cache-with-ssr-data.ts +7 -0
- package/src/lib/ts-lib-cache.ts +47 -0
- package/src/lib/types.ts +2 -0
- package/src/lib/utils/findTargetFile.ts +1 -1
- package/src/lib/utils/package-utils.ts +10 -0
- package/src/main.tsx +7 -0
- package/src/pages/dashboard.tsx +18 -5
- package/src/pages/view-package.tsx +15 -7
- package/src/types/package.ts +4 -0
- package/vite.config.ts +100 -1
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
export const fuzzyMatch = (
|
|
2
|
+
pattern: string,
|
|
3
|
+
text: string,
|
|
4
|
+
): { score: number; matches: number[] } => {
|
|
5
|
+
if (!pattern) return { score: 0, matches: [] }
|
|
6
|
+
|
|
7
|
+
const normalizePattern = (pat: string) => {
|
|
8
|
+
return pat.toLowerCase().split(" ").join("")
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const patternLower = normalizePattern(pattern)
|
|
12
|
+
const textLower = text.toLowerCase()
|
|
13
|
+
const matches: number[] = []
|
|
14
|
+
|
|
15
|
+
let patternIdx = 0
|
|
16
|
+
let score = 0
|
|
17
|
+
let consecutiveMatches = 0
|
|
18
|
+
let spaceBonus = 0
|
|
19
|
+
|
|
20
|
+
const spaceSegments = pattern.toLowerCase().trim().split(/\s+/)
|
|
21
|
+
const isSpaceSeparated = spaceSegments.length > 1
|
|
22
|
+
|
|
23
|
+
if (isSpaceSeparated) {
|
|
24
|
+
let segmentIdx = 0
|
|
25
|
+
let currentSegment = spaceSegments[0]
|
|
26
|
+
let segmentCharIdx = 0
|
|
27
|
+
|
|
28
|
+
for (
|
|
29
|
+
let i = 0;
|
|
30
|
+
i < textLower.length && segmentIdx < spaceSegments.length;
|
|
31
|
+
i++
|
|
32
|
+
) {
|
|
33
|
+
const char = textLower[i]
|
|
34
|
+
const targetChar = currentSegment[segmentCharIdx]
|
|
35
|
+
|
|
36
|
+
if (char === targetChar) {
|
|
37
|
+
matches.push(i)
|
|
38
|
+
segmentCharIdx++
|
|
39
|
+
consecutiveMatches++
|
|
40
|
+
score += 1 + consecutiveMatches * 0.5
|
|
41
|
+
|
|
42
|
+
if (i === 0 || /[/\-_.]/.test(text[i - 1])) {
|
|
43
|
+
score += 2
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (segmentCharIdx >= currentSegment.length) {
|
|
47
|
+
segmentIdx++
|
|
48
|
+
spaceBonus += 3
|
|
49
|
+
|
|
50
|
+
if (segmentIdx < spaceSegments.length) {
|
|
51
|
+
currentSegment = spaceSegments[segmentIdx]
|
|
52
|
+
segmentCharIdx = 0
|
|
53
|
+
consecutiveMatches = 0
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
if (
|
|
58
|
+
segmentCharIdx > 0 &&
|
|
59
|
+
/[/\-_.]/.test(char) &&
|
|
60
|
+
segmentIdx < spaceSegments.length - 1
|
|
61
|
+
) {
|
|
62
|
+
segmentIdx++
|
|
63
|
+
if (segmentIdx < spaceSegments.length) {
|
|
64
|
+
currentSegment = spaceSegments[segmentIdx]
|
|
65
|
+
segmentCharIdx = 0
|
|
66
|
+
consecutiveMatches = 0
|
|
67
|
+
if (char === currentSegment[0]) {
|
|
68
|
+
matches.push(i)
|
|
69
|
+
segmentCharIdx = 1
|
|
70
|
+
score += 2
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
consecutiveMatches = 0
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (
|
|
80
|
+
segmentIdx < spaceSegments.length ||
|
|
81
|
+
(segmentIdx === spaceSegments.length - 1 &&
|
|
82
|
+
segmentCharIdx < currentSegment.length)
|
|
83
|
+
) {
|
|
84
|
+
return { score: -1, matches: [] }
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
score += spaceBonus
|
|
88
|
+
} else {
|
|
89
|
+
for (
|
|
90
|
+
let i = 0;
|
|
91
|
+
i < textLower.length && patternIdx < patternLower.length;
|
|
92
|
+
i++
|
|
93
|
+
) {
|
|
94
|
+
if (textLower[i] === patternLower[patternIdx]) {
|
|
95
|
+
matches.push(i)
|
|
96
|
+
patternIdx++
|
|
97
|
+
consecutiveMatches++
|
|
98
|
+
|
|
99
|
+
score += 1 + consecutiveMatches * 0.5
|
|
100
|
+
|
|
101
|
+
if (i === 0 || /[/\-_.]/.test(text[i - 1])) {
|
|
102
|
+
score += 2
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
consecutiveMatches = 0
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (patternIdx !== patternLower.length) return { score: -1, matches: [] }
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
score += Math.max(0, 100 - text.length) * 0.1
|
|
113
|
+
|
|
114
|
+
const fileName = text.split("/").pop() || text
|
|
115
|
+
const queryFileName = pattern.replace(/\s+/g, "")
|
|
116
|
+
if (fileName.toLowerCase().includes(queryFileName.toLowerCase())) {
|
|
117
|
+
score += 5
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return { score, matches }
|
|
121
|
+
}
|
|
@@ -33,7 +33,7 @@ export const ConfirmDeletePackageDialog = ({
|
|
|
33
33
|
|
|
34
34
|
return (
|
|
35
35
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
36
|
-
<DialogContent>
|
|
36
|
+
<DialogContent className="w-[90vw]">
|
|
37
37
|
<DialogHeader>
|
|
38
38
|
<DialogTitle>Confirm Delete Package</DialogTitle>
|
|
39
39
|
</DialogHeader>
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "../ui/dialog"
|
|
2
|
+
import { Button } from "../ui/button"
|
|
3
|
+
import { createUseDialog } from "./create-use-dialog"
|
|
4
|
+
import { useState } from "react"
|
|
5
|
+
|
|
6
|
+
export const ConfirmDiscardChangesDialog = ({
|
|
7
|
+
open,
|
|
8
|
+
onOpenChange,
|
|
9
|
+
onConfirm,
|
|
10
|
+
}: {
|
|
11
|
+
open: boolean
|
|
12
|
+
onOpenChange: (open: boolean) => void
|
|
13
|
+
onConfirm: () => void
|
|
14
|
+
}) => {
|
|
15
|
+
const [isConfirming, setIsConfirming] = useState(false)
|
|
16
|
+
|
|
17
|
+
const handleDiscard = () => {
|
|
18
|
+
onConfirm()
|
|
19
|
+
onOpenChange(false)
|
|
20
|
+
setIsConfirming(false)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const handleCancel = () => {
|
|
24
|
+
onOpenChange(false)
|
|
25
|
+
setIsConfirming(false)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<Dialog
|
|
30
|
+
open={open}
|
|
31
|
+
onOpenChange={(open) => {
|
|
32
|
+
onOpenChange(open)
|
|
33
|
+
if (!open) setIsConfirming(false)
|
|
34
|
+
}}
|
|
35
|
+
>
|
|
36
|
+
<DialogContent className="w-[90vw]">
|
|
37
|
+
<DialogHeader>
|
|
38
|
+
<DialogTitle>Discard Changes</DialogTitle>
|
|
39
|
+
</DialogHeader>
|
|
40
|
+
<p>Are you sure you want to discard all unsaved changes?</p>
|
|
41
|
+
<p className="text-red-600 font-medium">
|
|
42
|
+
This action cannot be undone.
|
|
43
|
+
</p>
|
|
44
|
+
<div className="flex justify-end space-x-2 mt-4">
|
|
45
|
+
<Button variant="outline" onClick={handleCancel}>
|
|
46
|
+
Cancel
|
|
47
|
+
</Button>
|
|
48
|
+
{!isConfirming ? (
|
|
49
|
+
<Button
|
|
50
|
+
variant="destructive"
|
|
51
|
+
className="bg-red-600 hover:bg-red-700"
|
|
52
|
+
onClick={() => setIsConfirming(true)}
|
|
53
|
+
>
|
|
54
|
+
Discard Changes
|
|
55
|
+
</Button>
|
|
56
|
+
) : (
|
|
57
|
+
<Button
|
|
58
|
+
variant="destructive"
|
|
59
|
+
onClick={handleDiscard}
|
|
60
|
+
className="bg-red-600 hover:bg-red-700"
|
|
61
|
+
>
|
|
62
|
+
Yes, Discard All Changes
|
|
63
|
+
</Button>
|
|
64
|
+
)}
|
|
65
|
+
</div>
|
|
66
|
+
</DialogContent>
|
|
67
|
+
</Dialog>
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export const useConfirmDiscardChangesDialog = createUseDialog(
|
|
72
|
+
ConfirmDiscardChangesDialog,
|
|
73
|
+
)
|
|
@@ -207,7 +207,7 @@ export const EditPackageDetailsDialog = ({
|
|
|
207
207
|
return (
|
|
208
208
|
<div>
|
|
209
209
|
<Dialog open={showConfirmDelete} onOpenChange={setShowConfirmDelete}>
|
|
210
|
-
<DialogContent className="
|
|
210
|
+
<DialogContent className="w-[90vw] p-6 rounded-2xl shadow-lg">
|
|
211
211
|
<DialogHeader>
|
|
212
212
|
<DialogTitle className="text-left">Confirm Deletion</DialogTitle>
|
|
213
213
|
<DialogDescription className="text-left">
|
|
@@ -255,7 +255,7 @@ export const EditPackageDetailsDialog = ({
|
|
|
255
255
|
onChange={(e) =>
|
|
256
256
|
setFormData((prev) => ({
|
|
257
257
|
...prev,
|
|
258
|
-
unscopedPackageName: e.target.value,
|
|
258
|
+
unscopedPackageName: e.target.value.replace(/\s+/g, ""),
|
|
259
259
|
}))
|
|
260
260
|
}
|
|
261
261
|
placeholder="Enter package name"
|