sibujs 4.13.1 → 4.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/browser.cjs +15 -2
- package/dist/browser.js +9 -7
- package/dist/build.cjs +880 -281
- package/dist/build.d.cts +68 -3
- package/dist/build.d.ts +68 -3
- package/dist/build.js +88 -30
- package/dist/cdn.dev.global.js +12 -12
- package/dist/cdn.full.dev.global.js +13 -13
- package/dist/cdn.full.global.js +12 -12
- package/dist/cdn.global.js +12 -12
- package/dist/{chunk-J6FW5TV6.js → chunk-3HEX6QJQ.js} +5 -3
- package/dist/chunk-3HZOSMPX.js +90 -0
- package/dist/{chunk-K4LNUT5L.js → chunk-3T7TWMSD.js} +8 -6
- package/dist/{chunk-ADZHPN2B.js → chunk-4XCWNGRY.js} +3 -3
- package/dist/{chunk-2NC56RGY.js → chunk-55TAOW5M.js} +2 -2
- package/dist/{chunk-G3Z2FEBR.js → chunk-B2NLNZ3E.js} +119 -26
- package/dist/{chunk-EXXSN3BW.js → chunk-B3HOT4TK.js} +1 -1
- package/dist/{chunk-QKFVMIAV.js → chunk-FCWOMATN.js} +11 -3
- package/dist/{chunk-QC3NP47A.js → chunk-FFXZ6ELZ.js} +10 -6
- package/dist/{chunk-TUCPL2HB.js → chunk-GIJ33UJZ.js} +1 -1
- package/dist/chunk-KTJC7QPA.js +195 -0
- package/dist/chunk-L2IPKGUJ.js +2596 -0
- package/dist/{chunk-4UTGDVSA.js → chunk-LAHX7XFG.js} +7 -14
- package/dist/{chunk-PBJYCE2Z.js → chunk-LJ2LR5P4.js} +5 -5
- package/dist/{chunk-AM6DZLBM.js → chunk-LJMX4SQ7.js} +2 -2
- package/dist/{chunk-5RIBLY2N.js → chunk-LUZXFMKH.js} +6 -6
- package/dist/{chunk-VFPLWUT7.js → chunk-LZKKMDQF.js} +151 -86
- package/dist/{chunk-J4X7ICH4.js → chunk-NIHGSXOX.js} +8 -6
- package/dist/chunk-NT3ZYB5S.js +167 -0
- package/dist/{chunk-2O6JJCUR.js → chunk-OLMZF4RU.js} +49 -8
- package/dist/{chunk-22OPSWMF.js → chunk-OPRQW4LI.js} +2 -2
- package/dist/chunk-R5U7XKVJ.js +16 -0
- package/dist/{chunk-KC62VURU.js → chunk-RBRITLFL.js} +10 -8
- package/dist/{chunk-F2UWOZ6J.js → chunk-RVWJGWCL.js} +2 -2
- package/dist/{chunk-NYNYSPK7.js → chunk-S37PZD6I.js} +30 -45
- package/dist/chunk-TOV4PN3P.js +2015 -0
- package/dist/{chunk-C73VBPEF.js → chunk-TS6JDK7Y.js} +8 -8
- package/dist/{chunk-EU7T7EB3.js → chunk-TZNR6E6D.js} +4 -4
- package/dist/chunk-UYTYNCMZ.js +199 -0
- package/dist/{chunk-OIKD7YDY.js → chunk-VIAVYBNQ.js} +6 -5
- package/dist/{chunk-QZ47OZ25.js → chunk-WFMMSMA5.js} +8 -6
- package/dist/chunk-YIXMS546.js +1901 -0
- package/dist/{chunk-5XUGJM3J.js → chunk-YPLQQTWS.js} +1 -1
- package/dist/{chunk-CPQKWCJ2.js → chunk-ZKI4SDZ2.js} +16 -10
- package/dist/{chunk-YFTBCCVH.js → chunk-ZYK4NZZA.js} +5 -3
- package/dist/data.cjs +265 -35
- package/dist/data.d.cts +31 -1
- package/dist/data.d.ts +31 -1
- package/dist/data.js +16 -10
- package/dist/devtools.cjs +15 -2
- package/dist/devtools.js +9 -7
- package/dist/{dispose-GEIG2KOF.js → dispose-EIHHHDC7.js} +3 -1
- package/dist/ecosystem.cjs +62 -23
- package/dist/ecosystem.js +14 -12
- package/dist/extras.cjs +3562 -270
- package/dist/extras.d.cts +3 -3
- package/dist/extras.d.ts +3 -3
- package/dist/extras.js +39 -29
- package/dist/index.cjs +442 -253
- package/dist/index.d.cts +93 -283
- package/dist/index.d.ts +93 -283
- package/dist/index.js +26 -16
- package/dist/motion.cjs +12 -1
- package/dist/motion.js +6 -4
- package/dist/patterns.cjs +15 -2
- package/dist/patterns.js +10 -8
- package/dist/performance.cjs +36 -2
- package/dist/performance.d.cts +2 -2
- package/dist/performance.d.ts +2 -2
- package/dist/performance.js +14 -10
- package/dist/plugins.cjs +5267 -1807
- package/dist/plugins.d.cts +8 -834
- package/dist/plugins.d.ts +8 -834
- package/dist/plugins.js +64 -2329
- package/dist/prerenderServer-MXJEVWA3.js +350 -0
- package/dist/renderRoute-DP20XwMS.d.cts +86 -0
- package/dist/renderRoute-fxgsm2Ir.d.ts +86 -0
- package/dist/routeHead-CE9SV-cH.d.cts +995 -0
- package/dist/routeHead-DzVxPviY.d.ts +995 -0
- package/dist/{routeMiddleware-B1sp4P7a.d.ts → routeMiddleware-BySbueoE.d.ts} +0 -25
- package/dist/{routeMiddleware-CedQTsLK.d.cts → routeMiddleware-CijZD5eW.d.cts} +0 -25
- package/dist/{ssr-VBM6J5SJ.js → ssr-HHU3DAD2.js} +15 -6
- package/dist/ssr-JpGpHnpC.d.cts +841 -0
- package/dist/ssr-JpGpHnpC.d.ts +841 -0
- package/dist/ssr-dom.cjs +1904 -0
- package/dist/ssr-dom.d.cts +343 -0
- package/dist/ssr-dom.d.ts +343 -0
- package/dist/ssr-dom.js +19 -0
- package/dist/ssr.cjs +7677 -2069
- package/dist/ssr.d.cts +63 -5
- package/dist/ssr.d.ts +63 -5
- package/dist/ssr.js +136 -14
- package/dist/testing.cjs +6585 -87
- package/dist/testing.d.cts +80 -1
- package/dist/testing.d.ts +80 -1
- package/dist/testing.js +117 -4
- package/dist/ui.cjs +36 -2
- package/dist/ui.js +17 -14
- package/dist/widgets.cjs +14 -1
- package/dist/widgets.js +11 -9
- package/package.json +9 -2
- package/dist/chunk-2F4PSJ5Z.js +0 -765
- package/dist/chunk-7XHATCIH.js +0 -121
- package/dist/chunk-B36ADEIR.js +0 -21
- package/dist/ssr-Db0Sgdu3.d.cts +0 -245
- package/dist/ssr-Db0Sgdu3.d.ts +0 -245
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isUnsafeKey,
|
|
3
|
+
readOwnGlobal
|
|
4
|
+
} from "./chunk-62BDYGAG.js";
|
|
5
|
+
import {
|
|
6
|
+
getRequestStore
|
|
7
|
+
} from "./chunk-UYTYNCMZ.js";
|
|
8
|
+
|
|
9
|
+
// src/utils/transfer.ts
|
|
10
|
+
var TRANSFER_GLOBAL = "__SIBU_TRANSFER__";
|
|
11
|
+
var TRANSFER_VERSION = 1;
|
|
12
|
+
var REGISTRY_KEY = /* @__PURE__ */ Symbol.for("sibujs.transfer.v1");
|
|
13
|
+
function registry() {
|
|
14
|
+
const g = globalThis;
|
|
15
|
+
let r = g[REGISTRY_KEY];
|
|
16
|
+
if (!r) {
|
|
17
|
+
r = { collectors: /* @__PURE__ */ new Map(), payload: void 0 };
|
|
18
|
+
g[REGISTRY_KEY] = r;
|
|
19
|
+
}
|
|
20
|
+
return r;
|
|
21
|
+
}
|
|
22
|
+
function registerTransferCollector(section, collect) {
|
|
23
|
+
registry().collectors.set(section, collect);
|
|
24
|
+
}
|
|
25
|
+
function collectTransfer() {
|
|
26
|
+
if (!getRequestStore()) return null;
|
|
27
|
+
const out = {};
|
|
28
|
+
let any = false;
|
|
29
|
+
for (const [section, collect] of registry().collectors) {
|
|
30
|
+
const entries = collect();
|
|
31
|
+
if (!entries) continue;
|
|
32
|
+
const safe = {};
|
|
33
|
+
for (const key of Object.keys(entries)) if (!isUnsafeKey(key)) safe[key] = entries[key];
|
|
34
|
+
if (Object.keys(safe).length > 0) {
|
|
35
|
+
out[section] = safe;
|
|
36
|
+
any = true;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (!any) return null;
|
|
40
|
+
out.v = TRANSFER_VERSION;
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
function isPlainRecord(value) {
|
|
44
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
|
|
45
|
+
const proto = Object.getPrototypeOf(value);
|
|
46
|
+
return proto === Object.prototype || proto === null;
|
|
47
|
+
}
|
|
48
|
+
function readPayload() {
|
|
49
|
+
const r = registry();
|
|
50
|
+
if (r.payload !== void 0) return r.payload;
|
|
51
|
+
r.payload = null;
|
|
52
|
+
if (typeof window === "undefined" || getRequestStore()) return null;
|
|
53
|
+
const raw = readOwnGlobal(TRANSFER_GLOBAL);
|
|
54
|
+
if (!isPlainRecord(raw) || raw.v !== TRANSFER_VERSION) return null;
|
|
55
|
+
const sections = /* @__PURE__ */ Object.create(null);
|
|
56
|
+
for (const key of Object.keys(raw)) {
|
|
57
|
+
const section = raw[key];
|
|
58
|
+
if (key === "v" || isUnsafeKey(key) || !isPlainRecord(section)) continue;
|
|
59
|
+
const entries = /* @__PURE__ */ Object.create(null);
|
|
60
|
+
for (const k of Object.keys(section)) if (!isUnsafeKey(k)) entries[k] = section[k];
|
|
61
|
+
sections[key] = entries;
|
|
62
|
+
}
|
|
63
|
+
r.payload = sections;
|
|
64
|
+
return sections;
|
|
65
|
+
}
|
|
66
|
+
function takeTransferred(section, key) {
|
|
67
|
+
const entries = readPayload()?.[section];
|
|
68
|
+
if (!entries || !Object.hasOwn(entries, key)) return void 0;
|
|
69
|
+
const value = entries[key];
|
|
70
|
+
delete entries[key];
|
|
71
|
+
return value;
|
|
72
|
+
}
|
|
73
|
+
function takeTransferredSection(section) {
|
|
74
|
+
const payload = readPayload();
|
|
75
|
+
const entries = payload?.[section];
|
|
76
|
+
if (!payload || !entries) return {};
|
|
77
|
+
delete payload[section];
|
|
78
|
+
return entries;
|
|
79
|
+
}
|
|
80
|
+
function __resetTransfer() {
|
|
81
|
+
registry().payload = void 0;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export {
|
|
85
|
+
registerTransferCollector,
|
|
86
|
+
collectTransfer,
|
|
87
|
+
takeTransferred,
|
|
88
|
+
takeTransferredSection,
|
|
89
|
+
__resetTransfer
|
|
90
|
+
};
|
|
@@ -2,21 +2,23 @@ import {
|
|
|
2
2
|
ContextualRefusal,
|
|
3
3
|
contextualAttributeRefusal,
|
|
4
4
|
settleAttributeProvenance
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-RVWJGWCL.js";
|
|
6
6
|
import {
|
|
7
7
|
isEventHandlerAttr,
|
|
8
8
|
isHtmlContentAttribute,
|
|
9
9
|
resolveAttributeValue
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-B3HOT4TK.js";
|
|
11
11
|
import {
|
|
12
12
|
reactiveBinding
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-LAHX7XFG.js";
|
|
14
|
+
import {
|
|
15
|
+
reportError
|
|
16
|
+
} from "./chunk-S37PZD6I.js";
|
|
14
17
|
import {
|
|
15
18
|
DEV,
|
|
16
19
|
devWarn,
|
|
17
|
-
devWarnLazy
|
|
18
|
-
|
|
19
|
-
} from "./chunk-NYNYSPK7.js";
|
|
20
|
+
devWarnLazy
|
|
21
|
+
} from "./chunk-NT3ZYB5S.js";
|
|
20
22
|
|
|
21
23
|
// src/utils/setSafeAttribute.ts
|
|
22
24
|
var HTML_NS = "http://www.w3.org/1999/xhtml";
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isSSR
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-UYTYNCMZ.js";
|
|
4
4
|
import {
|
|
5
5
|
resumeTracking,
|
|
6
6
|
suspendTracking,
|
|
7
7
|
track
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-LAHX7XFG.js";
|
|
9
9
|
import {
|
|
10
10
|
devAssert
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-NT3ZYB5S.js";
|
|
12
12
|
|
|
13
13
|
// src/core/signals/watch.ts
|
|
14
14
|
function watch(getter, callback) {
|
|
@@ -3,11 +3,11 @@ import {
|
|
|
3
3
|
} from "./chunk-5HZXGZ6T.js";
|
|
4
4
|
import {
|
|
5
5
|
signal
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-FCWOMATN.js";
|
|
7
7
|
import {
|
|
8
8
|
registerDisposer,
|
|
9
9
|
reportError
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-S37PZD6I.js";
|
|
11
11
|
|
|
12
12
|
// src/ui/transition.ts
|
|
13
13
|
function transition(element, options = {}) {
|
|
@@ -1,28 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
registerTransferCollector,
|
|
3
|
+
takeTransferred,
|
|
4
|
+
takeTransferredSection
|
|
5
|
+
} from "./chunk-3HZOSMPX.js";
|
|
1
6
|
import {
|
|
2
7
|
derived
|
|
3
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-ZYK4NZZA.js";
|
|
4
9
|
import {
|
|
5
10
|
globalSingleton
|
|
6
11
|
} from "./chunk-7ZHH77QA.js";
|
|
7
12
|
import {
|
|
8
13
|
effect
|
|
9
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-FFXZ6ELZ.js";
|
|
10
15
|
import {
|
|
11
16
|
sanitizeUrl
|
|
12
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-B3HOT4TK.js";
|
|
13
18
|
import {
|
|
14
|
-
getRequestScopedCache
|
|
15
|
-
|
|
19
|
+
getRequestScopedCache,
|
|
20
|
+
isSSR,
|
|
21
|
+
requestSlot,
|
|
22
|
+
trackPending
|
|
23
|
+
} from "./chunk-UYTYNCMZ.js";
|
|
16
24
|
import {
|
|
17
25
|
batch,
|
|
18
26
|
signal
|
|
19
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-FCWOMATN.js";
|
|
20
28
|
import {
|
|
21
29
|
untracked
|
|
22
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-LAHX7XFG.js";
|
|
23
31
|
import {
|
|
24
32
|
reportError
|
|
25
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-S37PZD6I.js";
|
|
26
34
|
|
|
27
35
|
// src/data/abort.ts
|
|
28
36
|
function isAbortError(error) {
|
|
@@ -218,8 +226,34 @@ function sharedView(entry) {
|
|
|
218
226
|
}
|
|
219
227
|
var globalQueryCache = globalSingleton(/* @__PURE__ */ Symbol.for("sibujs.query.cache.v1"), () => /* @__PURE__ */ new Map());
|
|
220
228
|
function getActiveQueryCache() {
|
|
221
|
-
|
|
229
|
+
const requestCache = getRequestScopedCache("query");
|
|
230
|
+
if (requestCache) return requestCache;
|
|
231
|
+
primeFromTransfer();
|
|
232
|
+
return globalQueryCache;
|
|
233
|
+
}
|
|
234
|
+
var SERVER_EFFECT = { server: true };
|
|
235
|
+
function primeFromTransfer() {
|
|
236
|
+
const entries = takeTransferredSection("q");
|
|
237
|
+
const now = Date.now();
|
|
238
|
+
for (const key of Object.keys(entries)) {
|
|
239
|
+
const record = entries[key];
|
|
240
|
+
if (!record || typeof record !== "object" || record.d === void 0) continue;
|
|
241
|
+
if (globalQueryCache.has(key)) continue;
|
|
242
|
+
const entry = getOrCreateEntry(globalQueryCache, key, record.d);
|
|
243
|
+
const t = typeof record.t === "number" && Number.isFinite(record.t) ? record.t : now;
|
|
244
|
+
entry.dataUpdatedAt = Math.min(t, now);
|
|
245
|
+
}
|
|
222
246
|
}
|
|
247
|
+
registerTransferCollector("q", () => {
|
|
248
|
+
const cache = getRequestScopedCache("query");
|
|
249
|
+
if (!cache) return void 0;
|
|
250
|
+
const out = {};
|
|
251
|
+
for (const [key, entry] of cache) {
|
|
252
|
+
if (entry.noTransfer || entry.data === void 0 || entry.error) continue;
|
|
253
|
+
out[key] = { d: entry.data, t: entry.dataUpdatedAt };
|
|
254
|
+
}
|
|
255
|
+
return out;
|
|
256
|
+
});
|
|
223
257
|
function abandonEntry(entry) {
|
|
224
258
|
if (entry.gcTimer) clearTimeout(entry.gcTimer);
|
|
225
259
|
entry.gcTimer = null;
|
|
@@ -265,11 +299,13 @@ function query(key, fetcher, options = {}) {
|
|
|
265
299
|
onError,
|
|
266
300
|
onSettled,
|
|
267
301
|
select,
|
|
268
|
-
structuralSharing = true
|
|
302
|
+
structuralSharing = true,
|
|
303
|
+
ssr = true
|
|
269
304
|
} = options;
|
|
305
|
+
const onServer = isSSR();
|
|
270
306
|
const resolveKey = typeof key === "function" ? key : () => key;
|
|
271
307
|
const enabledGate = typeof enabled === "function" ? derived(() => Boolean(enabled())) : null;
|
|
272
|
-
const isEnabled = enabledGate ?? (() => Boolean(enabled));
|
|
308
|
+
const isEnabled = onServer && !ssr ? () => false : enabledGate ?? (() => Boolean(enabled));
|
|
273
309
|
const cache = getActiveQueryCache();
|
|
274
310
|
const [data, setData] = signal(initialData);
|
|
275
311
|
const [isFetching, setIsFetching] = signal(false);
|
|
@@ -343,7 +379,7 @@ function query(key, fetcher, options = {}) {
|
|
|
343
379
|
selectedEntry = entry;
|
|
344
380
|
selectedValue = value;
|
|
345
381
|
setData(value);
|
|
346
|
-
}) : null;
|
|
382
|
+
}, SERVER_EFFECT) : null;
|
|
347
383
|
function detachFromEntry() {
|
|
348
384
|
const entry = attachedEntry;
|
|
349
385
|
const key2 = attachedKey;
|
|
@@ -426,7 +462,7 @@ function query(key, fetcher, options = {}) {
|
|
|
426
462
|
runCallback("query onSettled", () => onSettled?.());
|
|
427
463
|
return;
|
|
428
464
|
}
|
|
429
|
-
entry.promise = promise;
|
|
465
|
+
entry.promise = trackPending(promise, `query:${key2}`, false);
|
|
430
466
|
try {
|
|
431
467
|
const result = await promise;
|
|
432
468
|
if (entry.generation !== generation) return;
|
|
@@ -498,6 +534,7 @@ function query(key, fetcher, options = {}) {
|
|
|
498
534
|
return;
|
|
499
535
|
}
|
|
500
536
|
const entry = getOrCreateEntry(cache, key2, initialData);
|
|
537
|
+
if (!ssr) entry.noTransfer = true;
|
|
501
538
|
const reattached = attachedEntry !== entry;
|
|
502
539
|
attachToEntry(entry, key2);
|
|
503
540
|
if (keyChanged) setIsFetching(entry.promise !== null);
|
|
@@ -519,15 +556,15 @@ function query(key, fetcher, options = {}) {
|
|
|
519
556
|
if (on && (entry.data === void 0 || isDataStale)) {
|
|
520
557
|
doFetch();
|
|
521
558
|
}
|
|
522
|
-
});
|
|
523
|
-
if (refetchInterval && refetchInterval > 0) {
|
|
559
|
+
}, SERVER_EFFECT);
|
|
560
|
+
if (!onServer && refetchInterval && refetchInterval > 0) {
|
|
524
561
|
intervalTimer = setInterval(() => {
|
|
525
562
|
if (!disposed && currentKey) doFetch();
|
|
526
563
|
}, refetchInterval);
|
|
527
564
|
}
|
|
528
565
|
let focusHandler = null;
|
|
529
566
|
let onlineHandler = null;
|
|
530
|
-
if (typeof globalThis !== "undefined" && typeof globalThis.addEventListener === "function") {
|
|
567
|
+
if (!onServer && typeof globalThis !== "undefined" && typeof globalThis.addEventListener === "function") {
|
|
531
568
|
if (refetchOnWindowFocus) {
|
|
532
569
|
focusHandler = () => {
|
|
533
570
|
if (!disposed && currentKey) doFetch();
|
|
@@ -956,6 +993,28 @@ function throttle(getter, interval) {
|
|
|
956
993
|
}
|
|
957
994
|
|
|
958
995
|
// src/data/resource.ts
|
|
996
|
+
function transferSlot() {
|
|
997
|
+
return requestSlot("resource:transfer", () => /* @__PURE__ */ new Map());
|
|
998
|
+
}
|
|
999
|
+
function withheldSlot() {
|
|
1000
|
+
return requestSlot("resource:transfer:withheld", () => /* @__PURE__ */ new Set());
|
|
1001
|
+
}
|
|
1002
|
+
registerTransferCollector("r", () => {
|
|
1003
|
+
const slot = transferSlot();
|
|
1004
|
+
if (!slot || slot.size === 0) return void 0;
|
|
1005
|
+
const withheld = withheldSlot();
|
|
1006
|
+
const out = {};
|
|
1007
|
+
let any = false;
|
|
1008
|
+
for (const [key, value] of slot) {
|
|
1009
|
+
if (withheld?.has(key)) continue;
|
|
1010
|
+
out[key] = value;
|
|
1011
|
+
any = true;
|
|
1012
|
+
}
|
|
1013
|
+
return any ? out : void 0;
|
|
1014
|
+
});
|
|
1015
|
+
function withholdTransfer(key) {
|
|
1016
|
+
withheldSlot()?.add(key);
|
|
1017
|
+
}
|
|
959
1018
|
function resource(sourceOrFetcher, fetcherOrOptions, maybeOptions) {
|
|
960
1019
|
let source = null;
|
|
961
1020
|
let fetcher;
|
|
@@ -969,10 +1028,14 @@ function resource(sourceOrFetcher, fetcherOrOptions, maybeOptions) {
|
|
|
969
1028
|
fetcher = (_source, info) => rawFetcher(info);
|
|
970
1029
|
options = fetcherOrOptions ?? {};
|
|
971
1030
|
}
|
|
972
|
-
const
|
|
1031
|
+
const transferred = options.key !== void 0 ? takeTransferred("r", options.key) : void 0;
|
|
1032
|
+
const hydrated = transferred !== void 0;
|
|
1033
|
+
const initialValue = hydrated ? transferred : options.initialValue;
|
|
1034
|
+
const onServer = isSSR();
|
|
1035
|
+
const [data, setData] = signal(initialValue);
|
|
973
1036
|
const [loading, setLoading] = signal(false);
|
|
974
1037
|
const [error, setError] = signal(void 0);
|
|
975
|
-
let currentData =
|
|
1038
|
+
let currentData = initialValue;
|
|
976
1039
|
function commitData(next, explicit) {
|
|
977
1040
|
const sharing = options.structuralSharing ?? true;
|
|
978
1041
|
const shared = untracked(
|
|
@@ -980,6 +1043,7 @@ function resource(sourceOrFetcher, fetcherOrOptions, maybeOptions) {
|
|
|
980
1043
|
);
|
|
981
1044
|
currentData = shared.ok ? shared.value : next;
|
|
982
1045
|
setData(currentData);
|
|
1046
|
+
if (onServer && options.key !== void 0) transferSlot()?.set(options.key, currentData);
|
|
983
1047
|
return currentData;
|
|
984
1048
|
}
|
|
985
1049
|
let abortController = null;
|
|
@@ -1025,19 +1089,28 @@ function resource(sourceOrFetcher, fetcherOrOptions, maybeOptions) {
|
|
|
1025
1089
|
}
|
|
1026
1090
|
}
|
|
1027
1091
|
}
|
|
1092
|
+
const run = (sourceValue) => trackPending(doFetch(sourceValue), "resource", false);
|
|
1028
1093
|
if (source) {
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1094
|
+
let skipFirst = hydrated;
|
|
1095
|
+
effectCleanup = effect(
|
|
1096
|
+
() => {
|
|
1097
|
+
const sourceValue = source();
|
|
1098
|
+
if (skipFirst) {
|
|
1099
|
+
skipFirst = false;
|
|
1100
|
+
return;
|
|
1101
|
+
}
|
|
1102
|
+
run(sourceValue);
|
|
1103
|
+
},
|
|
1104
|
+
{ server: true }
|
|
1105
|
+
);
|
|
1106
|
+
} else if (options.immediate !== false && !hydrated) {
|
|
1107
|
+
run(void 0);
|
|
1035
1108
|
}
|
|
1036
1109
|
return {
|
|
1037
1110
|
data,
|
|
1038
1111
|
loading,
|
|
1039
1112
|
error,
|
|
1040
|
-
refetch: () =>
|
|
1113
|
+
refetch: () => run(source ? source() : void 0),
|
|
1041
1114
|
mutate: (value) => {
|
|
1042
1115
|
const newValue = typeof value === "function" ? value(currentData) : value;
|
|
1043
1116
|
commitData(newValue, true);
|
|
@@ -1338,8 +1411,27 @@ function currentScope() {
|
|
|
1338
1411
|
}
|
|
1339
1412
|
return scope;
|
|
1340
1413
|
}
|
|
1414
|
+
function automaticKey(loader, context) {
|
|
1415
|
+
const key = `loader:${context.path}${loader.name ? `:${loader.name}` : ""}`;
|
|
1416
|
+
const cache = getRequestScopedCache("routeLoader");
|
|
1417
|
+
if (!cache) return key;
|
|
1418
|
+
let owners = cache.get("owners");
|
|
1419
|
+
if (!owners) {
|
|
1420
|
+
owners = /* @__PURE__ */ new Map();
|
|
1421
|
+
cache.set("owners", owners);
|
|
1422
|
+
}
|
|
1423
|
+
const owner = owners.get(key);
|
|
1424
|
+
if (owner === void 0) {
|
|
1425
|
+
owners.set(key, loader);
|
|
1426
|
+
return key;
|
|
1427
|
+
}
|
|
1428
|
+
if (owner === loader) return key;
|
|
1429
|
+
withholdTransfer(key);
|
|
1430
|
+
return void 0;
|
|
1431
|
+
}
|
|
1341
1432
|
function executeLoader(loader, context, options) {
|
|
1342
|
-
const
|
|
1433
|
+
const key = options?.key ?? automaticKey(loader, context);
|
|
1434
|
+
const res = resource(({ signal: signal2 }) => loader(context, { signal: signal2 }), { ...options, key });
|
|
1343
1435
|
const disposeResource = res.dispose;
|
|
1344
1436
|
res.dispose = () => {
|
|
1345
1437
|
_disposed.add(res);
|
|
@@ -1667,6 +1759,7 @@ export {
|
|
|
1667
1759
|
previous,
|
|
1668
1760
|
debounce,
|
|
1669
1761
|
throttle,
|
|
1762
|
+
withholdTransfer,
|
|
1670
1763
|
resource,
|
|
1671
1764
|
offlineStore,
|
|
1672
1765
|
syncAdapter,
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
drainNotificationQueue,
|
|
3
|
-
emitDevtools,
|
|
4
3
|
notifySubscribers,
|
|
5
4
|
queueSignalNotification,
|
|
6
5
|
recordDependency
|
|
7
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-LAHX7XFG.js";
|
|
8
7
|
import {
|
|
9
8
|
DEV
|
|
10
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-NT3ZYB5S.js";
|
|
11
10
|
|
|
12
11
|
// src/reactivity/batch.ts
|
|
13
12
|
var batchDepth = 0;
|
|
@@ -59,6 +58,14 @@ var batch = API.batch;
|
|
|
59
58
|
var enqueueBatchedSignal = API.enqueueBatchedSignal;
|
|
60
59
|
var isBatching = API.isBatching;
|
|
61
60
|
|
|
61
|
+
// src/core/devtoolsHook.ts
|
|
62
|
+
function emitDevtools(hook, event, payload) {
|
|
63
|
+
try {
|
|
64
|
+
hook.emit(event, payload);
|
|
65
|
+
} catch {
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
62
69
|
// src/core/signals/signal.ts
|
|
63
70
|
var _g = globalThis;
|
|
64
71
|
function signal(initial, options) {
|
|
@@ -145,6 +152,7 @@ export {
|
|
|
145
152
|
batch,
|
|
146
153
|
enqueueBatchedSignal,
|
|
147
154
|
isBatching,
|
|
155
|
+
emitDevtools,
|
|
148
156
|
signal,
|
|
149
157
|
external
|
|
150
158
|
};
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isSSR
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-UYTYNCMZ.js";
|
|
4
|
+
import {
|
|
5
|
+
emitDevtools
|
|
6
|
+
} from "./chunk-FCWOMATN.js";
|
|
4
7
|
import {
|
|
5
8
|
cleanup,
|
|
6
|
-
emitDevtools,
|
|
7
9
|
getOwnerScope,
|
|
8
10
|
retrack,
|
|
9
11
|
runWithOwnerScope,
|
|
10
12
|
untracked
|
|
11
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-LAHX7XFG.js";
|
|
12
14
|
import {
|
|
13
|
-
devAssert,
|
|
14
15
|
reportError
|
|
15
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-S37PZD6I.js";
|
|
17
|
+
import {
|
|
18
|
+
devAssert
|
|
19
|
+
} from "./chunk-NT3ZYB5S.js";
|
|
16
20
|
|
|
17
21
|
// src/core/signals/effect.ts
|
|
18
22
|
var _g = globalThis;
|
|
@@ -94,7 +98,7 @@ function disposeEffect(ctx) {
|
|
|
94
98
|
}
|
|
95
99
|
function effect(effectFn, options) {
|
|
96
100
|
devAssert(typeof effectFn === "function", "effect: argument must be a function.");
|
|
97
|
-
if (isSSR()) return () => {
|
|
101
|
+
if (isSSR() && !options?.server) return () => {
|
|
98
102
|
};
|
|
99
103
|
const ctx = {
|
|
100
104
|
fn: effectFn,
|