@korajs/cli 0.5.0 → 1.0.0-beta.0
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/LICENSE +21 -0
- package/dist/bin.cjs +2656 -207
- package/dist/bin.cjs.map +1 -1
- package/dist/bin.js +152 -96
- package/dist/bin.js.map +1 -1
- package/dist/chunk-5NI2FEQL.js +92 -0
- package/dist/chunk-5NI2FEQL.js.map +1 -0
- package/dist/chunk-6C4BHSRA.js +82 -0
- package/dist/chunk-6C4BHSRA.js.map +1 -0
- package/dist/{chunk-3WNFM3QB.js → chunk-B5YS4STN.js} +78 -99
- package/dist/chunk-B5YS4STN.js.map +1 -0
- package/dist/{chunk-PSRM56B7.js → chunk-BWTKRKNJ.js} +60 -7
- package/dist/chunk-BWTKRKNJ.js.map +1 -0
- package/dist/{chunk-SOTZIWIF.js → chunk-EOWLAAIV.js} +5 -3
- package/dist/{chunk-SOTZIWIF.js.map → chunk-EOWLAAIV.js.map} +1 -1
- package/dist/create.cjs +82 -7
- package/dist/create.cjs.map +1 -1
- package/dist/create.js +3 -2
- package/dist/create.js.map +1 -1
- package/dist/index.cjs +65 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -2
- package/dist/lab-manager-KUDII6BT.js +280 -0
- package/dist/lab-manager-KUDII6BT.js.map +1 -0
- package/dist/schema-loader-GGHECMTM.js +9 -0
- package/dist/schema-loader-GGHECMTM.js.map +1 -0
- package/dist/spectator-manager-E2LH2P54.js +142 -0
- package/dist/spectator-manager-E2LH2P54.js.map +1 -0
- package/dist/studio-server-NIFKZI4F.js +1738 -0
- package/dist/studio-server-NIFKZI4F.js.map +1 -0
- package/package.json +8 -6
- package/templates/react-basic/AGENTS.md +87 -0
- package/templates/react-sync/AGENTS.md +87 -0
- package/templates/react-sync/src/App.tsx +8 -0
- package/templates/react-sync/src/index.css +11 -0
- package/templates/react-tailwind/AGENTS.md +87 -0
- package/templates/react-tailwind-sync/AGENTS.md +87 -0
- package/templates/react-tailwind-sync/src/App.tsx +28 -0
- package/templates/svelte-basic/.env.example +3 -0
- package/templates/svelte-basic/AGENTS.md +76 -0
- package/templates/svelte-basic/README.md.hbs +62 -0
- package/templates/svelte-basic/index.html.hbs +12 -0
- package/templates/svelte-basic/kora.config.ts +12 -0
- package/templates/svelte-basic/package.json.hbs +27 -0
- package/templates/svelte-basic/src/App.svelte +127 -0
- package/templates/svelte-basic/src/Root.svelte +14 -0
- package/templates/svelte-basic/src/index.css +287 -0
- package/templates/svelte-basic/src/kora-worker.ts +9 -0
- package/templates/svelte-basic/src/main.ts +16 -0
- package/templates/svelte-basic/src/modules/todos/todo.mutations.ts +25 -0
- package/templates/svelte-basic/src/modules/todos/todo.queries.ts +5 -0
- package/templates/svelte-basic/src/modules/todos/todo.schema.ts +10 -0
- package/templates/svelte-basic/src/modules/todos/useTodos.ts +25 -0
- package/templates/svelte-basic/src/schema.ts +9 -0
- package/templates/svelte-basic/src/vite-env.d.ts +12 -0
- package/templates/svelte-basic/svelte.config.js +5 -0
- package/templates/svelte-basic/tsconfig.json.hbs +14 -0
- package/templates/svelte-basic/vite.config.ts +52 -0
- package/templates/svelte-sync/.env.example +25 -0
- package/templates/svelte-sync/AGENTS.md +76 -0
- package/templates/svelte-sync/README.md.hbs +105 -0
- package/templates/svelte-sync/index.html.hbs +12 -0
- package/templates/svelte-sync/kora.config.ts +17 -0
- package/templates/svelte-sync/package.json.hbs +43 -0
- package/templates/svelte-sync/server.ts +90 -0
- package/templates/svelte-sync/src/App.svelte +150 -0
- package/templates/svelte-sync/src/Root.svelte +22 -0
- package/templates/svelte-sync/src/auth.ts +25 -0
- package/templates/svelte-sync/src/index.css +339 -0
- package/templates/svelte-sync/src/kora-worker.ts +9 -0
- package/templates/svelte-sync/src/main.ts +32 -0
- package/templates/svelte-sync/src/modules/todos/todo.mutations.ts +25 -0
- package/templates/svelte-sync/src/modules/todos/todo.queries.ts +5 -0
- package/templates/svelte-sync/src/modules/todos/todo.schema.ts +10 -0
- package/templates/svelte-sync/src/modules/todos/useTodos.ts +25 -0
- package/templates/svelte-sync/src/schema.ts +9 -0
- package/templates/svelte-sync/src/vite-env.d.ts +21 -0
- package/templates/svelte-sync/svelte.config.js +5 -0
- package/templates/svelte-sync/tsconfig.json.hbs +14 -0
- package/templates/svelte-sync/vite.config.ts +79 -0
- package/templates/svelte-tailwind/AGENTS.md +76 -0
- package/templates/svelte-tailwind/README.md.hbs +62 -0
- package/templates/svelte-tailwind/index.html.hbs +12 -0
- package/templates/svelte-tailwind/kora.config.ts +12 -0
- package/templates/svelte-tailwind/package.json.hbs +30 -0
- package/templates/svelte-tailwind/src/App.svelte +75 -0
- package/templates/svelte-tailwind/src/Root.svelte +14 -0
- package/templates/svelte-tailwind/src/index.css +7 -0
- package/templates/svelte-tailwind/src/kora-worker.ts +9 -0
- package/templates/svelte-tailwind/src/main.ts +16 -0
- package/templates/svelte-tailwind/src/modules/todos/todo.mutations.ts +25 -0
- package/templates/svelte-tailwind/src/modules/todos/todo.queries.ts +5 -0
- package/templates/svelte-tailwind/src/modules/todos/todo.schema.ts +10 -0
- package/templates/svelte-tailwind/src/modules/todos/useTodos.ts +25 -0
- package/templates/svelte-tailwind/src/schema.ts +9 -0
- package/templates/svelte-tailwind/src/vite-env.d.ts +12 -0
- package/templates/svelte-tailwind/svelte.config.js +5 -0
- package/templates/svelte-tailwind/tsconfig.json.hbs +14 -0
- package/templates/svelte-tailwind/vite.config.ts +53 -0
- package/templates/svelte-tailwind-sync/.env.example +25 -0
- package/templates/svelte-tailwind-sync/AGENTS.md +76 -0
- package/templates/svelte-tailwind-sync/README.md.hbs +105 -0
- package/templates/svelte-tailwind-sync/index.html.hbs +12 -0
- package/templates/svelte-tailwind-sync/kora.config.ts +17 -0
- package/templates/svelte-tailwind-sync/package.json.hbs +46 -0
- package/templates/svelte-tailwind-sync/server.ts +90 -0
- package/templates/svelte-tailwind-sync/src/App.svelte +192 -0
- package/templates/svelte-tailwind-sync/src/Root.svelte +26 -0
- package/templates/svelte-tailwind-sync/src/auth.ts +25 -0
- package/templates/svelte-tailwind-sync/src/index.css +7 -0
- package/templates/svelte-tailwind-sync/src/kora-worker.ts +9 -0
- package/templates/svelte-tailwind-sync/src/main.ts +32 -0
- package/templates/svelte-tailwind-sync/src/modules/todos/todo.mutations.ts +25 -0
- package/templates/svelte-tailwind-sync/src/modules/todos/todo.queries.ts +5 -0
- package/templates/svelte-tailwind-sync/src/modules/todos/todo.schema.ts +10 -0
- package/templates/svelte-tailwind-sync/src/modules/todos/useTodos.ts +25 -0
- package/templates/svelte-tailwind-sync/src/schema.ts +9 -0
- package/templates/svelte-tailwind-sync/src/vite-env.d.ts +21 -0
- package/templates/svelte-tailwind-sync/svelte.config.js +5 -0
- package/templates/svelte-tailwind-sync/tsconfig.json.hbs +14 -0
- package/templates/svelte-tailwind-sync/vite.config.ts +80 -0
- package/templates/tauri-react/AGENTS.md +91 -0
- package/templates/vue-basic/AGENTS.md +84 -0
- package/templates/vue-basic/README.md.hbs +62 -0
- package/templates/vue-basic/index.html.hbs +12 -0
- package/templates/vue-basic/kora.config.ts +12 -0
- package/templates/vue-basic/package.json.hbs +26 -0
- package/templates/vue-basic/src/App.vue +117 -0
- package/templates/vue-basic/src/index.css +287 -0
- package/templates/vue-basic/src/kora-worker.ts +9 -0
- package/templates/vue-basic/src/main.ts +20 -0
- package/templates/vue-basic/src/modules/todos/todo.mutations.ts +25 -0
- package/templates/vue-basic/src/modules/todos/todo.queries.ts +5 -0
- package/templates/vue-basic/src/modules/todos/todo.schema.ts +10 -0
- package/templates/vue-basic/src/modules/todos/useTodos.ts +32 -0
- package/templates/vue-basic/src/schema.ts +9 -0
- package/templates/vue-basic/src/vite-env.d.ts +17 -0
- package/templates/vue-basic/tsconfig.json.hbs +15 -0
- package/templates/vue-basic/vite.config.ts +69 -0
- package/templates/vue-sync/.env.example +25 -0
- package/templates/vue-sync/AGENTS.md +84 -0
- package/templates/vue-sync/README.md.hbs +105 -0
- package/templates/vue-sync/index.html.hbs +12 -0
- package/templates/vue-sync/kora.config.ts +17 -0
- package/templates/vue-sync/package.json.hbs +42 -0
- package/templates/vue-sync/server.ts +90 -0
- package/templates/vue-sync/src/App.vue +135 -0
- package/templates/vue-sync/src/auth.ts +25 -0
- package/templates/vue-sync/src/index.css +339 -0
- package/templates/vue-sync/src/kora-worker.ts +9 -0
- package/templates/vue-sync/src/main.ts +47 -0
- package/templates/vue-sync/src/modules/todos/todo.mutations.ts +25 -0
- package/templates/vue-sync/src/modules/todos/todo.queries.ts +5 -0
- package/templates/vue-sync/src/modules/todos/todo.schema.ts +10 -0
- package/templates/vue-sync/src/modules/todos/useTodos.ts +32 -0
- package/templates/vue-sync/src/schema.ts +9 -0
- package/templates/vue-sync/src/vite-env.d.ts +26 -0
- package/templates/vue-sync/tsconfig.json.hbs +15 -0
- package/templates/vue-sync/vite.config.ts +79 -0
- package/templates/vue-tailwind/AGENTS.md +84 -0
- package/templates/vue-tailwind/README.md.hbs +62 -0
- package/templates/vue-tailwind/index.html.hbs +12 -0
- package/templates/vue-tailwind/kora.config.ts +12 -0
- package/templates/vue-tailwind/package.json.hbs +29 -0
- package/templates/vue-tailwind/src/App.vue +135 -0
- package/templates/vue-tailwind/src/index.css +7 -0
- package/templates/vue-tailwind/src/kora-worker.ts +9 -0
- package/templates/vue-tailwind/src/main.ts +31 -0
- package/templates/vue-tailwind/src/modules/todos/todo.mutations.ts +25 -0
- package/templates/vue-tailwind/src/modules/todos/todo.queries.ts +5 -0
- package/templates/vue-tailwind/src/modules/todos/todo.schema.ts +10 -0
- package/templates/vue-tailwind/src/modules/todos/useTodos.ts +32 -0
- package/templates/vue-tailwind/src/schema.ts +9 -0
- package/templates/vue-tailwind/src/vite-env.d.ts +17 -0
- package/templates/vue-tailwind/tsconfig.json.hbs +15 -0
- package/templates/vue-tailwind/vite.config.ts +70 -0
- package/templates/vue-tailwind-sync/.env.example +25 -0
- package/templates/vue-tailwind-sync/AGENTS.md +84 -0
- package/templates/vue-tailwind-sync/README.md.hbs +105 -0
- package/templates/vue-tailwind-sync/index.html.hbs +12 -0
- package/templates/vue-tailwind-sync/kora.config.ts +17 -0
- package/templates/vue-tailwind-sync/package.json.hbs +45 -0
- package/templates/vue-tailwind-sync/server.ts +90 -0
- package/templates/vue-tailwind-sync/src/App.vue +245 -0
- package/templates/vue-tailwind-sync/src/auth.ts +25 -0
- package/templates/vue-tailwind-sync/src/index.css +7 -0
- package/templates/vue-tailwind-sync/src/kora-worker.ts +9 -0
- package/templates/vue-tailwind-sync/src/main.ts +56 -0
- package/templates/vue-tailwind-sync/src/modules/todos/todo.mutations.ts +25 -0
- package/templates/vue-tailwind-sync/src/modules/todos/todo.queries.ts +5 -0
- package/templates/vue-tailwind-sync/src/modules/todos/todo.schema.ts +10 -0
- package/templates/vue-tailwind-sync/src/modules/todos/useTodos.ts +32 -0
- package/templates/vue-tailwind-sync/src/schema.ts +9 -0
- package/templates/vue-tailwind-sync/src/vite-env.d.ts +26 -0
- package/templates/vue-tailwind-sync/tsconfig.json.hbs +15 -0
- package/templates/vue-tailwind-sync/vite.config.ts +80 -0
- package/dist/chunk-3WNFM3QB.js.map +0 -1
- package/dist/chunk-PSRM56B7.js.map +0 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"noUncheckedIndexedAccess": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"types": ["vite/client"]
|
|
11
|
+
},
|
|
12
|
+
"include": ["src/**/*.ts", "src/**/*.svelte"],
|
|
13
|
+
"exclude": ["node_modules"]
|
|
14
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { copyFileSync, existsSync, readdirSync } from 'node:fs'
|
|
2
|
+
import { join, resolve } from 'node:path'
|
|
3
|
+
import { svelte } from '@sveltejs/vite-plugin-svelte'
|
|
4
|
+
import tailwindcss from '@tailwindcss/vite'
|
|
5
|
+
import type { Plugin } from 'vite'
|
|
6
|
+
import { defineConfig } from 'vite'
|
|
7
|
+
|
|
8
|
+
function crossOriginIsolation(): Plugin {
|
|
9
|
+
return {
|
|
10
|
+
name: 'cross-origin-isolation',
|
|
11
|
+
configureServer(server) {
|
|
12
|
+
server.middlewares.use((_req, res, next) => {
|
|
13
|
+
res.setHeader('Cross-Origin-Opener-Policy', 'same-origin')
|
|
14
|
+
res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp')
|
|
15
|
+
next()
|
|
16
|
+
})
|
|
17
|
+
},
|
|
18
|
+
configurePreviewServer(server) {
|
|
19
|
+
server.middlewares.use((_req, res, next) => {
|
|
20
|
+
res.setHeader('Cross-Origin-Opener-Policy', 'same-origin')
|
|
21
|
+
res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp')
|
|
22
|
+
next()
|
|
23
|
+
})
|
|
24
|
+
},
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function sqliteWasmHotfix(): Plugin {
|
|
29
|
+
return {
|
|
30
|
+
name: 'sqlite-wasm-hotfix',
|
|
31
|
+
apply: 'build',
|
|
32
|
+
closeBundle() {
|
|
33
|
+
const assetsDir = resolve('dist', 'assets')
|
|
34
|
+
if (!existsSync(assetsDir)) return
|
|
35
|
+
for (const file of readdirSync(assetsDir)) {
|
|
36
|
+
if (/^sqlite3-.+\.wasm$/.test(file)) {
|
|
37
|
+
copyFileSync(join(assetsDir, file), join(assetsDir, 'sqlite3.wasm'))
|
|
38
|
+
break
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export default defineConfig({
|
|
46
|
+
plugins: [svelte(), tailwindcss(), crossOriginIsolation(), sqliteWasmHotfix()],
|
|
47
|
+
worker: { format: 'es' },
|
|
48
|
+
optimizeDeps: {
|
|
49
|
+
exclude: ['@sqlite.org/sqlite-wasm', '@korajs/store'],
|
|
50
|
+
include: ['yjs'],
|
|
51
|
+
},
|
|
52
|
+
resolve: { dedupe: ['yjs'] },
|
|
53
|
+
})
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Kora Sync Server
|
|
2
|
+
# WebSocket URL for the sync server (used by the client)
|
|
3
|
+
VITE_SYNC_URL=ws://localhost:3001
|
|
4
|
+
|
|
5
|
+
# Sync server port
|
|
6
|
+
PORT=3001
|
|
7
|
+
|
|
8
|
+
# Server database
|
|
9
|
+
# Leave DATABASE_URL empty to use SQLite at KORA_SERVER_DB.
|
|
10
|
+
KORA_SERVER_DB=./kora-server.db
|
|
11
|
+
DATABASE_URL=
|
|
12
|
+
|
|
13
|
+
# Operational endpoints (/__kora, /__kora/status, /__kora/events, /__kora/metrics, backups)
|
|
14
|
+
# Set these in production. Use Authorization: Bearer <token> when calling protected endpoints.
|
|
15
|
+
KORA_ADMIN_TOKEN=
|
|
16
|
+
KORA_METRICS_TOKEN=
|
|
17
|
+
KORA_BACKUP_TOKEN=
|
|
18
|
+
|
|
19
|
+
# Optional sync path
|
|
20
|
+
KORA_SYNC_PATH=/kora-sync
|
|
21
|
+
|
|
22
|
+
# Auth
|
|
23
|
+
# Set this to enable built-in /auth/* routes and authenticated sync.
|
|
24
|
+
# Generate with: node -e "console.log(require('node:crypto').randomBytes(32).toString('hex'))"
|
|
25
|
+
KORA_AUTH_SECRET=
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
Guidance for AI coding agents working in this project. Humans: this is useful for you too.
|
|
4
|
+
|
|
5
|
+
## What this project is
|
|
6
|
+
|
|
7
|
+
This is a **Kora.js** application: an offline-first app where all data lives in a local SQLite database (WASM + OPFS in the browser) and optionally syncs across devices through a Kora sync server. Offline is the normal state, not an error state. Full docs: https://korajs.dev and machine-readable index at https://korajs.dev/llms.txt (complete docs in one file: https://korajs.dev/llms-full.txt).
|
|
8
|
+
|
|
9
|
+
## Golden rules
|
|
10
|
+
|
|
11
|
+
1. **The schema is the source of truth.** All collections are defined in `src/schema.ts` with `defineSchema` and the `t.*` field builders. To add or change data shapes, edit the schema first; types flow from it automatically. Never hand-write types for records.
|
|
12
|
+
2. **Never fetch application data over HTTP.** Do not add REST or GraphQL calls for app data, and do not talk to the sync server directly. Read and write through Kora collections only; sync happens automatically in the background.
|
|
13
|
+
3. **Await readiness before direct collection access.** Outside the UI bindings, `await app.ready` before calling `app.<collection>` methods. The bindings handle this for you inside components.
|
|
14
|
+
4. **Offline must keep working.** Any feature you add must function with the network off. Never gate a write or a read on connectivity. If you find yourself checking `navigator.onLine` before a data operation, you are doing it wrong.
|
|
15
|
+
5. **Surface mutation errors.** Fire-and-forget mutate calls swallow errors into the mutation state. Always render the mutation's `error` in the UI or handle the promise from the async variant. Silent failure is the worst failure.
|
|
16
|
+
6. **Do not touch `src/kora-worker.ts`.** It wires the SQLite WASM binary URL for both dev and production builds. Changing it breaks production builds in ways that only show up after deploy.
|
|
17
|
+
7. **Do not add a state management library for server or app data.** Kora's reactive queries are the store. Local UI state (form inputs, toggles) can use the framework's normal state tools.
|
|
18
|
+
|
|
19
|
+
## Data API cheat sheet
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
await app.ready
|
|
23
|
+
const rec = await app.todos.insert({ title: 'x' }) // defaults and .auto() fields applied
|
|
24
|
+
await app.todos.update(rec.id, { completed: true }) // partial update, changed fields only
|
|
25
|
+
await app.todos.delete(rec.id)
|
|
26
|
+
const one = await app.todos.findById(rec.id)
|
|
27
|
+
const unsubscribe = app.todos
|
|
28
|
+
.where({ completed: false })
|
|
29
|
+
.orderBy('createdAt', 'desc')
|
|
30
|
+
.subscribe((rows) => {/* fires immediately, then on every change */})
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Schema example (`src/schema.ts`):
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { defineSchema, t } from 'korajs'
|
|
37
|
+
|
|
38
|
+
export default defineSchema({
|
|
39
|
+
version: 1,
|
|
40
|
+
collections: {
|
|
41
|
+
todos: {
|
|
42
|
+
fields: {
|
|
43
|
+
title: t.string(),
|
|
44
|
+
completed: t.boolean().default(false),
|
|
45
|
+
tags: t.array(t.string()).default([]),
|
|
46
|
+
priority: t.enum(['low', 'medium', 'high']).default('medium'),
|
|
47
|
+
createdAt: t.timestamp().auto(), // set automatically; never pass it on insert
|
|
48
|
+
},
|
|
49
|
+
indexes: ['completed', 'createdAt'],
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
})
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
If you bump collections in a way that changes shapes, increment `version` and run `npx kora migrate`.
|
|
56
|
+
|
|
57
|
+
## Project conventions
|
|
58
|
+
|
|
59
|
+
- Feature code lives in `src/modules/<feature>/` with the pattern: `<feature>.schema.ts` (collection definition, imported into `src/schema.ts`), `<feature>.queries.ts` (query builders), `<feature>.mutations.ts` (mutation functions taking a collection accessor).
|
|
60
|
+
- Conflict handling is declarative. Concurrent edits merge automatically (last-write-wins per field, add-wins for arrays). If a field needs domain-specific merging (counters, quantities), add a `resolve` function in the schema rather than writing sync logic.
|
|
61
|
+
- `kora.config.ts` controls the dev environment (ports, sync server, schema watcher).
|
|
62
|
+
|
|
63
|
+
## Commands
|
|
64
|
+
|
|
65
|
+
- `npm run dev` starts everything: Vite dev server (port 5173), local sync server (port 3001), and the schema watcher.
|
|
66
|
+
- `npm run build` type-checks and builds for production.
|
|
67
|
+
- `npx kora doctor` diagnoses a broken setup.
|
|
68
|
+
- DevTools overlay: press Ctrl+Shift+K (Cmd+Shift+K on macOS) in the running app to inspect operations, merges, and sync status.
|
|
69
|
+
|
|
70
|
+
## Sync and auth
|
|
71
|
+
|
|
72
|
+
Sync is configured in `src/main.*` via `createApp({ sync: { url, authClient } })`. In dev, the sync URL is derived from the page host and proxied by Vite; in production set `VITE_SYNC_URL`. Auth (if present in this template) uses `@korajs/auth`; the client is created in `src/auth.ts`. Local writes work without sign-in; sync requires the server to accept the connection.
|
|
73
|
+
|
|
74
|
+
## Svelte bindings
|
|
75
|
+
|
|
76
|
+
Kora's Svelte package exposes store-based bindings from `@korajs/svelte`, wired through the provider set up in the app entry. Queries are reactive stores that read synchronously from the local database; mutations expose error state that must be surfaced in the UI. Avoid loading spinners for local reads.
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# {{projectName}}
|
|
2
|
+
|
|
3
|
+
An offline-first application built with [Kora.js](https://ehoneahobed.github.io/kora/).
|
|
4
|
+
|
|
5
|
+
## Getting Started
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm run dev
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
This starts both the Vite dev server and the Kora sync server.
|
|
12
|
+
|
|
13
|
+
- **App**: http://localhost:5173
|
|
14
|
+
- **Sync server**: ws://localhost:3001
|
|
15
|
+
|
|
16
|
+
## Project Structure
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
src/
|
|
20
|
+
schema.ts # Schema entry point
|
|
21
|
+
auth.ts # Auth client and OAuth callback handling
|
|
22
|
+
main.tsx # App initialization and Kora setup
|
|
23
|
+
App.tsx # Main application component
|
|
24
|
+
modules/
|
|
25
|
+
todos/
|
|
26
|
+
todo.schema.ts # Todo collection definition
|
|
27
|
+
todo.queries.ts # Reusable todo query builders
|
|
28
|
+
todo.mutations.ts # Todo mutation helpers
|
|
29
|
+
useTodos.ts # React hook connecting todos to the UI
|
|
30
|
+
kora-worker.ts # SQLite WASM web worker
|
|
31
|
+
index.css # Styles
|
|
32
|
+
server.ts # Kora sync server
|
|
33
|
+
kora.config.ts # Kora configuration
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
In a feature module, `schema` defines data shape, `queries` contain reads only, `mutations` contain
|
|
37
|
+
writes, and `useTodos.ts` is the React binding that exposes todo data and actions to components.
|
|
38
|
+
|
|
39
|
+
## Environment Variables
|
|
40
|
+
|
|
41
|
+
| Variable | Default | Description |
|
|
42
|
+
|----------|---------|-------------|
|
|
43
|
+
| `VITE_SYNC_URL` | `ws://localhost:3001` | WebSocket URL for the sync server |
|
|
44
|
+
| `VITE_AUTH_URL` | current origin | HTTP URL for `/auth/*` routes |
|
|
45
|
+
| `PORT` | `3001` | Sync server port |
|
|
46
|
+
| `KORA_SERVER_DB` | `./kora-server.db` | SQLite file used by the sync server when `DATABASE_URL` is empty |
|
|
47
|
+
| `KORA_AUTH_DB` | `./kora-auth.db` | SQLite file used by OAuth state and linked identities when `DATABASE_URL` is empty |
|
|
48
|
+
| `DATABASE_URL` | (none) | PostgreSQL connection string for production sync server deployments |
|
|
49
|
+
| `KORA_SYNC_PATH` | `/kora-sync` | WebSocket path exposed by the sync server |
|
|
50
|
+
| `KORA_AUTH_SECRET` | (none) | Enables built-in `/auth/*` routes and authenticated sync when set |
|
|
51
|
+
| `KORA_GOOGLE_CLIENT_ID` | (none) | Enables Google OAuth when set with `KORA_GOOGLE_REDIRECT_URI` |
|
|
52
|
+
| `KORA_GOOGLE_CLIENT_SECRET` | (none) | Google OAuth client secret for confidential web clients |
|
|
53
|
+
| `KORA_GOOGLE_REDIRECT_URI` | (none) | OAuth callback URL, usually your app URL that handles `code` and `state` |
|
|
54
|
+
| `KORA_OAUTH_PKCE` | `true` when no client secret | Enables PKCE for public desktop/mobile OAuth clients |
|
|
55
|
+
| `KORA_ADMIN_TOKEN` | (none) | Protects `/__kora`, `/__kora/status`, and `/__kora/events` |
|
|
56
|
+
| `KORA_METRICS_TOKEN` | (none) | Protects `/__kora/metrics` |
|
|
57
|
+
| `KORA_BACKUP_TOKEN` | (none) | Protects server backup and restore endpoints |
|
|
58
|
+
|
|
59
|
+
## Authentication
|
|
60
|
+
|
|
61
|
+
Set `KORA_AUTH_SECRET` to enable built-in auth on the sync server. Generate a secret with:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
node -e "console.log(require('node:crypto').randomBytes(32).toString('hex'))"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The template already creates `src/auth.ts`, wraps the app in `AuthProvider`, and wires sync with `createKoraAuthSync({ authClient, schema })`. To enable Google OAuth, set:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
KORA_AUTH_SECRET=...
|
|
71
|
+
KORA_GOOGLE_CLIENT_ID=...
|
|
72
|
+
KORA_GOOGLE_CLIENT_SECRET=...
|
|
73
|
+
KORA_GOOGLE_REDIRECT_URI=http://localhost:5173
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Use `authClient.signInWithOAuth('google')` for web redirect sign-in, or `authClient.getOAuthAuthorizationUrl('google')` plus `authClient.completeOAuthSignIn('google', { code, state })` for custom handoff flows. See the [Authentication Guide](https://ehoneahobed.github.io/kora/guide/authentication).
|
|
77
|
+
|
|
78
|
+
## Scripts
|
|
79
|
+
|
|
80
|
+
| Script | Description |
|
|
81
|
+
|--------|-------------|
|
|
82
|
+
| `npm run dev` | Start dev server + sync server |
|
|
83
|
+
| `npm run dev:server` | Start sync server only |
|
|
84
|
+
| `npm run build` | Build for production |
|
|
85
|
+
| `npm run preview` | Preview production build |
|
|
86
|
+
|
|
87
|
+
## Deployment
|
|
88
|
+
|
|
89
|
+
The client and sync server must be deployed separately:
|
|
90
|
+
|
|
91
|
+
- **Client**: Any static host (Vercel, Netlify, Cloudflare Pages)
|
|
92
|
+
- **Sync server**: Any Node.js host with WebSocket support (Railway, Render, Fly.io)
|
|
93
|
+
|
|
94
|
+
Set `VITE_SYNC_URL` to your deployed sync server URL when building:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
VITE_SYNC_URL=wss://your-server.example.com npm run build
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Learn More
|
|
101
|
+
|
|
102
|
+
- [Documentation](https://ehoneahobed.github.io/kora/)
|
|
103
|
+
- [Storage Configuration](https://ehoneahobed.github.io/kora/guide/storage-configuration)
|
|
104
|
+
- [Sync Configuration](https://ehoneahobed.github.io/kora/guide/sync-configuration)
|
|
105
|
+
- [Deployment Guide](https://ehoneahobed.github.io/kora/guide/deployment)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>{{projectName}}</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<div id="app"></div>
|
|
10
|
+
<script type="module" src="/src/main.ts"></script>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { defineConfig } from 'korajs/config'
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
schema: './src/schema.ts',
|
|
5
|
+
dev: {
|
|
6
|
+
port: 5173,
|
|
7
|
+
sync: {
|
|
8
|
+
enabled: true,
|
|
9
|
+
port: 3001,
|
|
10
|
+
store: 'sqlite',
|
|
11
|
+
},
|
|
12
|
+
watch: {
|
|
13
|
+
enabled: true,
|
|
14
|
+
debounceMs: 300,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
})
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{projectName}}",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "kora dev",
|
|
8
|
+
"dev:server": "tsx server.ts",
|
|
9
|
+
"build": "vite build",
|
|
10
|
+
"check": "svelte-check --tsconfig ./tsconfig.json",
|
|
11
|
+
"start": "node --import tsx server.ts",
|
|
12
|
+
"preview": "vite preview"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"korajs": "{{koraVersion}}",
|
|
16
|
+
"@korajs/auth": "{{koraVersion}}",
|
|
17
|
+
"@korajs/svelte": "{{koraVersion}}",
|
|
18
|
+
"@korajs/store": "{{koraVersion}}",
|
|
19
|
+
"@lucide/svelte": "^0.468.0",
|
|
20
|
+
"@sqlite.org/sqlite-wasm": ">=3.51.0-build1",
|
|
21
|
+
"svelte": "^5.0.0",
|
|
22
|
+
"ws": "^8.18.0",
|
|
23
|
+
"yjs": "^13.6.30"
|
|
24
|
+
},
|
|
25
|
+
"pnpm": {
|
|
26
|
+
"onlyBuiltDependencies": [
|
|
27
|
+
"better-sqlite3",
|
|
28
|
+
"esbuild",
|
|
29
|
+
"protobufjs"
|
|
30
|
+
]
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@korajs/cli": "{{koraVersion}}",
|
|
34
|
+
"@korajs/server": "{{koraVersion}}",
|
|
35
|
+
"@sveltejs/vite-plugin-svelte": "^5.0.0",
|
|
36
|
+
"@tailwindcss/vite": "^4.0.0",
|
|
37
|
+
"@types/ws": "^8.5.0",
|
|
38
|
+
"better-sqlite3": "^12.9.0",
|
|
39
|
+
"postgres": "^3.4.0",
|
|
40
|
+
"svelte-check": "^4.1.0",
|
|
41
|
+
"tailwindcss": "^4.0.0",
|
|
42
|
+
"tsx": "^4.19.0",
|
|
43
|
+
"typescript": "^5.7.0",
|
|
44
|
+
"vite": "^6.0.0"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type CreateKoraAuthServerOptions,
|
|
3
|
+
createKoraAuthServer,
|
|
4
|
+
createPostgresOAuthStores,
|
|
5
|
+
createSqliteOAuthStores,
|
|
6
|
+
googleProvider,
|
|
7
|
+
} from '@korajs/auth/server'
|
|
8
|
+
import {
|
|
9
|
+
createPostgresServerStore,
|
|
10
|
+
createProductionServer,
|
|
11
|
+
createSqliteServerStore,
|
|
12
|
+
} from '@korajs/server'
|
|
13
|
+
import schema from './src/schema'
|
|
14
|
+
|
|
15
|
+
async function createStore() {
|
|
16
|
+
if (process.env.DATABASE_URL) {
|
|
17
|
+
return createPostgresServerStore({
|
|
18
|
+
connectionString: process.env.DATABASE_URL,
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return createSqliteServerStore({
|
|
23
|
+
filename: process.env.KORA_SERVER_DB || './kora-server.db',
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function start() {
|
|
28
|
+
const store = await createStore()
|
|
29
|
+
await store.setSchema(schema)
|
|
30
|
+
|
|
31
|
+
const syncPath = process.env.KORA_SYNC_PATH || '/kora-sync'
|
|
32
|
+
const auth = await createAuth()
|
|
33
|
+
const server = createProductionServer({
|
|
34
|
+
store,
|
|
35
|
+
port: Number(process.env.PORT) || 3001,
|
|
36
|
+
staticDir: './dist',
|
|
37
|
+
syncPath,
|
|
38
|
+
httpRoutes: auth ? [{ path: '/auth', handle: auth.handleRequest }] : undefined,
|
|
39
|
+
syncOptions: auth ? { auth: auth.auth } : undefined,
|
|
40
|
+
operationalAuth: {
|
|
41
|
+
adminToken: process.env.KORA_ADMIN_TOKEN,
|
|
42
|
+
metricsToken: process.env.KORA_METRICS_TOKEN,
|
|
43
|
+
backupToken: process.env.KORA_BACKUP_TOKEN,
|
|
44
|
+
},
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
const url = await server.start()
|
|
48
|
+
console.log(`Kora app running at ${url}`)
|
|
49
|
+
console.log(` Sync endpoint: ${url.replace('http', 'ws')}${syncPath}`)
|
|
50
|
+
if (auth) console.log(` Auth endpoint: ${url}/auth`)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
void start()
|
|
54
|
+
|
|
55
|
+
async function createAuth() {
|
|
56
|
+
if (!process.env.KORA_AUTH_SECRET) {
|
|
57
|
+
return null
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const oauth = await createOAuthConfig()
|
|
61
|
+
return createKoraAuthServer({
|
|
62
|
+
jwtSecret: process.env.KORA_AUTH_SECRET,
|
|
63
|
+
...(oauth ? { oauth } : {}),
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function createOAuthConfig(): Promise<CreateKoraAuthServerOptions['oauth'] | undefined> {
|
|
68
|
+
if (!process.env.KORA_GOOGLE_CLIENT_ID || !process.env.KORA_GOOGLE_REDIRECT_URI) {
|
|
69
|
+
return undefined
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const oauthStores = process.env.DATABASE_URL
|
|
73
|
+
? await createPostgresOAuthStores({ connectionString: process.env.DATABASE_URL })
|
|
74
|
+
: await createSqliteOAuthStores({
|
|
75
|
+
filename: process.env.KORA_AUTH_DB || './kora-auth.db',
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
providers: [
|
|
80
|
+
googleProvider({
|
|
81
|
+
clientId: process.env.KORA_GOOGLE_CLIENT_ID,
|
|
82
|
+
clientSecret: process.env.KORA_GOOGLE_CLIENT_SECRET,
|
|
83
|
+
redirectUri: process.env.KORA_GOOGLE_REDIRECT_URI,
|
|
84
|
+
pkce: process.env.KORA_OAUTH_PKCE === 'true' || !process.env.KORA_GOOGLE_CLIENT_SECRET,
|
|
85
|
+
}),
|
|
86
|
+
],
|
|
87
|
+
stateStore: oauthStores.stateStore,
|
|
88
|
+
linkedIdentityStore: oauthStores.linkedIdentityStore,
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { createAuthStore } from '@korajs/auth/svelte'
|
|
3
|
+
import { createSyncStatusStore } from '@korajs/svelte'
|
|
4
|
+
import {
|
|
5
|
+
AlertCircle,
|
|
6
|
+
CheckCircle2,
|
|
7
|
+
Circle,
|
|
8
|
+
ClipboardList,
|
|
9
|
+
Loader2,
|
|
10
|
+
Plus,
|
|
11
|
+
Trash2,
|
|
12
|
+
Wifi,
|
|
13
|
+
WifiOff,
|
|
14
|
+
} from '@lucide/svelte'
|
|
15
|
+
import { createTodosStores } from './modules/todos/useTodos'
|
|
16
|
+
|
|
17
|
+
type Filter = 'all' | 'active' | 'completed'
|
|
18
|
+
|
|
19
|
+
const syncStatus = createSyncStatusStore()
|
|
20
|
+
const auth = createAuthStore()
|
|
21
|
+
const todos = createTodosStores()
|
|
22
|
+
const { allTodos, activeTodos, completedTodos, addTodo, toggleTodo, deleteTodo } = todos
|
|
23
|
+
|
|
24
|
+
const filter = $state<Filter>('all')
|
|
25
|
+
let input = $state('')
|
|
26
|
+
|
|
27
|
+
const filteredTodos = $derived(
|
|
28
|
+
filter === 'active' ? $activeTodos : filter === 'completed' ? $completedTodos : $allTodos,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
const syncBadge = $derived.by(() => {
|
|
32
|
+
const s = $syncStatus.status
|
|
33
|
+
const pending = $syncStatus.pendingOperations ?? 0
|
|
34
|
+
const map: Record<string, { icon: typeof Wifi; color: string; label: string }> = {
|
|
35
|
+
connected: { icon: Wifi, color: 'text-emerald-400', label: 'Connected' },
|
|
36
|
+
syncing: { icon: Wifi, color: 'text-amber-400', label: 'Syncing' },
|
|
37
|
+
synced: { icon: Wifi, color: 'text-emerald-400', label: 'Synced' },
|
|
38
|
+
offline: { icon: WifiOff, color: 'text-gray-500', label: 'Offline' },
|
|
39
|
+
error: { icon: AlertCircle, color: 'text-red-400', label: 'Error' },
|
|
40
|
+
}
|
|
41
|
+
return { ...(map[s] ?? map.offline), pending }
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
function handleSubmit(event: SubmitEvent): void {
|
|
45
|
+
event.preventDefault()
|
|
46
|
+
const title = input.trim()
|
|
47
|
+
if (!title) return
|
|
48
|
+
addTodo.mutate({ title })
|
|
49
|
+
input = ''
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function clearCompleted(): void {
|
|
53
|
+
for (const todo of $completedTodos) {
|
|
54
|
+
deleteTodo.mutate(todo.id)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function emptyMessage(f: Filter): string {
|
|
59
|
+
if (f === 'all') return 'No tasks yet. Add one above!'
|
|
60
|
+
if (f === 'active') return 'All caught up! No active tasks.'
|
|
61
|
+
return 'No completed tasks yet.'
|
|
62
|
+
}
|
|
63
|
+
</script>
|
|
64
|
+
|
|
65
|
+
<div class="min-h-screen bg-gray-950 text-gray-100">
|
|
66
|
+
<div class="mx-auto max-w-2xl px-4 py-12">
|
|
67
|
+
<div class="mb-8 flex items-center justify-between">
|
|
68
|
+
<div class="flex items-center gap-3">
|
|
69
|
+
<ClipboardList class="h-8 w-8 text-indigo-400" />
|
|
70
|
+
<h1 class="text-2xl font-bold">My Tasks</h1>
|
|
71
|
+
</div>
|
|
72
|
+
<div class="flex items-center gap-2">
|
|
73
|
+
<div class="flex items-center gap-2 rounded-full bg-gray-800 px-3 py-1.5 text-sm">
|
|
74
|
+
<svelte:component this={syncBadge.icon} class="h-4 w-4 {syncBadge.color}" />
|
|
75
|
+
<span class={syncBadge.color}>{syncBadge.label}</span>
|
|
76
|
+
{#if syncBadge.pending > 0}
|
|
77
|
+
<span class="rounded-full bg-gray-700 px-2 py-0.5 text-xs text-gray-400">
|
|
78
|
+
{syncBadge.pending} pending
|
|
79
|
+
</span>
|
|
80
|
+
{/if}
|
|
81
|
+
</div>
|
|
82
|
+
{#if $auth.isAuthenticated}
|
|
83
|
+
<button
|
|
84
|
+
type="button"
|
|
85
|
+
class="max-w-44 truncate rounded-full border border-gray-700 bg-gray-900 px-3 py-1.5 text-sm text-gray-300"
|
|
86
|
+
onclick={() => $auth.signOut()}
|
|
87
|
+
>
|
|
88
|
+
{$auth.user?.email || 'Sign out'}
|
|
89
|
+
</button>
|
|
90
|
+
{:else}
|
|
91
|
+
<button
|
|
92
|
+
type="button"
|
|
93
|
+
class="rounded-full border border-gray-700 bg-gray-900 px-3 py-1.5 text-sm text-gray-300"
|
|
94
|
+
onclick={() => $auth.signInWithOAuth('google')}
|
|
95
|
+
>
|
|
96
|
+
Sign in
|
|
97
|
+
</button>
|
|
98
|
+
{/if}
|
|
99
|
+
</div>
|
|
100
|
+
</div>
|
|
101
|
+
|
|
102
|
+
{#if $auth.error}
|
|
103
|
+
<div class="mb-4 rounded-lg border border-red-400/30 px-3 py-2 text-sm text-red-300">
|
|
104
|
+
{$auth.error}
|
|
105
|
+
</div>
|
|
106
|
+
{/if}
|
|
107
|
+
|
|
108
|
+
<div class="mb-8 grid grid-cols-3 gap-4">
|
|
109
|
+
<div class="rounded-lg border border-gray-800 bg-gray-900 p-4">
|
|
110
|
+
<p class="text-sm text-gray-500">Total</p>
|
|
111
|
+
<p class="text-2xl font-bold text-gray-300">{$allTodos.length}</p>
|
|
112
|
+
</div>
|
|
113
|
+
<div class="rounded-lg border border-gray-800 bg-gray-900 p-4">
|
|
114
|
+
<p class="text-sm text-gray-500">Remaining</p>
|
|
115
|
+
<p class="text-2xl font-bold text-amber-400">{$activeTodos.length}</p>
|
|
116
|
+
</div>
|
|
117
|
+
<div class="rounded-lg border border-gray-800 bg-gray-900 p-4">
|
|
118
|
+
<p class="text-sm text-gray-500">Done</p>
|
|
119
|
+
<p class="text-2xl font-bold text-emerald-400">{$completedTodos.length}</p>
|
|
120
|
+
</div>
|
|
121
|
+
</div>
|
|
122
|
+
|
|
123
|
+
<form class="mb-8 flex gap-3" onsubmit={handleSubmit}>
|
|
124
|
+
<input
|
|
125
|
+
bind:value={input}
|
|
126
|
+
type="text"
|
|
127
|
+
placeholder="What needs to be done?"
|
|
128
|
+
class="flex-1 rounded-lg border border-gray-700 bg-gray-900 px-4 py-3 text-gray-100 placeholder-gray-500 outline-none focus:border-indigo-500"
|
|
129
|
+
/>
|
|
130
|
+
<button
|
|
131
|
+
type="submit"
|
|
132
|
+
disabled={!input.trim()}
|
|
133
|
+
class="flex items-center gap-2 rounded-lg bg-indigo-600 px-5 py-3 font-medium text-white disabled:opacity-50"
|
|
134
|
+
>
|
|
135
|
+
<Plus class="h-4 w-4" />
|
|
136
|
+
Add
|
|
137
|
+
</button>
|
|
138
|
+
</form>
|
|
139
|
+
|
|
140
|
+
<div class="mb-6 flex gap-2">
|
|
141
|
+
{#each ['all', 'active', 'completed'] as const as f}
|
|
142
|
+
<button
|
|
143
|
+
type="button"
|
|
144
|
+
class="rounded-lg px-4 py-2 text-sm font-medium {filter === f
|
|
145
|
+
? 'bg-indigo-600 text-white'
|
|
146
|
+
: 'bg-gray-800 text-gray-400'}"
|
|
147
|
+
onclick={() => (filter = f)}
|
|
148
|
+
>
|
|
149
|
+
{f.charAt(0).toUpperCase() + f.slice(1)}
|
|
150
|
+
</button>
|
|
151
|
+
{/each}
|
|
152
|
+
</div>
|
|
153
|
+
|
|
154
|
+
<div class="space-y-2">
|
|
155
|
+
{#if filteredTodos.length === 0}
|
|
156
|
+
<div class="rounded-lg border border-dashed border-gray-800 py-12 text-center text-gray-600">
|
|
157
|
+
{emptyMessage(filter)}
|
|
158
|
+
</div>
|
|
159
|
+
{:else}
|
|
160
|
+
{#each filteredTodos as todo (todo.id)}
|
|
161
|
+
<div
|
|
162
|
+
class="group flex items-center gap-3 rounded-lg border border-gray-800 bg-gray-900 px-4 py-3"
|
|
163
|
+
>
|
|
164
|
+
<button
|
|
165
|
+
type="button"
|
|
166
|
+
class="text-gray-500 hover:text-indigo-400"
|
|
167
|
+
onclick={() => toggleTodo.mutate(todo.id, { completed: !todo.completed })}
|
|
168
|
+
>
|
|
169
|
+
{#if todo.completed}
|
|
170
|
+
<CheckCircle2 class="h-5 w-5 text-emerald-400" />
|
|
171
|
+
{:else}
|
|
172
|
+
<Circle class="h-5 w-5" />
|
|
173
|
+
{/if}
|
|
174
|
+
</button>
|
|
175
|
+
<span class="flex-1 {todo.completed ? 'line-through text-gray-500' : ''}">
|
|
176
|
+
{String(todo.title)}
|
|
177
|
+
</span>
|
|
178
|
+
<button
|
|
179
|
+
type="button"
|
|
180
|
+
class="text-gray-600 opacity-0 group-hover:opacity-100 hover:text-red-400"
|
|
181
|
+
onclick={() => deleteTodo.mutate(todo.id)}
|
|
182
|
+
>
|
|
183
|
+
<Trash2 class="h-4 w-4" />
|
|
184
|
+
</button>
|
|
185
|
+
</div>
|
|
186
|
+
{/each}
|
|
187
|
+
{/if}
|
|
188
|
+
</div>
|
|
189
|
+
|
|
190
|
+
<p class="mt-12 text-center text-xs text-gray-700">Powered by Kora — offline-first, real-time sync</p>
|
|
191
|
+
</div>
|
|
192
|
+
</div>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { AuthClient } from '@korajs/auth'
|
|
3
|
+
import AuthProvider from '@korajs/auth/svelte/AuthProvider.svelte'
|
|
4
|
+
import type { KoraAppLike } from '@korajs/svelte'
|
|
5
|
+
import KoraProvider from '@korajs/svelte/KoraProvider.svelte'
|
|
6
|
+
import App from './App.svelte'
|
|
7
|
+
|
|
8
|
+
const { kora, authClient }: { kora: KoraAppLike; authClient: AuthClient } = $props()
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<AuthProvider client={authClient}>
|
|
12
|
+
{#snippet fallback()}
|
|
13
|
+
<div class="flex h-screen items-center justify-center bg-gray-950 text-gray-400">
|
|
14
|
+
Restoring session...
|
|
15
|
+
</div>
|
|
16
|
+
{/snippet}
|
|
17
|
+
|
|
18
|
+
<KoraProvider app={kora}>
|
|
19
|
+
{#snippet fallback()}
|
|
20
|
+
<div class="flex h-screen items-center justify-center bg-gray-950 text-gray-400">
|
|
21
|
+
Loading...
|
|
22
|
+
</div>
|
|
23
|
+
{/snippet}
|
|
24
|
+
<App />
|
|
25
|
+
</KoraProvider>
|
|
26
|
+
</AuthProvider>
|