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
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { _ as runWithOwner$1, c as getOwner$1, i as batch, l as giveKey, n as addMount, o as dispose, r as adopt, t as addCleanup, u as handleError, w as withStaticRender } from "./graph-SIvYLXSv.js";
|
|
2
|
+
// src/core/owner.ts
|
|
3
|
+
function getOwner() {
|
|
4
|
+
return getOwner$1();
|
|
5
|
+
}
|
|
6
|
+
function runWithOwner(owner, fn) {
|
|
7
|
+
return runWithOwner$1(owner, fn);
|
|
8
|
+
}
|
|
9
|
+
function createRoot(fn) {
|
|
10
|
+
const root = {
|
|
11
|
+
kind: 3,
|
|
12
|
+
owner: getOwner$1(),
|
|
13
|
+
children: null,
|
|
14
|
+
cleanups: null,
|
|
15
|
+
disposed: false,
|
|
16
|
+
handler: null
|
|
17
|
+
};
|
|
18
|
+
giveKey(root);
|
|
19
|
+
const disposeRoot = () => batch(() => dispose(root));
|
|
20
|
+
return batch(() => {
|
|
21
|
+
try {
|
|
22
|
+
return runWithOwner$1(root, () => fn(disposeRoot));
|
|
23
|
+
} catch (error) {
|
|
24
|
+
dispose(root);
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function keyedRoot(key, hydratable, fn) {
|
|
30
|
+
return createRoot((dispose) => {
|
|
31
|
+
const root = getOwner$1();
|
|
32
|
+
root.key = key;
|
|
33
|
+
root.keyCount = 0;
|
|
34
|
+
if (hydratable) root.hydratable = true;
|
|
35
|
+
return fn(dispose);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function onCleanup(fn) {
|
|
39
|
+
if (!addCleanup(fn) && true) console.warn("[keits] onCleanup was called outside an owner, so it will never run.");
|
|
40
|
+
}
|
|
41
|
+
function onMount(fn) {
|
|
42
|
+
addMount(fn);
|
|
43
|
+
}
|
|
44
|
+
function catchError(fn, handler) {
|
|
45
|
+
const boundary = {
|
|
46
|
+
kind: 3,
|
|
47
|
+
owner: null,
|
|
48
|
+
children: null,
|
|
49
|
+
cleanups: null,
|
|
50
|
+
disposed: false,
|
|
51
|
+
handler
|
|
52
|
+
};
|
|
53
|
+
adopt(boundary);
|
|
54
|
+
return batch(() => {
|
|
55
|
+
try {
|
|
56
|
+
return runWithOwner$1(boundary, fn);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
handleError(error, boundary);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function renderStatic(fn) {
|
|
64
|
+
return withStaticRender(() => createRoot((dispose) => {
|
|
65
|
+
try {
|
|
66
|
+
return fn();
|
|
67
|
+
} finally {
|
|
68
|
+
dispose();
|
|
69
|
+
}
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
export { onCleanup as a, runWithOwner as c, keyedRoot as i, createRoot as n, onMount as o, getOwner as r, renderStatic as s, catchError as t };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { _ as runWithOwner, c as getOwner, r as adopt } from "./graph-SIvYLXSv.js";
|
|
2
|
+
// src/core/context.ts
|
|
3
|
+
function createContext(defaultValue, options) {
|
|
4
|
+
const context = { defaultValue };
|
|
5
|
+
if (options?.name !== void 0) context.name = options.name;
|
|
6
|
+
return context;
|
|
7
|
+
}
|
|
8
|
+
function provide(context, value, fn) {
|
|
9
|
+
const provider = {
|
|
10
|
+
kind: 3,
|
|
11
|
+
owner: null,
|
|
12
|
+
children: null,
|
|
13
|
+
cleanups: null,
|
|
14
|
+
disposed: false,
|
|
15
|
+
handler: null,
|
|
16
|
+
context: {
|
|
17
|
+
key: context,
|
|
18
|
+
value
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
adopt(provider);
|
|
22
|
+
return runWithOwner(provider, fn);
|
|
23
|
+
}
|
|
24
|
+
function useContext(context) {
|
|
25
|
+
for (let o = getOwner(); o !== null; o = o.owner) if (o.kind === 3 && o.context?.key === context) return o.context.value;
|
|
26
|
+
return context.defaultValue;
|
|
27
|
+
}
|
|
28
|
+
// src/async/render-context.ts
|
|
29
|
+
var RenderContext = createContext(null);
|
|
30
|
+
var hydratedValue = null;
|
|
31
|
+
function setHydratedValue(lookup) {
|
|
32
|
+
hydratedValue = lookup;
|
|
33
|
+
}
|
|
34
|
+
export { provide as a, createContext as i, hydratedValue as n, useContext as o, setHydratedValue as r, RenderContext as t };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { c as getOwner, f as isStaticRender, g as runEffect, i as batch, m as nextKey, r as adopt } from "./graph-SIvYLXSv.js";
|
|
2
|
+
// src/core/effect.ts
|
|
3
|
+
function effect(fn, options) {
|
|
4
|
+
if (isStaticRender()) {
|
|
5
|
+
nextKey();
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
if (getOwner() === null) console.warn(`[keits] effect(${options?.name === void 0 ? "" : `"${options.name}"`}) was created outside a root (createRoot, mount, or a component): nothing will ever dispose it. Create it inside one.`);
|
|
9
|
+
createEffect(fn, options?.name);
|
|
10
|
+
}
|
|
11
|
+
function createEffect(fn, name) {
|
|
12
|
+
const node = {
|
|
13
|
+
kind: 1,
|
|
14
|
+
fn,
|
|
15
|
+
state: 0,
|
|
16
|
+
sources: [],
|
|
17
|
+
flushId: 0,
|
|
18
|
+
flushRuns: 0,
|
|
19
|
+
owner: null,
|
|
20
|
+
children: null,
|
|
21
|
+
cleanups: null,
|
|
22
|
+
disposed: false
|
|
23
|
+
};
|
|
24
|
+
if (name !== void 0) node.name = name;
|
|
25
|
+
adopt(node);
|
|
26
|
+
batch(() => runEffect(node));
|
|
27
|
+
}
|
|
28
|
+
// src/dom/render-effect.ts
|
|
29
|
+
function renderEffect(fn) {
|
|
30
|
+
createEffect(fn);
|
|
31
|
+
}
|
|
32
|
+
export { effect as n, renderEffect as t };
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { i as createContext, n as hydratedValue, o as useContext, t as RenderContext } from "./render-context-k2uu_dM_.js";
|
|
2
|
+
import { S as untrack, c as getOwner, i as batch, m as nextKey, s as getObserver, t as addCleanup, u as handleError } from "./graph-SIvYLXSv.js";
|
|
3
|
+
import { t as signal } from "./signal-B3xOKbVm.js";
|
|
4
|
+
import { t as renderEffect } from "./render-effect-Uk9dDmuU.js";
|
|
5
|
+
// src/async/suspense-context.ts
|
|
6
|
+
var SuspenseContext = createContext(null);
|
|
7
|
+
// src/async/resource.ts
|
|
8
|
+
function resource(first, second, third) {
|
|
9
|
+
const hasSource = typeof second === "function";
|
|
10
|
+
const source = hasSource ? first : () => true;
|
|
11
|
+
const fetcher = hasSource ? second : (_, info) => first(info);
|
|
12
|
+
const options = hasSource ? third : second;
|
|
13
|
+
const owner = getOwner();
|
|
14
|
+
const key = nextKey();
|
|
15
|
+
const tracker = useContext(RenderContext);
|
|
16
|
+
const hydrated = key !== null && tracker === null ? hydratedValue?.(key) : void 0;
|
|
17
|
+
const hasInitial = hydrated !== void 0 || options !== void 0 && "initialValue" in options;
|
|
18
|
+
const value = signal(hydrated !== void 0 ? hydrated.value : options?.initialValue);
|
|
19
|
+
const state = signal(hasInitial ? "ready" : "unresolved");
|
|
20
|
+
const failure = signal(null);
|
|
21
|
+
let controller = null;
|
|
22
|
+
let version = 0;
|
|
23
|
+
let waiters = [];
|
|
24
|
+
let currentSource = null;
|
|
25
|
+
const settleWaiters = () => {
|
|
26
|
+
const list = waiters;
|
|
27
|
+
waiters = [];
|
|
28
|
+
for (const done of list) done();
|
|
29
|
+
};
|
|
30
|
+
function load(src, refetching) {
|
|
31
|
+
controller?.abort();
|
|
32
|
+
controller = null;
|
|
33
|
+
const id = ++version;
|
|
34
|
+
if (src === null || src === void 0 || src === false) {
|
|
35
|
+
currentSource = null;
|
|
36
|
+
state.set(untrack(value) === void 0 ? "unresolved" : "ready");
|
|
37
|
+
settleWaiters();
|
|
38
|
+
return Promise.resolve();
|
|
39
|
+
}
|
|
40
|
+
currentSource = src;
|
|
41
|
+
const abort = new AbortController();
|
|
42
|
+
controller = abort;
|
|
43
|
+
let result;
|
|
44
|
+
try {
|
|
45
|
+
result = fetcher(src, {
|
|
46
|
+
signal: abort.signal,
|
|
47
|
+
refetching,
|
|
48
|
+
value: untrack(value)
|
|
49
|
+
});
|
|
50
|
+
} catch (error) {
|
|
51
|
+
fail(error);
|
|
52
|
+
return Promise.resolve();
|
|
53
|
+
}
|
|
54
|
+
if (!isPromiseLike(result)) {
|
|
55
|
+
succeed(result);
|
|
56
|
+
return Promise.resolve();
|
|
57
|
+
}
|
|
58
|
+
state.set(untrack(value) === void 0 && untrack(state) !== "ready" ? "pending" : "refreshing");
|
|
59
|
+
const loading = Promise.resolve(result).then((data) => {
|
|
60
|
+
if (id === version) succeed(data);
|
|
61
|
+
}, (error) => {
|
|
62
|
+
if (id === version) fail(error);
|
|
63
|
+
});
|
|
64
|
+
tracker?.wait(loading);
|
|
65
|
+
return loading;
|
|
66
|
+
}
|
|
67
|
+
function succeed(data) {
|
|
68
|
+
controller = null;
|
|
69
|
+
if (key !== null) tracker?.store(key, data, owner);
|
|
70
|
+
batch(() => {
|
|
71
|
+
value.set(() => data);
|
|
72
|
+
failure.set(null);
|
|
73
|
+
state.set("ready");
|
|
74
|
+
});
|
|
75
|
+
settleWaiters();
|
|
76
|
+
}
|
|
77
|
+
function fail(error) {
|
|
78
|
+
controller = null;
|
|
79
|
+
batch(() => {
|
|
80
|
+
failure.set({ error });
|
|
81
|
+
state.set("errored");
|
|
82
|
+
});
|
|
83
|
+
settleWaiters();
|
|
84
|
+
}
|
|
85
|
+
let skipFirst = hydrated !== void 0;
|
|
86
|
+
renderEffect(() => {
|
|
87
|
+
const src = source();
|
|
88
|
+
if (skipFirst) {
|
|
89
|
+
skipFirst = false;
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
untrack(() => load(src, false));
|
|
93
|
+
});
|
|
94
|
+
addCleanup(() => {
|
|
95
|
+
version++;
|
|
96
|
+
controller?.abort();
|
|
97
|
+
controller = null;
|
|
98
|
+
});
|
|
99
|
+
let warned = false;
|
|
100
|
+
const read = () => {
|
|
101
|
+
if (!warned && owner !== null && getObserver() === owner) {
|
|
102
|
+
warned = true;
|
|
103
|
+
console.warn("[keits] A resource is read inside the same `() =>` function that created it. When its data arrives that function runs again and creates a new resource, which loads again: an endless loop. Create the resource in the component body, and read it inside `() =>`.");
|
|
104
|
+
}
|
|
105
|
+
const current = state();
|
|
106
|
+
if (current === "errored") throw failure().error;
|
|
107
|
+
if (current === "pending") {
|
|
108
|
+
const boundary = useContext(SuspenseContext);
|
|
109
|
+
if (boundary !== null) boundary.wait(resourceApi, (done) => waiters.push(done));
|
|
110
|
+
}
|
|
111
|
+
return value();
|
|
112
|
+
};
|
|
113
|
+
const resourceApi = Object.assign(read, {
|
|
114
|
+
state: () => state(),
|
|
115
|
+
loading: () => {
|
|
116
|
+
const current = state();
|
|
117
|
+
return current === "pending" || current === "refreshing";
|
|
118
|
+
},
|
|
119
|
+
error: () => failure()?.error,
|
|
120
|
+
refetch: () => untrack(() => load(currentSource ?? source(), true)),
|
|
121
|
+
mutate: (next) => batch(() => {
|
|
122
|
+
value.set(() => next);
|
|
123
|
+
failure.set(null);
|
|
124
|
+
state.set(next === void 0 ? "unresolved" : "ready");
|
|
125
|
+
}),
|
|
126
|
+
optimistic: async (update, action) => {
|
|
127
|
+
const previous = untrack(value);
|
|
128
|
+
const next = update(previous);
|
|
129
|
+
value.set(() => next);
|
|
130
|
+
try {
|
|
131
|
+
await action();
|
|
132
|
+
return true;
|
|
133
|
+
} catch (error) {
|
|
134
|
+
if (untrack(value) === next) value.set(() => previous);
|
|
135
|
+
batch(() => handleError(error, owner));
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
return resourceApi;
|
|
141
|
+
}
|
|
142
|
+
function isPromiseLike(value) {
|
|
143
|
+
return typeof value?.then === "function";
|
|
144
|
+
}
|
|
145
|
+
export { SuspenseContext as n, resource as t };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { h as notify, x as track } from "./graph-SIvYLXSv.js";
|
|
2
|
+
// src/core/signal.ts
|
|
3
|
+
function signal(value, options) {
|
|
4
|
+
const node = {
|
|
5
|
+
kind: 0,
|
|
6
|
+
value,
|
|
7
|
+
equals: options?.equals ?? Object.is,
|
|
8
|
+
observers: [],
|
|
9
|
+
seenBy: 0
|
|
10
|
+
};
|
|
11
|
+
if (options?.name !== void 0) node.name = options.name;
|
|
12
|
+
const read = () => {
|
|
13
|
+
track(node);
|
|
14
|
+
return node.value;
|
|
15
|
+
};
|
|
16
|
+
const set = (next) => {
|
|
17
|
+
const value = typeof next === "function" ? next(node.value) : next;
|
|
18
|
+
if (node.equals !== false && node.equals(node.value, value)) return;
|
|
19
|
+
node.value = value;
|
|
20
|
+
notify(node);
|
|
21
|
+
};
|
|
22
|
+
return Object.assign(read, { set });
|
|
23
|
+
}
|
|
24
|
+
export { signal as t };
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { t as UNSAFE_KEYS } from "./unsafe-keys-CB1P22No.js";
|
|
2
|
+
import { S as untrack, h as notify, i as batch, p as isTracking, x as track } from "./graph-SIvYLXSv.js";
|
|
3
|
+
// src/core/store.ts
|
|
4
|
+
var RAW = Symbol("raw");
|
|
5
|
+
var SHAPE = Symbol("shape");
|
|
6
|
+
var proxies = /* @__PURE__ */ new WeakMap();
|
|
7
|
+
var nodeMaps = /* @__PURE__ */ new WeakMap();
|
|
8
|
+
var writing = 0;
|
|
9
|
+
function store(initial, options) {
|
|
10
|
+
const state = wrap(initial);
|
|
11
|
+
const name = options?.name;
|
|
12
|
+
const setState = (fn) => {
|
|
13
|
+
writing++;
|
|
14
|
+
try {
|
|
15
|
+
untrack(() => batch(() => fn(state)));
|
|
16
|
+
} finally {
|
|
17
|
+
writing--;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
if (name !== void 0) storeNames.set(unwrap(state), name);
|
|
21
|
+
return [state, setState];
|
|
22
|
+
}
|
|
23
|
+
var storeNames = /* @__PURE__ */ new WeakMap();
|
|
24
|
+
function unwrap(value) {
|
|
25
|
+
if (value !== null && typeof value === "object") {
|
|
26
|
+
const raw = value[RAW];
|
|
27
|
+
if (raw !== void 0) return raw;
|
|
28
|
+
}
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
function isWrappable(value) {
|
|
32
|
+
if (value === null || typeof value !== "object" || value === Object.prototype) return false;
|
|
33
|
+
if (Array.isArray(value)) return true;
|
|
34
|
+
const proto = Object.getPrototypeOf(value);
|
|
35
|
+
return proto === Object.prototype || proto === null;
|
|
36
|
+
}
|
|
37
|
+
function wrap(value) {
|
|
38
|
+
if (!isWrappable(value)) return value;
|
|
39
|
+
let proxy = proxies.get(value);
|
|
40
|
+
if (proxy === void 0) {
|
|
41
|
+
proxy = new Proxy(value, handler);
|
|
42
|
+
proxies.set(value, proxy);
|
|
43
|
+
}
|
|
44
|
+
return proxy;
|
|
45
|
+
}
|
|
46
|
+
function getNode(target, key) {
|
|
47
|
+
let nodes = nodeMaps.get(target);
|
|
48
|
+
if (nodes === void 0) nodeMaps.set(target, nodes = /* @__PURE__ */ new Map());
|
|
49
|
+
let node = nodes.get(key);
|
|
50
|
+
if (node === void 0) nodes.set(key, node = {
|
|
51
|
+
kind: 0,
|
|
52
|
+
observers: [],
|
|
53
|
+
seenBy: 0
|
|
54
|
+
});
|
|
55
|
+
return node;
|
|
56
|
+
}
|
|
57
|
+
function notifyKey(target, key) {
|
|
58
|
+
const node = nodeMaps.get(target)?.get(key);
|
|
59
|
+
if (node !== void 0) notify(node);
|
|
60
|
+
}
|
|
61
|
+
function readOnlyError(target) {
|
|
62
|
+
const name = storeNames.get(target);
|
|
63
|
+
return /* @__PURE__ */ new Error(`[keits] Store${name ? ` "${name}"` : ""} is read-only here. Change it inside setState(draft => { ... }).`);
|
|
64
|
+
}
|
|
65
|
+
var handler = {
|
|
66
|
+
get(target, key) {
|
|
67
|
+
if (key === RAW) return target;
|
|
68
|
+
const value = target[key];
|
|
69
|
+
if (isTracking() && (Object.hasOwn(target, key) || !(key in target))) track(getNode(target, key));
|
|
70
|
+
return wrap(value);
|
|
71
|
+
},
|
|
72
|
+
has(target, key) {
|
|
73
|
+
if (isTracking()) track(getNode(target, key));
|
|
74
|
+
return key in target;
|
|
75
|
+
},
|
|
76
|
+
ownKeys(target) {
|
|
77
|
+
if (isTracking()) track(getNode(target, SHAPE));
|
|
78
|
+
return Reflect.ownKeys(target);
|
|
79
|
+
},
|
|
80
|
+
set(target, key, value) {
|
|
81
|
+
if (writing === 0) {
|
|
82
|
+
const error = readOnlyError(target);
|
|
83
|
+
if (error) throw error;
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
const record = target;
|
|
87
|
+
const next = unwrap(value);
|
|
88
|
+
const hadKey = Object.hasOwn(target, key);
|
|
89
|
+
const prev = record[key];
|
|
90
|
+
const isArray = Array.isArray(target);
|
|
91
|
+
const prevLength = isArray ? target.length : 0;
|
|
92
|
+
if (hadKey && Object.is(prev, next)) return true;
|
|
93
|
+
record[key] = next;
|
|
94
|
+
notifyKey(target, key);
|
|
95
|
+
if (!hadKey) notifyKey(target, SHAPE);
|
|
96
|
+
if (isArray) {
|
|
97
|
+
const length = target.length;
|
|
98
|
+
if (length !== prevLength) {
|
|
99
|
+
if (key !== "length") notifyKey(target, "length");
|
|
100
|
+
notifyKey(target, SHAPE);
|
|
101
|
+
for (let i = length; i < prevLength; i++) notifyKey(target, String(i));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return true;
|
|
105
|
+
},
|
|
106
|
+
deleteProperty(target, key) {
|
|
107
|
+
if (writing === 0) {
|
|
108
|
+
const error = readOnlyError(target);
|
|
109
|
+
if (error) throw error;
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
if (!Object.hasOwn(target, key)) return true;
|
|
113
|
+
delete target[key];
|
|
114
|
+
notifyKey(target, key);
|
|
115
|
+
notifyKey(target, SHAPE);
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
function reconcile(target, source, options = {}) {
|
|
120
|
+
if (writing === 0) throw new Error("[keits] reconcile() must be called inside setState.");
|
|
121
|
+
reconcileInto(wrap(unwrap(target)), unwrap(source), options.key);
|
|
122
|
+
}
|
|
123
|
+
function reconcileInto(target, source, key) {
|
|
124
|
+
const raw = unwrap(target);
|
|
125
|
+
const draft = target;
|
|
126
|
+
if (Array.isArray(raw) && Array.isArray(source)) {
|
|
127
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
128
|
+
if (key !== void 0) {
|
|
129
|
+
for (const item of raw) if (isWrappable(item)) byKey.set(item[key], item);
|
|
130
|
+
}
|
|
131
|
+
for (let i = 0; i < source.length; i++) {
|
|
132
|
+
const next = source[i];
|
|
133
|
+
const existing = key !== void 0 && isWrappable(next) ? byKey.get(next[key]) : raw[i];
|
|
134
|
+
draft[i] = matchAndUpdate(existing, next, key);
|
|
135
|
+
}
|
|
136
|
+
if (raw.length !== source.length) draft.length = source.length;
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
for (const k of Object.keys(source)) {
|
|
140
|
+
if (UNSAFE_KEYS.has(k)) continue;
|
|
141
|
+
draft[k] = matchAndUpdate(raw[k], source[k], key);
|
|
142
|
+
}
|
|
143
|
+
for (const k of Object.keys(raw)) if (!Object.hasOwn(source, k)) delete draft[k];
|
|
144
|
+
}
|
|
145
|
+
function matchAndUpdate(existing, next, key) {
|
|
146
|
+
if (isWrappable(existing) && isWrappable(next) && Array.isArray(existing) === Array.isArray(next)) {
|
|
147
|
+
reconcileInto(wrap(existing), next, key);
|
|
148
|
+
return existing;
|
|
149
|
+
}
|
|
150
|
+
return next;
|
|
151
|
+
}
|
|
152
|
+
export { store as n, unwrap as r, reconcile as t };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { i as head, r as renderToString, t as hydrate } from "./shared/hydrate-C8cOsDDH.js";
|
|
2
|
+
import { c as getOwner, f as isStaticRender } from "./shared/graph-SIvYLXSv.js";
|
|
3
|
+
import { a as onCleanup, n as createRoot } from "./shared/owner-BuwIoI4j.js";
|
|
4
|
+
import { a as hooks, n as insert } from "./shared/namespaces-Cz82B0Pr.js";
|
|
5
|
+
// src/static/island.ts
|
|
6
|
+
function island(name, component, options = {}) {
|
|
7
|
+
const render = (props) => {
|
|
8
|
+
const element = hooks.element("keits-island", null);
|
|
9
|
+
element.setAttribute("data-island", name);
|
|
10
|
+
element.setAttribute("style", "display: contents");
|
|
11
|
+
if (options.when !== void 0 && options.when !== "load") element.setAttribute("data-when", options.when);
|
|
12
|
+
const dispose = createRoot((end) => {
|
|
13
|
+
const root = getOwner();
|
|
14
|
+
if (isStaticRender()) {
|
|
15
|
+
root.hydratable = true;
|
|
16
|
+
if (root.key !== void 0) element.setAttribute("data-key", root.key);
|
|
17
|
+
element.setAttribute("data-props", propsJson(name, props));
|
|
18
|
+
}
|
|
19
|
+
insert(element, component(props));
|
|
20
|
+
return end;
|
|
21
|
+
});
|
|
22
|
+
onCleanup(dispose);
|
|
23
|
+
return element;
|
|
24
|
+
};
|
|
25
|
+
return Object.assign(render, {
|
|
26
|
+
island: name,
|
|
27
|
+
component
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function propsJson(name, props) {
|
|
31
|
+
JSON.stringify(props ?? {}, (key, value) => {
|
|
32
|
+
if (typeof value === "function" || typeof value === "symbol") throw new Error(`[keits/static] Island "${name}": prop "${key}" is a ${typeof value}. Island props travel in the HTML, so they must be JSON.`);
|
|
33
|
+
return value;
|
|
34
|
+
});
|
|
35
|
+
return JSON.stringify(props ?? {});
|
|
36
|
+
}
|
|
37
|
+
function hydrateIslands(islands, root = document) {
|
|
38
|
+
for (const element of root.querySelectorAll("keits-island[data-key]")) {
|
|
39
|
+
if (element.parentElement?.closest("keits-island") != null) continue;
|
|
40
|
+
const name = element.getAttribute("data-island") ?? "";
|
|
41
|
+
const entry = Object.hasOwn(islands, name) ? islands[name] : void 0;
|
|
42
|
+
if (entry === void 0) {
|
|
43
|
+
console.warn(`[keits] hydrateIslands(): no island called "${name}" was given, so it stays static.`);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const start = () => {
|
|
47
|
+
if ("island" in entry) return hydrateIsland(element, entry);
|
|
48
|
+
Promise.resolve(entry()).then((loaded) => hydrateIsland(element, "island" in loaded ? loaded : loaded.default), (error) => setTimeout(() => {
|
|
49
|
+
throw error;
|
|
50
|
+
}));
|
|
51
|
+
};
|
|
52
|
+
when(element, element.getAttribute("data-when") ?? "load", start);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function hydrateIsland(element, found) {
|
|
56
|
+
const key = element.getAttribute("data-key");
|
|
57
|
+
const props = JSON.parse(element.getAttribute("data-props") ?? "{}");
|
|
58
|
+
element.removeAttribute("data-key");
|
|
59
|
+
element.removeAttribute("data-props");
|
|
60
|
+
hydrate(() => found.component(props), element, key);
|
|
61
|
+
}
|
|
62
|
+
function when(element, moment, start) {
|
|
63
|
+
if (moment === "visible" && typeof IntersectionObserver === "function") {
|
|
64
|
+
const observer = new IntersectionObserver((entries) => {
|
|
65
|
+
if (entries.some((entry) => entry.isIntersecting)) {
|
|
66
|
+
observer.disconnect();
|
|
67
|
+
start();
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
for (const child of element.children) observer.observe(child);
|
|
71
|
+
if (element.children.length === 0) start();
|
|
72
|
+
} else if (moment === "idle" && typeof requestIdleCallback === "function") requestIdleCallback(() => start());
|
|
73
|
+
else if (moment === "idle") setTimeout(start, 1);
|
|
74
|
+
else start();
|
|
75
|
+
}
|
|
76
|
+
export { head, hydrate, hydrateIslands, island, renderToString };
|
package/dist/dev/svg.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as createFactory } from "./shared/element-DXwmUAnz.js";
|
|
2
|
+
import { t as SVG_NS } from "./shared/namespaces-Cz82B0Pr.js";
|
|
2
3
|
// src/svg/element.ts
|
|
3
4
|
function svg(tag) {
|
|
4
5
|
return createFactory(tag, SVG_NS);
|