keits 0.0.4 → 0.1.1
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 +10 -5
- package/dist/dev/index.js +28 -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-Bgf6SNbW.js +21 -0
- package/dist/dev/shared/{graph-D6-x_CWC.js → graph-SIvYLXSv.js} +62 -3
- package/dist/dev/shared/hydrate-g_akkVyT.js +588 -0
- package/dist/dev/shared/{element-CQPqagu1.js → insert-DadcXJL8.js} +116 -86
- package/dist/dev/shared/mount-BtpMEhSZ.js +23 -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 +236 -0
- package/dist/dev/vite.js +141 -0
- package/dist/prod/api.js +76 -71
- package/dist/prod/forms.js +89 -84
- package/dist/prod/index.js +58 -66
- package/dist/prod/router.js +86 -73
- package/dist/prod/shared/{computed-CAPpOLCY.js → computed-BjqJ6Pps.js} +1 -1
- package/dist/prod/shared/element-B-0tH1YW.js +15 -0
- package/dist/prod/shared/{graph-C_aA46c6.js → graph-CR2WKbwr.js} +107 -63
- package/dist/prod/shared/hydrate-DhHCtdOz.js +480 -0
- package/dist/prod/shared/insert-CbcOsYmu.js +192 -0
- package/dist/prod/shared/mount-BEAO35S_.js +18 -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 +161 -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/props.d.ts +2 -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 +69 -0
- package/dist/types/vite/index.d.ts +24 -0
- package/package.json +35 -8
- 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) => {
|
|
@@ -93,6 +95,7 @@ function form(options) {
|
|
|
93
95
|
const submitting = signal(false);
|
|
94
96
|
const validating = signal(false);
|
|
95
97
|
let checkId = 0;
|
|
98
|
+
let resets = 0;
|
|
96
99
|
const read = (value) => typeof value === "function" ? value() : value;
|
|
97
100
|
const snapshot = () => structuredClone(unwrap(values));
|
|
98
101
|
const runChecks = () => {
|
|
@@ -280,8 +283,9 @@ function form(options) {
|
|
|
280
283
|
focusFirstError();
|
|
281
284
|
return false;
|
|
282
285
|
}
|
|
286
|
+
const resetsBefore = resets;
|
|
283
287
|
await handler(options.schema ? checked.output : sent);
|
|
284
|
-
baseline.set(() => sent);
|
|
288
|
+
if (resets === resetsBefore) baseline.set(() => sent);
|
|
285
289
|
return true;
|
|
286
290
|
} catch (error) {
|
|
287
291
|
if (result.setErrors(error)) {
|
|
@@ -296,6 +300,7 @@ function form(options) {
|
|
|
296
300
|
},
|
|
297
301
|
reset(next) {
|
|
298
302
|
const start = structuredClone(next ?? untrack(baseline));
|
|
303
|
+
resets++;
|
|
299
304
|
batch(() => {
|
|
300
305
|
setValues((draft) => replaceKeys(draft, structuredClone(start)));
|
|
301
306
|
baseline.set(() => start);
|
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-Bgf6SNbW.js";
|
|
9
|
+
import { l as withoutClaims, r as restoreSelectValue, s as hooks, t as insert } from "./shared/insert-DadcXJL8.js";
|
|
10
|
+
import { t as mount } from "./shared/mount-BtpMEhSZ.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;
|
|
@@ -220,6 +204,7 @@ function $for(each, render, options) {
|
|
|
220
204
|
fallback = createRow(options.fallback, null);
|
|
221
205
|
moveRow(parent, fallback, end);
|
|
222
206
|
}
|
|
207
|
+
restoreSelectValue(parent);
|
|
223
208
|
return;
|
|
224
209
|
}
|
|
225
210
|
if (fallback !== null) {
|
|
@@ -256,6 +241,7 @@ function $for(each, render, options) {
|
|
|
256
241
|
anchor = row.first;
|
|
257
242
|
}
|
|
258
243
|
rows = next;
|
|
244
|
+
restoreSelectValue(parent);
|
|
259
245
|
}
|
|
260
246
|
function createItemRow(item, i) {
|
|
261
247
|
let setIndex = () => {};
|
|
@@ -333,7 +319,7 @@ function $catch(children, fallback) {
|
|
|
333
319
|
const current = failure();
|
|
334
320
|
if (current !== null) return untrack(() => fallback(current.error, reset));
|
|
335
321
|
return untrack(() => catchError(() => {
|
|
336
|
-
const content =
|
|
322
|
+
const content = hooks.fragment();
|
|
337
323
|
insert(content, children());
|
|
338
324
|
return content;
|
|
339
325
|
}, (error) => failure.set({ error })));
|
|
@@ -341,14 +327,21 @@ function $catch(children, fallback) {
|
|
|
341
327
|
}
|
|
342
328
|
// src/flow/portal.ts
|
|
343
329
|
function $portal(children, target) {
|
|
344
|
-
if (isStaticRender())
|
|
330
|
+
if (isStaticRender()) {
|
|
331
|
+
nextKey();
|
|
332
|
+
return null;
|
|
333
|
+
}
|
|
345
334
|
const host = target === void 0 ? document.body : target;
|
|
346
335
|
if (host === null) throw new Error("[keits] $portal(): the target element was not found (null).");
|
|
347
336
|
const start = hooks.marker();
|
|
348
337
|
const end = hooks.marker();
|
|
349
338
|
host.append(start, end);
|
|
350
|
-
|
|
339
|
+
const disposeContent = createRoot((dispose) => {
|
|
340
|
+
withoutClaims(() => insert(host, untrack(children), end));
|
|
341
|
+
return dispose;
|
|
342
|
+
});
|
|
351
343
|
addCleanup(() => {
|
|
344
|
+
disposeContent();
|
|
352
345
|
let node = start;
|
|
353
346
|
while (node !== null) {
|
|
354
347
|
const next = node === end ? null : node.nextSibling;
|
|
@@ -371,7 +364,7 @@ function $suspense(children, fallback) {
|
|
|
371
364
|
pendingCount.set((n) => n - 1);
|
|
372
365
|
});
|
|
373
366
|
} };
|
|
374
|
-
const offscreen =
|
|
367
|
+
const offscreen = hooks.fragment();
|
|
375
368
|
const contentStart = hooks.marker();
|
|
376
369
|
const contentEnd = hooks.marker();
|
|
377
370
|
offscreen.append(contentStart, contentEnd);
|
|
@@ -384,7 +377,7 @@ function $suspense(children, fallback) {
|
|
|
384
377
|
last: contentEnd
|
|
385
378
|
};
|
|
386
379
|
const end = hooks.marker();
|
|
387
|
-
const container =
|
|
380
|
+
const container = hooks.fragment();
|
|
388
381
|
container.append(end);
|
|
389
382
|
let fallbackRow = null;
|
|
390
383
|
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 };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { n as applyProps, s as hooks, t as insert } from "./insert-DadcXJL8.js";
|
|
2
|
+
// src/dom/element.ts
|
|
3
|
+
function html(tag) {
|
|
4
|
+
return createFactory(tag, null);
|
|
5
|
+
}
|
|
6
|
+
function createFactory(tag, namespace) {
|
|
7
|
+
return (first, children) => {
|
|
8
|
+
const element = hooks.element(tag, namespace);
|
|
9
|
+
if (isProps(first)) {
|
|
10
|
+
insert(element, children);
|
|
11
|
+
applyProps(element, first);
|
|
12
|
+
if (typeof first.ref === "function") first.ref(element);
|
|
13
|
+
} else if (first === null || first === void 0) insert(element, children);
|
|
14
|
+
else insert(element, first);
|
|
15
|
+
return element;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function isProps(value) {
|
|
19
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && typeof value.nodeType !== "number";
|
|
20
|
+
}
|
|
21
|
+
export { html as n, createFactory as t };
|
|
@@ -12,6 +12,7 @@ var mounts = [];
|
|
|
12
12
|
var lastWritten = null;
|
|
13
13
|
var unhandledErrors = [];
|
|
14
14
|
var staticDepth = 0;
|
|
15
|
+
var staticRoots = 0;
|
|
15
16
|
function track(source) {
|
|
16
17
|
const observer = currentObserver;
|
|
17
18
|
if (observer === null || source.seenBy === currentRunId) return;
|
|
@@ -26,6 +27,9 @@ function track(source) {
|
|
|
26
27
|
function isTracking() {
|
|
27
28
|
return currentObserver !== null;
|
|
28
29
|
}
|
|
30
|
+
function getObserver() {
|
|
31
|
+
return currentObserver;
|
|
32
|
+
}
|
|
29
33
|
function notify(source) {
|
|
30
34
|
if (source.observers.length === 0) return;
|
|
31
35
|
lastWritten = source;
|
|
@@ -213,6 +217,32 @@ function adopt(node) {
|
|
|
213
217
|
const owner = currentOwner;
|
|
214
218
|
node.owner = owner;
|
|
215
219
|
if (owner !== null) (owner.children ??= []).push(node);
|
|
220
|
+
giveKey(node);
|
|
221
|
+
}
|
|
222
|
+
var keying = 0;
|
|
223
|
+
function startKeys() {
|
|
224
|
+
keying++;
|
|
225
|
+
}
|
|
226
|
+
function stopKeys() {
|
|
227
|
+
keying--;
|
|
228
|
+
}
|
|
229
|
+
function nextKey() {
|
|
230
|
+
const owner = currentOwner;
|
|
231
|
+
if (keying === 0 || owner === null || owner.key === void 0) return null;
|
|
232
|
+
const index = owner.keyCount ?? 0;
|
|
233
|
+
owner.keyCount = index + 1;
|
|
234
|
+
return `${owner.key}.${index}`;
|
|
235
|
+
}
|
|
236
|
+
function giveKey(node) {
|
|
237
|
+
const key = nextKey();
|
|
238
|
+
if (key !== null) {
|
|
239
|
+
node.key = key;
|
|
240
|
+
node.keyCount = 0;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
function insideHydratable(from = currentOwner) {
|
|
244
|
+
for (let owner = from; owner !== null; owner = owner.owner) if (owner.kind === 3 && owner.hydratable) return true;
|
|
245
|
+
return false;
|
|
216
246
|
}
|
|
217
247
|
function getOwner() {
|
|
218
248
|
return currentOwner;
|
|
@@ -235,7 +265,7 @@ function addCleanup(fn) {
|
|
|
235
265
|
return true;
|
|
236
266
|
}
|
|
237
267
|
function addMount(fn) {
|
|
238
|
-
if (
|
|
268
|
+
if (isStaticRender()) return;
|
|
239
269
|
queueMount(currentOwner, fn);
|
|
240
270
|
}
|
|
241
271
|
function queueMount(owner, fn) {
|
|
@@ -279,6 +309,7 @@ function cleanNode(node) {
|
|
|
279
309
|
const cleanups = node.cleanups;
|
|
280
310
|
node.children = null;
|
|
281
311
|
node.cleanups = null;
|
|
312
|
+
if (node.key !== void 0) node.keyCount = 0;
|
|
282
313
|
if (children !== null) for (let i = children.length - 1; i >= 0; i--) dispose(children[i]);
|
|
283
314
|
if (cleanups !== null) for (let i = cleanups.length - 1; i >= 0; i--) try {
|
|
284
315
|
cleanups[i]();
|
|
@@ -311,7 +342,35 @@ function handleError(error, owner) {
|
|
|
311
342
|
unhandledErrors.push(error);
|
|
312
343
|
}
|
|
313
344
|
function isStaticRender() {
|
|
314
|
-
|
|
345
|
+
if (staticDepth > 0) return true;
|
|
346
|
+
if (staticRoots === 0) return false;
|
|
347
|
+
for (let owner = currentOwner; owner !== null; owner = owner.owner) if (owner.kind === 3 && owner.static) return true;
|
|
348
|
+
return false;
|
|
349
|
+
}
|
|
350
|
+
function staticRoot(fn) {
|
|
351
|
+
const root = {
|
|
352
|
+
kind: 3,
|
|
353
|
+
owner: null,
|
|
354
|
+
children: null,
|
|
355
|
+
cleanups: null,
|
|
356
|
+
disposed: false,
|
|
357
|
+
handler: null,
|
|
358
|
+
static: true
|
|
359
|
+
};
|
|
360
|
+
staticRoots++;
|
|
361
|
+
let ended = false;
|
|
362
|
+
const end = () => {
|
|
363
|
+
if (ended) return;
|
|
364
|
+
ended = true;
|
|
365
|
+
staticRoots--;
|
|
366
|
+
batch(() => dispose(root));
|
|
367
|
+
};
|
|
368
|
+
try {
|
|
369
|
+
return batch(() => runWithOwner(root, () => fn(end)));
|
|
370
|
+
} catch (error) {
|
|
371
|
+
end();
|
|
372
|
+
throw error;
|
|
373
|
+
}
|
|
315
374
|
}
|
|
316
375
|
function withStaticRender(fn) {
|
|
317
376
|
staticDepth++;
|
|
@@ -321,4 +380,4 @@ function withStaticRender(fn) {
|
|
|
321
380
|
staticDepth--;
|
|
322
381
|
}
|
|
323
382
|
}
|
|
324
|
-
export {
|
|
383
|
+
export { updateIfNeeded as C, untrack as S, runWithOwner as _, deferMounts as a, stopKeys as b, getOwner as c, insideHydratable as d, isStaticRender as f, runEffect as g, notify as h, batch as i, giveKey as l, nextKey as m, addMount as n, dispose as o, isTracking as p, adopt as r, getObserver as s, addCleanup as t, handleError as u, startKeys as v, withStaticRender as w, track as x, staticRoot as y };
|