← ब्लॉग

Text.js 0.1

Text.js 0.1, DevTools कंसोल में रेंडर होने वाले ऐप के लिए React 19 रिकंसाइलर, Yoga लेआउट और फ़ाइल-सिस्टम App Router लाता है।

Adam

Text.js 0.1 टैग हो गया है। यह तीनों लेयर वाला पहला वर्शन है: @textjs/core कंसोल में फ़्रेम बनाता है, @textjs/react उन फ़्रेम में React 19 रेंडर करता है, और textjs एक App Router और CLI जोड़ता है।

App Router

रूट app/ में फ़ोल्डर होते हैं, जो Next.js App Router के नियमों का पालन करते हैं। यह create-text-app का dashboard टेम्प्लेट है:

app/├── layout.tsx├── page.tsx├── not-found.tsx├── deployments/│   └── [id]/│       └── page.tsx└── api/    └── metrics/        └── route.ts

लेआउट अपने नीचे के हर पेज को रैप करता है और नेविगेशन के दौरान अपना स्टेट बनाए रखता है। <Link> एक shortcut लेता है, जिससे एक कुंजी दबाने पर लिंक खुलता है, और activeClassName मौजूदा रूट के लिंक को स्टाइल करता है:

app/layout.tsxtsx
import type { ReactNode } from "react";import { Box, KeyHint, Text, useTheme, type Metadata } from "textjs";import Link from "textjs/link";export const metadata: Metadata = { title: { default: "Acme", template: "%s · Acme" } };export default function RootLayout({ children }: { children?: ReactNode }): ReactNode {  const theme = useTheme();  return (    <Box className="flex-col w-full h-full">      <Box className="flex-row h-1 px-1 gap-3 bg-surface shrink-0">        <Text bold color={theme.fg} wrap="nowrap">          ▼ Acme        </Text>        <Link href="/" shortcut="1" className="text-muted no-underline" activeClassName="text-fg bold">          1 Metrics        </Link>        <Link href="/deployments/dpl_a1" shortcut="2" className="text-muted no-underline" activeClassName="text-fg bold">          2 Latest deploy        </Link>      </Box>      <Box className="grow flex-col px-2 pt-1">{children}</Box>      <Box className="flex-row h-1 gap-2 pl-6 shrink-0 bg-surface">        <KeyHint keys="1-2" label="navigate" />        <KeyHint keys="tab" label="focus" />        <KeyHint keys="F2" label="devtools" />      </Box>    </Box>  );}

डायनामिक सेगमेंट Next.js की तरह ही काम करते हैं। [id] एक पैरामीटर बनता है, [...slug] बाकी पाथ को कैप्चर करता है और [[...slug]] पैरेंट से भी मैच करता है। स्टैटिक सेगमेंट को डायनामिक सेगमेंट पर प्राथमिकता मिलती है, और (marketing) जैसे रूट ग्रुप URL में कुछ जोड़े बिना फ़ाइलों को व्यवस्थित करते हैं।

app/deployments/[id]/page.tsxtsx
import { Box, Text, useInput } from "textjs";import { notFound, useParams, useRouter } from "textjs/navigation";import { DEPLOYMENTS } from "../../../lib/data";export default function DeploymentPage() {  const router = useRouter();  const { id } = useParams<{ id: string }>();  const deployment = DEPLOYMENTS.find((d) => d.id === id);  useInput((e) => {    if (e.key === "escape") router.back();  });  if (!deployment) notFound();  return (    <Box className="flex-col gap-1">      <Text bold>{deployment.id}</Text>      <Text>{deployment.branch}</Text>    </Box>  );}

loading.tsx और error.tsx फ़ाइलें सेगमेंट को Suspense बाउंड्री और एरर बाउंड्री में रैप करती हैं। एरर कंपोनेंट को एरर और एक reset फ़ंक्शन मिलता है:

app/deployments/error.tsxtsx
import { Box, Text, useInput, type ErrorComponentProps } from "textjs";export default function DeploymentsError({ error, reset }: ErrorComponentProps) {  useInput((e) => {    if (e.key === "r") reset();  });  return (    <Box className="flex-col grow items-center justify-center gap-1">      <Text bold>Something went wrong loading deployments.</Text>      <Text>{error.message}</Text>    </Box>  );}

रूट हैंडलर app/api में रहते हैं और एक मानक Response लौटाते हैं:

app/api/metrics/route.tsts
export function GET(): Response {  return Response.json({ cpu: Math.random(), memory: Math.random(), at: new Date().toISOString() });}

राउटर history.pushState के ज़रिए window.location को सिंक में रखता है, इसलिए वापस, आगे और डीप लिंक काम करते हैं, और metadata.title का मान document.title में लिखा जाता है। ऐप कंसोल में ड्रॉ करता है, और पेज पर एक फ़ोकस पैड होता है जो इनपुट इकट्ठा करता है।

CLI

  • text dev कमांड React Fast Refresh के साथ Vite शुरू करती है। फ़ाइल सेव करने पर कंसोल उसी जगह अपडेट होता है।
  • text build कमांड ऐप और उसके रूट हैंडलर का प्रोडक्शन बिल्ड लिखती है।
  • text start कमांड बिल्ड और रूट हैंडलर सर्व करती है।

create-text-app कमांड starter या dashboard टेम्प्लेट से प्रोजेक्ट का ढांचा तैयार करती है।

इंस्पेक्टर

चल रहे ऐप में कंसोल के अंदर [▼] इंस्पेक्टर खोलने के लिए Ctrl+` या F2 दबाएं। यह मैच हुआ रूट और उसके पैरामीटर, फ़्रेम का आकार, span की संख्या और फ़ेज़ की टाइमिंग, और डर्टी गेट से छोड़े गए फ़्रेम की संख्या दिखाता है। W कुंजी Yoga लेआउट को वायरफ़्रेम के रूप में ड्रॉ करती है।

0.1 में और भी

@textjs/react में PascalCase कंपोनेंट (Box, Text, ScrollBox, Input, Textarea, Select, Tabs, Code, Markdown, Diff, Modal, Spinner), सेल में काम करने वाली Tailwind-शैली की className यूटिलिटी और थीम शामिल हैं। लेआउट WebAssembly में Yoga पर चलता है।

पूरी सूची चेंजलॉग में है।