@tanstack/cta-ui 0.10.0-alpha.18
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/.cursorrules +7 -0
- package/LICENSE +21 -0
- package/app.config.js +22 -0
- package/components.json +21 -0
- package/lib/index.ts +22 -0
- package/lib-dist/index.d.ts +1 -0
- package/lib-dist/index.js +13 -0
- package/package.json +58 -0
- package/public/favicon.ico +0 -0
- package/public/logo192.png +0 -0
- package/public/logo512.png +0 -0
- package/public/manifest.json +25 -0
- package/public/robots.txt +3 -0
- package/src/api.ts +6 -0
- package/src/client.tsx +8 -0
- package/src/components/Header.tsx +13 -0
- package/src/components/applied-add-on.tsx +149 -0
- package/src/components/file-tree.tsx +77 -0
- package/src/components/file-viewer.tsx +59 -0
- package/src/components/ui/button.tsx +59 -0
- package/src/components/ui/checkbox.tsx +30 -0
- package/src/components/ui/dialog.tsx +133 -0
- package/src/components/ui/table.tsx +114 -0
- package/src/components/ui/tabs.tsx +64 -0
- package/src/components/ui/toggle-group.tsx +71 -0
- package/src/components/ui/toggle.tsx +47 -0
- package/src/components/ui/tree-view.tsx +492 -0
- package/src/integrations/tanstack-query/layout.tsx +5 -0
- package/src/integrations/tanstack-query/root-provider.tsx +15 -0
- package/src/lib/server-fns.ts +78 -0
- package/src/lib/utils.ts +6 -0
- package/src/logo.svg +44 -0
- package/src/routeTree.gen.ts +111 -0
- package/src/router.tsx +32 -0
- package/src/routes/__root.tsx +57 -0
- package/src/routes/api.demo-names.ts +11 -0
- package/src/routes/demo.tanstack-query.tsx +28 -0
- package/src/routes/index.tsx +222 -0
- package/src/ssr.tsx +12 -0
- package/src/styles.css +138 -0
- package/tsconfig.json +28 -0
- package/tsconfig.lib.json +17 -0
package/.cursorrules
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021-present Tanner Linsley
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/app.config.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { defineConfig } from '@tanstack/react-start/config'
|
|
2
|
+
import viteTsConfigPaths from 'vite-tsconfig-paths'
|
|
3
|
+
import tailwindcss from '@tailwindcss/vite'
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
tsr: {
|
|
7
|
+
appDirectory: 'src',
|
|
8
|
+
},
|
|
9
|
+
vite: {
|
|
10
|
+
forceOptimizeDeps: true,
|
|
11
|
+
plugins: [
|
|
12
|
+
// this is the plugin that enables path aliases
|
|
13
|
+
viteTsConfigPaths({
|
|
14
|
+
projects: ['./tsconfig.json'],
|
|
15
|
+
}),
|
|
16
|
+
tailwindcss(),
|
|
17
|
+
],
|
|
18
|
+
optimizeDeps: {
|
|
19
|
+
exclude: [],
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
})
|
package/components.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema.json",
|
|
3
|
+
"style": "new-york",
|
|
4
|
+
"rsc": false,
|
|
5
|
+
"tsx": true,
|
|
6
|
+
"tailwind": {
|
|
7
|
+
"config": "",
|
|
8
|
+
"css": "src/styles.css",
|
|
9
|
+
"baseColor": "zinc",
|
|
10
|
+
"cssVariables": true,
|
|
11
|
+
"prefix": ""
|
|
12
|
+
},
|
|
13
|
+
"aliases": {
|
|
14
|
+
"components": "@/components",
|
|
15
|
+
"utils": "@/lib/utils",
|
|
16
|
+
"ui": "@/components/ui",
|
|
17
|
+
"lib": "@/lib",
|
|
18
|
+
"hooks": "@/hooks"
|
|
19
|
+
},
|
|
20
|
+
"iconLibrary": "lucide"
|
|
21
|
+
}
|
package/lib/index.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { dirname, resolve } from 'node:path'
|
|
2
|
+
import { fileURLToPath } from 'node:url'
|
|
3
|
+
|
|
4
|
+
export function launchUI() {
|
|
5
|
+
const projectPath = process.cwd()
|
|
6
|
+
|
|
7
|
+
process.env.PROJECT_PATH = projectPath
|
|
8
|
+
|
|
9
|
+
const configPath = resolve(
|
|
10
|
+
dirname(fileURLToPath(import.meta.url)),
|
|
11
|
+
'../app.config.js',
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
const developerPath = resolve(dirname(fileURLToPath(import.meta.url)), '..')
|
|
15
|
+
|
|
16
|
+
process.chdir(developerPath)
|
|
17
|
+
|
|
18
|
+
import(configPath).then(async (config) => {
|
|
19
|
+
const out = await config.default
|
|
20
|
+
await out.dev()
|
|
21
|
+
})
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function launchUI(): void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { dirname, resolve } from 'node:path';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
export function launchUI() {
|
|
4
|
+
const projectPath = process.cwd();
|
|
5
|
+
process.env.PROJECT_PATH = projectPath;
|
|
6
|
+
const configPath = resolve(dirname(fileURLToPath(import.meta.url)), '../app.config.js');
|
|
7
|
+
const developerPath = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
8
|
+
process.chdir(developerPath);
|
|
9
|
+
import(configPath).then(async (config) => {
|
|
10
|
+
const out = await config.default;
|
|
11
|
+
await out.dev();
|
|
12
|
+
});
|
|
13
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tanstack/cta-ui",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"main": "./lib-dist/index.js",
|
|
5
|
+
"types": "./lib-dist/index.d.ts",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@codemirror/lang-css": "^6.3.1",
|
|
8
|
+
"@codemirror/lang-html": "^6.4.9",
|
|
9
|
+
"@codemirror/lang-javascript": "^6.2.3",
|
|
10
|
+
"@codemirror/lang-json": "^6.0.1",
|
|
11
|
+
"@radix-ui/react-accordion": "^1.2.3",
|
|
12
|
+
"@radix-ui/react-checkbox": "^1.1.4",
|
|
13
|
+
"@radix-ui/react-dialog": "^1.1.6",
|
|
14
|
+
"@radix-ui/react-slot": "^1.1.2",
|
|
15
|
+
"@radix-ui/react-tabs": "^1.1.3",
|
|
16
|
+
"@radix-ui/react-toggle": "^1.1.2",
|
|
17
|
+
"@radix-ui/react-toggle-group": "^1.1.2",
|
|
18
|
+
"@tailwindcss/vite": "^4.0.6",
|
|
19
|
+
"@tanstack/react-query": "^5.66.5",
|
|
20
|
+
"@tanstack/react-query-devtools": "^5.66.5",
|
|
21
|
+
"@tanstack/react-router": "^1.114.3",
|
|
22
|
+
"@tanstack/react-router-devtools": "^1.114.3",
|
|
23
|
+
"@tanstack/react-router-with-query": "^1.114.3",
|
|
24
|
+
"@tanstack/react-start": "^1.114.3",
|
|
25
|
+
"@tanstack/router-plugin": "^1.114.3",
|
|
26
|
+
"@uiw/codemirror-theme-okaidia": "^4.23.10",
|
|
27
|
+
"@uiw/react-codemirror": "^4.23.10",
|
|
28
|
+
"class-variance-authority": "^0.7.1",
|
|
29
|
+
"clsx": "^2.1.1",
|
|
30
|
+
"execa": "^9.5.2",
|
|
31
|
+
"lucide-react": "^0.476.0",
|
|
32
|
+
"react": "^19.0.0",
|
|
33
|
+
"react-codemirror-merge": "^4.23.10",
|
|
34
|
+
"react-dom": "^19.0.0",
|
|
35
|
+
"tailwind-merge": "^3.0.2",
|
|
36
|
+
"tailwindcss": "^4.0.6",
|
|
37
|
+
"tailwindcss-animate": "^1.0.7",
|
|
38
|
+
"vinxi": "^0.5.3",
|
|
39
|
+
"vite-tsconfig-paths": "^5.1.4",
|
|
40
|
+
"@tanstack/cta-custom-add-on": "0.10.0-alpha.18",
|
|
41
|
+
"@tanstack/cta-engine": "0.10.0-alpha.18"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@testing-library/dom": "^10.4.0",
|
|
45
|
+
"@testing-library/react": "^16.2.0",
|
|
46
|
+
"@types/node": "^22.13.14",
|
|
47
|
+
"@types/react": "^19.0.8",
|
|
48
|
+
"@types/react-dom": "^19.0.3",
|
|
49
|
+
"@vitejs/plugin-react": "^4.3.4",
|
|
50
|
+
"jsdom": "^26.0.0",
|
|
51
|
+
"typescript": "^5.7.2",
|
|
52
|
+
"vite": "^6.1.0",
|
|
53
|
+
"vitest": "^3.0.5",
|
|
54
|
+
"web-vitals": "^4.2.4"
|
|
55
|
+
},
|
|
56
|
+
"version": "0.10.0-alpha.18",
|
|
57
|
+
"scripts": {}
|
|
58
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"short_name": "TanStack App",
|
|
3
|
+
"name": "Create TanStack App Sample",
|
|
4
|
+
"icons": [
|
|
5
|
+
{
|
|
6
|
+
"src": "favicon.ico",
|
|
7
|
+
"sizes": "64x64 32x32 24x24 16x16",
|
|
8
|
+
"type": "image/x-icon"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"src": "logo192.png",
|
|
12
|
+
"type": "image/png",
|
|
13
|
+
"sizes": "192x192"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"src": "logo512.png",
|
|
17
|
+
"type": "image/png",
|
|
18
|
+
"sizes": "512x512"
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"start_url": ".",
|
|
22
|
+
"display": "standalone",
|
|
23
|
+
"theme_color": "#000000",
|
|
24
|
+
"background_color": "#ffffff"
|
|
25
|
+
}
|
package/src/api.ts
ADDED
package/src/client.tsx
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Link } from "@tanstack/react-router";
|
|
2
|
+
|
|
3
|
+
export default function Header() {
|
|
4
|
+
return (
|
|
5
|
+
<header className="p-2 flex gap-2 bg-white text-black justify-between">
|
|
6
|
+
<nav className="flex flex-row">
|
|
7
|
+
<div className="px-2 font-bold">
|
|
8
|
+
<Link to="/">Home</Link>
|
|
9
|
+
</div>
|
|
10
|
+
</nav>
|
|
11
|
+
</header>
|
|
12
|
+
);
|
|
13
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
|
|
3
|
+
import { Checkbox } from '@/components/ui/checkbox'
|
|
4
|
+
import { ToggleGroup, ToggleGroupItem } from '@/components/ui/toggle-group'
|
|
5
|
+
|
|
6
|
+
import { runCreateApp } from '@/lib/server-fns'
|
|
7
|
+
import FileViewer from './file-viewer'
|
|
8
|
+
import FileTree from './file-tree'
|
|
9
|
+
|
|
10
|
+
import type { Mode } from '@tanstack/cta-engine'
|
|
11
|
+
|
|
12
|
+
export default function AppliedAddOn({
|
|
13
|
+
projectPath,
|
|
14
|
+
output: originalOutput,
|
|
15
|
+
addOnInfo,
|
|
16
|
+
outputWithoutAddon: originalOutputWithoutAddon,
|
|
17
|
+
originalOptions,
|
|
18
|
+
addOns,
|
|
19
|
+
}: {
|
|
20
|
+
projectPath: string
|
|
21
|
+
output: {
|
|
22
|
+
files: Record<string, string>
|
|
23
|
+
}
|
|
24
|
+
outputWithoutAddon: {
|
|
25
|
+
files: Record<string, string>
|
|
26
|
+
}
|
|
27
|
+
addOnInfo: {
|
|
28
|
+
templates: Array<string>
|
|
29
|
+
}
|
|
30
|
+
originalOptions: {
|
|
31
|
+
existingAddOns: Array<string>
|
|
32
|
+
mode: Mode
|
|
33
|
+
}
|
|
34
|
+
addOns: Record<string, Array<any>>
|
|
35
|
+
}) {
|
|
36
|
+
const [selectedFile, setSelectedFile] = useState<string | null>(null)
|
|
37
|
+
|
|
38
|
+
const [options, setOptions] = useState(originalOptions)
|
|
39
|
+
const [output, setOutput] = useState(originalOutput)
|
|
40
|
+
const [outputWithoutAddon, setOutputWithoutAddon] = useState(
|
|
41
|
+
originalOutputWithoutAddon,
|
|
42
|
+
)
|
|
43
|
+
const [selectedAddOns, setSelectedAddOns] = useState<Array<string>>([])
|
|
44
|
+
|
|
45
|
+
async function updateOptions(
|
|
46
|
+
updatedOptions: Partial<typeof options>,
|
|
47
|
+
updatedAddOns: Array<string> = [],
|
|
48
|
+
) {
|
|
49
|
+
const newMode = updatedOptions.mode || options.mode
|
|
50
|
+
const existingAddOns = [
|
|
51
|
+
...(originalOptions.existingAddOns || []),
|
|
52
|
+
...(updatedAddOns || []),
|
|
53
|
+
].filter((id) => addOns[newMode as Mode].some((addOn) => addOn.id === id))
|
|
54
|
+
|
|
55
|
+
const newOptions = {
|
|
56
|
+
...options,
|
|
57
|
+
...updatedOptions,
|
|
58
|
+
existingAddOns,
|
|
59
|
+
}
|
|
60
|
+
setOptions(newOptions)
|
|
61
|
+
const [newOutput, newOutputWithoutAddon] = await Promise.all([
|
|
62
|
+
runCreateApp({
|
|
63
|
+
data: { withAddOn: true, options: newOptions },
|
|
64
|
+
}),
|
|
65
|
+
runCreateApp({
|
|
66
|
+
data: { withAddOn: false, options: newOptions },
|
|
67
|
+
}),
|
|
68
|
+
])
|
|
69
|
+
setOutput(newOutput)
|
|
70
|
+
setOutputWithoutAddon(newOutputWithoutAddon)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<div>
|
|
75
|
+
<div className="flex flex-row items-center mb-5">
|
|
76
|
+
<ToggleGroup
|
|
77
|
+
type="single"
|
|
78
|
+
value={options.mode}
|
|
79
|
+
onValueChange={(v: string) => {
|
|
80
|
+
if (v) {
|
|
81
|
+
updateOptions(
|
|
82
|
+
{
|
|
83
|
+
mode: v as Mode,
|
|
84
|
+
},
|
|
85
|
+
selectedAddOns,
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
}}
|
|
89
|
+
>
|
|
90
|
+
<ToggleGroupItem
|
|
91
|
+
value="code-router"
|
|
92
|
+
disabled={!addOnInfo.templates.includes('code-router')}
|
|
93
|
+
>
|
|
94
|
+
Code Router
|
|
95
|
+
</ToggleGroupItem>
|
|
96
|
+
<ToggleGroupItem
|
|
97
|
+
value="file-router"
|
|
98
|
+
disabled={!addOnInfo.templates.includes('file-router')}
|
|
99
|
+
>
|
|
100
|
+
File Router
|
|
101
|
+
</ToggleGroupItem>
|
|
102
|
+
</ToggleGroup>
|
|
103
|
+
<div className="flex flex-row ml-5 flex-wrap">
|
|
104
|
+
{addOns[options.mode as Mode].map((addOn) => (
|
|
105
|
+
<div key={addOn.name} className="mr-2 flex items-center">
|
|
106
|
+
<Checkbox
|
|
107
|
+
id={addOn.id}
|
|
108
|
+
checked={
|
|
109
|
+
originalOptions.existingAddOns.includes(addOn.id) ||
|
|
110
|
+
selectedAddOns.includes(addOn.id)
|
|
111
|
+
}
|
|
112
|
+
disabled={originalOptions.existingAddOns.includes(addOn.id)}
|
|
113
|
+
onClick={() => {
|
|
114
|
+
let updatedAddOns = selectedAddOns.includes(addOn.id)
|
|
115
|
+
? selectedAddOns.filter((id) => id !== addOn.id)
|
|
116
|
+
: [...selectedAddOns, addOn.id]
|
|
117
|
+
setSelectedAddOns(updatedAddOns)
|
|
118
|
+
updateOptions({}, updatedAddOns)
|
|
119
|
+
}}
|
|
120
|
+
/>
|
|
121
|
+
<label htmlFor={addOn.id} className="ml-2">
|
|
122
|
+
{addOn.name}
|
|
123
|
+
</label>
|
|
124
|
+
</div>
|
|
125
|
+
))}
|
|
126
|
+
</div>
|
|
127
|
+
</div>
|
|
128
|
+
<div className="flex flex-row">
|
|
129
|
+
<FileTree
|
|
130
|
+
prefix={projectPath}
|
|
131
|
+
tree={output.files}
|
|
132
|
+
originalTree={outputWithoutAddon.files}
|
|
133
|
+
onFileSelected={(file) => {
|
|
134
|
+
setSelectedFile(file)
|
|
135
|
+
}}
|
|
136
|
+
/>
|
|
137
|
+
<div className="max-w-3/4 w-3/4 pl-2">
|
|
138
|
+
{selectedFile ? (
|
|
139
|
+
<FileViewer
|
|
140
|
+
filePath={selectedFile}
|
|
141
|
+
originalFile={outputWithoutAddon.files[selectedFile]}
|
|
142
|
+
modifiedFile={output.files[selectedFile]}
|
|
143
|
+
/>
|
|
144
|
+
) : null}
|
|
145
|
+
</div>
|
|
146
|
+
</div>
|
|
147
|
+
</div>
|
|
148
|
+
)
|
|
149
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { useMemo } from 'react'
|
|
2
|
+
import { FileText, Folder } from 'lucide-react'
|
|
3
|
+
|
|
4
|
+
import { TreeView } from '@/components/ui/tree-view'
|
|
5
|
+
|
|
6
|
+
import type { TreeDataItem } from '@/components/ui/tree-view'
|
|
7
|
+
|
|
8
|
+
export default function FileTree({
|
|
9
|
+
prefix,
|
|
10
|
+
tree,
|
|
11
|
+
originalTree,
|
|
12
|
+
onFileSelected,
|
|
13
|
+
extraTreeItems = [],
|
|
14
|
+
}: {
|
|
15
|
+
prefix: string
|
|
16
|
+
tree: Record<string, string>
|
|
17
|
+
originalTree: Record<string, string>
|
|
18
|
+
onFileSelected: (file: string) => void
|
|
19
|
+
extraTreeItems?: Array<TreeDataItem>
|
|
20
|
+
}) {
|
|
21
|
+
const computedTree = useMemo(() => {
|
|
22
|
+
const treeData: Array<TreeDataItem> = []
|
|
23
|
+
|
|
24
|
+
function changed(file: string) {
|
|
25
|
+
if (!originalTree[file]) {
|
|
26
|
+
return true
|
|
27
|
+
}
|
|
28
|
+
return tree[file] !== originalTree[file]
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
Object.keys(tree)
|
|
32
|
+
.sort()
|
|
33
|
+
.forEach((file) => {
|
|
34
|
+
const parts = file.replace(`${prefix}/`, '').split('/')
|
|
35
|
+
|
|
36
|
+
let currentLevel = treeData
|
|
37
|
+
parts.forEach((part, index) => {
|
|
38
|
+
const existingNode = currentLevel.find((node) => node.name === part)
|
|
39
|
+
if (existingNode) {
|
|
40
|
+
currentLevel = existingNode.children || []
|
|
41
|
+
} else {
|
|
42
|
+
const newNode: TreeDataItem = {
|
|
43
|
+
id: index === parts.length - 1 ? file : `${file}-${index}`,
|
|
44
|
+
name: part,
|
|
45
|
+
children: index < parts.length - 1 ? [] : undefined,
|
|
46
|
+
icon:
|
|
47
|
+
index < parts.length - 1
|
|
48
|
+
? () => <Folder className="w-4 h-4 mr-2" />
|
|
49
|
+
: () => <FileText className="w-4 h-4 mr-2" />,
|
|
50
|
+
onClick:
|
|
51
|
+
index === parts.length - 1
|
|
52
|
+
? () => {
|
|
53
|
+
onFileSelected(file)
|
|
54
|
+
}
|
|
55
|
+
: undefined,
|
|
56
|
+
className:
|
|
57
|
+
index === parts.length - 1 && changed(file)
|
|
58
|
+
? 'text-green-300'
|
|
59
|
+
: '',
|
|
60
|
+
}
|
|
61
|
+
currentLevel.push(newNode)
|
|
62
|
+
currentLevel = newNode.children!
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
return [...extraTreeItems, ...treeData]
|
|
67
|
+
}, [prefix, tree, originalTree, extraTreeItems])
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<TreeView
|
|
71
|
+
data={computedTree}
|
|
72
|
+
defaultNodeIcon={() => <Folder className="w-4 h-4 mr-2" />}
|
|
73
|
+
defaultLeafIcon={() => <FileText className="w-4 h-4 mr-2" />}
|
|
74
|
+
className="max-w-1/4 w-1/4 pr-2"
|
|
75
|
+
/>
|
|
76
|
+
)
|
|
77
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import CodeMirror from '@uiw/react-codemirror'
|
|
2
|
+
import CodeMirrorMerge from 'react-codemirror-merge'
|
|
3
|
+
|
|
4
|
+
import { javascript } from '@codemirror/lang-javascript'
|
|
5
|
+
import { json } from '@codemirror/lang-json'
|
|
6
|
+
import { css } from '@codemirror/lang-css'
|
|
7
|
+
import { html } from '@codemirror/lang-html'
|
|
8
|
+
|
|
9
|
+
import { okaidia } from '@uiw/codemirror-theme-okaidia'
|
|
10
|
+
|
|
11
|
+
export default function FileViewer({
|
|
12
|
+
originalFile,
|
|
13
|
+
modifiedFile,
|
|
14
|
+
filePath,
|
|
15
|
+
}: {
|
|
16
|
+
originalFile?: string
|
|
17
|
+
modifiedFile: string
|
|
18
|
+
filePath: string
|
|
19
|
+
}) {
|
|
20
|
+
function getLanguage(file: string) {
|
|
21
|
+
if (file.endsWith('.js') || file.endsWith('.jsx')) {
|
|
22
|
+
return javascript({ jsx: true })
|
|
23
|
+
}
|
|
24
|
+
if (file.endsWith('.ts') || file.endsWith('.tsx')) {
|
|
25
|
+
return javascript({ typescript: true, jsx: true })
|
|
26
|
+
}
|
|
27
|
+
if (file.endsWith('.json')) {
|
|
28
|
+
return json()
|
|
29
|
+
}
|
|
30
|
+
if (file.endsWith('.css')) {
|
|
31
|
+
return css()
|
|
32
|
+
}
|
|
33
|
+
if (file.endsWith('.html')) {
|
|
34
|
+
return html()
|
|
35
|
+
}
|
|
36
|
+
return javascript()
|
|
37
|
+
}
|
|
38
|
+
const language = getLanguage(filePath)
|
|
39
|
+
|
|
40
|
+
if (!originalFile || originalFile === modifiedFile) {
|
|
41
|
+
return (
|
|
42
|
+
<CodeMirror
|
|
43
|
+
value={modifiedFile}
|
|
44
|
+
theme={okaidia}
|
|
45
|
+
height="100vh"
|
|
46
|
+
width="100%"
|
|
47
|
+
readOnly
|
|
48
|
+
extensions={[language]}
|
|
49
|
+
className="text-lg"
|
|
50
|
+
/>
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
return (
|
|
54
|
+
<CodeMirrorMerge orientation="a-b" theme={okaidia} className="text-lg">
|
|
55
|
+
<CodeMirrorMerge.Original value={originalFile} extensions={[language]} />
|
|
56
|
+
<CodeMirrorMerge.Modified value={modifiedFile} extensions={[language]} />
|
|
57
|
+
</CodeMirrorMerge>
|
|
58
|
+
)
|
|
59
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import { Slot } from "@radix-ui/react-slot"
|
|
3
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
4
|
+
|
|
5
|
+
import { cn } from "@/lib/utils"
|
|
6
|
+
|
|
7
|
+
const buttonVariants = cva(
|
|
8
|
+
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
|
9
|
+
{
|
|
10
|
+
variants: {
|
|
11
|
+
variant: {
|
|
12
|
+
default:
|
|
13
|
+
"bg-primary text-primary-foreground shadow-xs hover:bg-primary/90",
|
|
14
|
+
destructive:
|
|
15
|
+
"bg-destructive text-white shadow-xs hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
|
16
|
+
outline:
|
|
17
|
+
"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
|
|
18
|
+
secondary:
|
|
19
|
+
"bg-secondary text-secondary-foreground shadow-xs hover:bg-secondary/80",
|
|
20
|
+
ghost:
|
|
21
|
+
"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
|
22
|
+
link: "text-primary underline-offset-4 hover:underline",
|
|
23
|
+
},
|
|
24
|
+
size: {
|
|
25
|
+
default: "h-9 px-4 py-2 has-[>svg]:px-3",
|
|
26
|
+
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
|
|
27
|
+
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
|
28
|
+
icon: "size-9",
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
defaultVariants: {
|
|
32
|
+
variant: "default",
|
|
33
|
+
size: "default",
|
|
34
|
+
},
|
|
35
|
+
}
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
function Button({
|
|
39
|
+
className,
|
|
40
|
+
variant,
|
|
41
|
+
size,
|
|
42
|
+
asChild = false,
|
|
43
|
+
...props
|
|
44
|
+
}: React.ComponentProps<"button"> &
|
|
45
|
+
VariantProps<typeof buttonVariants> & {
|
|
46
|
+
asChild?: boolean
|
|
47
|
+
}) {
|
|
48
|
+
const Comp = asChild ? Slot : "button"
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<Comp
|
|
52
|
+
data-slot="button"
|
|
53
|
+
className={cn(buttonVariants({ variant, size, className }))}
|
|
54
|
+
{...props}
|
|
55
|
+
/>
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { Button, buttonVariants }
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import * as CheckboxPrimitive from "@radix-ui/react-checkbox"
|
|
3
|
+
import { CheckIcon } from "lucide-react"
|
|
4
|
+
|
|
5
|
+
import { cn } from "@/lib/utils"
|
|
6
|
+
|
|
7
|
+
function Checkbox({
|
|
8
|
+
className,
|
|
9
|
+
...props
|
|
10
|
+
}: React.ComponentProps<typeof CheckboxPrimitive.Root>) {
|
|
11
|
+
return (
|
|
12
|
+
<CheckboxPrimitive.Root
|
|
13
|
+
data-slot="checkbox"
|
|
14
|
+
className={cn(
|
|
15
|
+
"peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
|
|
16
|
+
className
|
|
17
|
+
)}
|
|
18
|
+
{...props}
|
|
19
|
+
>
|
|
20
|
+
<CheckboxPrimitive.Indicator
|
|
21
|
+
data-slot="checkbox-indicator"
|
|
22
|
+
className="flex items-center justify-center text-current transition-none"
|
|
23
|
+
>
|
|
24
|
+
<CheckIcon className="size-3.5" />
|
|
25
|
+
</CheckboxPrimitive.Indicator>
|
|
26
|
+
</CheckboxPrimitive.Root>
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { Checkbox }
|