@kayjs/kay 2.0.0-beta.2 → 2.0.0-beta.4
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/llms.txt +42 -0
- package/package.json +24 -13
- package/src/build/bundle.ts +15 -53
- package/src/build/client-plugin.ts +108 -0
- package/src/build/compile.ts +9 -44
- package/src/build/graph.ts +16 -3
- package/src/build/index.ts +45 -25
- package/src/build/islands.ts +28 -30
- package/src/build/manifest.ts +9 -4
- package/src/build/prerender.ts +15 -7
- package/src/build/report.ts +82 -13
- package/src/build/resolve.ts +6 -7
- package/src/build/routes.ts +12 -21
- package/src/build/server-entry.ts +38 -0
- package/src/cli/check.ts +49 -43
- package/src/cli/commands.ts +224 -0
- package/src/cli/index.ts +46 -302
- package/src/cli/new.ts +15 -509
- package/src/cli/upgrade-plugins.ts +168 -0
- package/src/cli/upgrade.ts +220 -0
- package/src/compiler/analyze.ts +319 -565
- package/src/compiler/ast.ts +39 -0
- package/src/compiler/data-keys.ts +233 -0
- package/src/compiler/dom.ts +18 -15
- package/src/compiler/interactivity.ts +174 -0
- package/src/compiler/mistakes.ts +19 -1
- package/src/compiler/server-only.ts +4 -1
- package/src/compiler/shared.ts +1 -1
- package/src/compiler/ssr.ts +28 -28
- package/src/context.ts +1 -1
- package/src/dev/index.ts +19 -46
- package/src/dom/extras.ts +43 -12
- package/src/dom/index.ts +25 -1
- package/src/index.ts +0 -13
- package/src/jsx-runtime.ts +1 -1
- package/src/plugins/config.ts +49 -0
- package/src/plugins/context.ts +8 -28
- package/src/plugins/index.ts +10 -385
- package/src/plugins/load.ts +61 -0
- package/src/plugins/order.ts +107 -0
- package/src/plugins/public.ts +6 -0
- package/src/plugins/services.ts +35 -0
- package/src/plugins/types.ts +193 -0
- package/src/server/action-registry.ts +78 -0
- package/src/server/action.ts +8 -2
- package/src/server/app-entry.ts +23 -0
- package/src/server/assets.ts +182 -0
- package/src/server/document.ts +204 -0
- package/src/server/errors.ts +125 -0
- package/src/server/http.ts +14 -0
- package/src/server/index.ts +66 -766
- package/src/server/lifecycle.ts +22 -0
- package/src/server/loader.ts +60 -85
- package/src/server/page.ts +107 -0
- package/src/server/plugin-host.ts +165 -0
- package/src/server/public.ts +15 -0
- package/src/server/request-scope.ts +22 -0
- package/src/server/security.ts +40 -1
- package/src/server/static-dir.ts +22 -3
- package/src/server/stream.ts +95 -0
- package/src/ssr/context.ts +25 -0
- package/src/ssr/index.ts +10 -7
- package/src/test/browser.ts +180 -0
- package/src/test/index.ts +25 -6
- package/templates/_shared/AGENTS.md +5 -0
- package/templates/_shared/CLAUDE.md +1 -0
- package/templates/_shared/public/robots.txt +2 -0
- package/templates/_shared/tsconfig.json +19 -0
- package/templates/app/.env.example +4 -0
- package/templates/app/kay.config.ts +11 -0
- package/templates/app/package.json +20 -0
- package/templates/app/src/auth.ts +14 -0
- package/templates/app/src/routes/_layout.tsx +32 -0
- package/templates/app/src/routes/dashboard/_middleware.ts +3 -0
- package/templates/app/src/routes/dashboard/index.tsx +13 -0
- package/templates/app/src/routes/index.tsx +15 -0
- package/templates/app/src/routes/login.tsx +34 -0
- package/templates/app/src/styles/app.css +7 -0
- package/templates/blog/content/posts/welcome.md +9 -0
- package/templates/blog/kay.config.ts +23 -0
- package/templates/blog/package.json +21 -0
- package/templates/blog/src/posts.ts +26 -0
- package/templates/blog/src/routes/_layout.tsx +20 -0
- package/templates/blog/src/routes/blog/[slug].tsx +31 -0
- package/templates/blog/src/routes/index.tsx +29 -0
- package/templates/blog/src/styles/app.css +10 -0
- package/templates/fullstack/kay.config.ts +6 -0
- package/templates/fullstack/package.json +18 -0
- package/templates/fullstack/src/actions/greet.ts +19 -0
- package/templates/fullstack/src/components/Counter.tsx +10 -0
- package/templates/fullstack/src/components/GreetForm.tsx +26 -0
- package/templates/fullstack/src/routes/_layout.tsx +14 -0
- package/templates/fullstack/src/routes/api/health.ts +5 -0
- package/templates/fullstack/src/routes/index.tsx +13 -0
- package/templates/fullstack/src/styles/app.css +29 -0
- package/templates/minimal/kay.config.ts +6 -0
- package/templates/minimal/package.json +18 -0
- package/templates/minimal/src/components/Counter.tsx +10 -0
- package/templates/minimal/src/routes/_layout.tsx +14 -0
- package/templates/minimal/src/routes/index.tsx +11 -0
- package/templates/minimal/src/styles/app.css +22 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
body { margin: 0; background: var(--ui-paper); color: var(--ui-ink); font-family: var(--ui-font-body); }
|
|
2
|
+
.wrap { max-width: 52rem; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
|
|
3
|
+
.site-header { padding-bottom: 1.25rem; margin-bottom: 2rem; border-bottom: 1px solid var(--ui-line); }
|
|
4
|
+
.site-brand { font-family: var(--ui-font-display); font-size: 1.3rem; font-weight: 700; text-decoration: none; color: inherit; }
|
|
5
|
+
.page-title { margin: 0; font-family: var(--ui-font-display); }
|
|
6
|
+
.page-lead { margin: 0; color: var(--ui-muted); }
|
|
7
|
+
.m-0 { margin: 0; }
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Welcome to __APP_NAME__
|
|
3
|
+
date: 2026-11-23
|
|
4
|
+
description: A zero-JS static Markdown blog built with Kay v2.
|
|
5
|
+
tags: [kay, bun]
|
|
6
|
+
---
|
|
7
|
+
## Fast by Default
|
|
8
|
+
|
|
9
|
+
This post is rendered at build time using Bun's native Zig Markdown engine and ships **0 KB** of client JavaScript.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { content } from '@kayjs/content'
|
|
2
|
+
import { seo } from '@kayjs/seo'
|
|
3
|
+
import { ui } from '@kayjs/ui/plugin'
|
|
4
|
+
import { defineConfig } from '@kayjs/kay/config'
|
|
5
|
+
import { posts } from './src/posts'
|
|
6
|
+
|
|
7
|
+
export default defineConfig({
|
|
8
|
+
lang: 'en',
|
|
9
|
+
plugins: [
|
|
10
|
+
ui({ grammar: 'editorial' }),
|
|
11
|
+
seo({ site: 'https://example.com', titleTemplate: '%s — __APP_NAME__' }),
|
|
12
|
+
content({
|
|
13
|
+
feeds: [{
|
|
14
|
+
path: '/rss.xml',
|
|
15
|
+
title: '__APP_NAME__',
|
|
16
|
+
description: 'Articles & notes',
|
|
17
|
+
site: 'https://example.com',
|
|
18
|
+
linkPrefix: '/blog',
|
|
19
|
+
collection: posts,
|
|
20
|
+
}],
|
|
21
|
+
}),
|
|
22
|
+
],
|
|
23
|
+
})
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "__APP_NAME__",
|
|
3
|
+
"private": true,
|
|
4
|
+
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "kay dev",
|
|
7
|
+
"build": "kay build",
|
|
8
|
+
"start": "kay start",
|
|
9
|
+
"check": "kay check"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@kayjs/kay": "__KAY_VERSION__",
|
|
13
|
+
"@kayjs/content": "__KAY_VERSION__",
|
|
14
|
+
"@kayjs/seo": "__KAY_VERSION__",
|
|
15
|
+
"@kayjs/ui": "__KAY_VERSION__"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/bun": "latest",
|
|
19
|
+
"typescript": "^6.0.3"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from '@kayjs/kay/server'
|
|
2
|
+
import { defineCollection } from '@kayjs/content'
|
|
3
|
+
|
|
4
|
+
export interface PostMeta {
|
|
5
|
+
title: string
|
|
6
|
+
date: string
|
|
7
|
+
description?: string
|
|
8
|
+
tags?: string[]
|
|
9
|
+
draft?: boolean
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Any Standard Schema validator works here (Zod, Valibot, ArkType); this one keeps the template free of dependencies.
|
|
13
|
+
const postSchema: StandardSchemaV1<unknown, PostMeta> = {
|
|
14
|
+
'~standard': {
|
|
15
|
+
version: 1,
|
|
16
|
+
vendor: 'app',
|
|
17
|
+
validate(raw: unknown) {
|
|
18
|
+
const data = raw as Partial<PostMeta>
|
|
19
|
+
if (typeof data.title !== 'string' || typeof data.date !== 'string')
|
|
20
|
+
return { issues: [{ message: 'A post needs a title and a date', path: ['title'] }] }
|
|
21
|
+
return { value: data as PostMeta }
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const posts = defineCollection({ dir: 'content/posts', schema: postSchema })
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { KayChild } from '@kayjs/kay'
|
|
2
|
+
import { Head } from '@kayjs/kay'
|
|
3
|
+
import '../styles/app.css'
|
|
4
|
+
|
|
5
|
+
export default function Layout({ children }: { children: KayChild }) {
|
|
6
|
+
return (
|
|
7
|
+
<>
|
|
8
|
+
<Head>
|
|
9
|
+
<title>__APP_NAME__</title>
|
|
10
|
+
</Head>
|
|
11
|
+
<div class="wrap">
|
|
12
|
+
<header data-layout="split" class="site-header">
|
|
13
|
+
<a href="/" class="site-brand">__APP_NAME__</a>
|
|
14
|
+
<a href="/rss.xml" class="site-rss">RSS</a>
|
|
15
|
+
</header>
|
|
16
|
+
<main>{children}</main>
|
|
17
|
+
</div>
|
|
18
|
+
</>
|
|
19
|
+
)
|
|
20
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { RequestContext } from '@kayjs/kay/server'
|
|
2
|
+
import { Button, Stack } from '@kayjs/ui'
|
|
3
|
+
import { Head } from '@kayjs/kay'
|
|
4
|
+
import { posts } from '../../posts'
|
|
5
|
+
|
|
6
|
+
export const prerender = true
|
|
7
|
+
export function paths() {
|
|
8
|
+
return posts.paths('/blog')
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export async function load(ctx: RequestContext) {
|
|
12
|
+
const post = posts.get(ctx.params.slug ?? '')
|
|
13
|
+
if (!post)
|
|
14
|
+
return new Response('Not found', { status: 404 })
|
|
15
|
+
return { post }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default function PostPage({ data }: { data: { post: NonNullable<ReturnType<typeof posts.get>> } }) {
|
|
19
|
+
const { post } = data
|
|
20
|
+
return (
|
|
21
|
+
<Stack gap="md">
|
|
22
|
+
<Head><title>{post.data.title}</title></Head>
|
|
23
|
+
<article>
|
|
24
|
+
<h1 class="post-title">{post.data.title}</h1>
|
|
25
|
+
<p class="post-meta">{post.data.date} · {post.readingMinutes} min read</p>
|
|
26
|
+
<div innerHTML={post.html} />
|
|
27
|
+
</article>
|
|
28
|
+
<div><Button href="/" variant="outline">← All posts</Button></div>
|
|
29
|
+
</Stack>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Badge, Card, CardBody, CardFooter, CardHeader, Cluster, Stack } from '@kayjs/ui'
|
|
2
|
+
import { posts } from '../posts'
|
|
3
|
+
|
|
4
|
+
export const prerender = true
|
|
5
|
+
|
|
6
|
+
export default async function BlogIndex() {
|
|
7
|
+
const list = posts.all()
|
|
8
|
+
return (
|
|
9
|
+
<Stack gap="lg">
|
|
10
|
+
<h1 class="page-title">Articles</h1>
|
|
11
|
+
{list.map(post => (
|
|
12
|
+
<Card key={post.slug}>
|
|
13
|
+
<CardHeader>
|
|
14
|
+
<a href={`/blog/${post.slug}`} class="post-link">{post.data.title}</a>
|
|
15
|
+
</CardHeader>
|
|
16
|
+
<CardBody>
|
|
17
|
+
<p class="post-desc">{post.data.description ?? ''}</p>
|
|
18
|
+
</CardBody>
|
|
19
|
+
<CardFooter>
|
|
20
|
+
<Cluster>
|
|
21
|
+
<span>{post.data.date} · {post.readingMinutes} min read</span>
|
|
22
|
+
{(post.data.tags ?? []).map(tag => <Badge key={tag}>{tag}</Badge>)}
|
|
23
|
+
</Cluster>
|
|
24
|
+
</CardFooter>
|
|
25
|
+
</Card>
|
|
26
|
+
))}
|
|
27
|
+
</Stack>
|
|
28
|
+
)
|
|
29
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
body { margin: 0; background: var(--ui-paper); color: var(--ui-ink); font-family: var(--ui-font-body); }
|
|
2
|
+
.wrap { max-width: 46rem; margin: 0 auto; padding: 2rem 1.25rem 4rem; }
|
|
3
|
+
.site-header { padding-bottom: 1.25rem; margin-bottom: 2rem; border-bottom: 1px solid var(--ui-line); }
|
|
4
|
+
.site-brand { font-family: var(--ui-font-display); font-size: 1.35rem; font-weight: 700; text-decoration: none; color: inherit; }
|
|
5
|
+
.site-rss { font-size: 0.9rem; color: var(--ui-muted); }
|
|
6
|
+
.page-title { margin: 0; font-family: var(--ui-font-display); }
|
|
7
|
+
.post-link { color: inherit; text-decoration: none; }
|
|
8
|
+
.post-desc { margin: 0; color: var(--ui-muted); }
|
|
9
|
+
.post-title { font-family: var(--ui-font-display); margin-bottom: 0.25rem; }
|
|
10
|
+
.post-meta { color: var(--ui-muted); margin-top: 0; }
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "__APP_NAME__",
|
|
3
|
+
"private": true,
|
|
4
|
+
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "kay dev",
|
|
7
|
+
"build": "kay build",
|
|
8
|
+
"start": "kay start",
|
|
9
|
+
"check": "kay check"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@kayjs/kay": "__KAY_VERSION__"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@types/bun": "latest",
|
|
16
|
+
"typescript": "^6.0.3"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from '@kayjs/kay/server'
|
|
2
|
+
import { action } from '@kayjs/kay/server'
|
|
3
|
+
|
|
4
|
+
const nameSchema: StandardSchemaV1<{ name: string }> = {
|
|
5
|
+
'~standard': {
|
|
6
|
+
version: 1,
|
|
7
|
+
vendor: 'kay',
|
|
8
|
+
validate(raw: unknown) {
|
|
9
|
+
const name = String((raw as { name?: unknown })?.name ?? '').trim()
|
|
10
|
+
if (name.length < 2)
|
|
11
|
+
return { issues: [{ message: 'Enter at least 2 characters', path: ['name'] }] }
|
|
12
|
+
return { value: { name } }
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const greet = action(nameSchema, async ({ name }) => {
|
|
18
|
+
return { message: `Hello, ${name}!` }
|
|
19
|
+
})
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { signal } from '@kayjs/kay'
|
|
2
|
+
import { greet } from '../actions/greet'
|
|
3
|
+
|
|
4
|
+
export function GreetForm() {
|
|
5
|
+
const name = signal('')
|
|
6
|
+
const reply = signal('')
|
|
7
|
+
|
|
8
|
+
async function onSubmit(e: SubmitEvent) {
|
|
9
|
+
e.preventDefault()
|
|
10
|
+
const res = await greet({ name: name.value })
|
|
11
|
+
reply.value = res.ok ? res.data.message : res.error
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<form class="greet-form" action={greet.url} method="post" onSubmit={onSubmit}>
|
|
16
|
+
<input
|
|
17
|
+
name="name"
|
|
18
|
+
placeholder="Your name"
|
|
19
|
+
value={name.value}
|
|
20
|
+
onInput={(e) => { name.value = (e.target as HTMLInputElement).value }}
|
|
21
|
+
/>
|
|
22
|
+
<button type="submit">Greet</button>
|
|
23
|
+
{reply.value && <span>{reply.value}</span>}
|
|
24
|
+
</form>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { KayChild } from '@kayjs/kay'
|
|
2
|
+
import { Head } from '@kayjs/kay'
|
|
3
|
+
import '../styles/app.css'
|
|
4
|
+
|
|
5
|
+
export default function Layout({ children }: { children: KayChild }) {
|
|
6
|
+
return (
|
|
7
|
+
<>
|
|
8
|
+
<Head>
|
|
9
|
+
<title>__APP_NAME__</title>
|
|
10
|
+
</Head>
|
|
11
|
+
<main>{children}</main>
|
|
12
|
+
</>
|
|
13
|
+
)
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Counter } from '../components/Counter'
|
|
2
|
+
import { GreetForm } from '../components/GreetForm'
|
|
3
|
+
|
|
4
|
+
export default async function Home() {
|
|
5
|
+
return (
|
|
6
|
+
<section>
|
|
7
|
+
<h1>Welcome to Kay</h1>
|
|
8
|
+
<p>Zero-directive islands, Standard-Schema actions, and Bun speed.</p>
|
|
9
|
+
<Counter initial={0} />
|
|
10
|
+
<GreetForm />
|
|
11
|
+
</section>
|
|
12
|
+
)
|
|
13
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
*, *::before, *::after { box-sizing: border-box; }
|
|
2
|
+
body {
|
|
3
|
+
margin: 0;
|
|
4
|
+
font-family: system-ui, -apple-system, sans-serif;
|
|
5
|
+
line-height: 1.6;
|
|
6
|
+
color: #111827;
|
|
7
|
+
background: #fafafa;
|
|
8
|
+
}
|
|
9
|
+
main {
|
|
10
|
+
max-width: 44rem;
|
|
11
|
+
margin: 4rem auto;
|
|
12
|
+
padding: 0 1.5rem;
|
|
13
|
+
}
|
|
14
|
+
button {
|
|
15
|
+
font: inherit;
|
|
16
|
+
padding: 0.5rem 1rem;
|
|
17
|
+
border-radius: 6px;
|
|
18
|
+
border: 1px solid #d1d5db;
|
|
19
|
+
background: #fff;
|
|
20
|
+
cursor: pointer;
|
|
21
|
+
}
|
|
22
|
+
button:hover { background: #f3f4f6; }
|
|
23
|
+
|
|
24
|
+
.greet-form {
|
|
25
|
+
margin-top: 1.5rem;
|
|
26
|
+
display: flex;
|
|
27
|
+
gap: 0.5rem;
|
|
28
|
+
align-items: center;
|
|
29
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "__APP_NAME__",
|
|
3
|
+
"private": true,
|
|
4
|
+
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "kay dev",
|
|
7
|
+
"build": "kay build",
|
|
8
|
+
"start": "kay start",
|
|
9
|
+
"check": "kay check"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@kayjs/kay": "__KAY_VERSION__"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@types/bun": "latest",
|
|
16
|
+
"typescript": "^6.0.3"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { KayChild } from '@kayjs/kay'
|
|
2
|
+
import { Head } from '@kayjs/kay'
|
|
3
|
+
import '../styles/app.css'
|
|
4
|
+
|
|
5
|
+
export default function Layout({ children }: { children: KayChild }) {
|
|
6
|
+
return (
|
|
7
|
+
<>
|
|
8
|
+
<Head>
|
|
9
|
+
<title>__APP_NAME__</title>
|
|
10
|
+
</Head>
|
|
11
|
+
<main>{children}</main>
|
|
12
|
+
</>
|
|
13
|
+
)
|
|
14
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
*, *::before, *::after { box-sizing: border-box; }
|
|
2
|
+
body {
|
|
3
|
+
margin: 0;
|
|
4
|
+
font-family: system-ui, -apple-system, sans-serif;
|
|
5
|
+
line-height: 1.6;
|
|
6
|
+
color: #111827;
|
|
7
|
+
background: #fafafa;
|
|
8
|
+
}
|
|
9
|
+
main {
|
|
10
|
+
max-width: 44rem;
|
|
11
|
+
margin: 4rem auto;
|
|
12
|
+
padding: 0 1.5rem;
|
|
13
|
+
}
|
|
14
|
+
button {
|
|
15
|
+
font: inherit;
|
|
16
|
+
padding: 0.5rem 1rem;
|
|
17
|
+
border-radius: 6px;
|
|
18
|
+
border: 1px solid #d1d5db;
|
|
19
|
+
background: #fff;
|
|
20
|
+
cursor: pointer;
|
|
21
|
+
}
|
|
22
|
+
button:hover { background: #f3f4f6; }
|