All blocks

IDE Workspace

Multi-pane code IDE workspace with a filterable file tree, open and closable editor tabs, line-numbered syntax-highlighted code view, resizable Terminal / Problems / Output workbench, properties and history inspector, and live status bar.

stylex-routerv0.4.2main
stylex-router/src/router.ts
TypeScript60 lines
import { compilePattern, matchPath, type CompiledPattern } from "./match.ts";
import { compose, type Middleware } from "./middleware.ts";
export interface RouteContext {
request: Request;
params: Record<string, string>;
url: URL;
}
export type RouteHandler = (ctx: RouteContext) => Response | Promise<Response>;
export interface RouterOptions {
basePath?: string;
trailingSlash?: "ignore" | "strict";
notFound?: RouteHandler;
}
interface RouteRecord {
method: string;
compiled: CompiledPattern;
handler: RouteHandler;
}
export function createRouter(options: RouterOptions = {}) {
const routes: RouteRecord[] = [];
const middlewares: Middleware[] = [];
const basePath = options.basePath ?? "";
function register(method: string, pattern: string, handler: RouteHandler) {
routes.push({
method: method.toUpperCase(),
compiled: compilePattern(`${basePath}${pattern}`),
handler,
});
}
async function fetch(request: Request): Promise<Response> {
const url = new URL(request.url);
const pipeline = compose(middlewares);
for (const record of routes) {
if (record.method !== request.method && record.method !== "ALL") continue;
const params = matchPath(record.compiled, url.pathname);
if (!params) continue;
return pipeline({ request, params, url }, record.handler);
}
if (options.notFound) {
return options.notFound({ request, params: {}, url });
}
return new Response("Not Found", { status: 404 });
}
return {
use: (mw: Middleware) => void middlewares.push(mw),
get: (path: string, handler: RouteHandler) => register("GET", path, handler),
post: (path: string, handler: RouteHandler) => register("POST", path, handler),
fetch,
};
}

$ bun test

bun test v1.2.8 (stylex-router)

test/router.test.ts:

✓ stylex-router > matches static and param routes [1.14ms]

✓ stylex-router > runs middleware in declaration order [0.68ms]

✓ stylex-router > returns 404 for unknown paths [0.22ms]

3 pass · 0 fail · 5 expect() calls · Ran 3 tests across 1 file. [14.00ms]

$↵
main3/3 passing (14ms)
Ln 24, Col 1Spaces: 2UTF-8TypeScript

    Install

    Source

    components/blocks/ui-sdk/ide.tsx

    Inspired by the IDE template from Astryx (MIT License · Copyright (c) 2026 Meta Platforms, Inc.).