@weft-js/start 0.0.0-stage → 0.1.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 +16 -0
- package/README.md +41 -2
- package/package.json +107 -4
- package/src/app.mjs +82 -0
- package/src/auth/better-auth.ts +58 -0
- package/src/auth/drizzle.ts +17 -0
- package/src/auth.ts +47 -0
- package/src/boot.ts +44 -0
- package/src/builtin.tsx +19 -0
- package/src/bus/postgres.ts +91 -0
- package/src/bus.ts +48 -0
- package/src/capture.d.mts +1 -0
- package/src/capture.mjs +15 -0
- package/src/changes-sql.d.mts +14 -0
- package/src/changes-sql.mjs +99 -0
- package/src/changes.ts +253 -0
- package/src/channel-fake.ts +55 -0
- package/src/channel.ts +616 -0
- package/src/client.tsx +20 -0
- package/src/contract.mjs +308 -0
- package/src/data.ts +929 -0
- package/src/db/bun-sqlite.d.ts +10 -0
- package/src/db/changes-mysql.ts +86 -0
- package/src/db/changes-postgres.ts +159 -0
- package/src/db/changes-sqlite.ts +116 -0
- package/src/db/core.ts +63 -0
- package/src/db/index.ts +27 -0
- package/src/db/mysql.ts +67 -0
- package/src/db/postgres.ts +65 -0
- package/src/db/sqlite.ts +139 -0
- package/src/derive.d.mts +16 -0
- package/src/derive.mjs +140 -0
- package/src/dev-runtime.mjs +42 -0
- package/src/exec.ts +519 -0
- package/src/extension.ts +38 -0
- package/src/first-paint.ts +57 -0
- package/src/form.tsx +134 -0
- package/src/gate.css +6 -0
- package/src/hub.ts +822 -0
- package/src/index.ts +106 -0
- package/src/inline.mjs +2 -0
- package/src/inspect.mjs +280 -0
- package/src/link.ts +456 -0
- package/src/list-drizzle.ts +50 -0
- package/src/list.ts +224 -0
- package/src/listen.ts +28 -0
- package/src/live-fake.ts +42 -0
- package/src/live-target.mjs +144 -0
- package/src/live.ts +499 -0
- package/src/media.ts +43 -0
- package/src/migrations.mjs +19 -0
- package/src/mux-session.ts +6 -0
- package/src/mux.ts +135 -0
- package/src/og/DefaultCard.tsx +60 -0
- package/src/og/fonts.mjs +64 -0
- package/src/og/images.mjs +54 -0
- package/src/og/index.mjs +146 -0
- package/src/og/native.mjs +29 -0
- package/src/range.mjs +19 -0
- package/src/router.ts +149 -0
- package/src/routes.mjs +142 -0
- package/src/run.tsx +198 -0
- package/src/rust.ts +333 -0
- package/src/server.tsx +1014 -0
- package/src/shape.d.mts +3 -0
- package/src/shape.mjs +73 -0
- package/src/share-server.ts +208 -0
- package/src/share.ts +503 -0
- package/src/sheets.mjs +75 -0
- package/src/sidecar.mjs +503 -0
- package/src/socket.ts +389 -0
- package/src/stream.ts +13 -0
- package/src/verify.ts +251 -0
- package/src/view.tsx +47 -0
- package/src/vite.mjs +899 -0
package/src/view.tsx
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// The route views (research 25 §3): `<App>` renders level 0, and each level renders its route's component with the
|
|
2
|
+
// next level as `children`. The same file compiles for the server and the client, so both build the same tree and
|
|
3
|
+
// hydration keys line up. A level's hole reads only its route id: params and data reach the component as live
|
|
4
|
+
// props, so a navigation that keeps the route re-runs only the bindings that read what changed.
|
|
5
|
+
|
|
6
|
+
import { untrack } from '@weft-js/core'
|
|
7
|
+
import { active, level, type RouteState } from './router'
|
|
8
|
+
|
|
9
|
+
// The route state travels as a prop, not a context: a level's view runs later, in the hole that shows it, under that
|
|
10
|
+
// hole's owner. `active.route` is the state of the render in progress (a server pass is synchronous; the client has one).
|
|
11
|
+
export function App(props: { route: RouteState }) {
|
|
12
|
+
const route = (active.route = untrack(() => props.route))
|
|
13
|
+
return <Level route={route} depth={0} />
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function Level(props: { route: RouteState; depth: number }) {
|
|
17
|
+
const route = untrack(() => props.route)
|
|
18
|
+
const lv = level(route, untrack(() => props.depth))
|
|
19
|
+
const next = untrack(() => props.depth) + 1
|
|
20
|
+
const view = () => {
|
|
21
|
+
const id = lv.id.value
|
|
22
|
+
if (id === undefined) return null
|
|
23
|
+
const html = route.mount ? lv.html.value : undefined
|
|
24
|
+
if (html !== undefined) return route.mount!(html, untrack(() => props.depth), () => <Level route={route} depth={next} />)
|
|
25
|
+
const Route = route.comps[id] as ((props: { params: Record<string, string>; data: unknown; children: unknown }) => unknown) | undefined
|
|
26
|
+
if (!Route) return null
|
|
27
|
+
const body = () => <Route params={lv.params.value} data={lv.data.value}><Level route={route} depth={next} /></Route>
|
|
28
|
+
return route.around ? route.around(untrack(() => props.depth), id, body) : body()
|
|
29
|
+
}
|
|
30
|
+
return <>{view()}</>
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* `<a>` with `aria-current="page"` while its path is the current one. Any same-origin `<a href>` navigates on the
|
|
35
|
+
* client (start() listens for clicks); Link only adds the current-page state. In a static level the server writes it
|
|
36
|
+
* and start() updates it after a navigation, so a Link needs no code there.
|
|
37
|
+
*
|
|
38
|
+
* @weft static
|
|
39
|
+
*/
|
|
40
|
+
export function Link({ href, children, ...rest }: Record<string, unknown> & { href: string; class?: string; rel?: string; children?: unknown }) {
|
|
41
|
+
const route = active.route
|
|
42
|
+
return (
|
|
43
|
+
<a {...rest} href={href} aria-current={route && route.path.value.replace(/[?#].*/, '') === href ? 'page' : undefined}>
|
|
44
|
+
{children}
|
|
45
|
+
</a>
|
|
46
|
+
)
|
|
47
|
+
}
|