keits 0.0.4 → 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/README.md +93 -79
- package/dist/dev/api.js +8 -3
- package/dist/dev/forms.js +6 -4
- package/dist/dev/index.js +26 -35
- package/dist/dev/router.js +24 -7
- package/dist/dev/shared/{computed-3UO-KiH1.js → computed-DrF8O8b4.js} +1 -1
- package/dist/dev/shared/{element-CQPqagu1.js → element-DXwmUAnz.js} +30 -76
- package/dist/dev/shared/{graph-D6-x_CWC.js → graph-SIvYLXSv.js} +62 -3
- package/dist/dev/shared/hydrate-C8cOsDDH.js +588 -0
- package/dist/dev/shared/mount-CDB2HgN5.js +23 -0
- package/dist/dev/shared/namespaces-Cz82B0Pr.js +84 -0
- package/dist/dev/shared/{owner-Dmge21OW.js → owner-BuwIoI4j.js} +12 -2
- package/dist/dev/shared/render-context-k2uu_dM_.js +34 -0
- package/dist/dev/shared/render-effect-Uk9dDmuU.js +32 -0
- package/dist/dev/shared/{resource-CbXVATvq.js → resource-DlgzdtcG.js} +24 -33
- package/dist/dev/shared/{signal-BOXkY-Iv.js → signal-B3xOKbVm.js} +1 -1
- package/dist/dev/shared/{store-BzUN1qE5.js → store-0vEg2bQV.js} +7 -3
- package/dist/dev/shared/unsafe-keys-CB1P22No.js +8 -0
- package/dist/dev/static.js +76 -0
- package/dist/dev/svg.js +2 -1
- package/dist/dev/testing.js +216 -0
- package/dist/dev/vite.js +141 -0
- package/dist/prod/api.js +76 -71
- package/dist/prod/forms.js +63 -60
- package/dist/prod/index.js +56 -64
- package/dist/prod/router.js +86 -73
- package/dist/prod/shared/{computed-CAPpOLCY.js → computed-BjqJ6Pps.js} +1 -1
- package/dist/prod/shared/element-DCit4-3e.js +129 -0
- package/dist/prod/shared/{graph-C_aA46c6.js → graph-CR2WKbwr.js} +107 -63
- package/dist/prod/shared/hydrate-kKnJbkV7.js +480 -0
- package/dist/prod/shared/mount-DbeKIoyD.js +18 -0
- package/dist/prod/shared/namespaces-BSRrBJIU.js +71 -0
- package/dist/prod/shared/owner-DBi3odT4.js +67 -0
- package/dist/prod/shared/render-context-DF8lr1uu.js +30 -0
- package/dist/prod/shared/render-effect-UFDi2Pfh.js +25 -0
- package/dist/prod/shared/resource-Ch5tVseZ.js +91 -0
- package/dist/prod/shared/signal-BDMlfa0Z.js +16 -0
- package/dist/prod/shared/store-CvW0DbmK.js +110 -0
- package/dist/prod/shared/unsafe-keys-C5PMlerl.js +7 -0
- package/dist/prod/static.js +48 -0
- package/dist/prod/svg.js +3 -2
- package/dist/prod/testing.js +144 -0
- package/dist/prod/vite.js +106 -0
- package/dist/types/async/render-context.d.ts +10 -0
- package/dist/types/core/effect.d.ts +1 -0
- package/dist/types/core/graph.d.ts +11 -0
- package/dist/types/core/owner.d.ts +1 -0
- package/dist/types/core/unsafe-keys.d.ts +2 -0
- package/dist/types/dom/hooks.d.ts +4 -0
- package/dist/types/dom/types.d.ts +5 -0
- package/dist/types/router/index.d.ts +1 -0
- package/dist/types/router/match.d.ts +1 -0
- package/dist/types/router/types.d.ts +1 -0
- package/dist/types/static/head.d.ts +36 -0
- package/dist/types/static/hydrate.d.ts +3 -0
- package/dist/types/static/index.d.ts +4 -0
- package/dist/types/static/island.d.ts +14 -0
- package/dist/types/static/json.d.ts +1 -0
- package/dist/types/static/render.d.ts +11 -0
- package/dist/types/static/server-dom.d.ts +100 -0
- package/dist/types/testing/index.d.ts +62 -0
- package/dist/types/vite/index.d.ts +24 -0
- package/package.json +34 -7
- package/dist/dev/shared/render-effect-kOGnLNbL.js +0 -26
- package/dist/prod/shared/element-DGyQ01Vs.js +0 -164
- package/dist/prod/shared/owner-6BFHIPR9.js +0 -59
- package/dist/prod/shared/render-effect-DjaUT3Cn.js +0 -23
- package/dist/prod/shared/resource-CNC2DBO3.js +0 -109
- package/dist/prod/shared/signal-DGrl3r9T.js +0 -16
- package/dist/prod/shared/store-Dcscpk_h.js +0 -109
package/README.md
CHANGED
|
@@ -1,126 +1,140 @@
|
|
|
1
1
|
# keits
|
|
2
2
|
|
|
3
3
|
A fine-grained reactive TypeScript framework. Real DOM, no virtual DOM, zero dependencies.
|
|
4
|
-
|
|
5
|
-
> **Status: 0.0.x, early.** This release is the **reactive core** only. The DOM layer
|
|
6
|
-
> (`$div`, `mount`, `$if`, `$for`, …), router, forms and static builds are in progress.
|
|
7
|
-
> Expect breaking changes before 1.0.
|
|
4
|
+
Build SPAs, static websites with islands, and server-rendered apps from the same components.
|
|
8
5
|
|
|
9
6
|
```sh
|
|
10
7
|
npm install keits
|
|
11
8
|
```
|
|
12
9
|
|
|
13
|
-
About
|
|
14
|
-
|
|
10
|
+
About 7.4 KB min+gzip for the whole core. Everything is tree-shakable: a small app ships about 3 KB,
|
|
11
|
+
a static page with one interactive island about 4 KB.
|
|
12
|
+
|
|
13
|
+
> **Status: 0.1.** The API is complete and tested; expect small breaking changes before 1.0.
|
|
15
14
|
|
|
16
|
-
##
|
|
15
|
+
## A component
|
|
17
16
|
|
|
18
17
|
```ts
|
|
19
|
-
import {
|
|
18
|
+
import { $button, $p, mount, signal } from "keits";
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
const
|
|
20
|
+
function Counter() {
|
|
21
|
+
const count = signal(0);
|
|
22
|
+
return [
|
|
23
|
+
$p(() => `Clicked ${count()} times`), // a function child updates by itself
|
|
24
|
+
$button({ onclick: () => count.set((n) => n + 1) }, "+1"),
|
|
25
|
+
];
|
|
26
|
+
}
|
|
23
27
|
|
|
24
|
-
|
|
25
|
-
console.log(`${count()} × 2 = ${double()}`); // re-runs when count changes
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
count.set(1); // logs "1 × 2 = 2" before set() returns
|
|
29
|
-
count.set((prev) => prev + 1);
|
|
28
|
+
mount(Counter, document.getElementById("app")!);
|
|
30
29
|
```
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
- `batch(fn)` groups writes; `untrack(fn)` reads without subscribing.
|
|
31
|
+
Components run once. Only the parts that read a signal update, without re-rendering anything else.
|
|
32
|
+
Every HTML tag has a factory (`$div`, `$input`, ...); SVG ones come from `keits/svg`.
|
|
33
|
+
Text is always escaped: `unsafeHTML()` is the only way to insert HTML, and `javascript:` URLs are blocked.
|
|
34
|
+
|
|
35
|
+
## What's included
|
|
38
36
|
|
|
39
|
-
|
|
37
|
+
| Import | What it does |
|
|
38
|
+
| --- | --- |
|
|
39
|
+
| `keits` | `signal`, `computed`, `effect`, `batch`, `store`, context, error boundaries, the `$tag` factories, control flow (`$if`, `$for`, `$show`, `$switch`, `$dynamic`, `$portal`), `$catch`, `$suspense`, `resource`, `lazy` |
|
|
40
|
+
| `keits/router` | Typed routes, params and query (`navigate("/jobs/:id", { params: { id } })` is checked), layouts that stay mounted, guards, `onLeave`, link clicks, scroll restoration |
|
|
41
|
+
| `keits/api` | `createApi()`: JSON requests, `ApiError`, timeouts, one shared token refresh on 401, cached queries with `invalidate("/jobs")` |
|
|
42
|
+
| `keits/forms` | `form()`: `bind()` for inputs, Standard Schema (zod, valibot...) or plain checks, typed paths, lists, submit, server errors on their fields |
|
|
43
|
+
| `keits/static` | `renderToString()`, `head()`, `hydrate()`, `island()` and `hydrateIslands()` |
|
|
44
|
+
| `keits/vite` | Vite plugin: builds every page to HTML, with `sitemap.xml`, `robots.txt` and incremental builds |
|
|
45
|
+
| `keits/testing` | `render()`, queries by role, label and text, `user.click/type/submit`, `renderOnServer()` |
|
|
46
|
+
| `keits/svg` | SVG element factories |
|
|
40
47
|
|
|
41
|
-
|
|
42
|
-
created inside it, so nothing leaks.
|
|
48
|
+
## Data
|
|
43
49
|
|
|
44
50
|
```ts
|
|
45
|
-
import {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const id = setInterval(tick, 1000);
|
|
50
|
-
onCleanup(() => clearInterval(id)); // runs before each re-run, and on dispose
|
|
51
|
-
});
|
|
52
|
-
onMount(() => console.log("ready")); // once, after the current update settles
|
|
53
|
-
return dispose;
|
|
54
|
-
});
|
|
51
|
+
import { $for, $li, $suspense, $ul } from "keits";
|
|
52
|
+
import { createApi } from "keits/api";
|
|
53
|
+
|
|
54
|
+
const api = createApi({ baseUrl: "/api", headers: () => ({ Authorization: `Bearer ${token()}` }) });
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
function Jobs() {
|
|
57
|
+
const jobs = api.query<Job[]>("/jobs", { query: () => ({ page: page() }) }); // reloads when page changes
|
|
58
|
+
return $suspense(() => $ul($for(() => jobs() ?? [], (job) => $li(job.title))), () => "Loading…");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
await api.post("/jobs", { body: draft, invalidate: "/jobs" }); // lists under /jobs refresh
|
|
57
62
|
```
|
|
58
63
|
|
|
59
|
-
|
|
60
|
-
- Parent effects always run before their children.
|
|
61
|
-
- `getOwner()` / `runWithOwner(owner, fn)` resume an owner later, e.g. after an `await`.
|
|
64
|
+
Create resources and queries in the component body, and read them inside `() =>`.
|
|
62
65
|
|
|
63
|
-
##
|
|
66
|
+
## Routing
|
|
64
67
|
|
|
65
68
|
```ts
|
|
66
|
-
import {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
)
|
|
69
|
+
import { createRouter } from "keits/router";
|
|
70
|
+
|
|
71
|
+
export const router = createRouter({
|
|
72
|
+
routes: [
|
|
73
|
+
{
|
|
74
|
+
path: "/",
|
|
75
|
+
layout: Shell, // stays mounted while its pages change
|
|
76
|
+
children: [
|
|
77
|
+
{ path: "", component: Home },
|
|
78
|
+
{ path: "jobs/:id", component: Job, guard: () => loggedIn() || "/login" },
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
{ path: "*", component: NotFound },
|
|
82
|
+
],
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
mount(() => router.view(), document.getElementById("app")!);
|
|
76
86
|
```
|
|
77
87
|
|
|
78
|
-
|
|
79
|
-
the rest of the update still finishes and the error is rethrown afterwards (several
|
|
80
|
-
become one `AggregateError`). A failed effect keeps its subscriptions and retries when
|
|
81
|
-
its inputs change.
|
|
88
|
+
## Static sites and server rendering
|
|
82
89
|
|
|
83
|
-
|
|
90
|
+
Pages render to HTML at build time. Only islands load JavaScript in the browser:
|
|
84
91
|
|
|
85
92
|
```ts
|
|
86
|
-
|
|
93
|
+
// The interactive part. Everything else on the page stays plain HTML.
|
|
94
|
+
export const ContactForm = island("contact-form", (props: { to: string }) => ...);
|
|
87
95
|
|
|
88
|
-
|
|
96
|
+
// In the browser:
|
|
97
|
+
hydrateIslands({ "contact-form": () => import("./contact-form").then((m) => m.ContactForm) });
|
|
98
|
+
```
|
|
89
99
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
100
|
+
```ts
|
|
101
|
+
// vite.config.ts
|
|
102
|
+
import { keits } from "keits/vite";
|
|
103
|
+
export default { plugins: [keits({ entry: "src/server.ts", site: "https://example.com" })] };
|
|
104
|
+
|
|
105
|
+
// src/server.ts: the pages to build, and how to render one
|
|
106
|
+
export const pages = () => staticPaths(routes); // param routes list theirs with `paths: () => [...]`
|
|
107
|
+
export const render = (url: string) => renderToString(() => App(url));
|
|
93
108
|
```
|
|
94
109
|
|
|
95
|
-
|
|
110
|
+
`index.html` needs `<!--app-head-->` in `<head>` and `<!--app-html-->` where the page goes.
|
|
111
|
+
For a whole app, use `renderToString(App, { hydrate: true })` on the server and `hydrate(App, el)` in the browser.
|
|
96
112
|
|
|
97
|
-
|
|
113
|
+
## Testing
|
|
98
114
|
|
|
99
115
|
```ts
|
|
100
|
-
import {
|
|
116
|
+
import { cleanup, render, user } from "keits/testing";
|
|
101
117
|
|
|
102
|
-
|
|
118
|
+
afterEach(cleanup);
|
|
103
119
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
draft.filter = "paid";
|
|
120
|
+
it("signs up", () => {
|
|
121
|
+
const page = render(() => SignupForm());
|
|
122
|
+
user.type(page.getByLabelText("Email"), "kei@example.com");
|
|
123
|
+
user.click(page.getByRole("button", { name: "Sign up" }));
|
|
109
124
|
});
|
|
110
|
-
|
|
111
|
-
// Fresh data from an API: keep existing objects, update only what changed
|
|
112
|
-
setState((draft) => reconcile(draft.jobs, freshJobs, { key: "id" }));
|
|
113
|
-
|
|
114
|
-
localStorage.setItem("state", JSON.stringify(unwrap(state)));
|
|
115
125
|
```
|
|
116
126
|
|
|
117
|
-
|
|
127
|
+
## Security
|
|
128
|
+
|
|
129
|
+
- Text is always escaped, in the browser and on the server. `unsafeHTML()` is the only way to insert markup.
|
|
130
|
+
- URL props (`href`, `src`, `action`...) block `javascript:` URLs, `innerHTML` and `srcdoc` aren't allowed as props, and event props must be functions.
|
|
131
|
+
- Validate data you don't control with `parse`, so its types are true at runtime as well:
|
|
118
132
|
|
|
119
|
-
|
|
133
|
+
```ts
|
|
134
|
+
const comments = api.query("/comments", { parse: Comments.parse }); // a zod or valibot schema
|
|
135
|
+
```
|
|
120
136
|
|
|
121
|
-
|
|
122
|
-
are skipped, everything else works, and it all gets disposed afterwards. `isServer` is
|
|
123
|
-
`true` outside the browser.
|
|
137
|
+
- A plain object as the first argument is read as props. When a value from outside might not be a string, write `$p(String(value))` or put it after a props object: `$p({}, value)`. A plain object there is refused with an error.
|
|
124
138
|
|
|
125
139
|
## License
|
|
126
140
|
|
package/dist/dev/api.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { t as resource } from "./shared/resource-
|
|
2
|
-
import {
|
|
1
|
+
import { t as resource } from "./shared/resource-DlgzdtcG.js";
|
|
2
|
+
import { f as isStaticRender } from "./shared/graph-SIvYLXSv.js";
|
|
3
|
+
import { a as onCleanup } from "./shared/owner-BuwIoI4j.js";
|
|
3
4
|
// src/api/url.ts
|
|
4
5
|
function buildPath(path, params, query) {
|
|
5
6
|
const filled = path.replace(/:([A-Za-z0-9_]+)/g, (_, name) => {
|
|
6
7
|
const value = params?.[name];
|
|
7
8
|
if (value === void 0) throw new Error(`[keits/api] Missing param "${name}" for "${path}".`);
|
|
8
|
-
|
|
9
|
+
const text = String(value);
|
|
10
|
+
if (text === "." || text === "..") throw new Error(`[keits/api] Param "${name}" can't be "${text}" (in "${path}").`);
|
|
11
|
+
return encodeURIComponent(text);
|
|
9
12
|
});
|
|
10
13
|
if (query === void 0) return filled;
|
|
11
14
|
const search = new URLSearchParams();
|
|
@@ -122,6 +125,7 @@ function createApi(config = {}) {
|
|
|
122
125
|
refreshing = null;
|
|
123
126
|
});
|
|
124
127
|
async function send(method, path, options, retried = false) {
|
|
128
|
+
if (!/^\/(?![/\\])/.test(path)) throw new Error(`[keits/api] "${path}" must start with a single "/".`);
|
|
125
129
|
const url = base + path;
|
|
126
130
|
const headers = new Headers({ Accept: "application/json" });
|
|
127
131
|
const shared = typeof config.headers === "function" ? await config.headers() : config.headers;
|
|
@@ -201,6 +205,7 @@ function createApi(config = {}) {
|
|
|
201
205
|
return shownUrl;
|
|
202
206
|
};
|
|
203
207
|
const result = resource(key, (url, { refetching }) => {
|
|
208
|
+
if (isStaticRender()) return send("GET", url, {}).then(parse);
|
|
204
209
|
const cached = refetching ? null : cache.peek(url);
|
|
205
210
|
if (cached === null) return cache.fetch(url).then(parse);
|
|
206
211
|
if (cached.stale) cache.fetch(url).catch(() => {});
|
package/dist/dev/forms.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { t as computed } from "./shared/computed-
|
|
2
|
-
import {
|
|
3
|
-
import { t as signal } from "./shared/signal-
|
|
4
|
-
import { n as store, r as unwrap } from "./shared/store-
|
|
1
|
+
import { t as computed } from "./shared/computed-DrF8O8b4.js";
|
|
2
|
+
import { S as untrack, i as batch } from "./shared/graph-SIvYLXSv.js";
|
|
3
|
+
import { t as signal } from "./shared/signal-B3xOKbVm.js";
|
|
4
|
+
import { n as store, r as unwrap } from "./shared/store-0vEg2bQV.js";
|
|
5
|
+
import { t as UNSAFE_KEYS } from "./shared/unsafe-keys-CB1P22No.js";
|
|
5
6
|
// src/forms/paths.ts
|
|
6
7
|
function getAt(source, path) {
|
|
7
8
|
if (path === "") return source;
|
|
@@ -14,6 +15,7 @@ function getAt(source, path) {
|
|
|
14
15
|
}
|
|
15
16
|
function setAt(target, path, value) {
|
|
16
17
|
const keys = path.split(".");
|
|
18
|
+
if (keys.some((key) => UNSAFE_KEYS.has(key))) throw new Error(`[keits/forms] "${path}" is not a field path: "__proto__", "constructor" and "prototype" aren't allowed.`);
|
|
17
19
|
const last = keys.pop();
|
|
18
20
|
let current = target;
|
|
19
21
|
keys.forEach((key, i) => {
|
package/dist/dev/index.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { t as signal } from "./shared/signal-
|
|
2
|
-
import { n as effect, t as renderEffect } from "./shared/render-effect-
|
|
3
|
-
import { t as computed } from "./shared/computed-
|
|
4
|
-
import { a as deferMounts,
|
|
5
|
-
import { a as
|
|
6
|
-
import { a as
|
|
7
|
-
import { n as store, r as unwrap, t as reconcile } from "./shared/store-
|
|
8
|
-
import {
|
|
1
|
+
import { t as signal } from "./shared/signal-B3xOKbVm.js";
|
|
2
|
+
import { n as effect, t as renderEffect } from "./shared/render-effect-Uk9dDmuU.js";
|
|
3
|
+
import { t as computed } from "./shared/computed-DrF8O8b4.js";
|
|
4
|
+
import { S as untrack, a as deferMounts, f as isStaticRender, i as batch, m as nextKey, t as addCleanup } from "./shared/graph-SIvYLXSv.js";
|
|
5
|
+
import { a as onCleanup, c as runWithOwner, n as createRoot, o as onMount, r as getOwner, s as renderStatic, t as catchError } from "./shared/owner-BuwIoI4j.js";
|
|
6
|
+
import { a as provide, i as createContext, o as useContext } from "./shared/render-context-k2uu_dM_.js";
|
|
7
|
+
import { n as store, r as unwrap, t as reconcile } from "./shared/store-0vEg2bQV.js";
|
|
8
|
+
import { n as html } from "./shared/element-DXwmUAnz.js";
|
|
9
|
+
import { a as hooks, n as insert, s as withoutClaims } from "./shared/namespaces-Cz82B0Pr.js";
|
|
10
|
+
import { t as mount } from "./shared/mount-CDB2HgN5.js";
|
|
11
|
+
import { n as SuspenseContext, t as resource } from "./shared/resource-DlgzdtcG.js";
|
|
9
12
|
// src/core/env.ts
|
|
10
13
|
var isServer = typeof window === "undefined";
|
|
11
14
|
// src/dom/tags.ts
|
|
@@ -121,28 +124,9 @@ var $ul = /* @__PURE__ */ html("ul");
|
|
|
121
124
|
var $var = /* @__PURE__ */ html("var");
|
|
122
125
|
var $video = /* @__PURE__ */ html("video");
|
|
123
126
|
var $wbr = /* @__PURE__ */ html("wbr");
|
|
124
|
-
// src/dom/mount.ts
|
|
125
|
-
function mount(app, target) {
|
|
126
|
-
if (target === null) throw new Error("[keits] mount(): the target element was not found (null).");
|
|
127
|
-
const start = hooks.marker();
|
|
128
|
-
const end = hooks.marker();
|
|
129
|
-
target.append(start, end);
|
|
130
|
-
const dispose = createRoot((dispose) => {
|
|
131
|
-
insert(target, app(), end);
|
|
132
|
-
return dispose;
|
|
133
|
-
});
|
|
134
|
-
return () => {
|
|
135
|
-
dispose();
|
|
136
|
-
let node = start;
|
|
137
|
-
while (node !== null) {
|
|
138
|
-
const next = node === end ? null : node.nextSibling;
|
|
139
|
-
node.remove();
|
|
140
|
-
node = next;
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
127
|
// src/dom/unsafe.ts
|
|
145
128
|
function unsafeHTML(markup) {
|
|
129
|
+
if (hooks.html !== void 0) return hooks.html(markup);
|
|
146
130
|
const template = document.createElement("template");
|
|
147
131
|
template.innerHTML = markup;
|
|
148
132
|
return template.content;
|
|
@@ -158,7 +142,7 @@ function createRow(build, item) {
|
|
|
158
142
|
first: result,
|
|
159
143
|
last: result
|
|
160
144
|
};
|
|
161
|
-
const holder =
|
|
145
|
+
const holder = hooks.fragment();
|
|
162
146
|
const first = hooks.marker();
|
|
163
147
|
const last = hooks.marker();
|
|
164
148
|
holder.append(first, last);
|
|
@@ -199,7 +183,7 @@ function removeRow(row) {
|
|
|
199
183
|
// src/flow/for.ts
|
|
200
184
|
function $for(each, render, options) {
|
|
201
185
|
const end = hooks.marker();
|
|
202
|
-
const container =
|
|
186
|
+
const container = hooks.fragment();
|
|
203
187
|
container.append(end);
|
|
204
188
|
let rows = [];
|
|
205
189
|
let fallback = null;
|
|
@@ -333,7 +317,7 @@ function $catch(children, fallback) {
|
|
|
333
317
|
const current = failure();
|
|
334
318
|
if (current !== null) return untrack(() => fallback(current.error, reset));
|
|
335
319
|
return untrack(() => catchError(() => {
|
|
336
|
-
const content =
|
|
320
|
+
const content = hooks.fragment();
|
|
337
321
|
insert(content, children());
|
|
338
322
|
return content;
|
|
339
323
|
}, (error) => failure.set({ error })));
|
|
@@ -341,14 +325,21 @@ function $catch(children, fallback) {
|
|
|
341
325
|
}
|
|
342
326
|
// src/flow/portal.ts
|
|
343
327
|
function $portal(children, target) {
|
|
344
|
-
if (isStaticRender())
|
|
328
|
+
if (isStaticRender()) {
|
|
329
|
+
nextKey();
|
|
330
|
+
return null;
|
|
331
|
+
}
|
|
345
332
|
const host = target === void 0 ? document.body : target;
|
|
346
333
|
if (host === null) throw new Error("[keits] $portal(): the target element was not found (null).");
|
|
347
334
|
const start = hooks.marker();
|
|
348
335
|
const end = hooks.marker();
|
|
349
336
|
host.append(start, end);
|
|
350
|
-
|
|
337
|
+
const disposeContent = createRoot((dispose) => {
|
|
338
|
+
withoutClaims(() => insert(host, untrack(children), end));
|
|
339
|
+
return dispose;
|
|
340
|
+
});
|
|
351
341
|
addCleanup(() => {
|
|
342
|
+
disposeContent();
|
|
352
343
|
let node = start;
|
|
353
344
|
while (node !== null) {
|
|
354
345
|
const next = node === end ? null : node.nextSibling;
|
|
@@ -371,7 +362,7 @@ function $suspense(children, fallback) {
|
|
|
371
362
|
pendingCount.set((n) => n - 1);
|
|
372
363
|
});
|
|
373
364
|
} };
|
|
374
|
-
const offscreen =
|
|
365
|
+
const offscreen = hooks.fragment();
|
|
375
366
|
const contentStart = hooks.marker();
|
|
376
367
|
const contentEnd = hooks.marker();
|
|
377
368
|
offscreen.append(contentStart, contentEnd);
|
|
@@ -384,7 +375,7 @@ function $suspense(children, fallback) {
|
|
|
384
375
|
last: contentEnd
|
|
385
376
|
};
|
|
386
377
|
const end = hooks.marker();
|
|
387
|
-
const container =
|
|
378
|
+
const container = hooks.fragment();
|
|
388
379
|
container.append(end);
|
|
389
380
|
let fallbackRow = null;
|
|
390
381
|
addCleanup(() => fallbackRow?.dispose());
|
package/dist/dev/router.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as computed } from "./shared/computed-
|
|
2
|
-
import { t as signal } from "./shared/signal-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { t as computed } from "./shared/computed-DrF8O8b4.js";
|
|
2
|
+
import { t as signal } from "./shared/signal-B3xOKbVm.js";
|
|
3
|
+
import { S as untrack, _ as runWithOwner, c as getOwner, i as batch, n as addMount, u as handleError } from "./shared/graph-SIvYLXSv.js";
|
|
4
|
+
import { a as onCleanup } from "./shared/owner-BuwIoI4j.js";
|
|
5
5
|
// src/router/history.ts
|
|
6
6
|
var newKey = () => Math.random().toString(36).slice(2, 10);
|
|
7
7
|
var stateKey = () => window.history.state?.keitsKey ?? "start";
|
|
@@ -10,7 +10,7 @@ function browserHistory(base = "") {
|
|
|
10
10
|
return {
|
|
11
11
|
read() {
|
|
12
12
|
let path = window.location.pathname;
|
|
13
|
-
if (prefix !== "" && path.startsWith(prefix)) path = path.slice(prefix.length);
|
|
13
|
+
if (prefix !== "" && (path === prefix || path.startsWith(`${prefix}/`))) path = path.slice(prefix.length);
|
|
14
14
|
return {
|
|
15
15
|
path: path || "/",
|
|
16
16
|
search: window.location.search,
|
|
@@ -234,6 +234,23 @@ function fillParams(path, params) {
|
|
|
234
234
|
return encodeURIComponent(String(value));
|
|
235
235
|
});
|
|
236
236
|
}
|
|
237
|
+
async function staticPaths(routes) {
|
|
238
|
+
const urls = [];
|
|
239
|
+
for (const branch of compileRoutes(routes)) {
|
|
240
|
+
if (branch.keys.includes("*")) continue;
|
|
241
|
+
if (branch.keys.length === 0) {
|
|
242
|
+
urls.push(branch.path);
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
const withPaths = [...branch.routes].reverse().find((route) => route.paths !== void 0);
|
|
246
|
+
if (withPaths === void 0) {
|
|
247
|
+
console.warn(`[keits/router] staticPaths(): "${branch.path}" has params but no paths(), so it isn't built.`);
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
for (const params of await withPaths.paths()) urls.push(fillParams(branch.path, params));
|
|
251
|
+
}
|
|
252
|
+
return [...new Set(urls)];
|
|
253
|
+
}
|
|
237
254
|
// src/router/scroll.ts
|
|
238
255
|
function createScroller() {
|
|
239
256
|
const positions = /* @__PURE__ */ new Map();
|
|
@@ -268,7 +285,7 @@ function decodeHash(hash) {
|
|
|
268
285
|
}
|
|
269
286
|
// src/router/router.ts
|
|
270
287
|
function createRouter(config) {
|
|
271
|
-
const history = typeof config.history === "object" ? config.history : config.history === "hash" ? hashHistory() : browserHistory(config.base);
|
|
288
|
+
const history = typeof config.history === "object" ? config.history : config.history === "hash" ? hashHistory() : typeof window === "undefined" ? memoryHistory() : browserHistory(config.base);
|
|
272
289
|
const owner = getOwner();
|
|
273
290
|
const branches = compileRoutes(config.routes);
|
|
274
291
|
const sameLocation = (a, b) => a.path === b.path && a.search === b.search && a.hash === b.hash;
|
|
@@ -442,4 +459,4 @@ function shallowEqual(a, b) {
|
|
|
442
459
|
if (keys.length !== Object.keys(b).length) return false;
|
|
443
460
|
return keys.every((key) => Object.is(a[key], b[key]));
|
|
444
461
|
}
|
|
445
|
-
export { browserHistory, createRouter, hashHistory, memoryHistory };
|
|
462
|
+
export { browserHistory, createRouter, hashHistory, memoryHistory, staticPaths };
|
|
@@ -1,64 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
text: (value) => document.createTextNode(value),
|
|
6
|
-
marker: () => document.createComment("")
|
|
7
|
-
};
|
|
8
|
-
// src/dom/insert.ts
|
|
9
|
-
function insert(parent, child, before = null) {
|
|
10
|
-
if (child === null || child === void 0 || typeof child === "boolean") return;
|
|
11
|
-
if (typeof child === "function") return insertDynamic(parent, child, before);
|
|
12
|
-
if (isChildArray(child)) {
|
|
13
|
-
for (const item of child) insert(parent, item, before);
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
if (typeof child === "object") {
|
|
17
|
-
parent.insertBefore(child, before);
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
parent.insertBefore(hooks.text(String(child)), before);
|
|
21
|
-
}
|
|
22
|
-
function isChildArray(value) {
|
|
23
|
-
return Array.isArray(value);
|
|
24
|
-
}
|
|
25
|
-
function isTextValue(value) {
|
|
26
|
-
return value === null || typeof value !== "object" && typeof value !== "function";
|
|
27
|
-
}
|
|
28
|
-
function toText(value) {
|
|
29
|
-
return value === null || value === void 0 || typeof value === "boolean" ? "" : String(value);
|
|
30
|
-
}
|
|
31
|
-
function insertDynamic(parent, fn, before) {
|
|
32
|
-
const text = hooks.text("");
|
|
33
|
-
parent.insertBefore(text, before);
|
|
34
|
-
let start = null;
|
|
35
|
-
let end = null;
|
|
36
|
-
renderEffect(() => {
|
|
37
|
-
const value = fn();
|
|
38
|
-
if (start === null || end === null) {
|
|
39
|
-
if (isTextValue(value)) {
|
|
40
|
-
const next = toText(value);
|
|
41
|
-
if (text.data !== next) text.data = next;
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
start = hooks.marker();
|
|
45
|
-
end = hooks.marker();
|
|
46
|
-
text.before(start);
|
|
47
|
-
text.after(end);
|
|
48
|
-
text.remove();
|
|
49
|
-
}
|
|
50
|
-
clearRange(start, end);
|
|
51
|
-
insert(end.parentNode, value, end);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
function clearRange(start, end) {
|
|
55
|
-
let node = start.nextSibling;
|
|
56
|
-
while (node !== null && node !== end) {
|
|
57
|
-
const next = node.nextSibling;
|
|
58
|
-
node.remove();
|
|
59
|
-
node = next;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
1
|
+
import { a as hooks, n as insert } from "./namespaces-Cz82B0Pr.js";
|
|
2
|
+
import { _ as runWithOwner, c as getOwner, f as isStaticRender, i as batch, u as handleError } from "./graph-SIvYLXSv.js";
|
|
3
|
+
import { t as UNSAFE_KEYS } from "./unsafe-keys-CB1P22No.js";
|
|
4
|
+
import { t as renderEffect } from "./render-effect-Uk9dDmuU.js";
|
|
62
5
|
// src/dom/events.ts
|
|
63
6
|
function applyEvent(element, key, value) {
|
|
64
7
|
let handler = value;
|
|
@@ -84,24 +27,24 @@ function listen(element, type, handler, options) {
|
|
|
84
27
|
function isPromiseLike(value) {
|
|
85
28
|
return typeof value?.then === "function";
|
|
86
29
|
}
|
|
87
|
-
// src/dom/namespaces.ts
|
|
88
|
-
var SVG_NS = "http://www.w3.org/2000/svg";
|
|
89
30
|
// src/dom/props.ts
|
|
90
31
|
var UNSAFE_PROPS = /* @__PURE__ */ new Set([
|
|
91
|
-
"
|
|
92
|
-
"
|
|
32
|
+
"innerhtml",
|
|
33
|
+
"outerhtml",
|
|
93
34
|
"srcdoc"
|
|
94
35
|
]);
|
|
95
36
|
var URL_PROPS = /* @__PURE__ */ new Set([
|
|
96
37
|
"href",
|
|
97
38
|
"src",
|
|
98
39
|
"action",
|
|
99
|
-
"formAction",
|
|
100
40
|
"formaction",
|
|
101
41
|
"poster",
|
|
102
42
|
"cite",
|
|
103
43
|
"data",
|
|
104
|
-
"xlink:href"
|
|
44
|
+
"xlink:href",
|
|
45
|
+
"to",
|
|
46
|
+
"from",
|
|
47
|
+
"values"
|
|
105
48
|
]);
|
|
106
49
|
var BLOCKED_URL = "about:invalid#keits-blocked";
|
|
107
50
|
function applyProps(element, props) {
|
|
@@ -110,43 +53,54 @@ function applyProps(element, props) {
|
|
|
110
53
|
if (key === "ref") continue;
|
|
111
54
|
if (key === "class") applyClass(element, value);
|
|
112
55
|
else if (key === "style") applyStyle(element, value);
|
|
113
|
-
else if (key.startsWith("on")) applyEvent(element, key, value);
|
|
56
|
+
else if (key.toLowerCase().startsWith("on")) applyEvent(element, key, value);
|
|
114
57
|
else if (typeof value === "function") renderEffect(() => setProp(element, key, value()));
|
|
115
58
|
else setProp(element, key, value);
|
|
116
59
|
}
|
|
117
60
|
}
|
|
118
61
|
function setProp(element, key, value) {
|
|
119
|
-
|
|
120
|
-
if (
|
|
62
|
+
const name = key.toLowerCase();
|
|
63
|
+
if (UNSAFE_PROPS.has(name) || UNSAFE_KEYS.has(key) || name.startsWith("on") && typeof value === "string") throw new Error(`[keits] "${key}" is not allowed as a prop: it would allow HTML injection.`);
|
|
64
|
+
if (URL_PROPS.has(name) && value != null && value !== false && isJavaScriptUrl(String(value))) {
|
|
121
65
|
console.warn(`[keits] Blocked a javascript: URL in "${key}".`);
|
|
122
66
|
value = BLOCKED_URL;
|
|
123
67
|
}
|
|
124
68
|
if (key in element && element.namespaceURI !== "http://www.w3.org/2000/svg") {
|
|
125
69
|
element[key] = value;
|
|
126
70
|
if (isStaticRender()) reflectForStatic(element, key, value);
|
|
127
|
-
} else if (
|
|
71
|
+
} else if (key.startsWith("aria-") && typeof value === "boolean") element.setAttribute(key, String(value));
|
|
72
|
+
else if (value === null || value === void 0 || value === false) element.removeAttribute(key);
|
|
128
73
|
else element.setAttribute(key, value === true ? "" : String(value));
|
|
129
74
|
}
|
|
130
75
|
function isJavaScriptUrl(url) {
|
|
131
|
-
return url.replace(/[\u0000-\u0020]/g, "").toLowerCase().startsWith("javascript");
|
|
76
|
+
return url.replace(/[\u0000-\u0020]/g, "").toLowerCase().split(";").some((part) => part.startsWith("javascript:"));
|
|
132
77
|
}
|
|
133
78
|
function reflectForStatic(element, key, value) {
|
|
134
79
|
if (key === "value") {
|
|
135
80
|
if (element.localName === "textarea") element.textContent = value == null ? "" : String(value);
|
|
81
|
+
else if (element.localName === "select") selectOption(element, value == null ? "" : String(value));
|
|
136
82
|
else if (value == null) element.removeAttribute("value");
|
|
137
83
|
else element.setAttribute("value", String(value));
|
|
138
84
|
} else if (key === "checked" || key === "selected") element.toggleAttribute(key, value === true);
|
|
139
85
|
}
|
|
86
|
+
function selectOption(node, value) {
|
|
87
|
+
for (let child = node.firstChild; child !== null; child = child.nextSibling) {
|
|
88
|
+
if (child.nodeType !== 1) continue;
|
|
89
|
+
const element = child;
|
|
90
|
+
if (element.localName === "option") element.toggleAttribute("selected", (element.getAttribute("value") ?? element.textContent) === value);
|
|
91
|
+
else selectOption(element, value);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
140
94
|
function applyClass(element, value) {
|
|
141
95
|
if (typeof value === "function") {
|
|
142
96
|
renderEffect(() => writeClass(element, toClassString(value())));
|
|
143
97
|
return;
|
|
144
98
|
}
|
|
145
99
|
const fixed = [];
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
});
|
|
100
|
+
const reactive = [];
|
|
101
|
+
collectClasses(value, fixed, (name, on) => reactive.push([name, on]));
|
|
149
102
|
if (fixed.length > 0) element.classList.add(...fixed);
|
|
103
|
+
for (const [name, on] of reactive) renderEffect(() => element.classList.toggle(name, on()));
|
|
150
104
|
}
|
|
151
105
|
function writeClass(element, className) {
|
|
152
106
|
if (className === "") element.removeAttribute("class");
|
|
@@ -219,4 +173,4 @@ function createFactory(tag, namespace) {
|
|
|
219
173
|
function isProps(value) {
|
|
220
174
|
return typeof value === "object" && value !== null && !Array.isArray(value) && typeof value.nodeType !== "number";
|
|
221
175
|
}
|
|
222
|
-
export {
|
|
176
|
+
export { html as n, createFactory as t };
|