keits 0.0.3 → 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 +275 -0
- package/dist/dev/forms.js +330 -0
- package/dist/dev/index.js +26 -326
- package/dist/dev/router.js +24 -5
- package/dist/dev/shared/computed-DrF8O8b4.js +40 -0
- package/dist/dev/shared/{element-C4DfKtZW.js → element-DXwmUAnz.js} +32 -111
- 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-BuwIoI4j.js +72 -0
- 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-DlgzdtcG.js +145 -0
- package/dist/dev/shared/signal-B3xOKbVm.js +24 -0
- package/dist/dev/shared/store-0vEg2bQV.js +152 -0
- 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 +215 -0
- package/dist/prod/forms.js +240 -0
- package/dist/prod/index.js +110 -327
- package/dist/prod/router.js +83 -68
- package/dist/prod/shared/computed-BjqJ6Pps.js +33 -0
- 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/api/cache.d.ts +16 -0
- package/dist/types/api/client.d.ts +42 -0
- package/dist/types/api/error.d.ts +16 -0
- package/dist/types/api/index.d.ts +3 -0
- package/dist/types/api/url.d.ts +5 -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/forms/form.d.ts +55 -0
- package/dist/types/forms/index.d.ts +2 -0
- package/dist/types/forms/paths.d.ts +6 -0
- package/dist/types/forms/types.d.ts +38 -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 +46 -5
- package/dist/dev/shared/owner-DlUsXKXE.js +0 -122
- package/dist/prod/shared/element-DUtXb3px.js +0 -187
- package/dist/prod/shared/owner-DgJNPM0P.js +0 -104
package/dist/dev/index.js
CHANGED
|
@@ -1,180 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
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";
|
|
4
12
|
// src/core/env.ts
|
|
5
13
|
var isServer = typeof window === "undefined";
|
|
6
|
-
// src/core/context.ts
|
|
7
|
-
function createContext(defaultValue, options) {
|
|
8
|
-
const context = { defaultValue };
|
|
9
|
-
if (options?.name !== void 0) context.name = options.name;
|
|
10
|
-
return context;
|
|
11
|
-
}
|
|
12
|
-
function provide(context, value, fn) {
|
|
13
|
-
const provider = {
|
|
14
|
-
kind: 3,
|
|
15
|
-
owner: null,
|
|
16
|
-
children: null,
|
|
17
|
-
cleanups: null,
|
|
18
|
-
disposed: false,
|
|
19
|
-
handler: null,
|
|
20
|
-
context: {
|
|
21
|
-
key: context,
|
|
22
|
-
value
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
adopt(provider);
|
|
26
|
-
return runWithOwner$1(provider, fn);
|
|
27
|
-
}
|
|
28
|
-
function useContext(context) {
|
|
29
|
-
for (let o = getOwner$1(); o !== null; o = o.owner) if (o.kind === 3 && o.context?.key === context) return o.context.value;
|
|
30
|
-
return context.defaultValue;
|
|
31
|
-
}
|
|
32
|
-
// src/core/store.ts
|
|
33
|
-
var RAW = Symbol("raw");
|
|
34
|
-
var SHAPE = Symbol("shape");
|
|
35
|
-
var proxies = /* @__PURE__ */ new WeakMap();
|
|
36
|
-
var nodeMaps = /* @__PURE__ */ new WeakMap();
|
|
37
|
-
var writing = 0;
|
|
38
|
-
function store(initial, options) {
|
|
39
|
-
const state = wrap(initial);
|
|
40
|
-
const name = options?.name;
|
|
41
|
-
const setState = (fn) => {
|
|
42
|
-
writing++;
|
|
43
|
-
try {
|
|
44
|
-
untrack(() => batch(() => fn(state)));
|
|
45
|
-
} finally {
|
|
46
|
-
writing--;
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
if (name !== void 0) storeNames.set(unwrap(state), name);
|
|
50
|
-
return [state, setState];
|
|
51
|
-
}
|
|
52
|
-
var storeNames = /* @__PURE__ */ new WeakMap();
|
|
53
|
-
function unwrap(value) {
|
|
54
|
-
if (value !== null && typeof value === "object") {
|
|
55
|
-
const raw = value[RAW];
|
|
56
|
-
if (raw !== void 0) return raw;
|
|
57
|
-
}
|
|
58
|
-
return value;
|
|
59
|
-
}
|
|
60
|
-
function isWrappable(value) {
|
|
61
|
-
if (value === null || typeof value !== "object") return false;
|
|
62
|
-
if (Array.isArray(value)) return true;
|
|
63
|
-
const proto = Object.getPrototypeOf(value);
|
|
64
|
-
return proto === Object.prototype || proto === null;
|
|
65
|
-
}
|
|
66
|
-
function wrap(value) {
|
|
67
|
-
if (!isWrappable(value)) return value;
|
|
68
|
-
let proxy = proxies.get(value);
|
|
69
|
-
if (proxy === void 0) {
|
|
70
|
-
proxy = new Proxy(value, handler);
|
|
71
|
-
proxies.set(value, proxy);
|
|
72
|
-
}
|
|
73
|
-
return proxy;
|
|
74
|
-
}
|
|
75
|
-
function getNode(target, key) {
|
|
76
|
-
let nodes = nodeMaps.get(target);
|
|
77
|
-
if (nodes === void 0) nodeMaps.set(target, nodes = /* @__PURE__ */ new Map());
|
|
78
|
-
let node = nodes.get(key);
|
|
79
|
-
if (node === void 0) nodes.set(key, node = {
|
|
80
|
-
kind: 0,
|
|
81
|
-
observers: [],
|
|
82
|
-
seenBy: 0
|
|
83
|
-
});
|
|
84
|
-
return node;
|
|
85
|
-
}
|
|
86
|
-
function notifyKey(target, key) {
|
|
87
|
-
const node = nodeMaps.get(target)?.get(key);
|
|
88
|
-
if (node !== void 0) notify(node);
|
|
89
|
-
}
|
|
90
|
-
function readOnlyError(target) {
|
|
91
|
-
const name = storeNames.get(target);
|
|
92
|
-
return /* @__PURE__ */ new Error(`[keits] Store${name ? ` "${name}"` : ""} is read-only here. Change it inside setState(draft => { ... }).`);
|
|
93
|
-
}
|
|
94
|
-
var handler = {
|
|
95
|
-
get(target, key) {
|
|
96
|
-
if (key === RAW) return target;
|
|
97
|
-
const value = target[key];
|
|
98
|
-
if (isTracking() && (Object.hasOwn(target, key) || !(key in target))) track(getNode(target, key));
|
|
99
|
-
return wrap(value);
|
|
100
|
-
},
|
|
101
|
-
has(target, key) {
|
|
102
|
-
if (isTracking()) track(getNode(target, key));
|
|
103
|
-
return key in target;
|
|
104
|
-
},
|
|
105
|
-
ownKeys(target) {
|
|
106
|
-
if (isTracking()) track(getNode(target, SHAPE));
|
|
107
|
-
return Reflect.ownKeys(target);
|
|
108
|
-
},
|
|
109
|
-
set(target, key, value) {
|
|
110
|
-
if (writing === 0) {
|
|
111
|
-
const error = readOnlyError(target);
|
|
112
|
-
if (error) throw error;
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
const record = target;
|
|
116
|
-
const next = unwrap(value);
|
|
117
|
-
const hadKey = Object.hasOwn(target, key);
|
|
118
|
-
const prev = record[key];
|
|
119
|
-
const isArray = Array.isArray(target);
|
|
120
|
-
const prevLength = isArray ? target.length : 0;
|
|
121
|
-
if (hadKey && Object.is(prev, next)) return true;
|
|
122
|
-
record[key] = next;
|
|
123
|
-
notifyKey(target, key);
|
|
124
|
-
if (!hadKey) notifyKey(target, SHAPE);
|
|
125
|
-
if (isArray) {
|
|
126
|
-
const length = target.length;
|
|
127
|
-
if (length !== prevLength) {
|
|
128
|
-
if (key !== "length") notifyKey(target, "length");
|
|
129
|
-
notifyKey(target, SHAPE);
|
|
130
|
-
for (let i = length; i < prevLength; i++) notifyKey(target, String(i));
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return true;
|
|
134
|
-
},
|
|
135
|
-
deleteProperty(target, key) {
|
|
136
|
-
if (writing === 0) {
|
|
137
|
-
const error = readOnlyError(target);
|
|
138
|
-
if (error) throw error;
|
|
139
|
-
return false;
|
|
140
|
-
}
|
|
141
|
-
if (!Object.hasOwn(target, key)) return true;
|
|
142
|
-
delete target[key];
|
|
143
|
-
notifyKey(target, key);
|
|
144
|
-
notifyKey(target, SHAPE);
|
|
145
|
-
return true;
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
function reconcile(target, source, options = {}) {
|
|
149
|
-
if (writing === 0) throw new Error("[keits] reconcile() must be called inside setState.");
|
|
150
|
-
reconcileInto(wrap(unwrap(target)), unwrap(source), options.key);
|
|
151
|
-
}
|
|
152
|
-
function reconcileInto(target, source, key) {
|
|
153
|
-
const raw = unwrap(target);
|
|
154
|
-
const draft = target;
|
|
155
|
-
if (Array.isArray(raw) && Array.isArray(source)) {
|
|
156
|
-
const byKey = /* @__PURE__ */ new Map();
|
|
157
|
-
if (key !== void 0) {
|
|
158
|
-
for (const item of raw) if (isWrappable(item)) byKey.set(item[key], item);
|
|
159
|
-
}
|
|
160
|
-
for (let i = 0; i < source.length; i++) {
|
|
161
|
-
const next = source[i];
|
|
162
|
-
const existing = key !== void 0 && isWrappable(next) ? byKey.get(next[key]) : raw[i];
|
|
163
|
-
draft[i] = matchAndUpdate(existing, next, key);
|
|
164
|
-
}
|
|
165
|
-
if (raw.length !== source.length) draft.length = source.length;
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
for (const k of Object.keys(source)) draft[k] = matchAndUpdate(raw[k], source[k], key);
|
|
169
|
-
for (const k of Object.keys(raw)) if (!Object.hasOwn(source, k)) delete draft[k];
|
|
170
|
-
}
|
|
171
|
-
function matchAndUpdate(existing, next, key) {
|
|
172
|
-
if (isWrappable(existing) && isWrappable(next) && Array.isArray(existing) === Array.isArray(next)) {
|
|
173
|
-
reconcileInto(wrap(existing), next, key);
|
|
174
|
-
return existing;
|
|
175
|
-
}
|
|
176
|
-
return next;
|
|
177
|
-
}
|
|
178
14
|
// src/dom/tags.ts
|
|
179
15
|
var $a = /* @__PURE__ */ html("a");
|
|
180
16
|
var $abbr = /* @__PURE__ */ html("abbr");
|
|
@@ -288,28 +124,9 @@ var $ul = /* @__PURE__ */ html("ul");
|
|
|
288
124
|
var $var = /* @__PURE__ */ html("var");
|
|
289
125
|
var $video = /* @__PURE__ */ html("video");
|
|
290
126
|
var $wbr = /* @__PURE__ */ html("wbr");
|
|
291
|
-
// src/dom/mount.ts
|
|
292
|
-
function mount(app, target) {
|
|
293
|
-
if (target === null) throw new Error("[keits] mount(): the target element was not found (null).");
|
|
294
|
-
const start = hooks.marker();
|
|
295
|
-
const end = hooks.marker();
|
|
296
|
-
target.append(start, end);
|
|
297
|
-
const dispose = createRoot((dispose) => {
|
|
298
|
-
insert(target, app(), end);
|
|
299
|
-
return dispose;
|
|
300
|
-
});
|
|
301
|
-
return () => {
|
|
302
|
-
dispose();
|
|
303
|
-
let node = start;
|
|
304
|
-
while (node !== null) {
|
|
305
|
-
const next = node === end ? null : node.nextSibling;
|
|
306
|
-
node.remove();
|
|
307
|
-
node = next;
|
|
308
|
-
}
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
127
|
// src/dom/unsafe.ts
|
|
312
128
|
function unsafeHTML(markup) {
|
|
129
|
+
if (hooks.html !== void 0) return hooks.html(markup);
|
|
313
130
|
const template = document.createElement("template");
|
|
314
131
|
template.innerHTML = markup;
|
|
315
132
|
return template.content;
|
|
@@ -325,7 +142,7 @@ function createRow(build, item) {
|
|
|
325
142
|
first: result,
|
|
326
143
|
last: result
|
|
327
144
|
};
|
|
328
|
-
const holder =
|
|
145
|
+
const holder = hooks.fragment();
|
|
329
146
|
const first = hooks.marker();
|
|
330
147
|
const last = hooks.marker();
|
|
331
148
|
holder.append(first, last);
|
|
@@ -366,7 +183,7 @@ function removeRow(row) {
|
|
|
366
183
|
// src/flow/for.ts
|
|
367
184
|
function $for(each, render, options) {
|
|
368
185
|
const end = hooks.marker();
|
|
369
|
-
const container =
|
|
186
|
+
const container = hooks.fragment();
|
|
370
187
|
container.append(end);
|
|
371
188
|
let rows = [];
|
|
372
189
|
let fallback = null;
|
|
@@ -500,7 +317,7 @@ function $catch(children, fallback) {
|
|
|
500
317
|
const current = failure();
|
|
501
318
|
if (current !== null) return untrack(() => fallback(current.error, reset));
|
|
502
319
|
return untrack(() => catchError(() => {
|
|
503
|
-
const content =
|
|
320
|
+
const content = hooks.fragment();
|
|
504
321
|
insert(content, children());
|
|
505
322
|
return content;
|
|
506
323
|
}, (error) => failure.set({ error })));
|
|
@@ -508,14 +325,21 @@ function $catch(children, fallback) {
|
|
|
508
325
|
}
|
|
509
326
|
// src/flow/portal.ts
|
|
510
327
|
function $portal(children, target) {
|
|
511
|
-
if (isStaticRender())
|
|
328
|
+
if (isStaticRender()) {
|
|
329
|
+
nextKey();
|
|
330
|
+
return null;
|
|
331
|
+
}
|
|
512
332
|
const host = target === void 0 ? document.body : target;
|
|
513
333
|
if (host === null) throw new Error("[keits] $portal(): the target element was not found (null).");
|
|
514
334
|
const start = hooks.marker();
|
|
515
335
|
const end = hooks.marker();
|
|
516
336
|
host.append(start, end);
|
|
517
|
-
|
|
337
|
+
const disposeContent = createRoot((dispose) => {
|
|
338
|
+
withoutClaims(() => insert(host, untrack(children), end));
|
|
339
|
+
return dispose;
|
|
340
|
+
});
|
|
518
341
|
addCleanup(() => {
|
|
342
|
+
disposeContent();
|
|
519
343
|
let node = start;
|
|
520
344
|
while (node !== null) {
|
|
521
345
|
const next = node === end ? null : node.nextSibling;
|
|
@@ -525,8 +349,6 @@ function $portal(children, target) {
|
|
|
525
349
|
});
|
|
526
350
|
return null;
|
|
527
351
|
}
|
|
528
|
-
// src/async/suspense-context.ts
|
|
529
|
-
var SuspenseContext = createContext(null);
|
|
530
352
|
// src/flow/suspense.ts
|
|
531
353
|
function $suspense(children, fallback) {
|
|
532
354
|
const pendingCount = signal(0);
|
|
@@ -540,7 +362,7 @@ function $suspense(children, fallback) {
|
|
|
540
362
|
pendingCount.set((n) => n - 1);
|
|
541
363
|
});
|
|
542
364
|
} };
|
|
543
|
-
const offscreen =
|
|
365
|
+
const offscreen = hooks.fragment();
|
|
544
366
|
const contentStart = hooks.marker();
|
|
545
367
|
const contentEnd = hooks.marker();
|
|
546
368
|
offscreen.append(contentStart, contentEnd);
|
|
@@ -553,7 +375,7 @@ function $suspense(children, fallback) {
|
|
|
553
375
|
last: contentEnd
|
|
554
376
|
};
|
|
555
377
|
const end = hooks.marker();
|
|
556
|
-
const container =
|
|
378
|
+
const container = hooks.fragment();
|
|
557
379
|
container.append(end);
|
|
558
380
|
let fallbackRow = null;
|
|
559
381
|
addCleanup(() => fallbackRow?.dispose());
|
|
@@ -579,128 +401,6 @@ function $suspense(children, fallback) {
|
|
|
579
401
|
});
|
|
580
402
|
return container;
|
|
581
403
|
}
|
|
582
|
-
// src/async/resource.ts
|
|
583
|
-
function resource(first, second, third) {
|
|
584
|
-
const hasSource = typeof second === "function";
|
|
585
|
-
const source = hasSource ? first : () => true;
|
|
586
|
-
const fetcher = hasSource ? second : (_, info) => first(info);
|
|
587
|
-
const options = hasSource ? third : second;
|
|
588
|
-
const owner = getOwner$1();
|
|
589
|
-
const hasInitial = options !== void 0 && "initialValue" in options;
|
|
590
|
-
const value = signal(options?.initialValue);
|
|
591
|
-
const state = signal(hasInitial ? "ready" : "unresolved");
|
|
592
|
-
const failure = signal(null);
|
|
593
|
-
let controller = null;
|
|
594
|
-
let version = 0;
|
|
595
|
-
let waiters = [];
|
|
596
|
-
let currentSource = null;
|
|
597
|
-
const settleWaiters = () => {
|
|
598
|
-
const list = waiters;
|
|
599
|
-
waiters = [];
|
|
600
|
-
for (const done of list) done();
|
|
601
|
-
};
|
|
602
|
-
function load(src, refetching) {
|
|
603
|
-
controller?.abort();
|
|
604
|
-
controller = null;
|
|
605
|
-
const id = ++version;
|
|
606
|
-
if (src === null || src === void 0 || src === false) {
|
|
607
|
-
currentSource = null;
|
|
608
|
-
state.set(untrack(value) === void 0 ? "unresolved" : "ready");
|
|
609
|
-
settleWaiters();
|
|
610
|
-
return Promise.resolve();
|
|
611
|
-
}
|
|
612
|
-
currentSource = src;
|
|
613
|
-
const abort = new AbortController();
|
|
614
|
-
controller = abort;
|
|
615
|
-
let result;
|
|
616
|
-
try {
|
|
617
|
-
result = fetcher(src, {
|
|
618
|
-
signal: abort.signal,
|
|
619
|
-
refetching,
|
|
620
|
-
value: untrack(value)
|
|
621
|
-
});
|
|
622
|
-
} catch (error) {
|
|
623
|
-
fail(error);
|
|
624
|
-
return Promise.resolve();
|
|
625
|
-
}
|
|
626
|
-
if (!isPromiseLike(result)) {
|
|
627
|
-
succeed(result);
|
|
628
|
-
return Promise.resolve();
|
|
629
|
-
}
|
|
630
|
-
state.set(untrack(value) === void 0 && untrack(state) !== "ready" ? "pending" : "refreshing");
|
|
631
|
-
return Promise.resolve(result).then((data) => {
|
|
632
|
-
if (id === version) succeed(data);
|
|
633
|
-
}, (error) => {
|
|
634
|
-
if (id === version) fail(error);
|
|
635
|
-
});
|
|
636
|
-
}
|
|
637
|
-
function succeed(data) {
|
|
638
|
-
controller = null;
|
|
639
|
-
batch(() => {
|
|
640
|
-
value.set(() => data);
|
|
641
|
-
failure.set(null);
|
|
642
|
-
state.set("ready");
|
|
643
|
-
});
|
|
644
|
-
settleWaiters();
|
|
645
|
-
}
|
|
646
|
-
function fail(error) {
|
|
647
|
-
controller = null;
|
|
648
|
-
batch(() => {
|
|
649
|
-
failure.set({ error });
|
|
650
|
-
state.set("errored");
|
|
651
|
-
});
|
|
652
|
-
settleWaiters();
|
|
653
|
-
}
|
|
654
|
-
renderEffect(() => {
|
|
655
|
-
const src = source();
|
|
656
|
-
untrack(() => load(src, false));
|
|
657
|
-
});
|
|
658
|
-
addCleanup(() => {
|
|
659
|
-
version++;
|
|
660
|
-
controller?.abort();
|
|
661
|
-
controller = null;
|
|
662
|
-
});
|
|
663
|
-
const read = () => {
|
|
664
|
-
const current = state();
|
|
665
|
-
if (current === "errored") throw failure().error;
|
|
666
|
-
if (current === "pending") {
|
|
667
|
-
const boundary = useContext(SuspenseContext);
|
|
668
|
-
if (boundary !== null) boundary.wait(resourceApi, (done) => waiters.push(done));
|
|
669
|
-
}
|
|
670
|
-
return value();
|
|
671
|
-
};
|
|
672
|
-
const resourceApi = Object.assign(read, {
|
|
673
|
-
state: () => state(),
|
|
674
|
-
loading: () => {
|
|
675
|
-
const current = state();
|
|
676
|
-
return current === "pending" || current === "refreshing";
|
|
677
|
-
},
|
|
678
|
-
error: () => failure()?.error,
|
|
679
|
-
refetch: () => untrack(() => load(currentSource ?? source(), true)),
|
|
680
|
-
mutate: (next) => batch(() => {
|
|
681
|
-
value.set(() => next);
|
|
682
|
-
failure.set(null);
|
|
683
|
-
state.set(next === void 0 ? "unresolved" : "ready");
|
|
684
|
-
}),
|
|
685
|
-
optimistic: async (update, action) => {
|
|
686
|
-
const previous = untrack(value);
|
|
687
|
-
const next = update(previous);
|
|
688
|
-
value.set(() => next);
|
|
689
|
-
try {
|
|
690
|
-
await action();
|
|
691
|
-
return true;
|
|
692
|
-
} catch (error) {
|
|
693
|
-
if (untrack(value) === next) value.set(() => previous);
|
|
694
|
-
batch(() => handleError(error, owner));
|
|
695
|
-
return false;
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
});
|
|
699
|
-
return resourceApi;
|
|
700
|
-
}
|
|
701
|
-
function isPromiseLike(value) {
|
|
702
|
-
return typeof value?.then === "function";
|
|
703
|
-
}
|
|
704
404
|
// src/async/lazy.ts
|
|
705
405
|
function lazy(load) {
|
|
706
406
|
let loaded;
|
package/dist/dev/router.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
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";
|
|
3
5
|
// src/router/history.ts
|
|
4
6
|
var newKey = () => Math.random().toString(36).slice(2, 10);
|
|
5
7
|
var stateKey = () => window.history.state?.keitsKey ?? "start";
|
|
@@ -8,7 +10,7 @@ function browserHistory(base = "") {
|
|
|
8
10
|
return {
|
|
9
11
|
read() {
|
|
10
12
|
let path = window.location.pathname;
|
|
11
|
-
if (prefix !== "" && path.startsWith(prefix)) path = path.slice(prefix.length);
|
|
13
|
+
if (prefix !== "" && (path === prefix || path.startsWith(`${prefix}/`))) path = path.slice(prefix.length);
|
|
12
14
|
return {
|
|
13
15
|
path: path || "/",
|
|
14
16
|
search: window.location.search,
|
|
@@ -232,6 +234,23 @@ function fillParams(path, params) {
|
|
|
232
234
|
return encodeURIComponent(String(value));
|
|
233
235
|
});
|
|
234
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
|
+
}
|
|
235
254
|
// src/router/scroll.ts
|
|
236
255
|
function createScroller() {
|
|
237
256
|
const positions = /* @__PURE__ */ new Map();
|
|
@@ -266,7 +285,7 @@ function decodeHash(hash) {
|
|
|
266
285
|
}
|
|
267
286
|
// src/router/router.ts
|
|
268
287
|
function createRouter(config) {
|
|
269
|
-
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);
|
|
270
289
|
const owner = getOwner();
|
|
271
290
|
const branches = compileRoutes(config.routes);
|
|
272
291
|
const sameLocation = (a, b) => a.path === b.path && a.search === b.search && a.hash === b.hash;
|
|
@@ -440,4 +459,4 @@ function shallowEqual(a, b) {
|
|
|
440
459
|
if (keys.length !== Object.keys(b).length) return false;
|
|
441
460
|
return keys.every((key) => Object.is(a[key], b[key]));
|
|
442
461
|
}
|
|
443
|
-
export { browserHistory, createRouter, hashHistory, memoryHistory };
|
|
462
|
+
export { browserHistory, createRouter, hashHistory, memoryHistory, staticPaths };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { C as updateIfNeeded, r as adopt, x as track } from "./graph-SIvYLXSv.js";
|
|
2
|
+
// src/core/computed.ts
|
|
3
|
+
function computed(fn, options) {
|
|
4
|
+
const node = {
|
|
5
|
+
kind: 2,
|
|
6
|
+
fn,
|
|
7
|
+
value: void 0,
|
|
8
|
+
equals: options?.equals ?? Object.is,
|
|
9
|
+
hasValue: false,
|
|
10
|
+
hasError: false,
|
|
11
|
+
error: void 0,
|
|
12
|
+
computing: false,
|
|
13
|
+
state: 2,
|
|
14
|
+
sources: [],
|
|
15
|
+
observers: [],
|
|
16
|
+
seenBy: 0,
|
|
17
|
+
flushId: 0,
|
|
18
|
+
flushRuns: 0,
|
|
19
|
+
owner: null,
|
|
20
|
+
children: null,
|
|
21
|
+
cleanups: null,
|
|
22
|
+
disposed: false
|
|
23
|
+
};
|
|
24
|
+
if (options?.name !== void 0) node.name = options.name;
|
|
25
|
+
adopt(node);
|
|
26
|
+
return () => {
|
|
27
|
+
if (node.computing) throw cycleError(node);
|
|
28
|
+
if (node.state !== 0) updateIfNeeded(node);
|
|
29
|
+
track(node);
|
|
30
|
+
if (node.hasError) throw node.error;
|
|
31
|
+
return node.value;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function cycleError(node) {
|
|
35
|
+
{
|
|
36
|
+
const who = node.name ? `"${node.name}"` : "a computed";
|
|
37
|
+
return /* @__PURE__ */ new Error(`[keits] Cycle detected: ${who} reads itself (directly or through other computeds).`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export { computed as t };
|