@farm.js/core 0.1.17 → 0.1.19
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/after.cjs +12 -225
- package/dist/agent-runtime.cjs +83 -2800
- package/dist/api/client.cjs +17 -4060
- package/dist/api/route-manager.cjs +34 -4354
- package/dist/api/runtime.cjs +29 -2696
- package/dist/api.cjs +88 -8434
- package/dist/app-markdown.cjs +39 -280
- package/dist/app-markdown.mjs +3 -3
- package/dist/cache.cjs +38 -1560
- package/dist/chunk-22GUSVNJ.cjs +351 -0
- package/dist/{chunk-EN7WTEAY.mjs → chunk-2ANEVVF7.mjs} +1 -1
- package/dist/chunk-2CQ74SP6.cjs +13 -0
- package/dist/{chunk-YD4J4XCI.mjs → chunk-2GNATDDE.mjs} +1 -1
- package/dist/chunk-2SJ4RQ6P.cjs +57 -0
- package/dist/chunk-3376ZTRC.cjs +1 -0
- package/dist/chunk-4PNUXIVU.cjs +472 -0
- package/dist/chunk-4PPEPOZZ.cjs +21 -0
- package/dist/chunk-4ZFL5GFN.cjs +520 -0
- package/dist/chunk-5OVTOKGH.cjs +65 -0
- package/dist/chunk-5QIKR7RR.cjs +224 -0
- package/dist/chunk-5ZSWG4UX.cjs +127 -0
- package/dist/chunk-62YJ2IEB.cjs +238 -0
- package/dist/chunk-6EODJYCX.cjs +183 -0
- package/dist/chunk-6EXBPJ24.cjs +434 -0
- package/dist/chunk-6QQDAAAZ.cjs +38 -0
- package/dist/chunk-6V4TDWEC.cjs +455 -0
- package/dist/chunk-72ADZ6GQ.cjs +19 -0
- package/dist/chunk-75BRBIFP.cjs +172 -0
- package/dist/{chunk-ZCNJKLA2.mjs → chunk-7BC6GAL7.mjs} +1 -1
- package/dist/chunk-7W3CPVXS.cjs +24 -0
- package/dist/chunk-A6WIQH5Z.cjs +31 -0
- package/dist/chunk-A777V5WU.cjs +725 -0
- package/dist/chunk-AFOD3LYZ.cjs +377 -0
- package/dist/chunk-AH7HOAQ3.cjs +151 -0
- package/dist/chunk-AMDMVWMI.cjs +39 -0
- package/dist/chunk-AORPIPNB.cjs +552 -0
- package/dist/chunk-ARJWXNQL.cjs +256 -0
- package/dist/chunk-AYJR42WX.cjs +711 -0
- package/dist/chunk-BBVSJVBZ.cjs +600 -0
- package/dist/chunk-BIDYX3SL.cjs +91 -0
- package/dist/chunk-BYODCJD6.cjs +663 -0
- package/dist/chunk-C3VRMB6H.cjs +85 -0
- package/dist/chunk-C5GUTBZK.cjs +173 -0
- package/dist/chunk-CIAGU2X4.cjs +337 -0
- package/dist/chunk-CMGMGHUZ.cjs +27 -0
- package/dist/chunk-CXP5U3RW.cjs +54 -0
- package/dist/chunk-D2ULAULS.cjs +166 -0
- package/dist/chunk-D7JTOLFK.cjs +285 -0
- package/dist/chunk-DVM4FKZL.cjs +169 -0
- package/dist/chunk-DYEJQTDN.cjs +49 -0
- package/dist/chunk-E2ROOWQC.cjs +2225 -0
- package/dist/chunk-E3UK5IIB.cjs +593 -0
- package/dist/chunk-EM6SBQKM.cjs +470 -0
- package/dist/chunk-FJSWYIR7.cjs +482 -0
- package/dist/chunk-FK6GO24V.cjs +54 -0
- package/dist/{chunk-MVIWBEJF.mjs → chunk-FVZGEVTO.mjs} +7 -7
- package/dist/chunk-FXUUWYAX.cjs +654 -0
- package/dist/chunk-G3HRIVEY.cjs +395 -0
- package/dist/chunk-G643DQCH.cjs +13 -0
- package/dist/chunk-G7HXGLEC.cjs +175 -0
- package/dist/chunk-GDSHDTJ4.cjs +152 -0
- package/dist/chunk-GPVTX3HT.cjs +1415 -0
- package/dist/chunk-H6G5INWM.cjs +1094 -0
- package/dist/{chunk-DHDVMXYK.mjs → chunk-HALDNTIV.mjs} +30 -4
- package/dist/chunk-HBTUGXHS.cjs +180 -0
- package/dist/chunk-HREOKQWT.cjs +45 -0
- package/dist/{chunk-5QOEPUYE.mjs → chunk-HSDL2AUR.mjs} +1 -1
- package/dist/chunk-I4J452B7.cjs +435 -0
- package/dist/chunk-I57LW5VZ.cjs +94 -0
- package/dist/chunk-I5YBCWQ6.cjs +40 -0
- package/dist/chunk-I7PUUDGY.cjs +389 -0
- package/dist/chunk-IAMRBF3Z.cjs +86 -0
- package/dist/chunk-IQXFRNY2.cjs +169 -0
- package/dist/chunk-ISTFC3MZ.cjs +1357 -0
- package/dist/chunk-IXTFU4PL.cjs +2355 -0
- package/dist/chunk-J3LOGE4T.cjs +42 -0
- package/dist/chunk-J7FSKED3.cjs +93 -0
- package/dist/chunk-JDNHKPTD.cjs +22 -0
- package/dist/chunk-JSROZYYO.cjs +164 -0
- package/dist/chunk-K6FNHVDR.cjs +696 -0
- package/dist/chunk-KGZIORNL.cjs +43 -0
- package/dist/chunk-KR6CKSXT.cjs +15 -0
- package/dist/chunk-KROWKCUH.cjs +185 -0
- package/dist/chunk-KVFPGF2M.cjs +46 -0
- package/dist/{chunk-TNBAYAWO.mjs → chunk-L4DVIHOC.mjs} +1 -1
- package/dist/chunk-LCCBO7PJ.cjs +46 -0
- package/dist/chunk-LIUGYUX3.cjs +22 -0
- package/dist/chunk-LTNGXMQ6.cjs +55 -0
- package/dist/chunk-M2L4MYDQ.cjs +14 -0
- package/dist/chunk-MCJLA63J.cjs +1 -0
- package/dist/chunk-MKB2EGIR.cjs +148 -0
- package/dist/chunk-MQ3H6LT5.cjs +202 -0
- package/dist/chunk-MT763TDW.cjs +43 -0
- package/dist/{chunk-XWAYMDLB.mjs → chunk-MVUREHPN.mjs} +1 -1
- package/dist/chunk-MWSK6C4J.cjs +18 -0
- package/dist/chunk-MWWVKDW3.cjs +169 -0
- package/dist/{chunk-6VQIKZZO.mjs → chunk-N255VYFP.mjs} +1 -1
- package/dist/chunk-NBAHDVOJ.cjs +2040 -0
- package/dist/chunk-NO3WWW3N.cjs +192 -0
- package/dist/chunk-NSFC3LHB.cjs +10244 -0
- package/dist/chunk-NZKJGRB3.cjs +230 -0
- package/dist/chunk-OAVTUMJP.cjs +1496 -0
- package/dist/{chunk-SXHV42UQ.mjs → chunk-OFEY6KHO.mjs} +88 -13
- package/dist/chunk-OHY2ZWUG.cjs +25 -0
- package/dist/chunk-OI6CMLWX.cjs +47 -0
- package/dist/chunk-OWOUTKIJ.cjs +558 -0
- package/dist/chunk-OX6O6WVA.cjs +74 -0
- package/dist/chunk-OXSIH4D6.cjs +476 -0
- package/dist/chunk-OYDRPBBV.cjs +453 -0
- package/dist/chunk-OYEUREB6.cjs +35 -0
- package/dist/chunk-PCOTGFSM.cjs +139 -0
- package/dist/{chunk-76DG3LF3.mjs → chunk-PGQBL5DN.mjs} +1 -1
- package/dist/chunk-PZYCPSCC.cjs +35 -0
- package/dist/chunk-QBK2AA4U.cjs +445 -0
- package/dist/{chunk-UTBVHYS3.mjs → chunk-QBPKKQTD.mjs} +2 -2
- package/dist/chunk-QBPXNZGV.cjs +487 -0
- package/dist/chunk-QNPEUFHQ.cjs +27 -0
- package/dist/chunk-QZRVZSPN.cjs +236 -0
- package/dist/chunk-R5A5KNVX.cjs +20 -0
- package/dist/chunk-R5JIFR6B.cjs +42 -0
- package/dist/chunk-R6AIILII.cjs +193 -0
- package/dist/chunk-RFYO7QUD.cjs +9 -0
- package/dist/chunk-RG3ZOTG5.cjs +34 -0
- package/dist/chunk-ROUTX2E5.cjs +390 -0
- package/dist/chunk-RTHIVJ2G.cjs +54 -0
- package/dist/chunk-S27FMYAM.cjs +644 -0
- package/dist/chunk-S3A45T7F.cjs +166 -0
- package/dist/chunk-S3JO3N4H.cjs +17 -0
- package/dist/chunk-SK35NQKK.cjs +27 -0
- package/dist/chunk-SU7MH53P.cjs +180 -0
- package/dist/chunk-SVRTJOUF.cjs +113 -0
- package/dist/chunk-SWN467MP.cjs +18 -0
- package/dist/chunk-SYQ3MOWW.cjs +73 -0
- package/dist/chunk-T5CERMEH.cjs +417 -0
- package/dist/chunk-TFAXUHWX.cjs +206 -0
- package/dist/chunk-TIWHTW3Q.cjs +24 -0
- package/dist/chunk-TKJZFIML.cjs +20 -0
- package/dist/chunk-TKNSDBBN.cjs +193 -0
- package/dist/chunk-U4KT7QP3.cjs +23 -0
- package/dist/chunk-U5BMPGS3.cjs +862 -0
- package/dist/chunk-UJ2C4ICS.cjs +277 -0
- package/dist/chunk-UQZ4AYTH.cjs +168 -0
- package/dist/chunk-US2QVW3E.cjs +36 -0
- package/dist/{chunk-QGVJVSNX.mjs → chunk-V4AICMQA.mjs} +2 -2
- package/dist/chunk-VB6UCX3V.cjs +421 -0
- package/dist/chunk-VEKFLAQM.cjs +300 -0
- package/dist/chunk-VQDBNVOO.cjs +14 -0
- package/dist/chunk-W4E7WMXE.cjs +71 -0
- package/dist/chunk-WJ3HK3LJ.cjs +1102 -0
- package/dist/chunk-WMAPPDMM.cjs +28 -0
- package/dist/chunk-WMOGFOUJ.cjs +223 -0
- package/dist/chunk-WPYFSQKK.cjs +37 -0
- package/dist/{chunk-56DAX2BE.mjs → chunk-WZXN4R5Y.mjs} +24 -13
- package/dist/chunk-XDGMADQM.cjs +14225 -0
- package/dist/chunk-XGC343EY.cjs +443 -0
- package/dist/chunk-XSKZORAS.cjs +727 -0
- package/dist/chunk-XWAWFQFS.cjs +82 -0
- package/dist/chunk-Y4YMF2NQ.cjs +460 -0
- package/dist/chunk-Y4YWHNKU.cjs +250 -0
- package/dist/chunk-Y53ZSFN6.cjs +504 -0
- package/dist/chunk-YA6LLTIJ.cjs +411 -0
- package/dist/chunk-YFPGHF5F.cjs +202 -0
- package/dist/chunk-YJRZR7VU.cjs +28 -0
- package/dist/chunk-YTAABQEV.cjs +1 -0
- package/dist/chunk-YX3DBN4M.cjs +18 -0
- package/dist/chunk-YZTASLPQ.cjs +64 -0
- package/dist/chunk-Z5HIWVDP.cjs +2173 -0
- package/dist/chunk-ZEG3OPIB.cjs +93 -0
- package/dist/chunk-ZMN3H73H.cjs +155 -0
- package/dist/client/lifecycle.cjs +6 -35
- package/dist/client-plugins.cjs +7 -448
- package/dist/client.cjs +171 -9808
- package/dist/config.cjs +8 -36
- package/dist/cron.cjs +24 -491
- package/dist/deferred.cjs +26 -475
- package/dist/deployment.cjs +39 -210
- package/dist/devtools-5KGPDVKL.cjs +388 -0
- package/dist/{devtools-UFVTMQX5.mjs → devtools-FY5R7TQ4.mjs} +3 -3
- package/dist/devtools-client-4WAPJY5L.cjs +254 -0
- package/dist/devtools-ui-5GBDIGMK.cjs +1296 -0
- package/dist/docs.cjs +46 -5657
- package/dist/docs.mjs +5 -5
- package/dist/env-types.cjs +5 -226
- package/dist/env.cjs +21 -338
- package/dist/environment/vite.cjs +8 -372
- package/dist/environment.cjs +12 -94
- package/dist/font.cjs +13 -63
- package/dist/headers.cjs +7 -123
- package/dist/i18n/client.cjs +55 -294
- package/dist/i18n/index.cjs +22 -209
- package/dist/i18n/server.cjs +22 -745
- package/dist/image/server.cjs +13 -729
- package/dist/image/sharp.cjs +33 -171
- package/dist/image.cjs +41 -85
- package/dist/index.cjs +1151 -68080
- package/dist/index.mjs +14 -14
- package/dist/instrumentation.cjs +12 -138
- package/dist/integration-orm-55F7CII5.cjs +13 -0
- package/dist/integrations.cjs +55 -4090
- package/dist/internal/app-markdown-runtime.cjs +27 -224
- package/dist/internal/app-markdown-runtime.mjs +2 -2
- package/dist/internal/build-runtime.cjs +120 -52259
- package/dist/internal/build-runtime.mjs +13 -13
- package/dist/internal/cli-runtime.cjs +67 -13811
- package/dist/internal/cli-runtime.mjs +7 -7
- package/dist/internal/client-error-overlay.cjs +80 -733
- package/dist/internal/client-error-overlay.mjs +1 -1
- package/dist/internal/client-runtime.cjs +81 -913
- package/dist/internal/compression-runtime.cjs +8 -214
- package/dist/internal/config-runtime.cjs +42 -6547
- package/dist/internal/config-runtime.mjs +3 -3
- package/dist/internal/docs-precompiled-runtime.cjs +26 -46
- package/dist/internal/infra-analytics-runtime.cjs +10 -536
- package/dist/internal/isolated-boundary.cjs +14 -414
- package/dist/internal/metadata-image-runtime.cjs +7 -285
- package/dist/internal/product-telemetry-runtime.cjs +42 -97
- package/dist/internal/product-telemetry-runtime.mjs +1 -1
- package/dist/internal/production-node-env.cjs +6 -63
- package/dist/internal/production-runtime.cjs +418 -7133
- package/dist/internal/production-runtime.mjs +3 -3
- package/dist/internal/request-cookies.cjs +6 -54
- package/dist/json-ld.cjs +24 -50
- package/dist/layers-E4WPJNY5.cjs +17 -0
- package/dist/manager-G4B2IPYE.cjs +14 -0
- package/dist/markdown.cjs +21 -547
- package/dist/markdown.mjs +1 -1
- package/dist/middleware.cjs +36 -2995
- package/dist/navigation.cjs +22 -2588
- package/dist/nitro-4I2MYLY2.cjs +652 -0
- package/dist/observability.cjs +22 -614
- package/dist/og.cjs +5 -28
- package/dist/plugin.cjs +106 -37442
- package/dist/plugin.mjs +9 -9
- package/dist/query/client.cjs +113 -449
- package/dist/query/index.cjs +26 -288
- package/dist/query/parsers.cjs +23 -247
- package/dist/query/server.cjs +36 -298
- package/dist/renderer/react/client.cjs +9 -43
- package/dist/renderer/react/server.cjs +40 -103
- package/dist/renderer/react/vite.cjs +7 -29
- package/dist/renderer-client.cjs +126 -4295
- package/dist/renderer.cjs +31 -249
- package/dist/request.cjs +5 -68
- package/dist/router.cjs +11 -474
- package/dist/routes.cjs +42 -2461
- package/dist/{schema-dev-notice-2IE2F2XI.mjs → schema-dev-notice-O67CPXJ6.mjs} +1 -1
- package/dist/schema-dev-notice-Y7MQEFGN.cjs +56 -0
- package/dist/schema.cjs +6 -33
- package/dist/search-client-G3RICOFU.cjs +13 -0
- package/dist/server-action-security.cjs +25 -541
- package/dist/server-fn-client.cjs +6 -337
- package/dist/server-fn.cjs +32 -1841
- package/dist/server-plugins.cjs +15 -884
- package/dist/server-query-client.cjs +15 -1883
- package/dist/server-query.cjs +16 -1838
- package/dist/server.cjs +296 -44681
- package/dist/server.mjs +11 -11
- package/dist/storage.cjs +57 -576
- package/dist/testing.cjs +89 -3186
- package/dist/theme/client.cjs +13 -108
- package/dist/theme/index.cjs +6 -68
- package/dist/theme/runtime.cjs +13 -78
- package/dist/theme/server.cjs +10 -179
- package/dist/version.cjs +4 -32
- package/dist/version.mjs +1 -1
- package/dist/vite.cjs +119 -37773
- package/dist/vite.mjs +9 -9
- package/dist/workflows.cjs +19 -1040
- package/package.json +1 -1
|
@@ -0,0 +1,1496 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _chunkD7JTOLFKcjs = require('./chunk-D7JTOLFK.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
var _chunkIXTFU4PLcjs = require('./chunk-IXTFU4PL.cjs');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
var _chunkLTNGXMQ6cjs = require('./chunk-LTNGXMQ6.cjs');
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
var _chunkSU7MH53Pcjs = require('./chunk-SU7MH53P.cjs');
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
var _chunk5OVTOKGHcjs = require('./chunk-5OVTOKGH.cjs');
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
var _chunkSWN467MPcjs = require('./chunk-SWN467MP.cjs');
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
var _chunkI7PUUDGYcjs = require('./chunk-I7PUUDGY.cjs');
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
var _chunkOYEUREB6cjs = require('./chunk-OYEUREB6.cjs');
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
var _chunkZEG3OPIBcjs = require('./chunk-ZEG3OPIB.cjs');
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
var _chunkI57LW5VZcjs = require('./chunk-I57LW5VZ.cjs');
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
var _chunkS3JO3N4Hcjs = require('./chunk-S3JO3N4H.cjs');
|
|
45
|
+
|
|
46
|
+
// src/mutation-client.ts
|
|
47
|
+
var _react = require('react');
|
|
48
|
+
|
|
49
|
+
// src/client-network-status.ts
|
|
50
|
+
function isNavigatorOnline() {
|
|
51
|
+
if (typeof navigator === "undefined" || typeof navigator.onLine !== "boolean") return true;
|
|
52
|
+
return navigator.onLine;
|
|
53
|
+
}
|
|
54
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, isNavigatorOnline, "isNavigatorOnline");
|
|
55
|
+
function subscribeOnline(listener) {
|
|
56
|
+
if (typeof window === "undefined") return () => {
|
|
57
|
+
};
|
|
58
|
+
window.addEventListener("online", listener);
|
|
59
|
+
return () => window.removeEventListener("online", listener);
|
|
60
|
+
}
|
|
61
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, subscribeOnline, "subscribeOnline");
|
|
62
|
+
|
|
63
|
+
// src/mutation-client.ts
|
|
64
|
+
function useMutation(target, options = {}) {
|
|
65
|
+
return useMutationLifecycle(target, options).mutation;
|
|
66
|
+
}
|
|
67
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, useMutation, "useMutation");
|
|
68
|
+
function useMutationLifecycle(target, options = {}) {
|
|
69
|
+
const initialData = _nullishCoalesce(options.initialData, () => ( null));
|
|
70
|
+
const optionsRef = _react.useRef.call(void 0, options);
|
|
71
|
+
const targetRef = _react.useRef.call(void 0, target);
|
|
72
|
+
const requestIdRef = _react.useRef.call(void 0, 0);
|
|
73
|
+
const lastResetIdRef = _react.useRef.call(void 0, 0);
|
|
74
|
+
const initialState = {
|
|
75
|
+
pendingCount: 0,
|
|
76
|
+
pausedCount: 0,
|
|
77
|
+
status: "idle",
|
|
78
|
+
data: initialData,
|
|
79
|
+
error: null,
|
|
80
|
+
variables: void 0
|
|
81
|
+
};
|
|
82
|
+
const stateRef = _react.useRef.call(void 0, initialState);
|
|
83
|
+
const resetWakersRef = _react.useRef.call(void 0, /* @__PURE__ */ new Set());
|
|
84
|
+
const [state, setState] = _react.useState.call(void 0, initialState);
|
|
85
|
+
optionsRef.current = options;
|
|
86
|
+
targetRef.current = target;
|
|
87
|
+
const setMutationState = _react.useCallback.call(void 0,
|
|
88
|
+
(value) => {
|
|
89
|
+
const next = typeof value === "function" ? value(stateRef.current) : value;
|
|
90
|
+
stateRef.current = next;
|
|
91
|
+
setState(next);
|
|
92
|
+
},
|
|
93
|
+
[]
|
|
94
|
+
);
|
|
95
|
+
const waitForReconnect = _react.useCallback.call(void 0,
|
|
96
|
+
async (requestId) => {
|
|
97
|
+
while (!isNavigatorOnline()) {
|
|
98
|
+
if (requestId < lastResetIdRef.current) return;
|
|
99
|
+
setMutationState((current) => ({ ...current, pausedCount: current.pausedCount + 1 }));
|
|
100
|
+
try {
|
|
101
|
+
await new Promise((resolve) => {
|
|
102
|
+
const wake = /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, () => {
|
|
103
|
+
unsubscribe();
|
|
104
|
+
resetWakersRef.current.delete(wake);
|
|
105
|
+
resolve();
|
|
106
|
+
}, "wake");
|
|
107
|
+
const unsubscribe = subscribeOnline(wake);
|
|
108
|
+
resetWakersRef.current.add(wake);
|
|
109
|
+
});
|
|
110
|
+
} finally {
|
|
111
|
+
setMutationState((current) => ({
|
|
112
|
+
...current,
|
|
113
|
+
pausedCount: Math.max(0, current.pausedCount - 1)
|
|
114
|
+
}));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
[setMutationState]
|
|
119
|
+
);
|
|
120
|
+
const mutatePreparedAsync = _react.useCallback.call(void 0,
|
|
121
|
+
async (prepare) => {
|
|
122
|
+
const requestId = ++requestIdRef.current;
|
|
123
|
+
const currentOptions = optionsRef.current;
|
|
124
|
+
const previousData = stateRef.current.data;
|
|
125
|
+
let variables;
|
|
126
|
+
let preparationFailed = false;
|
|
127
|
+
let preparationError;
|
|
128
|
+
try {
|
|
129
|
+
variables = prepare();
|
|
130
|
+
} catch (error) {
|
|
131
|
+
preparationFailed = true;
|
|
132
|
+
preparationError = error;
|
|
133
|
+
}
|
|
134
|
+
const optimisticData = preparationFailed ? void 0 : _optionalChain([currentOptions, 'access', _ => _.optimistic, 'optionalCall', _2 => _2({ variables, current: previousData })]);
|
|
135
|
+
const hasOptimisticData = optimisticData !== void 0;
|
|
136
|
+
setMutationState((current) => {
|
|
137
|
+
if (requestId < lastResetIdRef.current) return current;
|
|
138
|
+
const pendingCount = current.pendingCount + 1;
|
|
139
|
+
if (requestId !== requestIdRef.current) return { ...current, pendingCount };
|
|
140
|
+
return {
|
|
141
|
+
pendingCount,
|
|
142
|
+
pausedCount: current.pausedCount,
|
|
143
|
+
status: "pending",
|
|
144
|
+
data: hasOptimisticData ? optimisticData : currentOptions.resetOnMutate === false ? current.data : null,
|
|
145
|
+
error: null,
|
|
146
|
+
variables
|
|
147
|
+
};
|
|
148
|
+
});
|
|
149
|
+
const mutationTarget = targetRef.current;
|
|
150
|
+
const isAPITarget = _chunkIXTFU4PLcjs.isAPIRouteRef.call(void 0, mutationTarget);
|
|
151
|
+
const sharedOptimistic = !preparationFailed && !isAPITarget ? _optionalChain([currentOptions, 'access', _3 => _3.request, 'optionalAccess', _4 => _4.optimistic]) : void 0;
|
|
152
|
+
const sharedSnapshots = _optionalChain([sharedOptimistic, 'optionalAccess', _5 => _5.update, 'optionalAccess', _6 => _6.length]) ? _chunkIXTFU4PLcjs.applyServerFnOptimisticUpdates.call(void 0, sharedOptimistic.update) : [];
|
|
153
|
+
try {
|
|
154
|
+
if (preparationFailed) throw preparationError;
|
|
155
|
+
let data;
|
|
156
|
+
while (true) {
|
|
157
|
+
if (currentOptions.networkMode === "online") {
|
|
158
|
+
await waitForReconnect(requestId);
|
|
159
|
+
if (requestId < lastResetIdRef.current) {
|
|
160
|
+
throw new Error("Mutation reset while waiting for reconnection");
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
try {
|
|
164
|
+
const rawResult = isAPITarget ? await mutationTarget(variables, currentOptions.request) : await _chunkD7JTOLFKcjs.invokeMutationWithRetry.call(void 0,
|
|
165
|
+
() => targetRef.current(variables),
|
|
166
|
+
_optionalChain([currentOptions, 'access', _7 => _7.request, 'optionalAccess', _8 => _8.retry]),
|
|
167
|
+
// A reset disowns this submission; stop scheduling retries then.
|
|
168
|
+
() => requestId >= lastResetIdRef.current
|
|
169
|
+
);
|
|
170
|
+
data = unwrapMutationResult(rawResult, isAPITarget);
|
|
171
|
+
break;
|
|
172
|
+
} catch (cause) {
|
|
173
|
+
if (currentOptions.networkMode === "online" && !isNavigatorOnline() && requestId >= lastResetIdRef.current && isConnectivityFailure(cause)) {
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
throw cause;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
_chunkIXTFU4PLcjs.settleServerFnOptimisticUpdates.call(void 0, sharedSnapshots, "commit");
|
|
180
|
+
if (!isAPITarget && _optionalChain([currentOptions, 'access', _9 => _9.request, 'optionalAccess', _10 => _10.invalidate])) {
|
|
181
|
+
for (const key of _chunkIXTFU4PLcjs.resolveServerFnInvalidateTargets.call(void 0, currentOptions.request.invalidate)) {
|
|
182
|
+
_chunkZEG3OPIBcjs.notifyFarmCacheInvalidation.call(void 0, key);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
const isLatestRequest = requestId === requestIdRef.current;
|
|
186
|
+
setMutationState((current) => {
|
|
187
|
+
if (requestId < lastResetIdRef.current) return current;
|
|
188
|
+
const pendingCount = Math.max(0, current.pendingCount - 1);
|
|
189
|
+
if (!isLatestRequest) {
|
|
190
|
+
return {
|
|
191
|
+
...current,
|
|
192
|
+
pendingCount
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
return {
|
|
196
|
+
pendingCount,
|
|
197
|
+
pausedCount: current.pausedCount,
|
|
198
|
+
status: "success",
|
|
199
|
+
data,
|
|
200
|
+
error: null,
|
|
201
|
+
variables
|
|
202
|
+
};
|
|
203
|
+
});
|
|
204
|
+
if (isLatestRequest) {
|
|
205
|
+
_chunkLTNGXMQ6cjs.notifyClientObserver.call(void 0, currentOptions.onSuccess, [data, variables], "Mutation onSuccess");
|
|
206
|
+
if (requestId === requestIdRef.current) {
|
|
207
|
+
_chunkLTNGXMQ6cjs.notifyClientObserver.call(void 0,
|
|
208
|
+
currentOptions.onSettled,
|
|
209
|
+
[data, null, variables],
|
|
210
|
+
"Mutation onSettled"
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return data;
|
|
215
|
+
} catch (cause) {
|
|
216
|
+
_chunkIXTFU4PLcjs.settleServerFnOptimisticUpdates.call(void 0,
|
|
217
|
+
sharedSnapshots,
|
|
218
|
+
_optionalChain([sharedOptimistic, 'optionalAccess', _11 => _11.rollbackOnError]) ? "rollback" : "invalidate"
|
|
219
|
+
);
|
|
220
|
+
const error = normalizeMutationError(cause);
|
|
221
|
+
const isLatestRequest = requestId === requestIdRef.current;
|
|
222
|
+
setMutationState((current) => {
|
|
223
|
+
if (requestId < lastResetIdRef.current) return current;
|
|
224
|
+
const pendingCount = Math.max(0, current.pendingCount - 1);
|
|
225
|
+
if (!isLatestRequest) {
|
|
226
|
+
return {
|
|
227
|
+
...current,
|
|
228
|
+
pendingCount
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
return {
|
|
232
|
+
pendingCount,
|
|
233
|
+
pausedCount: current.pausedCount,
|
|
234
|
+
status: "error",
|
|
235
|
+
data: hasOptimisticData && currentOptions.rollbackOnError ? previousData : currentOptions.resetOnMutate === false ? current.data : null,
|
|
236
|
+
error,
|
|
237
|
+
variables
|
|
238
|
+
};
|
|
239
|
+
});
|
|
240
|
+
if (isLatestRequest) {
|
|
241
|
+
_chunkLTNGXMQ6cjs.notifyClientObserver.call(void 0, currentOptions.onError, [error, variables], "Mutation onError");
|
|
242
|
+
if (requestId === requestIdRef.current) {
|
|
243
|
+
_chunkLTNGXMQ6cjs.notifyClientObserver.call(void 0,
|
|
244
|
+
currentOptions.onSettled,
|
|
245
|
+
[null, error, variables],
|
|
246
|
+
"Mutation onSettled"
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
throw error;
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
[setMutationState, waitForReconnect]
|
|
254
|
+
);
|
|
255
|
+
const mutateAsync = _react.useCallback.call(void 0,
|
|
256
|
+
(variables) => mutatePreparedAsync(() => variables),
|
|
257
|
+
[mutatePreparedAsync]
|
|
258
|
+
);
|
|
259
|
+
const mutate = _react.useCallback.call(void 0,
|
|
260
|
+
(variables) => {
|
|
261
|
+
void mutateAsync(variables).catch(() => {
|
|
262
|
+
});
|
|
263
|
+
},
|
|
264
|
+
[mutateAsync]
|
|
265
|
+
);
|
|
266
|
+
const reset = _react.useCallback.call(void 0, () => {
|
|
267
|
+
lastResetIdRef.current = ++requestIdRef.current;
|
|
268
|
+
setMutationState({
|
|
269
|
+
pendingCount: 0,
|
|
270
|
+
pausedCount: 0,
|
|
271
|
+
status: "idle",
|
|
272
|
+
data: _nullishCoalesce(optionsRef.current.initialData, () => ( null)),
|
|
273
|
+
error: null,
|
|
274
|
+
variables: void 0
|
|
275
|
+
});
|
|
276
|
+
const wakers = Array.from(resetWakersRef.current);
|
|
277
|
+
resetWakersRef.current.clear();
|
|
278
|
+
for (const wake of wakers) wake();
|
|
279
|
+
}, [setMutationState]);
|
|
280
|
+
const mutation = _react.useMemo.call(void 0,
|
|
281
|
+
() => ({
|
|
282
|
+
pending: state.pendingCount > 0,
|
|
283
|
+
paused: state.pausedCount > 0,
|
|
284
|
+
status: state.status,
|
|
285
|
+
data: state.data,
|
|
286
|
+
error: state.error,
|
|
287
|
+
variables: state.variables,
|
|
288
|
+
mutate,
|
|
289
|
+
mutateAsync,
|
|
290
|
+
reset
|
|
291
|
+
}),
|
|
292
|
+
[
|
|
293
|
+
mutate,
|
|
294
|
+
mutateAsync,
|
|
295
|
+
reset,
|
|
296
|
+
state.data,
|
|
297
|
+
state.error,
|
|
298
|
+
state.pausedCount,
|
|
299
|
+
state.pendingCount,
|
|
300
|
+
state.status,
|
|
301
|
+
state.variables
|
|
302
|
+
]
|
|
303
|
+
);
|
|
304
|
+
return { mutation, mutatePreparedAsync };
|
|
305
|
+
}
|
|
306
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, useMutationLifecycle, "useMutationLifecycle");
|
|
307
|
+
function isConnectivityFailure(error) {
|
|
308
|
+
if (error instanceof TypeError) return true;
|
|
309
|
+
const code = _optionalChain([error, 'optionalAccess', _12 => _12.code]);
|
|
310
|
+
return code === "network_error" || code === "timeout";
|
|
311
|
+
}
|
|
312
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, isConnectivityFailure, "isConnectivityFailure");
|
|
313
|
+
function unwrapMutationResult(result, apiRoute) {
|
|
314
|
+
if (!apiRoute) return result;
|
|
315
|
+
const apiResult = result;
|
|
316
|
+
if (apiResult.error) {
|
|
317
|
+
throw apiResult.error;
|
|
318
|
+
}
|
|
319
|
+
return apiResult.data;
|
|
320
|
+
}
|
|
321
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, unwrapMutationResult, "unwrapMutationResult");
|
|
322
|
+
function normalizeMutationError(error) {
|
|
323
|
+
if (error instanceof Error) return error;
|
|
324
|
+
const normalized = new Error(typeof error === "string" ? error : "Mutation failed");
|
|
325
|
+
normalized.cause = error;
|
|
326
|
+
return normalized;
|
|
327
|
+
}
|
|
328
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, normalizeMutationError, "normalizeMutationError");
|
|
329
|
+
|
|
330
|
+
// src/fetcher-client.tsx
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
var _FetcherInputError = class _FetcherInputError extends Error {
|
|
339
|
+
constructor(cause) {
|
|
340
|
+
super(
|
|
341
|
+
cause instanceof Error ? cause.message : typeof cause === "string" ? cause : "Could not prepare form input"
|
|
342
|
+
);
|
|
343
|
+
this.name = "FetcherInputError";
|
|
344
|
+
this.code = "input_error";
|
|
345
|
+
this.status = 0;
|
|
346
|
+
this.data = void 0;
|
|
347
|
+
this.cause = cause;
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, _FetcherInputError, "FetcherInputError");
|
|
351
|
+
var FetcherInputError = _FetcherInputError;
|
|
352
|
+
var formDataContexts = /* @__PURE__ */ new WeakMap();
|
|
353
|
+
function useFetcher(target, options = {}) {
|
|
354
|
+
const targetRef = _react.useRef.call(void 0, target);
|
|
355
|
+
const optionsRef = _react.useRef.call(void 0, options);
|
|
356
|
+
const submissionIdRef = _react.useRef.call(void 0, 0);
|
|
357
|
+
const [formData, setFormData] = _react.useState.call(void 0, null);
|
|
358
|
+
const { mutation, mutatePreparedAsync } = useMutationLifecycle(target, options);
|
|
359
|
+
targetRef.current = target;
|
|
360
|
+
optionsRef.current = options;
|
|
361
|
+
const submitAsync = _react.useCallback.call(void 0,
|
|
362
|
+
async (input) => {
|
|
363
|
+
const submissionId = ++submissionIdRef.current;
|
|
364
|
+
const submittedFormData = isFormData(input) ? input : null;
|
|
365
|
+
setFormData(submittedFormData);
|
|
366
|
+
try {
|
|
367
|
+
return await mutatePreparedAsync(() => {
|
|
368
|
+
try {
|
|
369
|
+
return submittedFormData ? mapFetcherFormData(targetRef.current, submittedFormData, optionsRef.current) : input;
|
|
370
|
+
} catch (error) {
|
|
371
|
+
throw new FetcherInputError(error);
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
} finally {
|
|
375
|
+
if (submissionId === submissionIdRef.current) {
|
|
376
|
+
setFormData(null);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
},
|
|
380
|
+
[mutatePreparedAsync]
|
|
381
|
+
);
|
|
382
|
+
const submit = _react.useCallback.call(void 0,
|
|
383
|
+
(input) => {
|
|
384
|
+
void submitAsync(input).catch(() => {
|
|
385
|
+
});
|
|
386
|
+
},
|
|
387
|
+
[submitAsync]
|
|
388
|
+
);
|
|
389
|
+
const Form = _react.useMemo.call(void 0, () => {
|
|
390
|
+
const FetcherForm = /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, ({ action, method, encType, onSubmit, ...props }) => {
|
|
391
|
+
const targetValue = targetRef.current;
|
|
392
|
+
const metadata = _chunkIXTFU4PLcjs.getAPIRouteRefMetadata.call(void 0, targetValue);
|
|
393
|
+
const nativeAction = _nullishCoalesce(action, () => ( resolveFetcherFormAction(targetValue, metadata)));
|
|
394
|
+
const nativeMethod = _nullishCoalesce(method, () => ( (metadata && (metadata.method === "GET" || metadata.method === "POST") ? metadata.method.toLowerCase() : metadata ? "post" : void 0)));
|
|
395
|
+
const functionAction = typeof nativeAction === "function";
|
|
396
|
+
const handleSubmit = /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, (event) => {
|
|
397
|
+
_optionalChain([onSubmit, 'optionalCall', _13 => _13(event)]);
|
|
398
|
+
if (event.defaultPrevented) return;
|
|
399
|
+
event.preventDefault();
|
|
400
|
+
const submitter = getSubmitter(event);
|
|
401
|
+
const nextFormData = createSubmitterFormData(event.currentTarget, submitter);
|
|
402
|
+
formDataContexts.set(nextFormData, {
|
|
403
|
+
form: event.currentTarget,
|
|
404
|
+
submitter
|
|
405
|
+
});
|
|
406
|
+
void submitAsync(nextFormData).catch(() => {
|
|
407
|
+
});
|
|
408
|
+
}, "handleSubmit");
|
|
409
|
+
return _react.createElement.call(void 0, "form", {
|
|
410
|
+
...props,
|
|
411
|
+
action: nativeAction,
|
|
412
|
+
method: functionAction ? void 0 : nativeMethod,
|
|
413
|
+
encType: functionAction ? void 0 : encType,
|
|
414
|
+
onSubmit: handleSubmit
|
|
415
|
+
});
|
|
416
|
+
}, "FetcherForm");
|
|
417
|
+
FetcherForm.displayName = "FetcherForm";
|
|
418
|
+
return FetcherForm;
|
|
419
|
+
}, [submitAsync]);
|
|
420
|
+
const reset = _react.useCallback.call(void 0, () => {
|
|
421
|
+
submissionIdRef.current += 1;
|
|
422
|
+
setFormData(null);
|
|
423
|
+
mutation.reset();
|
|
424
|
+
}, [mutation.reset]);
|
|
425
|
+
return _react.useMemo.call(void 0,
|
|
426
|
+
() => ({
|
|
427
|
+
state: mutation.pending ? "submitting" : "idle",
|
|
428
|
+
status: mutation.status,
|
|
429
|
+
pending: mutation.pending,
|
|
430
|
+
paused: mutation.paused,
|
|
431
|
+
data: mutation.data,
|
|
432
|
+
error: mutation.error,
|
|
433
|
+
variables: mutation.variables,
|
|
434
|
+
formData,
|
|
435
|
+
submit,
|
|
436
|
+
submitAsync,
|
|
437
|
+
Form,
|
|
438
|
+
reset
|
|
439
|
+
}),
|
|
440
|
+
[
|
|
441
|
+
Form,
|
|
442
|
+
formData,
|
|
443
|
+
mutation.data,
|
|
444
|
+
mutation.error,
|
|
445
|
+
mutation.paused,
|
|
446
|
+
mutation.pending,
|
|
447
|
+
mutation.status,
|
|
448
|
+
mutation.variables,
|
|
449
|
+
reset,
|
|
450
|
+
submit,
|
|
451
|
+
submitAsync
|
|
452
|
+
]
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, useFetcher, "useFetcher");
|
|
456
|
+
function mapFetcherFormData(target, formData, options) {
|
|
457
|
+
const context = _nullishCoalesce(formDataContexts.get(formData), () => ( { form: null, submitter: null }));
|
|
458
|
+
if (options.mapFormData) {
|
|
459
|
+
return options.mapFormData(formData, context);
|
|
460
|
+
}
|
|
461
|
+
if (!_chunkIXTFU4PLcjs.isAPIRouteRef.call(void 0, target)) {
|
|
462
|
+
return formData;
|
|
463
|
+
}
|
|
464
|
+
const method = _optionalChain([_chunkIXTFU4PLcjs.getAPIRouteRefMetadata.call(void 0, target), 'optionalAccess', _14 => _14.method]);
|
|
465
|
+
const query = method === "GET" || method === "HEAD";
|
|
466
|
+
const encoding = _nullishCoalesce(_optionalChain([context, 'access', _15 => _15.submitter, 'optionalAccess', _16 => _16.getAttribute, 'call', _17 => _17("formenctype")]), () => ( _optionalChain([context, 'access', _18 => _18.form, 'optionalAccess', _19 => _19.enctype])));
|
|
467
|
+
if (!query && (_optionalChain([encoding, 'optionalAccess', _20 => _20.toLowerCase, 'call', _21 => _21()]) === "multipart/form-data" || Array.from(formData.values()).some((value) => typeof value !== "string"))) {
|
|
468
|
+
const body = new FormData();
|
|
469
|
+
for (const [key, value] of formData) {
|
|
470
|
+
if (!isUnsafeFormKey(key)) body.append(key, value);
|
|
471
|
+
}
|
|
472
|
+
return { body };
|
|
473
|
+
}
|
|
474
|
+
const values = formDataToObject(formData);
|
|
475
|
+
return query ? { query: values } : { body: values };
|
|
476
|
+
}
|
|
477
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, mapFetcherFormData, "mapFetcherFormData");
|
|
478
|
+
function resolveFetcherFormAction(target, metadata) {
|
|
479
|
+
if (!metadata) return isProgressiveFormAction(target) ? target : void 0;
|
|
480
|
+
if (metadata.sameOrigin) return metadata.path;
|
|
481
|
+
return new URL(metadata.path, metadata.baseURL).href;
|
|
482
|
+
}
|
|
483
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, resolveFetcherFormAction, "resolveFetcherFormAction");
|
|
484
|
+
function formDataToObject(formData) {
|
|
485
|
+
const output = /* @__PURE__ */ Object.create(null);
|
|
486
|
+
for (const [key, value] of formData.entries()) {
|
|
487
|
+
if (isUnsafeFormKey(key)) continue;
|
|
488
|
+
const current = output[key];
|
|
489
|
+
if (current === void 0) {
|
|
490
|
+
output[key] = value;
|
|
491
|
+
} else if (Array.isArray(current)) {
|
|
492
|
+
current.push(value);
|
|
493
|
+
} else {
|
|
494
|
+
output[key] = [current, value];
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
return output;
|
|
498
|
+
}
|
|
499
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, formDataToObject, "formDataToObject");
|
|
500
|
+
function isUnsafeFormKey(key) {
|
|
501
|
+
return key === "__proto__" || key === "constructor" || key === "prototype";
|
|
502
|
+
}
|
|
503
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, isUnsafeFormKey, "isUnsafeFormKey");
|
|
504
|
+
function createSubmitterFormData(form, submitter) {
|
|
505
|
+
try {
|
|
506
|
+
return new FormData(form, submitter);
|
|
507
|
+
} catch (e2) {
|
|
508
|
+
const formData = new FormData(form);
|
|
509
|
+
const candidate = submitter;
|
|
510
|
+
if (candidate && !candidate.disabled && candidate.name) {
|
|
511
|
+
formData.append(candidate.name, _nullishCoalesce(candidate.value, () => ( "")));
|
|
512
|
+
}
|
|
513
|
+
return formData;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, createSubmitterFormData, "createSubmitterFormData");
|
|
517
|
+
function getSubmitter(event) {
|
|
518
|
+
const nativeEvent = event.nativeEvent;
|
|
519
|
+
return nativeEvent.submitter instanceof HTMLElement ? nativeEvent.submitter : null;
|
|
520
|
+
}
|
|
521
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, getSubmitter, "getSubmitter");
|
|
522
|
+
function isProgressiveFormAction(target) {
|
|
523
|
+
const candidate = target;
|
|
524
|
+
return candidate.__farmServerFn === true || typeof candidate.$$FORM_ACTION === "function" || candidate.$$typeof === /* @__PURE__ */ Symbol.for("react.server.reference");
|
|
525
|
+
}
|
|
526
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, isProgressiveFormAction, "isProgressiveFormAction");
|
|
527
|
+
function isFormData(value) {
|
|
528
|
+
if (!value || typeof value !== "object") return false;
|
|
529
|
+
return typeof FormData !== "undefined" && value instanceof FormData || Object.prototype.toString.call(value) === "[object FormData]" && typeof value.entries === "function";
|
|
530
|
+
}
|
|
531
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, isFormData, "isFormData");
|
|
532
|
+
|
|
533
|
+
// src/cache-invalidation-broadcast.ts
|
|
534
|
+
var FARM_CACHE_INVALIDATION_CHANNEL = "farm:cache-invalidation";
|
|
535
|
+
var FARM_CACHE_INVALIDATION_BRIDGE = /* @__PURE__ */ Symbol.for("farm.cacheInvalidationBridge");
|
|
536
|
+
var bridgeGlobal = globalThis;
|
|
537
|
+
function enableCrossTabCacheInvalidation(options = {}) {
|
|
538
|
+
if (typeof BroadcastChannel !== "function") return () => {
|
|
539
|
+
};
|
|
540
|
+
const channelName = _nullishCoalesce(options.channelName, () => ( FARM_CACHE_INVALIDATION_CHANNEL));
|
|
541
|
+
const existing = bridgeGlobal[FARM_CACHE_INVALIDATION_BRIDGE];
|
|
542
|
+
let bridge;
|
|
543
|
+
if (existing) {
|
|
544
|
+
if (existing.channelName !== channelName) {
|
|
545
|
+
throw new Error(
|
|
546
|
+
`Cross-tab cache invalidation is already enabled on channel "${existing.channelName}".`
|
|
547
|
+
);
|
|
548
|
+
}
|
|
549
|
+
existing.refCount += 1;
|
|
550
|
+
bridge = existing;
|
|
551
|
+
} else {
|
|
552
|
+
bridge = createBridge(channelName);
|
|
553
|
+
bridgeGlobal[FARM_CACHE_INVALIDATION_BRIDGE] = bridge;
|
|
554
|
+
}
|
|
555
|
+
let disposed = false;
|
|
556
|
+
return () => {
|
|
557
|
+
if (disposed) return;
|
|
558
|
+
disposed = true;
|
|
559
|
+
bridge.refCount -= 1;
|
|
560
|
+
if (bridge.refCount === 0) {
|
|
561
|
+
bridge.teardown();
|
|
562
|
+
if (bridgeGlobal[FARM_CACHE_INVALIDATION_BRIDGE] === bridge) {
|
|
563
|
+
bridgeGlobal[FARM_CACHE_INVALIDATION_BRIDGE] = void 0;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, enableCrossTabCacheInvalidation, "enableCrossTabCacheInvalidation");
|
|
569
|
+
function createBridge(channelName) {
|
|
570
|
+
const channel = new BroadcastChannel(channelName);
|
|
571
|
+
let applyingRemote = false;
|
|
572
|
+
let pending = [];
|
|
573
|
+
let flushScheduled = false;
|
|
574
|
+
let closed = false;
|
|
575
|
+
const flush = /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, () => {
|
|
576
|
+
flushScheduled = false;
|
|
577
|
+
if (closed || pending.length === 0) return;
|
|
578
|
+
const encoded = _chunkZEG3OPIBcjs.encodeFarmCacheInvalidations.call(void 0, pending);
|
|
579
|
+
pending = [];
|
|
580
|
+
if (encoded !== null) channel.postMessage(encoded);
|
|
581
|
+
}, "flush");
|
|
582
|
+
const unsubscribe = _chunkZEG3OPIBcjs.subscribeFarmCacheInvalidation.call(void 0, (key, source) => {
|
|
583
|
+
if (applyingRemote || source !== "local" || closed) return;
|
|
584
|
+
pending.push(key);
|
|
585
|
+
if (!flushScheduled) {
|
|
586
|
+
flushScheduled = true;
|
|
587
|
+
queueMicrotask(flush);
|
|
588
|
+
}
|
|
589
|
+
});
|
|
590
|
+
channel.onmessage = (event) => {
|
|
591
|
+
const keys = _chunkZEG3OPIBcjs.decodeFarmCacheInvalidations.call(void 0,
|
|
592
|
+
typeof event.data === "string" ? event.data : void 0
|
|
593
|
+
);
|
|
594
|
+
if (keys.length === 0) return;
|
|
595
|
+
applyingRemote = true;
|
|
596
|
+
try {
|
|
597
|
+
for (const key of keys) _chunkZEG3OPIBcjs.notifyFarmCacheInvalidation.call(void 0, key, "broadcast");
|
|
598
|
+
} finally {
|
|
599
|
+
applyingRemote = false;
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
return {
|
|
603
|
+
channelName,
|
|
604
|
+
refCount: 1,
|
|
605
|
+
teardown() {
|
|
606
|
+
closed = true;
|
|
607
|
+
pending = [];
|
|
608
|
+
unsubscribe();
|
|
609
|
+
channel.onmessage = null;
|
|
610
|
+
channel.close();
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, createBridge, "createBridge");
|
|
615
|
+
|
|
616
|
+
// src/cache-invalidation-event-source.ts
|
|
617
|
+
var FARM_LIVE_CACHE_INVALIDATION_CONNECTIONS = /* @__PURE__ */ Symbol.for(
|
|
618
|
+
"farm.liveCacheInvalidationConnections"
|
|
619
|
+
);
|
|
620
|
+
var connectionGlobal = globalThis;
|
|
621
|
+
function getConnections() {
|
|
622
|
+
return _nullishCoalesce(connectionGlobal[FARM_LIVE_CACHE_INVALIDATION_CONNECTIONS], () => ( (connectionGlobal[FARM_LIVE_CACHE_INVALIDATION_CONNECTIONS] = /* @__PURE__ */ new Map())));
|
|
623
|
+
}
|
|
624
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, getConnections, "getConnections");
|
|
625
|
+
function enableLiveCacheInvalidation(options) {
|
|
626
|
+
if (typeof EventSource !== "function") return () => {
|
|
627
|
+
};
|
|
628
|
+
const baseUrl = typeof location === "object" ? location.href : void 0;
|
|
629
|
+
const url = baseUrl ? new URL(String(options.url), baseUrl).href : String(options.url);
|
|
630
|
+
const key = `${url}\0${options.withCredentials === true ? "include" : "same-origin"}`;
|
|
631
|
+
const connections = getConnections();
|
|
632
|
+
let connection = connections.get(key);
|
|
633
|
+
if (connection) {
|
|
634
|
+
connection.refCount += 1;
|
|
635
|
+
} else {
|
|
636
|
+
const source = new EventSource(url, {
|
|
637
|
+
withCredentials: options.withCredentials === true
|
|
638
|
+
});
|
|
639
|
+
connection = { refCount: 1, source };
|
|
640
|
+
source.onmessage = (event) => {
|
|
641
|
+
const keys = _chunkZEG3OPIBcjs.decodeFarmCacheInvalidations.call(void 0, event.data);
|
|
642
|
+
_chunkZEG3OPIBcjs.applyFarmCacheInvalidations.call(void 0, keys, "live");
|
|
643
|
+
};
|
|
644
|
+
connections.set(key, connection);
|
|
645
|
+
}
|
|
646
|
+
const claimedConnection = connection;
|
|
647
|
+
let disposed = false;
|
|
648
|
+
return () => {
|
|
649
|
+
if (disposed) return;
|
|
650
|
+
disposed = true;
|
|
651
|
+
claimedConnection.refCount -= 1;
|
|
652
|
+
if (claimedConnection.refCount > 0) return;
|
|
653
|
+
claimedConnection.source.onmessage = null;
|
|
654
|
+
claimedConnection.source.close();
|
|
655
|
+
if (connections.get(key) === claimedConnection) connections.delete(key);
|
|
656
|
+
};
|
|
657
|
+
}
|
|
658
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, enableLiveCacheInvalidation, "enableLiveCacheInvalidation");
|
|
659
|
+
|
|
660
|
+
// src/client-cache-persistence.ts
|
|
661
|
+
var FARM_CLIENT_CACHE_PERSIST_VERSION = "1";
|
|
662
|
+
function defineClientCacheAdapter(adapter) {
|
|
663
|
+
for (const method of ["keys", "get", "set", "delete", "clear"]) {
|
|
664
|
+
if (typeof _optionalChain([adapter, 'optionalAccess', _22 => _22[method]]) !== "function") {
|
|
665
|
+
throw new TypeError(
|
|
666
|
+
`defineClientCacheAdapter expects a "${method}" method. Implement keys/get/set/delete/clear over your storage.`
|
|
667
|
+
);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
return adapter;
|
|
671
|
+
}
|
|
672
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, defineClientCacheAdapter, "defineClientCacheAdapter");
|
|
673
|
+
function storageClientCacheAdapter(storage, options = {}) {
|
|
674
|
+
if (!storage || typeof storage.getItem !== "function" || typeof storage.setItem !== "function" || typeof storage.removeItem !== "function") {
|
|
675
|
+
throw new TypeError("storageClientCacheAdapter expects a compatible key-value client.");
|
|
676
|
+
}
|
|
677
|
+
const base = _nullishCoalesce(options.base, () => ( "farm-client-cache"));
|
|
678
|
+
const entryKey = /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, (key) => `${base}:${key}`, "entryKey");
|
|
679
|
+
const enumerate = _nullishCoalesce(_optionalChain([storage, 'access', _23 => _23.getKeys, 'optionalAccess', _24 => _24.bind, 'call', _25 => _25(storage)]), () => ( _optionalChain([storage, 'access', _26 => _26.keys, 'optionalAccess', _27 => _27.bind, 'call', _28 => _28(storage)])));
|
|
680
|
+
return {
|
|
681
|
+
async keys() {
|
|
682
|
+
if (!enumerate) return [];
|
|
683
|
+
const keys = await enumerate(base);
|
|
684
|
+
const prefix = `${base}:`;
|
|
685
|
+
return keys.filter((key) => key.startsWith(prefix)).map((key) => key.slice(prefix.length));
|
|
686
|
+
},
|
|
687
|
+
async get(key) {
|
|
688
|
+
return await _asyncNullishCoalesce(await storage.getItem(entryKey(key)), async () => ( null));
|
|
689
|
+
},
|
|
690
|
+
async set(key, entry) {
|
|
691
|
+
await storage.setItem(entryKey(key), entry);
|
|
692
|
+
},
|
|
693
|
+
async delete(key) {
|
|
694
|
+
await storage.removeItem(entryKey(key));
|
|
695
|
+
},
|
|
696
|
+
async clear() {
|
|
697
|
+
if (storage.clear) {
|
|
698
|
+
await storage.clear(base);
|
|
699
|
+
return;
|
|
700
|
+
}
|
|
701
|
+
if (!enumerate) return;
|
|
702
|
+
const prefix = `${base}:`;
|
|
703
|
+
for (const key of await enumerate(base)) {
|
|
704
|
+
if (key.startsWith(prefix)) await storage.removeItem(key);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, storageClientCacheAdapter, "storageClientCacheAdapter");
|
|
710
|
+
var activeEngine;
|
|
711
|
+
function reportPersistenceFailure(error) {
|
|
712
|
+
const report = typeof reportError === "function" ? reportError : console.error;
|
|
713
|
+
if (error instanceof Error) {
|
|
714
|
+
report(error);
|
|
715
|
+
return;
|
|
716
|
+
}
|
|
717
|
+
const normalized = new Error("Client cache persistence failed");
|
|
718
|
+
normalized.cause = error;
|
|
719
|
+
report(normalized);
|
|
720
|
+
}
|
|
721
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, reportPersistenceFailure, "reportPersistenceFailure");
|
|
722
|
+
function disableEngine(engine, error) {
|
|
723
|
+
if (engine.disabled) return;
|
|
724
|
+
engine.disabled = true;
|
|
725
|
+
engine.pendingSets.clear();
|
|
726
|
+
engine.pendingDeletes.clear();
|
|
727
|
+
if (engine.flushTimer !== void 0) {
|
|
728
|
+
clearTimeout(engine.flushTimer);
|
|
729
|
+
engine.flushTimer = void 0;
|
|
730
|
+
}
|
|
731
|
+
reportPersistenceFailure(error);
|
|
732
|
+
}
|
|
733
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, disableEngine, "disableEngine");
|
|
734
|
+
function scheduleFlush(engine) {
|
|
735
|
+
if (engine.disabled || engine.flushTimer !== void 0) return;
|
|
736
|
+
const timer = setTimeout(() => {
|
|
737
|
+
engine.flushTimer = void 0;
|
|
738
|
+
void flushEngine(engine);
|
|
739
|
+
}, engine.flushDelayMs);
|
|
740
|
+
_optionalChain([timer, 'access', _29 => _29.unref, 'optionalCall', _30 => _30()]);
|
|
741
|
+
engine.flushTimer = timer;
|
|
742
|
+
}
|
|
743
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, scheduleFlush, "scheduleFlush");
|
|
744
|
+
async function flushEngine(engine) {
|
|
745
|
+
if (engine.flushing) return engine.flushing;
|
|
746
|
+
if (engine.disabled || engine.clearing) return;
|
|
747
|
+
if (engine.pendingSets.size === 0 && engine.pendingDeletes.size === 0) return;
|
|
748
|
+
const run = (async () => {
|
|
749
|
+
while (!engine.disabled && !engine.clearing && (engine.pendingSets.size > 0 || engine.pendingDeletes.size > 0)) {
|
|
750
|
+
const sets = Array.from(engine.pendingSets.entries());
|
|
751
|
+
const deletes = Array.from(engine.pendingDeletes);
|
|
752
|
+
engine.pendingSets.clear();
|
|
753
|
+
engine.pendingDeletes.clear();
|
|
754
|
+
try {
|
|
755
|
+
if (sets.length > 0) {
|
|
756
|
+
if (engine.adapter.setMany) await engine.adapter.setMany(sets);
|
|
757
|
+
else for (const [key, entry] of sets) await engine.adapter.set(key, entry);
|
|
758
|
+
}
|
|
759
|
+
for (const key of deletes) await engine.adapter.delete(key);
|
|
760
|
+
} catch (error) {
|
|
761
|
+
disableEngine(engine, error);
|
|
762
|
+
return;
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
})();
|
|
766
|
+
engine.flushing = run;
|
|
767
|
+
try {
|
|
768
|
+
await run;
|
|
769
|
+
} finally {
|
|
770
|
+
engine.flushing = void 0;
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, flushEngine, "flushEngine");
|
|
774
|
+
async function hydrateEngine(engine) {
|
|
775
|
+
const generation = engine.hydrationGeneration;
|
|
776
|
+
const now = Date.now();
|
|
777
|
+
const keys = await engine.adapter.keys();
|
|
778
|
+
if (engine.disabled || generation !== engine.hydrationGeneration) return;
|
|
779
|
+
if (keys.length === 0) return;
|
|
780
|
+
const persisted = engine.adapter.getMany ? await engine.adapter.getMany(keys) : await Promise.all(keys.map((key) => engine.adapter.get(key)));
|
|
781
|
+
if (engine.disabled || generation !== engine.hydrationGeneration) return;
|
|
782
|
+
engine.hydrating = true;
|
|
783
|
+
try {
|
|
784
|
+
for (let index = 0; index < keys.length; index += 1) {
|
|
785
|
+
const key = keys[index];
|
|
786
|
+
const entry = persisted[index];
|
|
787
|
+
if (engine.disabled || generation !== engine.hydrationGeneration) return;
|
|
788
|
+
if (!entry || entry.version !== engine.version || entry.gcAt !== void 0 && now >= entry.gcAt) {
|
|
789
|
+
engine.pendingDeletes.add(key);
|
|
790
|
+
continue;
|
|
791
|
+
}
|
|
792
|
+
if (engine.cache.get(key, now)) continue;
|
|
793
|
+
engine.cache.set(key, {
|
|
794
|
+
data: entry.data,
|
|
795
|
+
updatedAt: entry.updatedAt,
|
|
796
|
+
staleAt: 0,
|
|
797
|
+
gcAt: entry.gcAt,
|
|
798
|
+
status: "success",
|
|
799
|
+
error: null,
|
|
800
|
+
persist: true
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
} finally {
|
|
804
|
+
engine.hydrating = false;
|
|
805
|
+
}
|
|
806
|
+
if (engine.pendingDeletes.size > 0) scheduleFlush(engine);
|
|
807
|
+
}
|
|
808
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, hydrateEngine, "hydrateEngine");
|
|
809
|
+
function createSink(engine) {
|
|
810
|
+
return {
|
|
811
|
+
onSet(key, entry) {
|
|
812
|
+
if (engine.disabled || engine.hydrating) return;
|
|
813
|
+
if (!entry.persist || entry.fetching || entry.error || entry.status === "pending") return;
|
|
814
|
+
if (engine.persistKey && !engine.persistKey(key)) return;
|
|
815
|
+
engine.pendingDeletes.delete(key);
|
|
816
|
+
engine.pendingSets.set(key, {
|
|
817
|
+
data: entry.data,
|
|
818
|
+
updatedAt: entry.updatedAt,
|
|
819
|
+
staleAt: entry.staleAt,
|
|
820
|
+
gcAt: entry.gcAt,
|
|
821
|
+
version: engine.version
|
|
822
|
+
});
|
|
823
|
+
scheduleFlush(engine);
|
|
824
|
+
},
|
|
825
|
+
onDelete(key) {
|
|
826
|
+
if (engine.disabled) return;
|
|
827
|
+
engine.pendingSets.delete(key);
|
|
828
|
+
engine.pendingDeletes.add(key);
|
|
829
|
+
scheduleFlush(engine);
|
|
830
|
+
},
|
|
831
|
+
onClear() {
|
|
832
|
+
if (engine.disabled || engine.clearing) return;
|
|
833
|
+
engine.hydrationGeneration += 1;
|
|
834
|
+
engine.pendingSets.clear();
|
|
835
|
+
engine.pendingDeletes.clear();
|
|
836
|
+
void engine.adapter.clear().catch((error) => disableEngine(engine, error));
|
|
837
|
+
}
|
|
838
|
+
};
|
|
839
|
+
}
|
|
840
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, createSink, "createSink");
|
|
841
|
+
function initPersistedClientCache(adapter, options = {}) {
|
|
842
|
+
defineClientCacheAdapter(adapter);
|
|
843
|
+
disposePersistedClientCache();
|
|
844
|
+
const engine = {
|
|
845
|
+
adapter,
|
|
846
|
+
cache: _chunkI7PUUDGYcjs.getFarmClientDataCache.call(void 0, ),
|
|
847
|
+
version: options.version ? `${FARM_CLIENT_CACHE_PERSIST_VERSION}:${options.version}` : FARM_CLIENT_CACHE_PERSIST_VERSION,
|
|
848
|
+
persistKey: options.persistKey,
|
|
849
|
+
flushDelayMs: _nullishCoalesce(options.flushDelayMs, () => ( 300)),
|
|
850
|
+
pendingSets: /* @__PURE__ */ new Map(),
|
|
851
|
+
pendingDeletes: /* @__PURE__ */ new Set(),
|
|
852
|
+
flushTimer: void 0,
|
|
853
|
+
hydrating: false,
|
|
854
|
+
hydrationGeneration: 0,
|
|
855
|
+
disabled: false,
|
|
856
|
+
clearing: false,
|
|
857
|
+
flushing: void 0
|
|
858
|
+
};
|
|
859
|
+
activeEngine = engine;
|
|
860
|
+
engine.cache.attachPersistence(createSink(engine));
|
|
861
|
+
void hydrateEngine(engine).catch((error) => disableEngine(engine, error));
|
|
862
|
+
return () => {
|
|
863
|
+
if (activeEngine !== engine) return;
|
|
864
|
+
disposePersistedClientCache();
|
|
865
|
+
};
|
|
866
|
+
}
|
|
867
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, initPersistedClientCache, "initPersistedClientCache");
|
|
868
|
+
function initConfiguredClientCachePersistence(adapterModule, options = {}) {
|
|
869
|
+
try {
|
|
870
|
+
const adapter = _optionalChain([adapterModule, 'optionalAccess', _31 => _31.default]);
|
|
871
|
+
if (!adapter) {
|
|
872
|
+
throw new Error(
|
|
873
|
+
"cache.client.adapter must default-export an adapter. Export defineClientCacheAdapter({ keys, get, set, delete, clear }) as the module default."
|
|
874
|
+
);
|
|
875
|
+
}
|
|
876
|
+
initPersistedClientCache(adapter, options);
|
|
877
|
+
} catch (error) {
|
|
878
|
+
reportPersistenceFailure(error);
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, initConfiguredClientCachePersistence, "initConfiguredClientCachePersistence");
|
|
882
|
+
function disposePersistedClientCache() {
|
|
883
|
+
const engine = activeEngine;
|
|
884
|
+
if (!engine) return;
|
|
885
|
+
activeEngine = void 0;
|
|
886
|
+
engine.disabled = true;
|
|
887
|
+
engine.cache.attachPersistence(void 0);
|
|
888
|
+
if (engine.flushTimer !== void 0) {
|
|
889
|
+
clearTimeout(engine.flushTimer);
|
|
890
|
+
engine.flushTimer = void 0;
|
|
891
|
+
}
|
|
892
|
+
engine.pendingSets.clear();
|
|
893
|
+
engine.pendingDeletes.clear();
|
|
894
|
+
}
|
|
895
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, disposePersistedClientCache, "disposePersistedClientCache");
|
|
896
|
+
async function clearPersistedCache() {
|
|
897
|
+
const engine = activeEngine;
|
|
898
|
+
if (!engine) {
|
|
899
|
+
_chunkI7PUUDGYcjs.getFarmClientDataCache.call(void 0, ).clear();
|
|
900
|
+
return;
|
|
901
|
+
}
|
|
902
|
+
engine.clearing = true;
|
|
903
|
+
engine.hydrationGeneration += 1;
|
|
904
|
+
try {
|
|
905
|
+
engine.pendingSets.clear();
|
|
906
|
+
engine.pendingDeletes.clear();
|
|
907
|
+
engine.cache.clear();
|
|
908
|
+
engine.pendingSets.clear();
|
|
909
|
+
engine.pendingDeletes.clear();
|
|
910
|
+
await engine.flushing;
|
|
911
|
+
engine.pendingSets.clear();
|
|
912
|
+
engine.pendingDeletes.clear();
|
|
913
|
+
await engine.adapter.clear();
|
|
914
|
+
} catch (error) {
|
|
915
|
+
disableEngine(engine, error);
|
|
916
|
+
} finally {
|
|
917
|
+
engine.clearing = false;
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, clearPersistedCache, "clearPersistedCache");
|
|
921
|
+
|
|
922
|
+
// src/store.ts
|
|
923
|
+
|
|
924
|
+
var RESERVED_STORE_KEYS = /* @__PURE__ */ new Set([
|
|
925
|
+
"use",
|
|
926
|
+
"get",
|
|
927
|
+
"set",
|
|
928
|
+
"replace",
|
|
929
|
+
"reset",
|
|
930
|
+
"subscribe"
|
|
931
|
+
]);
|
|
932
|
+
function cloneState(state) {
|
|
933
|
+
return { ...state };
|
|
934
|
+
}
|
|
935
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, cloneState, "cloneState");
|
|
936
|
+
function pickState(state, keys) {
|
|
937
|
+
const slice = {};
|
|
938
|
+
for (const key of keys) {
|
|
939
|
+
slice[key] = state[key];
|
|
940
|
+
}
|
|
941
|
+
return slice;
|
|
942
|
+
}
|
|
943
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, pickState, "pickState");
|
|
944
|
+
function getEnumerableKeys(state) {
|
|
945
|
+
return Reflect.ownKeys(state).filter(
|
|
946
|
+
(key) => Object.prototype.propertyIsEnumerable.call(state, key)
|
|
947
|
+
);
|
|
948
|
+
}
|
|
949
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, getEnumerableKeys, "getEnumerableKeys");
|
|
950
|
+
function getChangedKeys(state, previousState) {
|
|
951
|
+
const keys = /* @__PURE__ */ new Set([...getEnumerableKeys(state), ...getEnumerableKeys(previousState)]);
|
|
952
|
+
return [...keys].filter((key) => !Object.is(state[key], previousState[key]));
|
|
953
|
+
}
|
|
954
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, getChangedKeys, "getChangedKeys");
|
|
955
|
+
function normalizeKeys(keys) {
|
|
956
|
+
return Array.from(new Set(keys));
|
|
957
|
+
}
|
|
958
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, normalizeKeys, "normalizeKeys");
|
|
959
|
+
function resolveValue(value, previousValue) {
|
|
960
|
+
return typeof value === "function" ? value(previousValue) : value;
|
|
961
|
+
}
|
|
962
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, resolveValue, "resolveValue");
|
|
963
|
+
function isStoreKey(value) {
|
|
964
|
+
return typeof value === "string" || typeof value === "number" || typeof value === "symbol";
|
|
965
|
+
}
|
|
966
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, isStoreKey, "isStoreKey");
|
|
967
|
+
function createStore(initialState, extend) {
|
|
968
|
+
const initialSnapshot = cloneState(initialState);
|
|
969
|
+
let state = cloneState(initialState);
|
|
970
|
+
const subscriptions = /* @__PURE__ */ new Set();
|
|
971
|
+
const addSubscription = /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, (keys, notify) => {
|
|
972
|
+
const subscription = {
|
|
973
|
+
// Object property enumeration returns numeric keys as strings.
|
|
974
|
+
keys: _nullishCoalesce(_optionalChain([keys, 'optionalAccess', _32 => _32.map, 'call', _33 => _33((key) => typeof key === "number" ? String(key) : key)]), () => ( null)),
|
|
975
|
+
notify
|
|
976
|
+
};
|
|
977
|
+
subscriptions.add(subscription);
|
|
978
|
+
return () => {
|
|
979
|
+
subscriptions.delete(subscription);
|
|
980
|
+
};
|
|
981
|
+
}, "addSubscription");
|
|
982
|
+
const emit = /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, (nextState, previousState) => {
|
|
983
|
+
const changedKeys = getChangedKeys(nextState, previousState);
|
|
984
|
+
if (changedKeys.length === 0) {
|
|
985
|
+
return;
|
|
986
|
+
}
|
|
987
|
+
const changedKeySet = new Set(changedKeys);
|
|
988
|
+
for (const subscription of subscriptions) {
|
|
989
|
+
if (subscription.keys === null || subscription.keys.some((key) => changedKeySet.has(key))) {
|
|
990
|
+
subscription.notify(nextState, previousState);
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
}, "emit");
|
|
994
|
+
const getState = /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, (key) => {
|
|
995
|
+
return key === void 0 ? state : state[key];
|
|
996
|
+
}, "getState");
|
|
997
|
+
const replaceState2 = /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, (nextState) => {
|
|
998
|
+
const previousState = state;
|
|
999
|
+
const resolvedState = typeof nextState === "function" ? nextState(previousState) : nextState;
|
|
1000
|
+
state = resolvedState;
|
|
1001
|
+
emit(state, previousState);
|
|
1002
|
+
return state;
|
|
1003
|
+
}, "replaceState");
|
|
1004
|
+
const setState = /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, (keyOrPatch, value) => {
|
|
1005
|
+
const previousState = state;
|
|
1006
|
+
let nextState;
|
|
1007
|
+
if (isStoreKey(keyOrPatch)) {
|
|
1008
|
+
const key = keyOrPatch;
|
|
1009
|
+
const nextValue = resolveValue(value, previousState[key]);
|
|
1010
|
+
if (Object.is(previousState[key], nextValue)) {
|
|
1011
|
+
return nextValue;
|
|
1012
|
+
}
|
|
1013
|
+
nextState = {
|
|
1014
|
+
...previousState,
|
|
1015
|
+
[key]: nextValue
|
|
1016
|
+
};
|
|
1017
|
+
state = nextState;
|
|
1018
|
+
emit(nextState, previousState);
|
|
1019
|
+
return nextValue;
|
|
1020
|
+
}
|
|
1021
|
+
const patch = typeof keyOrPatch === "function" ? keyOrPatch(previousState) : keyOrPatch;
|
|
1022
|
+
nextState = {
|
|
1023
|
+
...previousState,
|
|
1024
|
+
...patch
|
|
1025
|
+
};
|
|
1026
|
+
state = nextState;
|
|
1027
|
+
emit(nextState, previousState);
|
|
1028
|
+
return nextState;
|
|
1029
|
+
}, "setState");
|
|
1030
|
+
const subscribeState = /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, (keyOrListener, listener) => {
|
|
1031
|
+
if (typeof keyOrListener === "function") {
|
|
1032
|
+
return addSubscription(null, (nextState, previousState) => {
|
|
1033
|
+
keyOrListener(nextState, previousState);
|
|
1034
|
+
});
|
|
1035
|
+
}
|
|
1036
|
+
if (Array.isArray(keyOrListener)) {
|
|
1037
|
+
const keys = normalizeKeys(keyOrListener);
|
|
1038
|
+
return addSubscription(keys, (nextState, previousState) => {
|
|
1039
|
+
listener(
|
|
1040
|
+
pickState(nextState, keys),
|
|
1041
|
+
pickState(previousState, keys)
|
|
1042
|
+
);
|
|
1043
|
+
});
|
|
1044
|
+
}
|
|
1045
|
+
const key = keyOrListener;
|
|
1046
|
+
return addSubscription([key], (nextState, previousState) => {
|
|
1047
|
+
listener(nextState[key], previousState[key]);
|
|
1048
|
+
});
|
|
1049
|
+
}, "subscribeState");
|
|
1050
|
+
const useStateValue = /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, (keyOrKeys) => {
|
|
1051
|
+
if (Array.isArray(keyOrKeys)) {
|
|
1052
|
+
const keys = normalizeKeys(keyOrKeys);
|
|
1053
|
+
let lastState = state;
|
|
1054
|
+
let lastSlice = pickState(state, keys);
|
|
1055
|
+
const getSnapshot = /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, () => {
|
|
1056
|
+
if (lastState !== state) {
|
|
1057
|
+
lastState = state;
|
|
1058
|
+
lastSlice = pickState(state, keys);
|
|
1059
|
+
}
|
|
1060
|
+
return lastSlice;
|
|
1061
|
+
}, "getSnapshot");
|
|
1062
|
+
return _react.useSyncExternalStore.call(void 0,
|
|
1063
|
+
(notify) => addSubscription(keys, () => notify()),
|
|
1064
|
+
getSnapshot,
|
|
1065
|
+
getSnapshot
|
|
1066
|
+
);
|
|
1067
|
+
}
|
|
1068
|
+
if (isStoreKey(keyOrKeys)) {
|
|
1069
|
+
return _react.useSyncExternalStore.call(void 0,
|
|
1070
|
+
(notify) => addSubscription([keyOrKeys], () => notify()),
|
|
1071
|
+
() => state[keyOrKeys],
|
|
1072
|
+
() => state[keyOrKeys]
|
|
1073
|
+
);
|
|
1074
|
+
}
|
|
1075
|
+
return _react.useSyncExternalStore.call(void 0,
|
|
1076
|
+
(notify) => addSubscription(null, () => notify()),
|
|
1077
|
+
() => state,
|
|
1078
|
+
() => state
|
|
1079
|
+
);
|
|
1080
|
+
}, "useStateValue");
|
|
1081
|
+
const store = {
|
|
1082
|
+
use: useStateValue,
|
|
1083
|
+
get: getState,
|
|
1084
|
+
set: setState,
|
|
1085
|
+
replace: replaceState2,
|
|
1086
|
+
reset: /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, () => replaceState2(cloneState(initialSnapshot)), "reset"),
|
|
1087
|
+
subscribe: subscribeState
|
|
1088
|
+
};
|
|
1089
|
+
for (const key of getEnumerableKeys(initialSnapshot)) {
|
|
1090
|
+
if (RESERVED_STORE_KEYS.has(key)) {
|
|
1091
|
+
throw new Error(
|
|
1092
|
+
`createStore does not allow the reserved key "${String(key)}" in the initial state.`
|
|
1093
|
+
);
|
|
1094
|
+
}
|
|
1095
|
+
const field = /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, (() => useStateValue(key)), "field");
|
|
1096
|
+
field.get = () => state[key];
|
|
1097
|
+
field.set = (value) => setState(key, value);
|
|
1098
|
+
field.subscribe = (listener) => subscribeState(key, listener);
|
|
1099
|
+
Object.defineProperty(store, key, {
|
|
1100
|
+
configurable: false,
|
|
1101
|
+
enumerable: true,
|
|
1102
|
+
value: field,
|
|
1103
|
+
writable: false
|
|
1104
|
+
});
|
|
1105
|
+
}
|
|
1106
|
+
if (extend) {
|
|
1107
|
+
const methods = extend(store);
|
|
1108
|
+
for (const [name, method] of Object.entries(methods)) {
|
|
1109
|
+
if (name in store) {
|
|
1110
|
+
throw new Error(
|
|
1111
|
+
`createStore cannot attach the method "${name}" because it already exists.`
|
|
1112
|
+
);
|
|
1113
|
+
}
|
|
1114
|
+
Object.defineProperty(store, name, {
|
|
1115
|
+
configurable: false,
|
|
1116
|
+
enumerable: true,
|
|
1117
|
+
value: method,
|
|
1118
|
+
writable: false
|
|
1119
|
+
});
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
return store;
|
|
1123
|
+
}
|
|
1124
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, createStore, "createStore");
|
|
1125
|
+
|
|
1126
|
+
// src/client/link.tsx
|
|
1127
|
+
|
|
1128
|
+
|
|
1129
|
+
// src/provider.tsx
|
|
1130
|
+
|
|
1131
|
+
var _jsxruntime = require('react/jsx-runtime');
|
|
1132
|
+
var FarmContext = _react.createContext.call(void 0, null);
|
|
1133
|
+
function FarmProvider({ children, config }) {
|
|
1134
|
+
const value = {
|
|
1135
|
+
config,
|
|
1136
|
+
basePath: _chunkI57LW5VZcjs.normalizeFarmBasePath.call(void 0, config.basePath)
|
|
1137
|
+
};
|
|
1138
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, FarmContext.Provider, { value, children });
|
|
1139
|
+
}
|
|
1140
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, FarmProvider, "FarmProvider");
|
|
1141
|
+
function useOptionalFarm() {
|
|
1142
|
+
return _react.useContext.call(void 0, FarmContext);
|
|
1143
|
+
}
|
|
1144
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, useOptionalFarm, "useOptionalFarm");
|
|
1145
|
+
|
|
1146
|
+
// src/client/link.tsx
|
|
1147
|
+
|
|
1148
|
+
function isModifierEvent(e) {
|
|
1149
|
+
return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
|
|
1150
|
+
}
|
|
1151
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, isModifierEvent, "isModifierEvent");
|
|
1152
|
+
function isExternalUrl(href) {
|
|
1153
|
+
return href.startsWith("//") || /^[a-zA-Z][a-zA-Z\d+.-]*:/.test(href);
|
|
1154
|
+
}
|
|
1155
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, isExternalUrl, "isExternalUrl");
|
|
1156
|
+
function getRouter() {
|
|
1157
|
+
if (typeof window !== "undefined" && window.__FARM_SPA_ROUTER__) {
|
|
1158
|
+
return window.__FARM_SPA_ROUTER__;
|
|
1159
|
+
}
|
|
1160
|
+
return null;
|
|
1161
|
+
}
|
|
1162
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, getRouter, "getRouter");
|
|
1163
|
+
function normalizePrefetch(prefetch2) {
|
|
1164
|
+
if (prefetch2 === false || prefetch2 === "none") {
|
|
1165
|
+
return { intent: false, viewport: false, render: false };
|
|
1166
|
+
}
|
|
1167
|
+
if (prefetch2 === true) {
|
|
1168
|
+
return { intent: true, viewport: true, render: false };
|
|
1169
|
+
}
|
|
1170
|
+
if (prefetch2 === "hover") {
|
|
1171
|
+
return { intent: true, viewport: false, render: false };
|
|
1172
|
+
}
|
|
1173
|
+
if (prefetch2 === "intent") {
|
|
1174
|
+
return { intent: true, viewport: false, render: false };
|
|
1175
|
+
}
|
|
1176
|
+
if (prefetch2 === "viewport") {
|
|
1177
|
+
return { intent: false, viewport: true, render: false };
|
|
1178
|
+
}
|
|
1179
|
+
if (prefetch2 === "render") {
|
|
1180
|
+
return { intent: false, viewport: false, render: true };
|
|
1181
|
+
}
|
|
1182
|
+
return { intent: false, viewport: false, render: false };
|
|
1183
|
+
}
|
|
1184
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, normalizePrefetch, "normalizePrefetch");
|
|
1185
|
+
function LinkInner({
|
|
1186
|
+
href,
|
|
1187
|
+
params,
|
|
1188
|
+
query,
|
|
1189
|
+
hash,
|
|
1190
|
+
trailingSlash,
|
|
1191
|
+
prefetch: prefetch2 = true,
|
|
1192
|
+
prefetchDelay = 50,
|
|
1193
|
+
replace = false,
|
|
1194
|
+
scroll = true,
|
|
1195
|
+
viewTransition = false,
|
|
1196
|
+
locale,
|
|
1197
|
+
onClick,
|
|
1198
|
+
target,
|
|
1199
|
+
onMouseEnter,
|
|
1200
|
+
onMouseLeave,
|
|
1201
|
+
onFocus,
|
|
1202
|
+
onBlur,
|
|
1203
|
+
onTouchStart,
|
|
1204
|
+
...props
|
|
1205
|
+
}, ref) {
|
|
1206
|
+
const elementRef = _react.useRef.call(void 0, null);
|
|
1207
|
+
const intentTimeoutRef = _react.useRef.call(void 0, null);
|
|
1208
|
+
const activePrefetch = _react.useRef.call(void 0, null);
|
|
1209
|
+
const farm = useOptionalFarm();
|
|
1210
|
+
const { intent, viewport, render } = normalizePrefetch(prefetch2);
|
|
1211
|
+
const baseHref = resolveLinkHref(href, params, {
|
|
1212
|
+
query,
|
|
1213
|
+
hash,
|
|
1214
|
+
trailingSlash: _nullishCoalesce(trailingSlash, () => ( _chunkOYEUREB6cjs.getFarmTrailingSlashPreference.call(void 0, )))
|
|
1215
|
+
});
|
|
1216
|
+
const localizedHref = _chunk5OVTOKGHcjs.localizeActiveFarmHref.call(void 0, baseHref, locale);
|
|
1217
|
+
const resolvedHref = isExternalUrl(localizedHref) ? localizedHref : _chunkI57LW5VZcjs.applyFarmBasePath.call(void 0, localizedHref, _nullishCoalesce(_optionalChain([farm, 'optionalAccess', _34 => _34.basePath]), () => ( _chunkI57LW5VZcjs.getFarmBasePath.call(void 0, ))));
|
|
1218
|
+
const isExternal = isExternalUrl(resolvedHref);
|
|
1219
|
+
const doPrefetch = _react.useCallback.call(void 0, () => {
|
|
1220
|
+
if (isExternal || activePrefetch.current) return;
|
|
1221
|
+
const router = getRouter();
|
|
1222
|
+
if (!router) return;
|
|
1223
|
+
const token = Symbol(resolvedHref);
|
|
1224
|
+
activePrefetch.current = token;
|
|
1225
|
+
const reset = /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, () => {
|
|
1226
|
+
if (activePrefetch.current === token) activePrefetch.current = null;
|
|
1227
|
+
}, "reset");
|
|
1228
|
+
try {
|
|
1229
|
+
void router.prefetch(resolvedHref).then(reset, reset);
|
|
1230
|
+
} catch (e3) {
|
|
1231
|
+
reset();
|
|
1232
|
+
}
|
|
1233
|
+
}, [resolvedHref, isExternal]);
|
|
1234
|
+
_react.useEffect.call(void 0, () => {
|
|
1235
|
+
activePrefetch.current = null;
|
|
1236
|
+
}, [resolvedHref]);
|
|
1237
|
+
_react.useEffect.call(void 0, () => {
|
|
1238
|
+
const element = elementRef.current;
|
|
1239
|
+
if (!element || isExternal) return;
|
|
1240
|
+
const router = getRouter();
|
|
1241
|
+
if (!router) return;
|
|
1242
|
+
if (viewport) {
|
|
1243
|
+
router.observeForPrefetch(element);
|
|
1244
|
+
return () => router.unobserveForPrefetch(element);
|
|
1245
|
+
}
|
|
1246
|
+
}, [resolvedHref, viewport, isExternal]);
|
|
1247
|
+
_react.useEffect.call(void 0, () => {
|
|
1248
|
+
if (!render || isExternal) return;
|
|
1249
|
+
let cancelled = false;
|
|
1250
|
+
let timeoutId = null;
|
|
1251
|
+
const tryRenderPrefetch = /* @__PURE__ */ _chunkS3JO3N4Hcjs.__name.call(void 0, () => {
|
|
1252
|
+
if (cancelled || activePrefetch.current) return;
|
|
1253
|
+
const router = getRouter();
|
|
1254
|
+
if (!router) {
|
|
1255
|
+
timeoutId = setTimeout(tryRenderPrefetch, 30);
|
|
1256
|
+
return;
|
|
1257
|
+
}
|
|
1258
|
+
doPrefetch();
|
|
1259
|
+
}, "tryRenderPrefetch");
|
|
1260
|
+
tryRenderPrefetch();
|
|
1261
|
+
return () => {
|
|
1262
|
+
cancelled = true;
|
|
1263
|
+
if (timeoutId) {
|
|
1264
|
+
clearTimeout(timeoutId);
|
|
1265
|
+
}
|
|
1266
|
+
};
|
|
1267
|
+
}, [render, isExternal, resolvedHref, doPrefetch]);
|
|
1268
|
+
_react.useEffect.call(void 0, () => {
|
|
1269
|
+
return () => {
|
|
1270
|
+
if (intentTimeoutRef.current) {
|
|
1271
|
+
clearTimeout(intentTimeoutRef.current);
|
|
1272
|
+
intentTimeoutRef.current = null;
|
|
1273
|
+
}
|
|
1274
|
+
};
|
|
1275
|
+
}, []);
|
|
1276
|
+
const cancelIntent = _react.useCallback.call(void 0, () => {
|
|
1277
|
+
if (intentTimeoutRef.current) {
|
|
1278
|
+
clearTimeout(intentTimeoutRef.current);
|
|
1279
|
+
intentTimeoutRef.current = null;
|
|
1280
|
+
}
|
|
1281
|
+
}, []);
|
|
1282
|
+
const scheduleIntentPrefetch = _react.useCallback.call(void 0, () => {
|
|
1283
|
+
if (isExternal || !intent || activePrefetch.current) return;
|
|
1284
|
+
cancelIntent();
|
|
1285
|
+
intentTimeoutRef.current = setTimeout(() => {
|
|
1286
|
+
intentTimeoutRef.current = null;
|
|
1287
|
+
doPrefetch();
|
|
1288
|
+
}, prefetchDelay);
|
|
1289
|
+
}, [intent, isExternal, prefetchDelay, doPrefetch, cancelIntent]);
|
|
1290
|
+
const handleMouseEnter = _react.useCallback.call(void 0,
|
|
1291
|
+
(event) => {
|
|
1292
|
+
_optionalChain([onMouseEnter, 'optionalCall', _35 => _35(event)]);
|
|
1293
|
+
scheduleIntentPrefetch();
|
|
1294
|
+
},
|
|
1295
|
+
[onMouseEnter, scheduleIntentPrefetch]
|
|
1296
|
+
);
|
|
1297
|
+
const handleMouseLeave = _react.useCallback.call(void 0,
|
|
1298
|
+
(event) => {
|
|
1299
|
+
_optionalChain([onMouseLeave, 'optionalCall', _36 => _36(event)]);
|
|
1300
|
+
cancelIntent();
|
|
1301
|
+
},
|
|
1302
|
+
[onMouseLeave, cancelIntent]
|
|
1303
|
+
);
|
|
1304
|
+
const handleTouchStart = _react.useCallback.call(void 0,
|
|
1305
|
+
(event) => {
|
|
1306
|
+
_optionalChain([onTouchStart, 'optionalCall', _37 => _37(event)]);
|
|
1307
|
+
scheduleIntentPrefetch();
|
|
1308
|
+
},
|
|
1309
|
+
[onTouchStart, scheduleIntentPrefetch]
|
|
1310
|
+
);
|
|
1311
|
+
const handleFocus = _react.useCallback.call(void 0,
|
|
1312
|
+
(event) => {
|
|
1313
|
+
_optionalChain([onFocus, 'optionalCall', _38 => _38(event)]);
|
|
1314
|
+
scheduleIntentPrefetch();
|
|
1315
|
+
},
|
|
1316
|
+
[onFocus, scheduleIntentPrefetch]
|
|
1317
|
+
);
|
|
1318
|
+
const handleBlur = _react.useCallback.call(void 0,
|
|
1319
|
+
(event) => {
|
|
1320
|
+
_optionalChain([onBlur, 'optionalCall', _39 => _39(event)]);
|
|
1321
|
+
cancelIntent();
|
|
1322
|
+
},
|
|
1323
|
+
[onBlur, cancelIntent]
|
|
1324
|
+
);
|
|
1325
|
+
const handleClick = _react.useCallback.call(void 0,
|
|
1326
|
+
(event) => {
|
|
1327
|
+
_optionalChain([onClick, 'optionalCall', _40 => _40(event)]);
|
|
1328
|
+
if (event.defaultPrevented) return;
|
|
1329
|
+
if (isExternal) return;
|
|
1330
|
+
if (event.currentTarget.hasAttribute("download")) return;
|
|
1331
|
+
if (target && target !== "_self") return;
|
|
1332
|
+
if (isModifierEvent(event)) return;
|
|
1333
|
+
if (event.button !== 0) return;
|
|
1334
|
+
if (typeof window !== "undefined") {
|
|
1335
|
+
event.preventDefault();
|
|
1336
|
+
if (_chunk5OVTOKGHcjs.isFarmLocaleChangeHref.call(void 0, localizedHref)) {
|
|
1337
|
+
window.location.assign(resolvedHref);
|
|
1338
|
+
return;
|
|
1339
|
+
}
|
|
1340
|
+
const router = getRouter();
|
|
1341
|
+
if (router) {
|
|
1342
|
+
router.navigate(resolvedHref, { replace, scroll, viewTransition });
|
|
1343
|
+
} else {
|
|
1344
|
+
if (replace) window.location.replace(resolvedHref);
|
|
1345
|
+
else window.location.href = resolvedHref;
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
},
|
|
1349
|
+
[localizedHref, resolvedHref, replace, scroll, viewTransition, target, isExternal, onClick]
|
|
1350
|
+
);
|
|
1351
|
+
const setRefs = _react.useCallback.call(void 0,
|
|
1352
|
+
(node) => {
|
|
1353
|
+
elementRef.current = node;
|
|
1354
|
+
if (typeof ref === "function") ref(node);
|
|
1355
|
+
else if (ref) ref.current = node;
|
|
1356
|
+
},
|
|
1357
|
+
[ref]
|
|
1358
|
+
);
|
|
1359
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1360
|
+
"a",
|
|
1361
|
+
{
|
|
1362
|
+
ref: setRefs,
|
|
1363
|
+
href: resolvedHref,
|
|
1364
|
+
target,
|
|
1365
|
+
onClick: handleClick,
|
|
1366
|
+
onMouseEnter: handleMouseEnter,
|
|
1367
|
+
onMouseLeave: handleMouseLeave,
|
|
1368
|
+
onFocus: handleFocus,
|
|
1369
|
+
onBlur: handleBlur,
|
|
1370
|
+
onTouchStart: handleTouchStart,
|
|
1371
|
+
...props,
|
|
1372
|
+
"data-farm-link": "",
|
|
1373
|
+
"data-replace": replace ? "" : void 0,
|
|
1374
|
+
"data-no-scroll": !scroll ? "" : void 0,
|
|
1375
|
+
"data-view-transition": viewTransition === "auto" ? "auto" : viewTransition ? "true" : void 0
|
|
1376
|
+
}
|
|
1377
|
+
);
|
|
1378
|
+
}
|
|
1379
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, LinkInner, "LinkInner");
|
|
1380
|
+
var LinkWithRef = _react.forwardRef.call(void 0, LinkInner);
|
|
1381
|
+
LinkWithRef.displayName = "Link";
|
|
1382
|
+
var Link = LinkWithRef;
|
|
1383
|
+
function resolveLinkHref(href, params, options) {
|
|
1384
|
+
if (isExternalUrl(href)) return href;
|
|
1385
|
+
const { pathname, query, hash } = splitInternalHref(href);
|
|
1386
|
+
const resolvedHref = _chunkSU7MH53Pcjs.buildFarmRoutePath.call(void 0, pathname, params, {
|
|
1387
|
+
query: mergeQueryParams(query, options.query),
|
|
1388
|
+
hash: _nullishCoalesce(options.hash, () => ( hash)),
|
|
1389
|
+
trailingSlash: options.trailingSlash
|
|
1390
|
+
});
|
|
1391
|
+
return applyPreservedSearchParams(resolvedHref);
|
|
1392
|
+
}
|
|
1393
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, resolveLinkHref, "resolveLinkHref");
|
|
1394
|
+
function splitInternalHref(href) {
|
|
1395
|
+
try {
|
|
1396
|
+
const url = new URL(href, "http://farm.local");
|
|
1397
|
+
return {
|
|
1398
|
+
pathname: url.pathname || "/",
|
|
1399
|
+
query: url.searchParams,
|
|
1400
|
+
hash: url.hash ? url.hash.slice(1) : void 0
|
|
1401
|
+
};
|
|
1402
|
+
} catch (e4) {
|
|
1403
|
+
const [withoutHash, rawHash] = href.split("#", 2);
|
|
1404
|
+
const [pathname, rawQuery] = withoutHash.split("?", 2);
|
|
1405
|
+
return {
|
|
1406
|
+
pathname: pathname || "/",
|
|
1407
|
+
query: new URLSearchParams(rawQuery || ""),
|
|
1408
|
+
hash: rawHash
|
|
1409
|
+
};
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, splitInternalHref, "splitInternalHref");
|
|
1413
|
+
function mergeQueryParams(current, next) {
|
|
1414
|
+
const merged = new URLSearchParams(current);
|
|
1415
|
+
if (next instanceof URLSearchParams) {
|
|
1416
|
+
for (const [key, value] of next.entries()) {
|
|
1417
|
+
merged.append(key, value);
|
|
1418
|
+
}
|
|
1419
|
+
} else if (next) {
|
|
1420
|
+
for (const [key, value] of Object.entries(next)) {
|
|
1421
|
+
const values = Array.isArray(value) ? value : [value];
|
|
1422
|
+
for (const item of values) {
|
|
1423
|
+
if (item == null) continue;
|
|
1424
|
+
merged.append(key, String(item));
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
return merged.toString() ? merged : void 0;
|
|
1429
|
+
}
|
|
1430
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, mergeQueryParams, "mergeQueryParams");
|
|
1431
|
+
function applyPreservedSearchParams(href) {
|
|
1432
|
+
if (typeof window === "undefined") return href;
|
|
1433
|
+
const manifest = window.__FARM_MANIFEST__;
|
|
1434
|
+
const routes = _optionalChain([manifest, 'optionalAccess', _41 => _41.routes]) && typeof manifest.routes === "object" ? Object.values(manifest.routes) : [];
|
|
1435
|
+
if (routes.length === 0) return href;
|
|
1436
|
+
const url = _chunkSWN467MPcjs.resolveFarmNavigationURL.call(void 0, href, window.location.href);
|
|
1437
|
+
const route = routes.find((candidate) => matchManifestRoute(url.pathname, candidate));
|
|
1438
|
+
const preserve = Array.isArray(_optionalChain([route, 'optionalAccess', _42 => _42.search, 'optionalAccess', _43 => _43.preserve])) ? route.search.preserve : [];
|
|
1439
|
+
if (preserve.length === 0) return href;
|
|
1440
|
+
const current = new URLSearchParams(window.location.search);
|
|
1441
|
+
let changed = false;
|
|
1442
|
+
for (const key of preserve) {
|
|
1443
|
+
if (url.searchParams.has(key) || !current.has(key)) continue;
|
|
1444
|
+
for (const value of current.getAll(key)) {
|
|
1445
|
+
url.searchParams.append(key, value);
|
|
1446
|
+
changed = true;
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
if (!changed) return href;
|
|
1450
|
+
return `${url.pathname}${url.search}${url.hash}`;
|
|
1451
|
+
}
|
|
1452
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, applyPreservedSearchParams, "applyPreservedSearchParams");
|
|
1453
|
+
function matchManifestRoute(pathname, route) {
|
|
1454
|
+
if (!route || !Array.isArray(route.segments)) return false;
|
|
1455
|
+
const routeSegments = route.segments;
|
|
1456
|
+
const normalized = pathname === "/" ? "" : pathname.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
1457
|
+
const pathSegments = normalized ? normalized.split("/") : [];
|
|
1458
|
+
const hasCatchAll = routeSegments.some((segment) => segment.isCatchAll);
|
|
1459
|
+
if (!hasCatchAll && pathSegments.length !== routeSegments.length) {
|
|
1460
|
+
return false;
|
|
1461
|
+
}
|
|
1462
|
+
for (let index = 0; index < routeSegments.length; index++) {
|
|
1463
|
+
const routeSegment = routeSegments[index];
|
|
1464
|
+
const pathSegment = pathSegments[index];
|
|
1465
|
+
if (routeSegment.isCatchAll) {
|
|
1466
|
+
return true;
|
|
1467
|
+
}
|
|
1468
|
+
if (pathSegment === void 0) {
|
|
1469
|
+
if (routeSegment.isOptional) continue;
|
|
1470
|
+
return false;
|
|
1471
|
+
}
|
|
1472
|
+
if (!routeSegment.isDynamic && routeSegment.segment !== pathSegment) {
|
|
1473
|
+
return false;
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
return pathSegments.length === routeSegments.length || hasCatchAll;
|
|
1477
|
+
}
|
|
1478
|
+
_chunkS3JO3N4Hcjs.__name.call(void 0, matchManifestRoute, "matchManifestRoute");
|
|
1479
|
+
|
|
1480
|
+
|
|
1481
|
+
|
|
1482
|
+
|
|
1483
|
+
|
|
1484
|
+
|
|
1485
|
+
|
|
1486
|
+
|
|
1487
|
+
|
|
1488
|
+
|
|
1489
|
+
|
|
1490
|
+
|
|
1491
|
+
|
|
1492
|
+
|
|
1493
|
+
|
|
1494
|
+
|
|
1495
|
+
|
|
1496
|
+
exports.FarmProvider = FarmProvider; exports.useMutation = useMutation; exports.FetcherInputError = FetcherInputError; exports.useFetcher = useFetcher; exports.FARM_CACHE_INVALIDATION_CHANNEL = FARM_CACHE_INVALIDATION_CHANNEL; exports.enableCrossTabCacheInvalidation = enableCrossTabCacheInvalidation; exports.enableLiveCacheInvalidation = enableLiveCacheInvalidation; exports.FARM_CLIENT_CACHE_PERSIST_VERSION = FARM_CLIENT_CACHE_PERSIST_VERSION; exports.defineClientCacheAdapter = defineClientCacheAdapter; exports.storageClientCacheAdapter = storageClientCacheAdapter; exports.initPersistedClientCache = initPersistedClientCache; exports.initConfiguredClientCachePersistence = initConfiguredClientCachePersistence; exports.clearPersistedCache = clearPersistedCache; exports.createStore = createStore; exports.Link = Link;
|