keits 0.0.2 → 0.0.4
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/dist/dev/api.js +270 -0
- package/dist/dev/forms.js +328 -0
- package/dist/dev/index.js +290 -294
- package/dist/dev/router.js +445 -0
- package/dist/dev/shared/computed-3UO-KiH1.js +40 -0
- package/dist/dev/shared/element-CQPqagu1.js +222 -0
- package/dist/dev/shared/graph-D6-x_CWC.js +324 -0
- package/dist/dev/shared/owner-Dmge21OW.js +62 -0
- package/dist/dev/shared/render-effect-kOGnLNbL.js +26 -0
- package/dist/dev/shared/resource-CbXVATvq.js +154 -0
- package/dist/dev/shared/signal-BOXkY-Iv.js +24 -0
- package/dist/dev/shared/store-BzUN1qE5.js +148 -0
- package/dist/dev/svg.js +1 -1
- package/dist/prod/api.js +210 -0
- package/dist/prod/forms.js +237 -0
- package/dist/prod/index.js +209 -234
- package/dist/prod/router.js +345 -0
- package/dist/prod/shared/computed-CAPpOLCY.js +33 -0
- package/dist/prod/shared/element-DGyQ01Vs.js +164 -0
- package/dist/prod/shared/graph-C_aA46c6.js +240 -0
- package/dist/prod/shared/owner-6BFHIPR9.js +59 -0
- package/dist/prod/shared/render-effect-DjaUT3Cn.js +23 -0
- package/dist/prod/shared/resource-CNC2DBO3.js +109 -0
- package/dist/prod/shared/signal-DGrl3r9T.js +16 -0
- package/dist/prod/shared/store-Dcscpk_h.js +109 -0
- package/dist/prod/svg.js +1 -1
- 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/index.d.ts +2 -0
- package/dist/types/async/lazy.d.ts +7 -0
- package/dist/types/async/resource.d.ts +23 -0
- package/dist/types/async/suspense-context.d.ts +4 -0
- package/dist/types/core/graph.d.ts +8 -0
- package/dist/types/dom/types.d.ts +1 -1
- package/dist/types/flow/catch.d.ts +2 -0
- package/dist/types/flow/dynamic.d.ts +6 -0
- package/dist/types/flow/for.d.ts +7 -0
- package/dist/types/flow/if.d.ts +4 -0
- package/dist/types/flow/index.d.ts +8 -0
- package/dist/types/flow/portal.d.ts +2 -0
- package/dist/types/flow/range.d.ts +11 -0
- package/dist/types/flow/show.d.ts +1 -0
- package/dist/types/flow/suspense.d.ts +2 -0
- package/dist/types/flow/switch.d.ts +9 -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/index.d.ts +2 -0
- package/dist/types/router/history.d.ts +21 -0
- package/dist/types/router/index.d.ts +3 -0
- package/dist/types/router/links.d.ts +1 -0
- package/dist/types/router/match.d.ts +15 -0
- package/dist/types/router/router.d.ts +10 -0
- package/dist/types/router/scroll.d.ts +5 -0
- package/dist/types/router/types.d.ts +87 -0
- package/dist/types/svg/types.d.ts +1 -1
- package/package.json +37 -6
- package/dist/dev/shared/element-By0uLZli.js +0 -544
- package/dist/prod/shared/element-C8c5hIhH.js +0 -394
package/dist/dev/index.js
CHANGED
|
@@ -1,298 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
// src/core/computed.ts
|
|
25
|
-
function computed(fn, options) {
|
|
26
|
-
const node = {
|
|
27
|
-
kind: 2,
|
|
28
|
-
fn,
|
|
29
|
-
value: void 0,
|
|
30
|
-
equals: options?.equals ?? Object.is,
|
|
31
|
-
hasValue: false,
|
|
32
|
-
hasError: false,
|
|
33
|
-
error: void 0,
|
|
34
|
-
computing: false,
|
|
35
|
-
state: 2,
|
|
36
|
-
sources: [],
|
|
37
|
-
observers: [],
|
|
38
|
-
seenBy: 0,
|
|
39
|
-
flushId: 0,
|
|
40
|
-
flushRuns: 0,
|
|
41
|
-
owner: null,
|
|
42
|
-
children: null,
|
|
43
|
-
cleanups: null,
|
|
44
|
-
disposed: false
|
|
45
|
-
};
|
|
46
|
-
if (options?.name !== void 0) node.name = options.name;
|
|
47
|
-
adopt(node);
|
|
48
|
-
return () => {
|
|
49
|
-
if (node.computing) throw cycleError(node);
|
|
50
|
-
if (node.state !== 0) updateIfNeeded(node);
|
|
51
|
-
track(node);
|
|
52
|
-
if (node.hasError) throw node.error;
|
|
53
|
-
return node.value;
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
function cycleError(node) {
|
|
57
|
-
{
|
|
58
|
-
const who = node.name ? `"${node.name}"` : "a computed";
|
|
59
|
-
return /* @__PURE__ */ new Error(`[keits] Cycle detected: ${who} reads itself (directly or through other computeds).`);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
1
|
+
import { t as signal } from "./shared/signal-BOXkY-Iv.js";
|
|
2
|
+
import { n as effect, t as renderEffect } from "./shared/render-effect-kOGnLNbL.js";
|
|
3
|
+
import { t as computed } from "./shared/computed-3UO-KiH1.js";
|
|
4
|
+
import { a as deferMounts, h as untrack, i as batch, l as isStaticRender, t as addCleanup } from "./shared/graph-D6-x_CWC.js";
|
|
5
|
+
import { a as onMount, i as onCleanup, n as createRoot, o as renderStatic, r as getOwner, s as runWithOwner, t as catchError } from "./shared/owner-Dmge21OW.js";
|
|
6
|
+
import { a as useContext, i as provide, n as SuspenseContext, r as createContext, t as resource } from "./shared/resource-CbXVATvq.js";
|
|
7
|
+
import { n as store, r as unwrap, t as reconcile } from "./shared/store-BzUN1qE5.js";
|
|
8
|
+
import { a as hooks, i as insert, n as html } from "./shared/element-CQPqagu1.js";
|
|
62
9
|
// src/core/env.ts
|
|
63
10
|
var isServer = typeof window === "undefined";
|
|
64
|
-
// src/core/owner.ts
|
|
65
|
-
function getOwner() {
|
|
66
|
-
return getOwner$1();
|
|
67
|
-
}
|
|
68
|
-
function runWithOwner(owner, fn) {
|
|
69
|
-
return runWithOwner$1(owner, fn);
|
|
70
|
-
}
|
|
71
|
-
function createRoot(fn) {
|
|
72
|
-
const root = {
|
|
73
|
-
kind: 3,
|
|
74
|
-
owner: getOwner$1(),
|
|
75
|
-
children: null,
|
|
76
|
-
cleanups: null,
|
|
77
|
-
disposed: false,
|
|
78
|
-
handler: null
|
|
79
|
-
};
|
|
80
|
-
const disposeRoot = () => batch(() => dispose(root));
|
|
81
|
-
return batch(() => {
|
|
82
|
-
try {
|
|
83
|
-
return runWithOwner$1(root, () => fn(disposeRoot));
|
|
84
|
-
} catch (error) {
|
|
85
|
-
dispose(root);
|
|
86
|
-
throw error;
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
function onCleanup(fn) {
|
|
91
|
-
if (!addCleanup(fn) && true) console.warn("[keits] onCleanup was called outside an owner, so it will never run.");
|
|
92
|
-
}
|
|
93
|
-
function onMount(fn) {
|
|
94
|
-
addMount(fn);
|
|
95
|
-
}
|
|
96
|
-
function catchError(fn, handler) {
|
|
97
|
-
const boundary = {
|
|
98
|
-
kind: 3,
|
|
99
|
-
owner: null,
|
|
100
|
-
children: null,
|
|
101
|
-
cleanups: null,
|
|
102
|
-
disposed: false,
|
|
103
|
-
handler
|
|
104
|
-
};
|
|
105
|
-
adopt(boundary);
|
|
106
|
-
return batch(() => {
|
|
107
|
-
try {
|
|
108
|
-
return runWithOwner$1(boundary, fn);
|
|
109
|
-
} catch (error) {
|
|
110
|
-
handleError(error, boundary);
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
function renderStatic(fn) {
|
|
116
|
-
return withStaticRender(() => createRoot((dispose) => {
|
|
117
|
-
try {
|
|
118
|
-
return fn();
|
|
119
|
-
} finally {
|
|
120
|
-
dispose();
|
|
121
|
-
}
|
|
122
|
-
}));
|
|
123
|
-
}
|
|
124
|
-
// src/core/context.ts
|
|
125
|
-
function createContext(defaultValue, options) {
|
|
126
|
-
const context = { defaultValue };
|
|
127
|
-
if (options?.name !== void 0) context.name = options.name;
|
|
128
|
-
return context;
|
|
129
|
-
}
|
|
130
|
-
function provide(context, value, fn) {
|
|
131
|
-
const provider = {
|
|
132
|
-
kind: 3,
|
|
133
|
-
owner: null,
|
|
134
|
-
children: null,
|
|
135
|
-
cleanups: null,
|
|
136
|
-
disposed: false,
|
|
137
|
-
handler: null,
|
|
138
|
-
context: {
|
|
139
|
-
key: context,
|
|
140
|
-
value
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
adopt(provider);
|
|
144
|
-
return runWithOwner$1(provider, fn);
|
|
145
|
-
}
|
|
146
|
-
function useContext(context) {
|
|
147
|
-
for (let o = getOwner$1(); o !== null; o = o.owner) if (o.kind === 3 && o.context?.key === context) return o.context.value;
|
|
148
|
-
return context.defaultValue;
|
|
149
|
-
}
|
|
150
|
-
// src/core/store.ts
|
|
151
|
-
var RAW = Symbol("raw");
|
|
152
|
-
var SHAPE = Symbol("shape");
|
|
153
|
-
var proxies = /* @__PURE__ */ new WeakMap();
|
|
154
|
-
var nodeMaps = /* @__PURE__ */ new WeakMap();
|
|
155
|
-
var writing = 0;
|
|
156
|
-
function store(initial, options) {
|
|
157
|
-
const state = wrap(initial);
|
|
158
|
-
const name = options?.name;
|
|
159
|
-
const setState = (fn) => {
|
|
160
|
-
writing++;
|
|
161
|
-
try {
|
|
162
|
-
untrack(() => batch(() => fn(state)));
|
|
163
|
-
} finally {
|
|
164
|
-
writing--;
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
if (name !== void 0) storeNames.set(unwrap(state), name);
|
|
168
|
-
return [state, setState];
|
|
169
|
-
}
|
|
170
|
-
var storeNames = /* @__PURE__ */ new WeakMap();
|
|
171
|
-
function unwrap(value) {
|
|
172
|
-
if (value !== null && typeof value === "object") {
|
|
173
|
-
const raw = value[RAW];
|
|
174
|
-
if (raw !== void 0) return raw;
|
|
175
|
-
}
|
|
176
|
-
return value;
|
|
177
|
-
}
|
|
178
|
-
function isWrappable(value) {
|
|
179
|
-
if (value === null || typeof value !== "object") return false;
|
|
180
|
-
if (Array.isArray(value)) return true;
|
|
181
|
-
const proto = Object.getPrototypeOf(value);
|
|
182
|
-
return proto === Object.prototype || proto === null;
|
|
183
|
-
}
|
|
184
|
-
function wrap(value) {
|
|
185
|
-
if (!isWrappable(value)) return value;
|
|
186
|
-
let proxy = proxies.get(value);
|
|
187
|
-
if (proxy === void 0) {
|
|
188
|
-
proxy = new Proxy(value, handler);
|
|
189
|
-
proxies.set(value, proxy);
|
|
190
|
-
}
|
|
191
|
-
return proxy;
|
|
192
|
-
}
|
|
193
|
-
function getNode(target, key) {
|
|
194
|
-
let nodes = nodeMaps.get(target);
|
|
195
|
-
if (nodes === void 0) nodeMaps.set(target, nodes = /* @__PURE__ */ new Map());
|
|
196
|
-
let node = nodes.get(key);
|
|
197
|
-
if (node === void 0) nodes.set(key, node = {
|
|
198
|
-
kind: 0,
|
|
199
|
-
observers: [],
|
|
200
|
-
seenBy: 0
|
|
201
|
-
});
|
|
202
|
-
return node;
|
|
203
|
-
}
|
|
204
|
-
function notifyKey(target, key) {
|
|
205
|
-
const node = nodeMaps.get(target)?.get(key);
|
|
206
|
-
if (node !== void 0) notify(node);
|
|
207
|
-
}
|
|
208
|
-
function readOnlyError(target) {
|
|
209
|
-
const name = storeNames.get(target);
|
|
210
|
-
return /* @__PURE__ */ new Error(`[keits] Store${name ? ` "${name}"` : ""} is read-only here. Change it inside setState(draft => { ... }).`);
|
|
211
|
-
}
|
|
212
|
-
var handler = {
|
|
213
|
-
get(target, key) {
|
|
214
|
-
if (key === RAW) return target;
|
|
215
|
-
const value = target[key];
|
|
216
|
-
if (isTracking() && (Object.hasOwn(target, key) || !(key in target))) track(getNode(target, key));
|
|
217
|
-
return wrap(value);
|
|
218
|
-
},
|
|
219
|
-
has(target, key) {
|
|
220
|
-
if (isTracking()) track(getNode(target, key));
|
|
221
|
-
return key in target;
|
|
222
|
-
},
|
|
223
|
-
ownKeys(target) {
|
|
224
|
-
if (isTracking()) track(getNode(target, SHAPE));
|
|
225
|
-
return Reflect.ownKeys(target);
|
|
226
|
-
},
|
|
227
|
-
set(target, key, value) {
|
|
228
|
-
if (writing === 0) {
|
|
229
|
-
const error = readOnlyError(target);
|
|
230
|
-
if (error) throw error;
|
|
231
|
-
return false;
|
|
232
|
-
}
|
|
233
|
-
const record = target;
|
|
234
|
-
const next = unwrap(value);
|
|
235
|
-
const hadKey = Object.hasOwn(target, key);
|
|
236
|
-
const prev = record[key];
|
|
237
|
-
const isArray = Array.isArray(target);
|
|
238
|
-
const prevLength = isArray ? target.length : 0;
|
|
239
|
-
if (hadKey && Object.is(prev, next)) return true;
|
|
240
|
-
record[key] = next;
|
|
241
|
-
notifyKey(target, key);
|
|
242
|
-
if (!hadKey) notifyKey(target, SHAPE);
|
|
243
|
-
if (isArray) {
|
|
244
|
-
const length = target.length;
|
|
245
|
-
if (length !== prevLength) {
|
|
246
|
-
if (key !== "length") notifyKey(target, "length");
|
|
247
|
-
notifyKey(target, SHAPE);
|
|
248
|
-
for (let i = length; i < prevLength; i++) notifyKey(target, String(i));
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
return true;
|
|
252
|
-
},
|
|
253
|
-
deleteProperty(target, key) {
|
|
254
|
-
if (writing === 0) {
|
|
255
|
-
const error = readOnlyError(target);
|
|
256
|
-
if (error) throw error;
|
|
257
|
-
return false;
|
|
258
|
-
}
|
|
259
|
-
if (!Object.hasOwn(target, key)) return true;
|
|
260
|
-
delete target[key];
|
|
261
|
-
notifyKey(target, key);
|
|
262
|
-
notifyKey(target, SHAPE);
|
|
263
|
-
return true;
|
|
264
|
-
}
|
|
265
|
-
};
|
|
266
|
-
function reconcile(target, source, options = {}) {
|
|
267
|
-
if (writing === 0) throw new Error("[keits] reconcile() must be called inside setState.");
|
|
268
|
-
reconcileInto(wrap(unwrap(target)), unwrap(source), options.key);
|
|
269
|
-
}
|
|
270
|
-
function reconcileInto(target, source, key) {
|
|
271
|
-
const raw = unwrap(target);
|
|
272
|
-
const draft = target;
|
|
273
|
-
if (Array.isArray(raw) && Array.isArray(source)) {
|
|
274
|
-
const byKey = /* @__PURE__ */ new Map();
|
|
275
|
-
if (key !== void 0) {
|
|
276
|
-
for (const item of raw) if (isWrappable(item)) byKey.set(item[key], item);
|
|
277
|
-
}
|
|
278
|
-
for (let i = 0; i < source.length; i++) {
|
|
279
|
-
const next = source[i];
|
|
280
|
-
const existing = key !== void 0 && isWrappable(next) ? byKey.get(next[key]) : raw[i];
|
|
281
|
-
draft[i] = matchAndUpdate(existing, next, key);
|
|
282
|
-
}
|
|
283
|
-
if (raw.length !== source.length) draft.length = source.length;
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
for (const k of Object.keys(source)) draft[k] = matchAndUpdate(raw[k], source[k], key);
|
|
287
|
-
for (const k of Object.keys(raw)) if (!Object.hasOwn(source, k)) delete draft[k];
|
|
288
|
-
}
|
|
289
|
-
function matchAndUpdate(existing, next, key) {
|
|
290
|
-
if (isWrappable(existing) && isWrappable(next) && Array.isArray(existing) === Array.isArray(next)) {
|
|
291
|
-
reconcileInto(wrap(existing), next, key);
|
|
292
|
-
return existing;
|
|
293
|
-
}
|
|
294
|
-
return next;
|
|
295
|
-
}
|
|
296
11
|
// src/dom/tags.ts
|
|
297
12
|
var $a = /* @__PURE__ */ html("a");
|
|
298
13
|
var $abbr = /* @__PURE__ */ html("abbr");
|
|
@@ -432,4 +147,285 @@ function unsafeHTML(markup) {
|
|
|
432
147
|
template.innerHTML = markup;
|
|
433
148
|
return template.content;
|
|
434
149
|
}
|
|
435
|
-
|
|
150
|
+
// src/flow/range.ts
|
|
151
|
+
function createRow(build, item) {
|
|
152
|
+
return createRoot((dispose) => {
|
|
153
|
+
const result = build();
|
|
154
|
+
if (isElement(result)) return {
|
|
155
|
+
item,
|
|
156
|
+
index: null,
|
|
157
|
+
dispose,
|
|
158
|
+
first: result,
|
|
159
|
+
last: result
|
|
160
|
+
};
|
|
161
|
+
const holder = document.createDocumentFragment();
|
|
162
|
+
const first = hooks.marker();
|
|
163
|
+
const last = hooks.marker();
|
|
164
|
+
holder.append(first, last);
|
|
165
|
+
insert(holder, result, last);
|
|
166
|
+
return {
|
|
167
|
+
item,
|
|
168
|
+
index: null,
|
|
169
|
+
dispose,
|
|
170
|
+
first,
|
|
171
|
+
last
|
|
172
|
+
};
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
function isElement(value) {
|
|
176
|
+
return typeof value === "object" && value !== null && value.nodeType === 1;
|
|
177
|
+
}
|
|
178
|
+
function moveRow(parent, row, anchor) {
|
|
179
|
+
if (row.first === row.last) {
|
|
180
|
+
parent.insertBefore(row.first, anchor);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
let node = row.first;
|
|
184
|
+
while (node !== null) {
|
|
185
|
+
const nextNode = node === row.last ? null : node.nextSibling;
|
|
186
|
+
parent.insertBefore(node, anchor);
|
|
187
|
+
node = nextNode;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
function removeRow(row) {
|
|
191
|
+
row.dispose();
|
|
192
|
+
let node = row.first;
|
|
193
|
+
while (node !== null) {
|
|
194
|
+
const nextNode = node === row.last ? null : node.nextSibling;
|
|
195
|
+
node.remove();
|
|
196
|
+
node = nextNode;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
// src/flow/for.ts
|
|
200
|
+
function $for(each, render, options) {
|
|
201
|
+
const end = hooks.marker();
|
|
202
|
+
const container = document.createDocumentFragment();
|
|
203
|
+
container.append(end);
|
|
204
|
+
let rows = [];
|
|
205
|
+
let fallback = null;
|
|
206
|
+
addCleanup(() => {
|
|
207
|
+
for (const row of rows) row.dispose();
|
|
208
|
+
fallback?.dispose();
|
|
209
|
+
});
|
|
210
|
+
renderEffect(() => {
|
|
211
|
+
const value = each();
|
|
212
|
+
update(value ? Array.from(value) : []);
|
|
213
|
+
});
|
|
214
|
+
function update(items) {
|
|
215
|
+
const parent = end.parentNode;
|
|
216
|
+
if (items.length === 0) {
|
|
217
|
+
for (const row of rows) removeRow(row);
|
|
218
|
+
rows = [];
|
|
219
|
+
if (fallback === null && options?.fallback) {
|
|
220
|
+
fallback = createRow(options.fallback, null);
|
|
221
|
+
moveRow(parent, fallback, end);
|
|
222
|
+
}
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
if (fallback !== null) {
|
|
226
|
+
removeRow(fallback);
|
|
227
|
+
fallback = null;
|
|
228
|
+
}
|
|
229
|
+
const available = /* @__PURE__ */ new Map();
|
|
230
|
+
rows.forEach((row, i) => {
|
|
231
|
+
const queue = available.get(row.item);
|
|
232
|
+
if (queue) queue.push(i);
|
|
233
|
+
else available.set(row.item, [i]);
|
|
234
|
+
});
|
|
235
|
+
const reused = new Array(rows.length).fill(false);
|
|
236
|
+
const next = new Array(items.length);
|
|
237
|
+
const oldIndex = new Array(items.length);
|
|
238
|
+
for (let i = 0; i < items.length; i++) {
|
|
239
|
+
const item = items[i];
|
|
240
|
+
const queue = available.get(item);
|
|
241
|
+
const old = queue !== void 0 && queue.length > 0 ? queue.shift() : -1;
|
|
242
|
+
if (old >= 0) {
|
|
243
|
+
const row = rows[old];
|
|
244
|
+
row.index(i);
|
|
245
|
+
reused[old] = true;
|
|
246
|
+
next[i] = row;
|
|
247
|
+
} else next[i] = createItemRow(item, i);
|
|
248
|
+
oldIndex[i] = old;
|
|
249
|
+
}
|
|
250
|
+
for (let i = 0; i < rows.length; i++) if (!reused[i]) removeRow(rows[i]);
|
|
251
|
+
const stay = longestIncreasing(oldIndex);
|
|
252
|
+
let anchor = end;
|
|
253
|
+
for (let i = next.length - 1; i >= 0; i--) {
|
|
254
|
+
const row = next[i];
|
|
255
|
+
if (!stay.has(i)) moveRow(parent, row, anchor);
|
|
256
|
+
anchor = row.first;
|
|
257
|
+
}
|
|
258
|
+
rows = next;
|
|
259
|
+
}
|
|
260
|
+
function createItemRow(item, i) {
|
|
261
|
+
let setIndex = () => {};
|
|
262
|
+
const row = createRow(() => {
|
|
263
|
+
const index = signal(i);
|
|
264
|
+
setIndex = index.set;
|
|
265
|
+
return render(item, index);
|
|
266
|
+
}, item);
|
|
267
|
+
row.index = setIndex;
|
|
268
|
+
return row;
|
|
269
|
+
}
|
|
270
|
+
return container;
|
|
271
|
+
}
|
|
272
|
+
function longestIncreasing(sequence) {
|
|
273
|
+
const tails = [];
|
|
274
|
+
const previous = new Array(sequence.length);
|
|
275
|
+
for (let i = 0; i < sequence.length; i++) {
|
|
276
|
+
const value = sequence[i];
|
|
277
|
+
if (value < 0) continue;
|
|
278
|
+
let low = 0;
|
|
279
|
+
let high = tails.length;
|
|
280
|
+
while (low < high) {
|
|
281
|
+
const mid = low + high >> 1;
|
|
282
|
+
if (sequence[tails[mid]] < value) low = mid + 1;
|
|
283
|
+
else high = mid;
|
|
284
|
+
}
|
|
285
|
+
previous[i] = low > 0 ? tails[low - 1] : -1;
|
|
286
|
+
tails[low] = i;
|
|
287
|
+
}
|
|
288
|
+
const result = /* @__PURE__ */ new Set();
|
|
289
|
+
let position = tails.length > 0 ? tails[tails.length - 1] : -1;
|
|
290
|
+
while (position >= 0) {
|
|
291
|
+
result.add(position);
|
|
292
|
+
position = previous[position];
|
|
293
|
+
}
|
|
294
|
+
return result;
|
|
295
|
+
}
|
|
296
|
+
// src/flow/if.ts
|
|
297
|
+
function $if(when, then, otherwise) {
|
|
298
|
+
const value = computed(when);
|
|
299
|
+
const isTruthy = computed(() => Boolean(value()));
|
|
300
|
+
const narrowed = value;
|
|
301
|
+
return () => isTruthy() ? untrack(() => then(narrowed)) : otherwise ? untrack(otherwise) : null;
|
|
302
|
+
}
|
|
303
|
+
// src/flow/show.ts
|
|
304
|
+
function $show(when, element) {
|
|
305
|
+
const original = element.style.display;
|
|
306
|
+
renderEffect(() => {
|
|
307
|
+
if (when()) element.style.display = original;
|
|
308
|
+
else element.style.display = "none";
|
|
309
|
+
});
|
|
310
|
+
return element;
|
|
311
|
+
}
|
|
312
|
+
// src/flow/switch.ts
|
|
313
|
+
function $switch(value, cases, fallback) {
|
|
314
|
+
const key = computed(value);
|
|
315
|
+
return () => {
|
|
316
|
+
const branch = cases[key()] ?? fallback;
|
|
317
|
+
return branch ? untrack(branch) : null;
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
// src/flow/dynamic.ts
|
|
321
|
+
function $dynamic(component, props) {
|
|
322
|
+
const current = computed(component);
|
|
323
|
+
return () => {
|
|
324
|
+
const Component = current();
|
|
325
|
+
return Component ? untrack(() => Component(props)) : null;
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
// src/flow/catch.ts
|
|
329
|
+
function $catch(children, fallback) {
|
|
330
|
+
const failure = signal(null);
|
|
331
|
+
const reset = () => failure.set(null);
|
|
332
|
+
return () => {
|
|
333
|
+
const current = failure();
|
|
334
|
+
if (current !== null) return untrack(() => fallback(current.error, reset));
|
|
335
|
+
return untrack(() => catchError(() => {
|
|
336
|
+
const content = document.createDocumentFragment();
|
|
337
|
+
insert(content, children());
|
|
338
|
+
return content;
|
|
339
|
+
}, (error) => failure.set({ error })));
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
// src/flow/portal.ts
|
|
343
|
+
function $portal(children, target) {
|
|
344
|
+
if (isStaticRender()) return null;
|
|
345
|
+
const host = target === void 0 ? document.body : target;
|
|
346
|
+
if (host === null) throw new Error("[keits] $portal(): the target element was not found (null).");
|
|
347
|
+
const start = hooks.marker();
|
|
348
|
+
const end = hooks.marker();
|
|
349
|
+
host.append(start, end);
|
|
350
|
+
insert(host, untrack(children), end);
|
|
351
|
+
addCleanup(() => {
|
|
352
|
+
let node = start;
|
|
353
|
+
while (node !== null) {
|
|
354
|
+
const next = node === end ? null : node.nextSibling;
|
|
355
|
+
node.remove();
|
|
356
|
+
node = next;
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
return null;
|
|
360
|
+
}
|
|
361
|
+
// src/flow/suspense.ts
|
|
362
|
+
function $suspense(children, fallback) {
|
|
363
|
+
const pendingCount = signal(0);
|
|
364
|
+
const pending = /* @__PURE__ */ new Set();
|
|
365
|
+
const boundary = { wait(key, subscribe) {
|
|
366
|
+
if (pending.has(key)) return;
|
|
367
|
+
pending.add(key);
|
|
368
|
+
pendingCount.set((n) => n + 1);
|
|
369
|
+
subscribe(() => {
|
|
370
|
+
pending.delete(key);
|
|
371
|
+
pendingCount.set((n) => n - 1);
|
|
372
|
+
});
|
|
373
|
+
} };
|
|
374
|
+
const offscreen = document.createDocumentFragment();
|
|
375
|
+
const contentStart = hooks.marker();
|
|
376
|
+
const contentEnd = hooks.marker();
|
|
377
|
+
offscreen.append(contentStart, contentEnd);
|
|
378
|
+
const { release } = deferMounts(() => provide(SuspenseContext, boundary, () => insert(offscreen, untrack(children), contentEnd)));
|
|
379
|
+
const content = {
|
|
380
|
+
item: null,
|
|
381
|
+
index: null,
|
|
382
|
+
dispose: () => {},
|
|
383
|
+
first: contentStart,
|
|
384
|
+
last: contentEnd
|
|
385
|
+
};
|
|
386
|
+
const end = hooks.marker();
|
|
387
|
+
const container = document.createDocumentFragment();
|
|
388
|
+
container.append(end);
|
|
389
|
+
let fallbackRow = null;
|
|
390
|
+
addCleanup(() => fallbackRow?.dispose());
|
|
391
|
+
renderEffect(() => {
|
|
392
|
+
const waiting = pendingCount() > 0;
|
|
393
|
+
untrack(() => {
|
|
394
|
+
const parent = end.parentNode;
|
|
395
|
+
if (waiting) {
|
|
396
|
+
moveRow(offscreen, content, null);
|
|
397
|
+
if (fallbackRow === null) {
|
|
398
|
+
fallbackRow = createRow(fallback, null);
|
|
399
|
+
moveRow(parent, fallbackRow, end);
|
|
400
|
+
}
|
|
401
|
+
} else {
|
|
402
|
+
if (fallbackRow !== null) {
|
|
403
|
+
removeRow(fallbackRow);
|
|
404
|
+
fallbackRow = null;
|
|
405
|
+
}
|
|
406
|
+
moveRow(parent, content, end);
|
|
407
|
+
release();
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
});
|
|
411
|
+
return container;
|
|
412
|
+
}
|
|
413
|
+
// src/async/lazy.ts
|
|
414
|
+
function lazy(load) {
|
|
415
|
+
let loaded;
|
|
416
|
+
let loading;
|
|
417
|
+
const preload = () => loading ??= Promise.resolve(load()).then((module) => loaded = module.default, (error) => {
|
|
418
|
+
loading = void 0;
|
|
419
|
+
throw error;
|
|
420
|
+
});
|
|
421
|
+
const Lazy = (props) => {
|
|
422
|
+
if (loaded !== void 0) return untrack(() => loaded(props));
|
|
423
|
+
const component = resource(() => loaded ?? preload());
|
|
424
|
+
return () => {
|
|
425
|
+
const Loaded = component();
|
|
426
|
+
return Loaded ? untrack(() => Loaded(props)) : null;
|
|
427
|
+
};
|
|
428
|
+
};
|
|
429
|
+
return Object.assign(Lazy, { preload });
|
|
430
|
+
}
|
|
431
|
+
export { $a, $abbr, $address, $area, $article, $aside, $audio, $b, $base, $bdi, $bdo, $blockquote, $body, $br, $button, $canvas, $caption, $catch, $cite, $code, $col, $colgroup, $data, $datalist, $dd, $del, $details, $dfn, $dialog, $div, $dl, $dt, $dynamic, $em, $embed, $fieldset, $figcaption, $figure, $footer, $for, $form, $h1, $h2, $h3, $h4, $h5, $h6, $head, $header, $hgroup, $hr, $html, $i, $if, $iframe, $img, $input, $ins, $kbd, $label, $legend, $li, $link, $main, $map, $mark, $menu, $meta, $meter, $nav, $noscript, $object, $ol, $optgroup, $option, $output, $p, $picture, $portal, $pre, $progress, $q, $rp, $rt, $ruby, $s, $samp, $script, $search, $section, $select, $show, $slot, $small, $source, $span, $strong, $style, $sub, $summary, $sup, $suspense, $switch, $table, $tbody, $td, $template, $textarea, $tfoot, $th, $thead, $time, $title, $tr, $track, $u, $ul, $var, $video, $wbr, batch, catchError, computed, createContext, createRoot, effect, getOwner, html, insert, isServer, isStaticRender, lazy, mount, onCleanup, onMount, provide, reconcile, renderStatic, resource, runWithOwner, signal, store, unsafeHTML, untrack, unwrap, useContext };
|