Skip to content

Commit

Permalink
feat: add tanstack router
Browse files Browse the repository at this point in the history
  • Loading branch information
heypoom committed Feb 9, 2024
1 parent 650b0a3 commit bddb030
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 24 deletions.
4 changes: 4 additions & 0 deletions canvas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/themes": "^2.0.2",
"@replit/codemirror-vim": "^6.1.0",
"@tanstack/react-query": "^5.18.1",
"@tanstack/react-router": "^1.15.23",
"@uiw/codemirror-themes": "^4.21.21",
"@uiw/react-codemirror": "^4.21.21",
"classnames": "^2.3.2",
Expand All @@ -54,6 +56,8 @@
"webmidi": "^3.1.8"
},
"devDependencies": {
"@tanstack/router-devtools": "^1.15.23",
"@tanstack/router-vite-plugin": "^1.15.22",
"@types/lodash": "^4.14.202",
"@types/react": "^18.2.45",
"@types/react-dom": "^18.2.18",
Expand Down
113 changes: 105 additions & 8 deletions canvas/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 13 additions & 15 deletions canvas/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import "./blocks/types/schema"
import { createRouter, RouterProvider } from "@tanstack/react-router"
import { StrictMode } from "react"

import { DndContext } from "@dnd-kit/core"
import { ReactFlowProvider } from "reactflow"
import { routeTree } from "./routeTree.gen"

import { Canvas } from "./canvas/Canvas"
import { SlashCommand } from "./canvas/components/SlashCommand"
import { Toolbar } from "./toolbar/Toolbar"
const router = createRouter({ routeTree })

declare module "@tanstack/react-router" {
interface Register {
router: typeof router
}
}

function App() {
return (
<DndContext>
<ReactFlowProvider>
<div className="relative bg-stone">
<Toolbar />
<Canvas />
<SlashCommand />
</div>
</ReactFlowProvider>
</DndContext>
<StrictMode>
<RouterProvider router={router} />
</StrictMode>
)
}

Expand Down
43 changes: 43 additions & 0 deletions canvas/src/routeTree.gen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* prettier-ignore-start */

/* eslint-disable */

// @ts-nocheck

// noinspection JSUnusedGlobalSymbols

// This file is auto-generated by TanStack Router

import { createFileRoute } from '@tanstack/react-router'

// Import Routes

import { Route as rootRoute } from './routes/__root'

// Create Virtual Routes

const IndexLazyImport = createFileRoute('/')()

// Create/Update Routes

const IndexLazyRoute = IndexLazyImport.update({
path: '/',
getParentRoute: () => rootRoute,
} as any).lazy(() => import('./routes/index.lazy').then((d) => d.Route))

// Populate the FileRoutesByPath interface

declare module '@tanstack/react-router' {
interface FileRoutesByPath {
'/': {
preLoaderRoute: typeof IndexLazyImport
parentRoute: typeof rootRoute
}
}
}

// Create and export the route tree

export const routeTree = rootRoute.addChildren([IndexLazyRoute])

/* prettier-ignore-end */
11 changes: 11 additions & 0 deletions canvas/src/routes/__root.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { createRootRoute, Outlet } from "@tanstack/react-router"
import { TanStackRouterDevtools } from "@tanstack/router-devtools"

export const Route = createRootRoute({
component: () => (
<>
<Outlet />
<TanStackRouterDevtools />
</>
),
})
24 changes: 24 additions & 0 deletions canvas/src/routes/index.lazy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { createLazyFileRoute } from "@tanstack/react-router"
import { ReactFlowProvider } from "reactflow"

import "@/blocks/types/schema"

import { Canvas } from "@/canvas/Canvas"
import { SlashCommand } from "@/canvas/components/SlashCommand"
import { Toolbar } from "@/toolbar/Toolbar"

export const Route = createLazyFileRoute("/")({
component: () => <Index />,
})

const Index = () => {
return (
<ReactFlowProvider>
<main className="relative bg-stone">
<Toolbar />
<Canvas />
<SlashCommand />
</main>
</ReactFlowProvider>
)
}
11 changes: 10 additions & 1 deletion canvas/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { lezer } from "@lezer/generator/rollup"
import { TanStackRouterVite } from "@tanstack/router-vite-plugin"
import react from "@vitejs/plugin-react"
import { defineConfig } from "vite"
import glsl from "vite-plugin-glsl"
Expand All @@ -7,5 +8,13 @@ import awaits from "vite-plugin-top-level-await"
import tsconfigPaths from "vite-tsconfig-paths"

export default defineConfig({
plugins: [tsconfigPaths(), react(), awaits(), ViteRsw(), glsl(), lezer()],
plugins: [
tsconfigPaths(),
react(),
awaits(),
ViteRsw(),
glsl(),
lezer(),
TanStackRouterVite(),
],
})

0 comments on commit bddb030

Please sign in to comment.