keits 0.0.2 → 0.0.3
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/index.js +409 -122
- package/dist/dev/router.js +443 -0
- package/dist/dev/shared/{element-By0uLZli.js → element-C4DfKtZW.js} +2 -291
- package/dist/dev/shared/graph-D6-x_CWC.js +324 -0
- package/dist/dev/shared/owner-DlUsXKXE.js +122 -0
- package/dist/dev/svg.js +1 -1
- package/dist/prod/index.js +350 -166
- package/dist/prod/router.js +343 -0
- package/dist/prod/shared/element-DUtXb3px.js +187 -0
- package/dist/prod/shared/graph-C_aA46c6.js +240 -0
- package/dist/prod/shared/owner-DgJNPM0P.js +104 -0
- package/dist/prod/svg.js +1 -1
- 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/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 +23 -6
- package/dist/prod/shared/element-C8c5hIhH.js +0 -394
package/dist/dev/index.js
CHANGED
|
@@ -1,126 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
// 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 { a as onMount, c as computed, i as onCleanup, l as signal, n as createRoot, o as renderStatic, r as getOwner, s as runWithOwner, t as catchError } from "./shared/owner-DlUsXKXE.js";
|
|
2
|
+
import { a as renderEffect, i as insert, n as html, o as hooks, s as effect } from "./shared/element-C4DfKtZW.js";
|
|
3
|
+
import { a as deferMounts, c as handleError, d as notify, h as untrack, i as batch, l as isStaticRender, m as track, p as runWithOwner$1, r as adopt, s as getOwner$1, t as addCleanup, u as isTracking } from "./shared/graph-D6-x_CWC.js";
|
|
62
4
|
// src/core/env.ts
|
|
63
5
|
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
6
|
// src/core/context.ts
|
|
125
7
|
function createContext(defaultValue, options) {
|
|
126
8
|
const context = { defaultValue };
|
|
@@ -432,4 +314,409 @@ function unsafeHTML(markup) {
|
|
|
432
314
|
template.innerHTML = markup;
|
|
433
315
|
return template.content;
|
|
434
316
|
}
|
|
435
|
-
|
|
317
|
+
// src/flow/range.ts
|
|
318
|
+
function createRow(build, item) {
|
|
319
|
+
return createRoot((dispose) => {
|
|
320
|
+
const result = build();
|
|
321
|
+
if (isElement(result)) return {
|
|
322
|
+
item,
|
|
323
|
+
index: null,
|
|
324
|
+
dispose,
|
|
325
|
+
first: result,
|
|
326
|
+
last: result
|
|
327
|
+
};
|
|
328
|
+
const holder = document.createDocumentFragment();
|
|
329
|
+
const first = hooks.marker();
|
|
330
|
+
const last = hooks.marker();
|
|
331
|
+
holder.append(first, last);
|
|
332
|
+
insert(holder, result, last);
|
|
333
|
+
return {
|
|
334
|
+
item,
|
|
335
|
+
index: null,
|
|
336
|
+
dispose,
|
|
337
|
+
first,
|
|
338
|
+
last
|
|
339
|
+
};
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
function isElement(value) {
|
|
343
|
+
return typeof value === "object" && value !== null && value.nodeType === 1;
|
|
344
|
+
}
|
|
345
|
+
function moveRow(parent, row, anchor) {
|
|
346
|
+
if (row.first === row.last) {
|
|
347
|
+
parent.insertBefore(row.first, anchor);
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
let node = row.first;
|
|
351
|
+
while (node !== null) {
|
|
352
|
+
const nextNode = node === row.last ? null : node.nextSibling;
|
|
353
|
+
parent.insertBefore(node, anchor);
|
|
354
|
+
node = nextNode;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
function removeRow(row) {
|
|
358
|
+
row.dispose();
|
|
359
|
+
let node = row.first;
|
|
360
|
+
while (node !== null) {
|
|
361
|
+
const nextNode = node === row.last ? null : node.nextSibling;
|
|
362
|
+
node.remove();
|
|
363
|
+
node = nextNode;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
// src/flow/for.ts
|
|
367
|
+
function $for(each, render, options) {
|
|
368
|
+
const end = hooks.marker();
|
|
369
|
+
const container = document.createDocumentFragment();
|
|
370
|
+
container.append(end);
|
|
371
|
+
let rows = [];
|
|
372
|
+
let fallback = null;
|
|
373
|
+
addCleanup(() => {
|
|
374
|
+
for (const row of rows) row.dispose();
|
|
375
|
+
fallback?.dispose();
|
|
376
|
+
});
|
|
377
|
+
renderEffect(() => {
|
|
378
|
+
const value = each();
|
|
379
|
+
update(value ? Array.from(value) : []);
|
|
380
|
+
});
|
|
381
|
+
function update(items) {
|
|
382
|
+
const parent = end.parentNode;
|
|
383
|
+
if (items.length === 0) {
|
|
384
|
+
for (const row of rows) removeRow(row);
|
|
385
|
+
rows = [];
|
|
386
|
+
if (fallback === null && options?.fallback) {
|
|
387
|
+
fallback = createRow(options.fallback, null);
|
|
388
|
+
moveRow(parent, fallback, end);
|
|
389
|
+
}
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
if (fallback !== null) {
|
|
393
|
+
removeRow(fallback);
|
|
394
|
+
fallback = null;
|
|
395
|
+
}
|
|
396
|
+
const available = /* @__PURE__ */ new Map();
|
|
397
|
+
rows.forEach((row, i) => {
|
|
398
|
+
const queue = available.get(row.item);
|
|
399
|
+
if (queue) queue.push(i);
|
|
400
|
+
else available.set(row.item, [i]);
|
|
401
|
+
});
|
|
402
|
+
const reused = new Array(rows.length).fill(false);
|
|
403
|
+
const next = new Array(items.length);
|
|
404
|
+
const oldIndex = new Array(items.length);
|
|
405
|
+
for (let i = 0; i < items.length; i++) {
|
|
406
|
+
const item = items[i];
|
|
407
|
+
const queue = available.get(item);
|
|
408
|
+
const old = queue !== void 0 && queue.length > 0 ? queue.shift() : -1;
|
|
409
|
+
if (old >= 0) {
|
|
410
|
+
const row = rows[old];
|
|
411
|
+
row.index(i);
|
|
412
|
+
reused[old] = true;
|
|
413
|
+
next[i] = row;
|
|
414
|
+
} else next[i] = createItemRow(item, i);
|
|
415
|
+
oldIndex[i] = old;
|
|
416
|
+
}
|
|
417
|
+
for (let i = 0; i < rows.length; i++) if (!reused[i]) removeRow(rows[i]);
|
|
418
|
+
const stay = longestIncreasing(oldIndex);
|
|
419
|
+
let anchor = end;
|
|
420
|
+
for (let i = next.length - 1; i >= 0; i--) {
|
|
421
|
+
const row = next[i];
|
|
422
|
+
if (!stay.has(i)) moveRow(parent, row, anchor);
|
|
423
|
+
anchor = row.first;
|
|
424
|
+
}
|
|
425
|
+
rows = next;
|
|
426
|
+
}
|
|
427
|
+
function createItemRow(item, i) {
|
|
428
|
+
let setIndex = () => {};
|
|
429
|
+
const row = createRow(() => {
|
|
430
|
+
const index = signal(i);
|
|
431
|
+
setIndex = index.set;
|
|
432
|
+
return render(item, index);
|
|
433
|
+
}, item);
|
|
434
|
+
row.index = setIndex;
|
|
435
|
+
return row;
|
|
436
|
+
}
|
|
437
|
+
return container;
|
|
438
|
+
}
|
|
439
|
+
function longestIncreasing(sequence) {
|
|
440
|
+
const tails = [];
|
|
441
|
+
const previous = new Array(sequence.length);
|
|
442
|
+
for (let i = 0; i < sequence.length; i++) {
|
|
443
|
+
const value = sequence[i];
|
|
444
|
+
if (value < 0) continue;
|
|
445
|
+
let low = 0;
|
|
446
|
+
let high = tails.length;
|
|
447
|
+
while (low < high) {
|
|
448
|
+
const mid = low + high >> 1;
|
|
449
|
+
if (sequence[tails[mid]] < value) low = mid + 1;
|
|
450
|
+
else high = mid;
|
|
451
|
+
}
|
|
452
|
+
previous[i] = low > 0 ? tails[low - 1] : -1;
|
|
453
|
+
tails[low] = i;
|
|
454
|
+
}
|
|
455
|
+
const result = /* @__PURE__ */ new Set();
|
|
456
|
+
let position = tails.length > 0 ? tails[tails.length - 1] : -1;
|
|
457
|
+
while (position >= 0) {
|
|
458
|
+
result.add(position);
|
|
459
|
+
position = previous[position];
|
|
460
|
+
}
|
|
461
|
+
return result;
|
|
462
|
+
}
|
|
463
|
+
// src/flow/if.ts
|
|
464
|
+
function $if(when, then, otherwise) {
|
|
465
|
+
const value = computed(when);
|
|
466
|
+
const isTruthy = computed(() => Boolean(value()));
|
|
467
|
+
const narrowed = value;
|
|
468
|
+
return () => isTruthy() ? untrack(() => then(narrowed)) : otherwise ? untrack(otherwise) : null;
|
|
469
|
+
}
|
|
470
|
+
// src/flow/show.ts
|
|
471
|
+
function $show(when, element) {
|
|
472
|
+
const original = element.style.display;
|
|
473
|
+
renderEffect(() => {
|
|
474
|
+
if (when()) element.style.display = original;
|
|
475
|
+
else element.style.display = "none";
|
|
476
|
+
});
|
|
477
|
+
return element;
|
|
478
|
+
}
|
|
479
|
+
// src/flow/switch.ts
|
|
480
|
+
function $switch(value, cases, fallback) {
|
|
481
|
+
const key = computed(value);
|
|
482
|
+
return () => {
|
|
483
|
+
const branch = cases[key()] ?? fallback;
|
|
484
|
+
return branch ? untrack(branch) : null;
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
// src/flow/dynamic.ts
|
|
488
|
+
function $dynamic(component, props) {
|
|
489
|
+
const current = computed(component);
|
|
490
|
+
return () => {
|
|
491
|
+
const Component = current();
|
|
492
|
+
return Component ? untrack(() => Component(props)) : null;
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
// src/flow/catch.ts
|
|
496
|
+
function $catch(children, fallback) {
|
|
497
|
+
const failure = signal(null);
|
|
498
|
+
const reset = () => failure.set(null);
|
|
499
|
+
return () => {
|
|
500
|
+
const current = failure();
|
|
501
|
+
if (current !== null) return untrack(() => fallback(current.error, reset));
|
|
502
|
+
return untrack(() => catchError(() => {
|
|
503
|
+
const content = document.createDocumentFragment();
|
|
504
|
+
insert(content, children());
|
|
505
|
+
return content;
|
|
506
|
+
}, (error) => failure.set({ error })));
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
// src/flow/portal.ts
|
|
510
|
+
function $portal(children, target) {
|
|
511
|
+
if (isStaticRender()) return null;
|
|
512
|
+
const host = target === void 0 ? document.body : target;
|
|
513
|
+
if (host === null) throw new Error("[keits] $portal(): the target element was not found (null).");
|
|
514
|
+
const start = hooks.marker();
|
|
515
|
+
const end = hooks.marker();
|
|
516
|
+
host.append(start, end);
|
|
517
|
+
insert(host, untrack(children), end);
|
|
518
|
+
addCleanup(() => {
|
|
519
|
+
let node = start;
|
|
520
|
+
while (node !== null) {
|
|
521
|
+
const next = node === end ? null : node.nextSibling;
|
|
522
|
+
node.remove();
|
|
523
|
+
node = next;
|
|
524
|
+
}
|
|
525
|
+
});
|
|
526
|
+
return null;
|
|
527
|
+
}
|
|
528
|
+
// src/async/suspense-context.ts
|
|
529
|
+
var SuspenseContext = createContext(null);
|
|
530
|
+
// src/flow/suspense.ts
|
|
531
|
+
function $suspense(children, fallback) {
|
|
532
|
+
const pendingCount = signal(0);
|
|
533
|
+
const pending = /* @__PURE__ */ new Set();
|
|
534
|
+
const boundary = { wait(key, subscribe) {
|
|
535
|
+
if (pending.has(key)) return;
|
|
536
|
+
pending.add(key);
|
|
537
|
+
pendingCount.set((n) => n + 1);
|
|
538
|
+
subscribe(() => {
|
|
539
|
+
pending.delete(key);
|
|
540
|
+
pendingCount.set((n) => n - 1);
|
|
541
|
+
});
|
|
542
|
+
} };
|
|
543
|
+
const offscreen = document.createDocumentFragment();
|
|
544
|
+
const contentStart = hooks.marker();
|
|
545
|
+
const contentEnd = hooks.marker();
|
|
546
|
+
offscreen.append(contentStart, contentEnd);
|
|
547
|
+
const { release } = deferMounts(() => provide(SuspenseContext, boundary, () => insert(offscreen, untrack(children), contentEnd)));
|
|
548
|
+
const content = {
|
|
549
|
+
item: null,
|
|
550
|
+
index: null,
|
|
551
|
+
dispose: () => {},
|
|
552
|
+
first: contentStart,
|
|
553
|
+
last: contentEnd
|
|
554
|
+
};
|
|
555
|
+
const end = hooks.marker();
|
|
556
|
+
const container = document.createDocumentFragment();
|
|
557
|
+
container.append(end);
|
|
558
|
+
let fallbackRow = null;
|
|
559
|
+
addCleanup(() => fallbackRow?.dispose());
|
|
560
|
+
renderEffect(() => {
|
|
561
|
+
const waiting = pendingCount() > 0;
|
|
562
|
+
untrack(() => {
|
|
563
|
+
const parent = end.parentNode;
|
|
564
|
+
if (waiting) {
|
|
565
|
+
moveRow(offscreen, content, null);
|
|
566
|
+
if (fallbackRow === null) {
|
|
567
|
+
fallbackRow = createRow(fallback, null);
|
|
568
|
+
moveRow(parent, fallbackRow, end);
|
|
569
|
+
}
|
|
570
|
+
} else {
|
|
571
|
+
if (fallbackRow !== null) {
|
|
572
|
+
removeRow(fallbackRow);
|
|
573
|
+
fallbackRow = null;
|
|
574
|
+
}
|
|
575
|
+
moveRow(parent, content, end);
|
|
576
|
+
release();
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
});
|
|
580
|
+
return container;
|
|
581
|
+
}
|
|
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
|
+
// src/async/lazy.ts
|
|
705
|
+
function lazy(load) {
|
|
706
|
+
let loaded;
|
|
707
|
+
let loading;
|
|
708
|
+
const preload = () => loading ??= Promise.resolve(load()).then((module) => loaded = module.default, (error) => {
|
|
709
|
+
loading = void 0;
|
|
710
|
+
throw error;
|
|
711
|
+
});
|
|
712
|
+
const Lazy = (props) => {
|
|
713
|
+
if (loaded !== void 0) return untrack(() => loaded(props));
|
|
714
|
+
const component = resource(() => loaded ?? preload());
|
|
715
|
+
return () => {
|
|
716
|
+
const Loaded = component();
|
|
717
|
+
return Loaded ? untrack(() => Loaded(props)) : null;
|
|
718
|
+
};
|
|
719
|
+
};
|
|
720
|
+
return Object.assign(Lazy, { preload });
|
|
721
|
+
}
|
|
722
|
+
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 };
|