@qwik.dev/router 2.0.0-rc.2 → 2.0.0-rc.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/adapters/netlify-edge/vite/index.d.ts +1 -1
- package/lib/adapters/netlify-edge/vite/index.mjs +1 -1
- package/lib/chunks/head.qwik.mjs +126 -43
- package/lib/chunks/user-response.mjs +22 -15
- package/lib/chunks/worker-thread.mjs +1 -1
- package/lib/index.d.ts +19 -11
- package/lib/index.qwik.mjs +393 -405
- package/lib/middleware/request-handler/index.d.ts +4 -4
- package/lib/middleware/request-handler/index.mjs +1 -1
- package/package.json +4 -4
package/lib/index.qwik.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as ensureSlash } from "./chunks/pathname.mjs";
|
|
2
|
-
import { $ as
|
|
3
|
-
import { SkipRender, Slot, _capturesObj, _fnSignal, _getConstProps, _getVarProps, _jsxSorted, _jsxSplit, _qrlSync, _restProps, _wrapProp, componentQrl, createComputedQrl,
|
|
4
|
-
import { _deserialize, _getContextContainer, _getContextHostElement, _hasStoreEffects, _regInlinedQrl, _requestPreload, _serialize, _waitUntilRendered, forceStoreEffects } from "@qwik.dev/core/internal";
|
|
2
|
+
import { $ as ContentInternalContext, A as isImmutableLoader, B as _getServiceWorkerUrl, C as getModuleRouteLoaders, F as restoreRouteLoaders, G as getRoutes, H as findRouterConfig, I as routeLoader$, J as RUN_PENDING_ACTION, K as getTrailingSlash, L as routeLoaderQrl, N as prepareRouteLoaders, Q as ContentContext, R as setLoaderSignalValue, U as getBasePathname, V as _setRouterConfig, W as getRouterConfig, X as preventNav, Y as internalState, Z as registerPreventNav, a as isPromise, at as RouteLocationContext, b as fetchRouteLoaderData, c as shouldPreload, ct as QACTION_KEY, d as loadRoute, dt as Q_ROUTE, et as DocumentHeadContext, f as matchRouteTree, g as clearNavFetchCache, h as abortRouteLoaderNavigation, i as getClientNavPath, it as RouteLoaderCtxContext, l as toPath, lt as QDATA_KEY, n as resolveHead, nt as RouteActionContext, o as isSameOrigin, ot as RouteNavigateContext, q as REFRESH_HEAD, rt as RouteActionRunnerContext, s as isSamePath, st as RouteStateContext, t as createDocumentHead, tt as HttpStatusContext, u as toUrl, ut as QFN_KEY, v as commitRouteLoaders, w as getRequestEvent, x as getClientRouteLoaders, y as ensureRouteLoaderSignals } from "./chunks/head.qwik.mjs";
|
|
3
|
+
import { SkipRender, Slot, _capturesObj, _fnSignal, _getConstProps, _getVarProps, _jsxSorted, _jsxSplit, _qrlSync, _restProps, _wrapProp, componentQrl, createComputedQrl, eventQrl, getLocale, implicit$FirstArg, inlinedQrl, isBrowser, isDev, isServer, noSerialize, untrack, useContext, useContextProvider, useServerData, useSignal, useStore, useTaskQrl, useVisibleTaskQrl, withLocale } from "@qwik.dev/core";
|
|
4
|
+
import { _deserialize, _getContextContainer, _getContextHostElement, _getDomContainer, _hasStoreEffects, _regInlinedQrl, _requestPreload, _serialize, _waitOn, _waitUntilRendered, forceStoreEffects } from "@qwik.dev/core/internal";
|
|
5
5
|
import { Fragment } from "@qwik.dev/core/jsx-runtime";
|
|
6
6
|
import * as v from "valibot";
|
|
7
7
|
import * as z$1 from "zod";
|
|
@@ -57,8 +57,12 @@ var prefetchLoaderData = (loadedRoute, url, manifestHash) => {
|
|
|
57
57
|
}).catch(() => {});
|
|
58
58
|
}
|
|
59
59
|
};
|
|
60
|
+
var DEFAULT_HTTP_STATUS = Object.freeze({
|
|
61
|
+
status: 200,
|
|
62
|
+
message: "OK"
|
|
63
|
+
});
|
|
60
64
|
/** @public */
|
|
61
|
-
var useHttpStatus = () => useContext(HttpStatusContext).value;
|
|
65
|
+
var useHttpStatus = () => useContext(HttpStatusContext).value ?? DEFAULT_HTTP_STATUS;
|
|
62
66
|
/** @public */
|
|
63
67
|
var useContent = () => useContext(ContentContext);
|
|
64
68
|
/**
|
|
@@ -73,11 +77,10 @@ var useLocation = () => useContext(RouteLocationContext);
|
|
|
73
77
|
var useNavigate = () => useContext(RouteNavigateContext);
|
|
74
78
|
/** @internal Implementation of usePreventNavigate$ */
|
|
75
79
|
var usePreventNavigateQrl = (fn) => {
|
|
76
|
-
const registerPreventNav = useContext(RoutePreventNavigateContext);
|
|
77
80
|
useVisibleTaskQrl(/*#__PURE__*/ inlinedQrl(() => {
|
|
78
|
-
let fn = _capturesObj._[0]
|
|
81
|
+
let fn = _capturesObj._[0];
|
|
79
82
|
return registerPreventNav(fn);
|
|
80
|
-
}, "usePreventNavigateQrl_useVisibleTask_BsYUaz9XhUs", [fn
|
|
83
|
+
}, "usePreventNavigateQrl_useVisibleTask_BsYUaz9XhUs", [fn]));
|
|
81
84
|
};
|
|
82
85
|
/**
|
|
83
86
|
* Prevent navigation attempts. This hook registers a callback that will be called before SPA or
|
|
@@ -131,6 +134,8 @@ var Link = /*#__PURE__*/ componentQrl(/*#__PURE__*/ inlinedQrl((props) => {
|
|
|
131
134
|
const shouldPrefetch = untrack(shouldPreload, clientNavPath, loc);
|
|
132
135
|
const shouldVisiblePrefetchBundles = !!clientNavPath && shouldPrefetch && !isDepratedPrefetchDisabled && (prefetchBundlesProp === "visible" || prefetchProp === "js" || prefetchProp === true);
|
|
133
136
|
const shouldVisiblePrefetchData = !!clientNavPath && shouldPrefetch && !isDepratedPrefetchDisabled && (prefetchDataProp === "visible" || prefetchProp === true);
|
|
137
|
+
const routes = shouldVisiblePrefetchBundles && findRouterConfig()?.routes;
|
|
138
|
+
const route = routes && untrack(() => matchRouteTree(routes, new URL(clientNavPath, loc.url).pathname));
|
|
134
139
|
const shouldPrefetchBundles = !!clientNavPath && prefetchBundlesProp !== "off" && shouldPrefetch && !isDepratedPrefetchDisabled;
|
|
135
140
|
const shouldPrefetchData = !!clientNavPath && prefetchDataProp !== "off" && shouldPrefetch && !isDepratedPrefetchDisabled;
|
|
136
141
|
const handleBundlePrefetch = shouldPrefetchBundles ? /*#__PURE__*/ inlinedQrl((_, elm) => {
|
|
@@ -164,13 +169,13 @@ var Link = /*#__PURE__*/ componentQrl(/*#__PURE__*/ inlinedQrl((props) => {
|
|
|
164
169
|
let nav = _capturesObj._[0], reload = _capturesObj._[1], replaceState = _capturesObj._[2], scroll = _capturesObj._[3];
|
|
165
170
|
if (event.defaultPrevented) {
|
|
166
171
|
if (elm.href) {
|
|
167
|
-
elm.setAttribute("
|
|
172
|
+
elm.setAttribute("data-navigating", "");
|
|
168
173
|
nav(elm.href, {
|
|
169
174
|
forceReload: reload,
|
|
170
175
|
replaceState,
|
|
171
176
|
scroll
|
|
172
|
-
}).
|
|
173
|
-
elm.removeAttribute("
|
|
177
|
+
}).finally(() => {
|
|
178
|
+
elm.removeAttribute("data-navigating");
|
|
174
179
|
});
|
|
175
180
|
}
|
|
176
181
|
}
|
|
@@ -181,10 +186,10 @@ var Link = /*#__PURE__*/ componentQrl(/*#__PURE__*/ inlinedQrl((props) => {
|
|
|
181
186
|
scroll
|
|
182
187
|
]) : null;
|
|
183
188
|
return /*#__PURE__*/ _jsxSplit("a", {
|
|
184
|
-
|
|
185
|
-
..._getConstProps({ "q:link": !!clientNavPath }),
|
|
189
|
+
"q:link": !!clientNavPath,
|
|
186
190
|
...linkProps,
|
|
187
191
|
"data-q-prefetch": shouldVisiblePrefetchBundles && shouldVisiblePrefetchData ? "bd" : shouldVisiblePrefetchBundles ? "b" : shouldVisiblePrefetchData ? "d" : null,
|
|
192
|
+
"data-q-route": route && !route.notFound ? "/" + route.routeParts.join("/") : void 0,
|
|
188
193
|
"q-e:click": [
|
|
189
194
|
preventDefault,
|
|
190
195
|
/*#__PURE__*/ inlinedQrl((_, elm) => {
|
|
@@ -230,11 +235,11 @@ var newScrollState = () => {
|
|
|
230
235
|
h: 0
|
|
231
236
|
};
|
|
232
237
|
};
|
|
233
|
-
var preloadRouteBundles = (
|
|
238
|
+
var preloadRouteBundles = (routeName, probability = .8) => {
|
|
234
239
|
if (isBrowser) {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
_requestPreload(
|
|
240
|
+
routeName = ensureSlash(routeName);
|
|
241
|
+
routeName = routeName.length > 1 && routeName.startsWith("/") ? routeName.slice(1) : routeName;
|
|
242
|
+
_requestPreload(routeName, probability);
|
|
238
243
|
}
|
|
239
244
|
};
|
|
240
245
|
var prefetchedLinks = /* @__PURE__ */ new WeakSet();
|
|
@@ -266,7 +271,8 @@ var createLinkPrefetchObserver = (manifestHash) => {
|
|
|
266
271
|
const currentUrl = new URL(location.href);
|
|
267
272
|
if (!isSameOrigin(url, currentUrl) || !shouldPreload(toPath(url), { url: currentUrl })) return;
|
|
268
273
|
const mode = anchor.getAttribute("data-q-prefetch") || "";
|
|
269
|
-
|
|
274
|
+
const routeName = anchor.getAttribute("data-q-route");
|
|
275
|
+
if (mode.includes("b") && routeName) preloadRouteBundles(routeName);
|
|
270
276
|
if (mode.includes("d")) prefetchRoute(url, true, .8, manifestHash, false);
|
|
271
277
|
};
|
|
272
278
|
if (typeof IntersectionObserver === "undefined") {
|
|
@@ -332,6 +338,7 @@ var createCurrentPathTracker = (initialPath) => {
|
|
|
332
338
|
var dispatchRouterPopstate = (document1, href) => {
|
|
333
339
|
document1.dispatchEvent(new CustomEvent(Q_ROUTER_POPSTATE_EVENT, { detail: { href } }));
|
|
334
340
|
};
|
|
341
|
+
var isPlainPrimaryClick = (event) => event.button === 0 && !(event.metaKey || event.ctrlKey || event.shiftKey || event.altKey);
|
|
335
342
|
var spa_init_default = eventQrl(/*#__PURE__*/ inlinedQrl((_, el) => {
|
|
336
343
|
if (!window._qRouterSPA && !window._qRouterInitPopstate) {
|
|
337
344
|
const currentPath = location.pathname + location.search;
|
|
@@ -389,7 +396,7 @@ var spa_init_default = eventQrl(/*#__PURE__*/ inlinedQrl((_, el) => {
|
|
|
389
396
|
};
|
|
390
397
|
}
|
|
391
398
|
window._qRouterInitAnchors = (event) => {
|
|
392
|
-
if (window._qRouterSPA || event.defaultPrevented) return;
|
|
399
|
+
if (window._qRouterSPA || event.defaultPrevented || !isPlainPrimaryClick(event)) return;
|
|
393
400
|
const target = event.target.closest("a[href]");
|
|
394
401
|
if (target && !target.hasAttribute("preventdefault:click")) {
|
|
395
402
|
const href = target.getAttribute("href");
|
|
@@ -520,10 +527,48 @@ var startViewTransition = (params) => {
|
|
|
520
527
|
var QWIK_CITY_SCROLLER = "_qCityScroller";
|
|
521
528
|
/** @public */
|
|
522
529
|
var QWIK_ROUTER_SCROLLER = "_qRouterScroller";
|
|
523
|
-
var
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
530
|
+
var ensureRouteInternal = (routeInternal, routeLocation) => routeInternal.untrackedValue ||= {
|
|
531
|
+
type: "initial",
|
|
532
|
+
dest: routeLocation.url
|
|
533
|
+
};
|
|
534
|
+
var getRouterContainer = () => _getDomContainer(document.documentElement);
|
|
535
|
+
var getServerHttpStatus = (notFound, response) => {
|
|
536
|
+
if (notFound) return {
|
|
537
|
+
status: 404,
|
|
538
|
+
message: "Not Found"
|
|
539
|
+
};
|
|
540
|
+
const message = response.statusMessage ?? "OK";
|
|
541
|
+
return response.status === 200 && message === "OK" ? void 0 : {
|
|
542
|
+
status: response.status,
|
|
543
|
+
message
|
|
544
|
+
};
|
|
545
|
+
};
|
|
546
|
+
/** Resolves once the loaders still fetching have settled and the renders they trigger have flushed. */
|
|
547
|
+
var whenRouteLoadersSettled = async (loaderState, container) => {
|
|
548
|
+
const pending = [];
|
|
549
|
+
for (const id in loaderState) {
|
|
550
|
+
const signal = loaderState[id];
|
|
551
|
+
if (signal.untrackedPending) pending.push(signal.promise().catch(() => {}));
|
|
552
|
+
}
|
|
553
|
+
if (pending.length === 0) return;
|
|
554
|
+
await Promise.all(pending);
|
|
555
|
+
await _waitUntilRendered(container);
|
|
556
|
+
};
|
|
557
|
+
var whenReady = async (read) => {
|
|
558
|
+
for (;;) try {
|
|
559
|
+
return untrack(read);
|
|
560
|
+
} catch (error) {
|
|
561
|
+
if (!isPromise(error)) throw error;
|
|
562
|
+
await error.catch(() => {});
|
|
563
|
+
}
|
|
564
|
+
};
|
|
565
|
+
var assignDocumentHead = (documentHead, head) => {
|
|
566
|
+
documentHead.links = head.links;
|
|
567
|
+
documentHead.meta = head.meta;
|
|
568
|
+
documentHead.styles = head.styles;
|
|
569
|
+
documentHead.scripts = head.scripts;
|
|
570
|
+
documentHead.title = head.title;
|
|
571
|
+
documentHead.frontmatter = head.frontmatter;
|
|
527
572
|
};
|
|
528
573
|
var getScroller = () => {
|
|
529
574
|
let scroller = document.getElementById(QWIK_ROUTER_SCROLLER);
|
|
@@ -547,17 +592,19 @@ var useQwikRouter = (props) => {
|
|
|
547
592
|
if (!urlEnv) throw new Error(`Missing Qwik URL Env Data`);
|
|
548
593
|
const serverHead = useServerData("documentHead");
|
|
549
594
|
const manifestHash = useServerData("containerAttributes")?.["q:manifest-hash"];
|
|
550
|
-
const
|
|
595
|
+
const locale = getLocale("");
|
|
596
|
+
const viewTransition = props?.viewTransition;
|
|
551
597
|
const routeLocationTarget = {
|
|
552
|
-
url,
|
|
598
|
+
url: new URL(urlEnv),
|
|
553
599
|
params: env.params,
|
|
554
600
|
isNavigating: false,
|
|
555
601
|
prevUrl: void 0
|
|
556
602
|
};
|
|
557
603
|
const routeLocation = useStore(routeLocationTarget, { deep: false });
|
|
558
604
|
const navResolver = {};
|
|
559
|
-
const routeLoaderCtx =
|
|
605
|
+
const routeLoaderCtx = env.routeLoaderCtx;
|
|
560
606
|
routeLoaderCtx.manifestHash = manifestHash;
|
|
607
|
+
Object.assign(routeLoaderCtx.loaderPaths, env.loadedRoute.$loaderPaths$);
|
|
561
608
|
const loaderState = {};
|
|
562
609
|
const contentModulesForInit = env.loadedRoute.$mods$;
|
|
563
610
|
const loaders = ensureRouteLoaderSignals(contentModulesForInit, loaderState, routeLoaderCtx, env.ev);
|
|
@@ -565,25 +612,15 @@ var useQwikRouter = (props) => {
|
|
|
565
612
|
const value = env.loaderValues[loader.__id];
|
|
566
613
|
setLoaderSignalValue(loaderState[loader.__id], value);
|
|
567
614
|
}
|
|
568
|
-
const routeInternal = useSignal(
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
});
|
|
572
|
-
const documentHead = useStore(() => createDocumentHead(serverHead, manifestHash));
|
|
615
|
+
const routeInternal = useSignal();
|
|
616
|
+
const documentHead = useStore(() => createDocumentHead(serverHead, manifestHash), { deep: false });
|
|
617
|
+
const pageModule = contentModulesForInit[contentModulesForInit.length - 1];
|
|
573
618
|
const content = useStore({
|
|
574
|
-
headings:
|
|
575
|
-
menu:
|
|
576
|
-
});
|
|
577
|
-
const contentInternal = useSignal();
|
|
578
|
-
/**
|
|
579
|
-
* Non-serializable navigation context passed from the nav task to the navigation task. Only the
|
|
580
|
-
* data that can't be derived from existing stores/signals.
|
|
581
|
-
*/
|
|
582
|
-
const navContext = useSignal();
|
|
583
|
-
const httpStatus = useSignal({
|
|
584
|
-
status: env.response.status,
|
|
585
|
-
message: env.loadedRoute.$notFound$ ? "Not Found" : env.response.statusMessage ?? ""
|
|
619
|
+
headings: pageModule.headings,
|
|
620
|
+
menu: env.loadedRoute.$menu$
|
|
586
621
|
});
|
|
622
|
+
const contentInternal = useSignal(noSerialize(contentModulesForInit));
|
|
623
|
+
const httpStatus = useSignal(getServerHttpStatus(env.loadedRoute.$notFound$, env.response));
|
|
587
624
|
const currentActionId = env.response.action;
|
|
588
625
|
const currentAction = currentActionId ? env.response.actionResult : void 0;
|
|
589
626
|
const actionState = useSignal(currentAction ? {
|
|
@@ -594,34 +631,15 @@ var useQwikRouter = (props) => {
|
|
|
594
631
|
status: env.response.status
|
|
595
632
|
}
|
|
596
633
|
} : void 0);
|
|
597
|
-
const
|
|
634
|
+
const serverActionData = currentActionId || env.response.status !== 200 ? {
|
|
598
635
|
action: currentActionId,
|
|
599
636
|
actionResult: currentAction,
|
|
600
637
|
status: env.response.status
|
|
601
|
-
} : void 0
|
|
602
|
-
const
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
if (!preventNav.$cbs$) return;
|
|
607
|
-
if ([...preventNav.$cbs$.values()].map((cb) => cb.resolved ? cb.resolved() : cb()).some(Boolean)) {
|
|
608
|
-
event.preventDefault();
|
|
609
|
-
event.returnValue = true;
|
|
610
|
-
}
|
|
611
|
-
};
|
|
612
|
-
(preventNav.$cbs$ ||= /* @__PURE__ */ new Set()).add(fn$);
|
|
613
|
-
fn$.resolve();
|
|
614
|
-
window.addEventListener("beforeunload", preventNav.$handler$);
|
|
615
|
-
return () => {
|
|
616
|
-
if (preventNav.$cbs$) {
|
|
617
|
-
preventNav.$cbs$.delete(fn$);
|
|
618
|
-
if (!preventNav.$cbs$.size) {
|
|
619
|
-
preventNav.$cbs$ = void 0;
|
|
620
|
-
window.removeEventListener("beforeunload", preventNav.$handler$);
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
};
|
|
624
|
-
}, "useQwikRouter_registerPreventNav_69B0DK0eZJc");
|
|
638
|
+
} : void 0;
|
|
639
|
+
const actionDataSignal = useSignal(serverActionData);
|
|
640
|
+
_waitOn(whenReady(() => {
|
|
641
|
+
for (const loader of loaders) if (!isImmutableLoader(loader.__id)) loaderState[loader.__id].untrackedPending;
|
|
642
|
+
}).then(() => whenReady(() => resolveHead(serverActionData, loaderState, routeLocation, contentModulesForInit, locale, serverHead))).then((head) => assignDocumentHead(documentHead, head)));
|
|
625
643
|
/**
|
|
626
644
|
* This is the `nav()` function that `useNavigation()` returns. It is also used internally for SPA
|
|
627
645
|
* navigations and is provided in context for use in loaders and actions.
|
|
@@ -630,132 +648,113 @@ var useQwikRouter = (props) => {
|
|
|
630
648
|
* treat it as a user-initiated navigation and allow scroll restoration to work. For this reason,
|
|
631
649
|
* make sure to change the address bar before awaiting anything.
|
|
632
650
|
*/
|
|
633
|
-
const goto = /*#__PURE__*/ inlinedQrl(
|
|
634
|
-
let
|
|
635
|
-
const
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
routeLocation.url = url;
|
|
640
|
-
}
|
|
641
|
-
const lastDest = routeInternal.value.dest;
|
|
642
|
-
const dest = path === void 0 ? lastDest : typeof path === "number" ? path : toUrl(path, routeLocation.url);
|
|
643
|
-
if (navResolver.p && !forceReload && typeof dest !== "number" && isSamePath(dest, lastDest) && dest.href === lastDest.href) return navResolver.p;
|
|
644
|
-
const attemptCount = ++internalState.attemptCount;
|
|
645
|
-
if (preventNav.$cbs$ && (forceReload || typeof dest === "number" || !isSamePath(dest, lastDest) || !isSameOrigin(dest, lastDest))) {
|
|
646
|
-
const prevents = await Promise.all([...preventNav.$cbs$.values()].map((cb) => cb(dest)));
|
|
647
|
-
if (attemptCount !== internalState.attemptCount || prevents.some(Boolean)) {
|
|
648
|
-
if (attemptCount === internalState.attemptCount && type === "popstate") history.pushState(null, "", lastDest);
|
|
651
|
+
const goto = /*#__PURE__*/ inlinedQrl((path, opt) => {
|
|
652
|
+
let actionDataSignal = _capturesObj._[0], actionState = _capturesObj._[1], content = _capturesObj._[2], contentInternal = _capturesObj._[3], documentHead = _capturesObj._[4], httpStatus = _capturesObj._[5], loaderState = _capturesObj._[6], locale = _capturesObj._[7], manifestHash = _capturesObj._[8], navResolver = _capturesObj._[9], routeInternal = _capturesObj._[10], routeLoaderCtx = _capturesObj._[11], routeLocation = _capturesObj._[12], routeLocationTarget = _capturesObj._[13], serverHead = _capturesObj._[14], viewTransition = _capturesObj._[15];
|
|
653
|
+
const startNavigation = async (path, opt) => {
|
|
654
|
+
if (path === REFRESH_HEAD) {
|
|
655
|
+
const contentModules = contentInternal.untrackedValue;
|
|
656
|
+
if (contentModules) updateHead(contentModules, actionDataSignal.untrackedValue, internalState.navCount);
|
|
649
657
|
return;
|
|
650
658
|
}
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
if (
|
|
662
|
-
|
|
659
|
+
if (path === RUN_PENDING_ACTION) return loadNavigation(ensureRouteInternal(routeInternal, routeLocation), actionState.value, getRouterContainer());
|
|
660
|
+
const { type = "link", forceReload = path === void 0, replaceState = false, scroll = true } = typeof opt === "object" ? opt : { forceReload: opt };
|
|
661
|
+
const current = ensureRouteInternal(routeInternal, routeLocation);
|
|
662
|
+
if (isBrowser && type === "link" && current.type === "initial") {
|
|
663
|
+
const url = new URL(window.location.href);
|
|
664
|
+
current.dest = url;
|
|
665
|
+
routeLocation.url = url;
|
|
666
|
+
}
|
|
667
|
+
const lastDest = current.dest;
|
|
668
|
+
const dest = path === void 0 ? lastDest : typeof path === "number" ? path : toUrl(path, routeLocation.url);
|
|
669
|
+
if (navResolver.p && !forceReload && typeof dest !== "number" && isSamePath(dest, lastDest) && dest.href === lastDest.href) return navResolver.p;
|
|
670
|
+
const attemptCount = ++internalState.attemptCount;
|
|
671
|
+
if (preventNav.$cbs$ && (forceReload || typeof dest === "number" || !isSamePath(dest, lastDest) || !isSameOrigin(dest, lastDest))) {
|
|
672
|
+
const prevents = await Promise.all([...preventNav.$cbs$.values()].map((cb) => cb(dest)));
|
|
673
|
+
if (attemptCount !== internalState.attemptCount || prevents.some(Boolean)) {
|
|
674
|
+
if (attemptCount === internalState.attemptCount && type === "popstate") history.pushState(null, "", lastDest);
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
if (typeof dest === "number") {
|
|
679
|
+
if (isBrowser) history.go(dest);
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
682
|
+
if (!isSameOrigin(dest, lastDest)) {
|
|
683
|
+
if (isBrowser) location.href = dest.href;
|
|
684
|
+
return;
|
|
685
|
+
}
|
|
686
|
+
if (!forceReload && isSamePath(dest, lastDest)) {
|
|
687
|
+
if (isBrowser) {
|
|
688
|
+
if (type === "link" && dest.href !== location.href) history.pushState(null, "", dest);
|
|
689
|
+
const scroller = getScroller();
|
|
690
|
+
restoreScroll(type, dest, new URL(location.href), scroller, getScrollHistory());
|
|
691
|
+
if (type === "popstate") window._qRouterScrollEnabled = true;
|
|
692
|
+
}
|
|
693
|
+
if (dest.href !== routeLocation.url.href) {
|
|
694
|
+
const newUrl = new URL(dest.href);
|
|
695
|
+
ensureRouteInternal(routeInternal, routeLocation).dest = newUrl;
|
|
696
|
+
routeLocation.url = newUrl;
|
|
697
|
+
const contentModules = contentInternal.untrackedValue;
|
|
698
|
+
if (contentModules) updateHead(contentModules, actionDataSignal.untrackedValue, internalState.navCount);
|
|
699
|
+
}
|
|
700
|
+
return navResolver.p;
|
|
701
|
+
}
|
|
702
|
+
const navCount = ++internalState.navCount;
|
|
703
|
+
internalState.currentTransition?.skipTransition();
|
|
704
|
+
navResolver.cancel?.();
|
|
705
|
+
navResolver.cancel = void 0;
|
|
706
|
+
navResolver.r?.();
|
|
707
|
+
let historyUpdated = false;
|
|
708
|
+
if (isBrowser) getClientRouteLoaders(routeLoaderCtx, routeLocation.url.href);
|
|
709
|
+
if (isBrowser && type === "link" && !forceReload) {
|
|
663
710
|
const scroller = getScroller();
|
|
664
|
-
|
|
665
|
-
|
|
711
|
+
window._qRouterScrollEnabled = false;
|
|
712
|
+
clearTimeout(window._qRouterScrollDebounce);
|
|
713
|
+
saveScrollHistory(currentScrollState(scroller));
|
|
714
|
+
clientNavigate(window, type, new URL(location.href), dest, replaceState);
|
|
715
|
+
historyUpdated = true;
|
|
666
716
|
}
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
717
|
+
const wasNavigating = routeLocation.isNavigating;
|
|
718
|
+
routeLocation.isNavigating = true;
|
|
719
|
+
const container = isBrowser ? _getContextContainer() : void 0;
|
|
720
|
+
if (container && !wasNavigating) {
|
|
721
|
+
await _waitUntilRendered(container);
|
|
722
|
+
if (navCount !== internalState.navCount) return;
|
|
671
723
|
}
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
if (isBrowser) getClientRouteLoaders(routeLoaderCtx, routeLocation.url.href);
|
|
681
|
-
if (isBrowser && type === "link" && !forceReload) {
|
|
682
|
-
const scroller = getScroller();
|
|
683
|
-
window._qRouterScrollEnabled = false;
|
|
684
|
-
clearTimeout(window._qRouterScrollDebounce);
|
|
685
|
-
saveScrollHistory(currentScrollState(scroller));
|
|
686
|
-
clientNavigate(window, type, new URL(location.href), dest, replaceState);
|
|
687
|
-
historyUpdated = true;
|
|
688
|
-
}
|
|
689
|
-
const wasNavigating = routeLocation.isNavigating;
|
|
690
|
-
routeLocation.isNavigating = true;
|
|
691
|
-
const container = isBrowser ? _getContextContainer() : void 0;
|
|
692
|
-
if (container && !wasNavigating) {
|
|
693
|
-
await _waitUntilRendered(container);
|
|
694
|
-
if (navCount !== internalState.navCount) return;
|
|
695
|
-
}
|
|
696
|
-
actionState.value = void 0;
|
|
697
|
-
routeInternal.value = {
|
|
698
|
-
type,
|
|
699
|
-
dest,
|
|
700
|
-
forceReload,
|
|
701
|
-
replaceState,
|
|
702
|
-
scroll,
|
|
703
|
-
historyUpdated
|
|
704
|
-
};
|
|
705
|
-
if (wasNavigating) abortRouteLoaderNavigation(routeLoaderCtx);
|
|
706
|
-
if (isBrowser) prefetchRoute(dest, false, .8, manifestHash, true);
|
|
707
|
-
navResolver.p = new Promise((resolve) => {
|
|
708
|
-
navResolver.r = () => {
|
|
709
|
-
navResolver.r = void 0;
|
|
710
|
-
navResolver.p = void 0;
|
|
711
|
-
resolve();
|
|
724
|
+
actionState.value = void 0;
|
|
725
|
+
const navigation = {
|
|
726
|
+
type,
|
|
727
|
+
dest,
|
|
728
|
+
forceReload,
|
|
729
|
+
replaceState,
|
|
730
|
+
scroll,
|
|
731
|
+
historyUpdated
|
|
712
732
|
};
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
let actionDataSignal = _capturesObj._[0], actionState = _capturesObj._[1], content = _capturesObj._[2], contentInternal = _capturesObj._[3], env = _capturesObj._[4], goto = _capturesObj._[5], httpStatus = _capturesObj._[6], loaderState = _capturesObj._[7], navContext = _capturesObj._[8], navResolver = _capturesObj._[9], routeInternal = _capturesObj._[10], routeLoaderCtx = _capturesObj._[11], routeLocation = _capturesObj._[12], routeLocationTarget = _capturesObj._[13];
|
|
739
|
-
const navigation = track(routeInternal);
|
|
740
|
-
const action = track(actionState);
|
|
741
|
-
action?.resolveDispatch?.();
|
|
742
|
-
if (action) action.resolveDispatch = void 0;
|
|
743
|
-
const prevUrl = routeLocation.url;
|
|
744
|
-
const navType = action ? "form" : navigation.type;
|
|
745
|
-
const replaceState = navigation.replaceState;
|
|
746
|
-
const navCountBefore = internalState.navCount;
|
|
747
|
-
let trackUrl;
|
|
748
|
-
let endpointResponse;
|
|
749
|
-
let actionData;
|
|
750
|
-
let actionLoaderHashes;
|
|
751
|
-
let loadedRoute;
|
|
752
|
-
if (isServer) {
|
|
753
|
-
trackUrl = new URL(navigation.dest, routeLocation.url);
|
|
754
|
-
loadedRoute = env.loadedRoute;
|
|
755
|
-
endpointResponse = env.response;
|
|
756
|
-
actionData = endpointResponse;
|
|
757
|
-
} else {
|
|
758
|
-
trackUrl = new URL(navigation.dest, location);
|
|
733
|
+
routeInternal.value = navigation;
|
|
734
|
+
if (wasNavigating) abortRouteLoaderNavigation(routeLoaderCtx);
|
|
735
|
+
if (isBrowser) prefetchRoute(dest, false, .8, manifestHash, true);
|
|
736
|
+
navResolver.p = new Promise((resolve) => {
|
|
737
|
+
navResolver.r = () => {
|
|
738
|
+
navResolver.r = void 0;
|
|
739
|
+
navResolver.p = void 0;
|
|
740
|
+
resolve();
|
|
741
|
+
};
|
|
742
|
+
});
|
|
743
|
+
const navigated = navResolver.p;
|
|
744
|
+
loadNavigation(navigation, void 0, container ?? getRouterContainer());
|
|
745
|
+
return navigated;
|
|
746
|
+
};
|
|
747
|
+
const loadNavigation = async (navigation, action, container) => {
|
|
748
|
+
action?.resolveDispatch?.();
|
|
749
|
+
if (action) action.resolveDispatch = void 0;
|
|
750
|
+
const prevUrl = routeLocation.url;
|
|
751
|
+
const navType = action ? "form" : navigation.type;
|
|
752
|
+
const replaceState = navigation.replaceState;
|
|
753
|
+
const navCountBefore = internalState.navCount;
|
|
754
|
+
let actionData;
|
|
755
|
+
let actionLoaderHashes;
|
|
756
|
+
let loadedRoute;
|
|
757
|
+
const trackUrl = new URL(navigation.dest, location);
|
|
759
758
|
const canceled = new Promise((resolve) => {
|
|
760
759
|
navResolver.cancel = () => resolve(void 0);
|
|
761
760
|
});
|
|
@@ -801,7 +800,7 @@ var useQwikRouter = (props) => {
|
|
|
801
800
|
}
|
|
802
801
|
if (result.redirect) {
|
|
803
802
|
if (result.redirect instanceof URL) location.href = result.redirect.href;
|
|
804
|
-
else
|
|
803
|
+
else startNavigation(result.redirect, { replaceState: true });
|
|
805
804
|
return;
|
|
806
805
|
}
|
|
807
806
|
actionData = {
|
|
@@ -812,210 +811,187 @@ var useQwikRouter = (props) => {
|
|
|
812
811
|
actionLoaderHashes = result.loaderHashes;
|
|
813
812
|
}
|
|
814
813
|
navResolver.cancel = void 0;
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
if (
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
814
|
+
const { $routeName$, $params$, $mods$, $menu$, $notFound$ } = loadedRoute;
|
|
815
|
+
const contentModules = $mods$;
|
|
816
|
+
routeLoaderCtx.goto = noSerialize(startNavigation);
|
|
817
|
+
const routeLoaders = prepareRouteLoaders(contentModules, loaderState, routeLoaderCtx, loadedRoute.$loaderPaths$, trackUrl, prevUrl, navCountBefore, action ? actionLoaderHashes ?? null : void 0, action ?? navigation);
|
|
818
|
+
await whenReady(() => {
|
|
819
|
+
for (let i = 0; i < routeLoaders.length; i++) {
|
|
820
|
+
const loader = routeLoaders[i];
|
|
821
|
+
if (!isImmutableLoader(loader.__id)) loaderState[loader.__id].untrackedPending;
|
|
822
|
+
}
|
|
823
|
+
});
|
|
824
|
+
clearNavFetchCache();
|
|
825
|
+
if (internalState.navCount !== navCountBefore) return;
|
|
826
|
+
if ($notFound$) httpStatus.value = {
|
|
827
|
+
status: 404,
|
|
828
|
+
message: "Not Found"
|
|
829
|
+
};
|
|
830
|
+
else if (actionData) httpStatus.value = {
|
|
831
|
+
status: actionData.status,
|
|
832
|
+
message: "OK"
|
|
833
|
+
};
|
|
834
|
+
else httpStatus.value = {
|
|
835
|
+
status: 200,
|
|
836
|
+
message: "OK"
|
|
837
|
+
};
|
|
838
|
+
const pageModule = contentModules[contentModules.length - 1];
|
|
839
|
+
if (isSamePath(trackUrl, navigation.dest)) trackUrl.hash = navigation.dest.hash;
|
|
840
|
+
if (navigation.dest.search && !!isSamePath(trackUrl, prevUrl)) trackUrl.search = navigation.dest.search;
|
|
841
|
+
let shouldForcePrevUrl = false;
|
|
842
|
+
let shouldForceUrl = false;
|
|
843
|
+
let shouldForceParams = false;
|
|
844
|
+
if (!isSamePath(trackUrl, prevUrl)) {
|
|
845
|
+
if (_hasStoreEffects(routeLocation, "prevUrl")) shouldForcePrevUrl = true;
|
|
846
|
+
routeLocationTarget.prevUrl = prevUrl;
|
|
847
|
+
}
|
|
848
|
+
if (routeLocationTarget.url !== trackUrl) {
|
|
849
|
+
if (_hasStoreEffects(routeLocation, "url")) shouldForceUrl = true;
|
|
850
|
+
routeLocationTarget.url = trackUrl;
|
|
851
|
+
}
|
|
852
|
+
if (routeLocationTarget.params !== $params$) {
|
|
853
|
+
if (_hasStoreEffects(routeLocation, "params")) shouldForceParams = true;
|
|
854
|
+
routeLocationTarget.params = $params$;
|
|
855
|
+
}
|
|
856
|
+
const nextRouteInternal = {
|
|
857
|
+
type: navType,
|
|
858
|
+
dest: trackUrl
|
|
859
|
+
};
|
|
860
|
+
if (navigation.forceReload !== void 0) nextRouteInternal.forceReload = navigation.forceReload;
|
|
861
|
+
if (navigation.replaceState !== void 0) nextRouteInternal.replaceState = navigation.replaceState;
|
|
862
|
+
if (navigation.scroll !== void 0) nextRouteInternal.scroll = navigation.scroll;
|
|
863
|
+
if (navigation.historyUpdated !== void 0) nextRouteInternal.historyUpdated = navigation.historyUpdated;
|
|
864
|
+
routeInternal.untrackedValue = nextRouteInternal;
|
|
865
|
+
content.headings = pageModule.headings;
|
|
866
|
+
content.menu = $menu$;
|
|
867
|
+
contentInternal.untrackedValue = noSerialize(contentModules);
|
|
868
|
+
actionDataSignal.untrackedValue = actionData;
|
|
869
|
+
commitNavigation({
|
|
870
|
+
routeName: $routeName$,
|
|
871
|
+
navType,
|
|
872
|
+
prevUrl,
|
|
873
|
+
replaceState,
|
|
874
|
+
shouldForcePrevUrl,
|
|
875
|
+
shouldForceUrl,
|
|
876
|
+
shouldForceParams,
|
|
877
|
+
navCount: navCountBefore,
|
|
878
|
+
contentModules,
|
|
879
|
+
actionData
|
|
880
|
+
}, nextRouteInternal, container);
|
|
841
881
|
};
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
882
|
+
const updateHead = (contentModules, actionData, navCount) => {
|
|
883
|
+
let head;
|
|
884
|
+
try {
|
|
885
|
+
head = resolveHead(actionData, loaderState, routeLocation, contentModules, locale, serverHead);
|
|
886
|
+
} catch (error) {
|
|
887
|
+
if (isPromise(error)) {
|
|
888
|
+
const retry = () => {
|
|
889
|
+
if (navCount === internalState.navCount) return updateHead(contentModules, actionData, navCount);
|
|
890
|
+
};
|
|
891
|
+
return error.then(retry, retry);
|
|
892
|
+
}
|
|
893
|
+
console.error(error);
|
|
894
|
+
return;
|
|
895
|
+
}
|
|
896
|
+
assignDocumentHead(documentHead, head);
|
|
845
897
|
};
|
|
846
|
-
const
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
if (
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
898
|
+
const commitNavigation = (nav, navigation, container) => {
|
|
899
|
+
if (nav.navCount !== internalState.navCount) return;
|
|
900
|
+
const { navType, prevUrl, replaceState, routeName } = nav;
|
|
901
|
+
const trackUrl = routeLocation.url;
|
|
902
|
+
const scroller = getScroller();
|
|
903
|
+
let scrollState;
|
|
904
|
+
if (navType === "popstate") scrollState = getScrollHistory();
|
|
905
|
+
if (navigation.scroll && (!navigation.forceReload || !isSamePath(trackUrl, prevUrl)) && (navType === "link" || navType === "popstate") || navType === "form" && !isSamePath(trackUrl, prevUrl)) document.__q_scroll_restore__ = () => restoreScroll(navType, trackUrl, prevUrl, scroller, scrollState);
|
|
906
|
+
initializeSPA(startNavigation, scroller);
|
|
907
|
+
if (navType !== "popstate") {
|
|
908
|
+
window._qRouterScrollEnabled = false;
|
|
909
|
+
clearTimeout(window._qRouterScrollDebounce);
|
|
910
|
+
if (!navigation.historyUpdated) saveScrollHistory(currentScrollState(scroller));
|
|
911
|
+
}
|
|
912
|
+
let didNavigate = false;
|
|
913
|
+
let navigatePromise;
|
|
914
|
+
let currentTransition;
|
|
915
|
+
const navigate = () => {
|
|
916
|
+
if (navigatePromise) return navigatePromise;
|
|
917
|
+
if (nav.navCount !== internalState.navCount) return Promise.resolve();
|
|
918
|
+
didNavigate = true;
|
|
919
|
+
if (navigation.historyUpdated) {
|
|
920
|
+
const currentPath = location.pathname + location.search + location.hash;
|
|
921
|
+
const nextPath = toPath(trackUrl);
|
|
922
|
+
if (currentPath !== nextPath) history.replaceState(history.state, "", nextPath);
|
|
923
|
+
} else clientNavigate(window, navType, prevUrl, trackUrl, replaceState);
|
|
924
|
+
const headUpdated = updateHead(nav.contentModules, nav.actionData, nav.navCount);
|
|
925
|
+
contentInternal.trigger();
|
|
926
|
+
return navigatePromise = Promise.all([_waitUntilRendered(container), headUpdated]).then(() => {
|
|
927
|
+
if (nav.navCount === internalState.navCount) commitRouteLoaders(loaderState, routeLoaderCtx, nav.navCount);
|
|
928
|
+
}, (error) => {
|
|
929
|
+
if (nav.navCount === internalState.navCount) restoreRouteLoaders(loaderState, routeLoaderCtx, nav.navCount);
|
|
930
|
+
throw error;
|
|
931
|
+
});
|
|
932
|
+
};
|
|
933
|
+
const _waitNextPage = () => {
|
|
934
|
+
if (!shouldStartViewTransition(viewTransition)) return navigate().then(() => void 0);
|
|
935
|
+
const { ready, transition } = startViewTransition({
|
|
936
|
+
update: navigate,
|
|
937
|
+
types: ["qwik-navigation"]
|
|
938
|
+
});
|
|
939
|
+
currentTransition = transition;
|
|
940
|
+
internalState.currentTransition = transition;
|
|
941
|
+
return ready.then(() => transition, (reason) => {
|
|
942
|
+
if (!didNavigate && nav.navCount === internalState.navCount) return navigate().then(() => transition);
|
|
943
|
+
if (reason?.name === "AbortError") return transition;
|
|
944
|
+
throw reason;
|
|
945
|
+
});
|
|
946
|
+
};
|
|
947
|
+
_waitNextPage().finally(() => {
|
|
948
|
+
if (currentTransition && internalState.currentTransition === currentTransition) internalState.currentTransition = void 0;
|
|
949
|
+
if (nav.navCount !== internalState.navCount) return;
|
|
950
|
+
container.element.setAttribute?.(Q_ROUTE, routeName);
|
|
951
|
+
saveScrollHistory(currentScrollState(scroller));
|
|
952
|
+
window._qRouterScrollEnabled = true;
|
|
953
|
+
callRestoreScrollOnDocument();
|
|
954
|
+
refreshLinkPrefetchObserver(manifestHash);
|
|
955
|
+
if (nav.shouldForcePrevUrl) forceStoreEffects(routeLocation, "prevUrl");
|
|
956
|
+
if (nav.shouldForceUrl) forceStoreEffects(routeLocation, "url");
|
|
957
|
+
if (nav.shouldForceParams) forceStoreEffects(routeLocation, "params");
|
|
958
|
+
whenRouteLoadersSettled(loaderState, container).then(() => {
|
|
959
|
+
if (nav.navCount !== internalState.navCount) return;
|
|
960
|
+
routeLocation.isNavigating = false;
|
|
961
|
+
navResolver.r?.();
|
|
962
|
+
});
|
|
963
|
+
});
|
|
867
964
|
};
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
if (navigation.scroll !== void 0) nextRouteInternal.scroll = navigation.scroll;
|
|
871
|
-
if (navigation.historyUpdated !== void 0) nextRouteInternal.historyUpdated = navigation.historyUpdated;
|
|
872
|
-
routeInternal.untrackedValue = nextRouteInternal;
|
|
873
|
-
content.headings = pageModule.headings;
|
|
874
|
-
content.menu = $menu$;
|
|
875
|
-
contentInternal.untrackedValue = noSerialize(contentModules);
|
|
876
|
-
actionDataSignal.value = actionData;
|
|
877
|
-
navContext.value = noSerialize({
|
|
878
|
-
routeName: $routeName$,
|
|
879
|
-
navType,
|
|
880
|
-
prevUrl,
|
|
881
|
-
replaceState,
|
|
882
|
-
shouldForcePrevUrl,
|
|
883
|
-
shouldForceUrl,
|
|
884
|
-
shouldForceParams,
|
|
885
|
-
navCount: navCountBefore
|
|
886
|
-
});
|
|
887
|
-
}, "useQwikRouter_useTask_XpalYii770E", [
|
|
965
|
+
return startNavigation(path, opt);
|
|
966
|
+
}, "useQwikRouter_goto_8j8Vrz2yUIM", [
|
|
888
967
|
actionDataSignal,
|
|
889
968
|
actionState,
|
|
890
969
|
content,
|
|
891
970
|
contentInternal,
|
|
892
|
-
env,
|
|
893
|
-
goto,
|
|
894
|
-
httpStatus,
|
|
895
|
-
loaderState,
|
|
896
|
-
navContext,
|
|
897
|
-
navResolver,
|
|
898
|
-
routeInternal,
|
|
899
|
-
routeLoaderCtx,
|
|
900
|
-
routeLocation,
|
|
901
|
-
routeLocationTarget
|
|
902
|
-
]), { deferUpdates: isServer });
|
|
903
|
-
/**
|
|
904
|
-
* Calc head. This is in a separate task so that loader updates can trigger head recalculation
|
|
905
|
-
* without re-running the navigation logic.
|
|
906
|
-
*
|
|
907
|
-
* Note that on the server these tasks run sequentially.
|
|
908
|
-
*/
|
|
909
|
-
useTaskQrl(/*#__PURE__*/ inlinedQrl(({ track }) => {
|
|
910
|
-
let actionDataSignal = _capturesObj._[0], contentInternal = _capturesObj._[1], documentHead = _capturesObj._[2], loaderState = _capturesObj._[3], navContext = _capturesObj._[4], routeLocation = _capturesObj._[5], serverHead = _capturesObj._[6];
|
|
911
|
-
const contentModules = track(contentInternal);
|
|
912
|
-
const nav = navContext.untrackedValue;
|
|
913
|
-
if (!isServer && routeLocation.isNavigating && nav && nav.navCount !== internalState.navCount) return;
|
|
914
|
-
if (!contentModules) return;
|
|
915
|
-
const actionData = track(actionDataSignal);
|
|
916
|
-
let head;
|
|
917
|
-
try {
|
|
918
|
-
head = track(() => resolveHead(actionData, loaderState, routeLocation, contentModules, getLocale(""), serverHead));
|
|
919
|
-
} catch (error) {
|
|
920
|
-
if (isServer || isPromise(error)) throw error;
|
|
921
|
-
console.error(error);
|
|
922
|
-
return;
|
|
923
|
-
}
|
|
924
|
-
documentHead.links = head.links;
|
|
925
|
-
documentHead.meta = head.meta;
|
|
926
|
-
documentHead.styles = head.styles;
|
|
927
|
-
documentHead.scripts = head.scripts;
|
|
928
|
-
documentHead.title = head.title;
|
|
929
|
-
documentHead.frontmatter = head.frontmatter;
|
|
930
|
-
}, "useQwikRouter_useTask_1_1sKEZ9Pg1ow", [
|
|
931
|
-
actionDataSignal,
|
|
932
|
-
contentInternal,
|
|
933
971
|
documentHead,
|
|
972
|
+
httpStatus,
|
|
934
973
|
loaderState,
|
|
935
|
-
|
|
936
|
-
routeLocation,
|
|
937
|
-
serverHead
|
|
938
|
-
]), { deferUpdates: isServer });
|
|
939
|
-
/** Actual navigation */
|
|
940
|
-
useTaskQrl(/*#__PURE__*/ inlinedQrl(({ track }) => {
|
|
941
|
-
let contentInternal = _capturesObj._[0], goto = _capturesObj._[1], loaderState = _capturesObj._[2], manifestHash = _capturesObj._[3], navContext = _capturesObj._[4], navResolver = _capturesObj._[5], props = _capturesObj._[6], routeInternal = _capturesObj._[7], routeLoaderCtx = _capturesObj._[8], routeLocation = _capturesObj._[9];
|
|
942
|
-
const nav = track(navContext);
|
|
943
|
-
if (isServer || !nav) return;
|
|
944
|
-
if (nav.navCount !== internalState.navCount) return;
|
|
945
|
-
const container = _getContextContainer();
|
|
946
|
-
const navigation = routeInternal.untrackedValue;
|
|
947
|
-
const { navType, prevUrl, replaceState, routeName } = nav;
|
|
948
|
-
const trackUrl = routeLocation.url;
|
|
949
|
-
const scroller = getScroller();
|
|
950
|
-
let scrollState;
|
|
951
|
-
if (navType === "popstate") scrollState = getScrollHistory();
|
|
952
|
-
if (navigation.scroll && (!navigation.forceReload || !isSamePath(trackUrl, prevUrl)) && (navType === "link" || navType === "popstate") || navType === "form" && !isSamePath(trackUrl, prevUrl)) document.__q_scroll_restore__ = () => restoreScroll(navType, trackUrl, prevUrl, scroller, scrollState);
|
|
953
|
-
initializeSPA(goto, scroller);
|
|
954
|
-
if (navType !== "popstate") {
|
|
955
|
-
window._qRouterScrollEnabled = false;
|
|
956
|
-
clearTimeout(window._qRouterScrollDebounce);
|
|
957
|
-
if (!navigation.historyUpdated) saveScrollHistory(currentScrollState(scroller));
|
|
958
|
-
}
|
|
959
|
-
let didNavigate = false;
|
|
960
|
-
let navigatePromise;
|
|
961
|
-
let currentTransition;
|
|
962
|
-
const navigate = () => {
|
|
963
|
-
if (navigatePromise) return navigatePromise;
|
|
964
|
-
if (nav.navCount !== internalState.navCount) return Promise.resolve();
|
|
965
|
-
didNavigate = true;
|
|
966
|
-
if (navigation.historyUpdated) {
|
|
967
|
-
const currentPath = location.pathname + location.search + location.hash;
|
|
968
|
-
const nextPath = toPath(trackUrl);
|
|
969
|
-
if (currentPath !== nextPath) history.replaceState(history.state, "", nextPath);
|
|
970
|
-
} else clientNavigate(window, navType, prevUrl, trackUrl, replaceState);
|
|
971
|
-
contentInternal.trigger();
|
|
972
|
-
return navigatePromise = _waitUntilRendered(container).then(() => {
|
|
973
|
-
if (nav.navCount === internalState.navCount) commitRouteLoaders(loaderState, routeLoaderCtx, nav.navCount);
|
|
974
|
-
}, (error) => {
|
|
975
|
-
if (nav.navCount === internalState.navCount) restoreRouteLoaders(loaderState, routeLoaderCtx, nav.navCount);
|
|
976
|
-
throw error;
|
|
977
|
-
});
|
|
978
|
-
};
|
|
979
|
-
const _waitNextPage = () => {
|
|
980
|
-
if (!shouldStartViewTransition(props?.viewTransition)) return navigate().then(() => void 0);
|
|
981
|
-
const { ready, transition } = startViewTransition({
|
|
982
|
-
update: navigate,
|
|
983
|
-
types: ["qwik-navigation"]
|
|
984
|
-
});
|
|
985
|
-
currentTransition = transition;
|
|
986
|
-
internalState.currentTransition = transition;
|
|
987
|
-
return ready.then(() => transition, (reason) => {
|
|
988
|
-
if (!didNavigate && nav.navCount === internalState.navCount) return navigate().then(() => transition);
|
|
989
|
-
if (reason?.name === "AbortError") return transition;
|
|
990
|
-
throw reason;
|
|
991
|
-
});
|
|
992
|
-
};
|
|
993
|
-
_waitNextPage().finally(() => {
|
|
994
|
-
if (currentTransition && internalState.currentTransition === currentTransition) internalState.currentTransition = void 0;
|
|
995
|
-
if (nav.navCount !== internalState.navCount) return;
|
|
996
|
-
container.element.setAttribute?.(Q_ROUTE, routeName);
|
|
997
|
-
saveScrollHistory(currentScrollState(scroller));
|
|
998
|
-
window._qRouterScrollEnabled = true;
|
|
999
|
-
callRestoreScrollOnDocument();
|
|
1000
|
-
refreshLinkPrefetchObserver(manifestHash);
|
|
1001
|
-
if (nav.shouldForcePrevUrl) forceStoreEffects(routeLocation, "prevUrl");
|
|
1002
|
-
if (nav.shouldForceUrl) forceStoreEffects(routeLocation, "url");
|
|
1003
|
-
if (nav.shouldForceParams) forceStoreEffects(routeLocation, "params");
|
|
1004
|
-
routeLocation.isNavigating = false;
|
|
1005
|
-
navResolver.r?.();
|
|
1006
|
-
});
|
|
1007
|
-
}, "useQwikRouter_useTask_2_yw17chooOac", [
|
|
1008
|
-
contentInternal,
|
|
1009
|
-
goto,
|
|
1010
|
-
loaderState,
|
|
974
|
+
locale,
|
|
1011
975
|
manifestHash,
|
|
1012
|
-
navContext,
|
|
1013
976
|
navResolver,
|
|
1014
|
-
props,
|
|
1015
977
|
routeInternal,
|
|
1016
978
|
routeLoaderCtx,
|
|
1017
|
-
routeLocation
|
|
1018
|
-
|
|
979
|
+
routeLocation,
|
|
980
|
+
routeLocationTarget,
|
|
981
|
+
serverHead,
|
|
982
|
+
viewTransition
|
|
983
|
+
]);
|
|
984
|
+
routeLoaderCtx.onValue = goto;
|
|
985
|
+
useContextProvider(ContentContext, content);
|
|
986
|
+
useContextProvider(ContentInternalContext, contentInternal);
|
|
987
|
+
useContextProvider(DocumentHeadContext, documentHead);
|
|
988
|
+
useContextProvider(HttpStatusContext, httpStatus);
|
|
989
|
+
useContextProvider(RouteLocationContext, routeLocation);
|
|
990
|
+
useContextProvider(RouteNavigateContext, goto);
|
|
991
|
+
useContextProvider(RouteActionRunnerContext, goto);
|
|
992
|
+
useContextProvider(RouteStateContext, loaderState);
|
|
993
|
+
useContextProvider(RouteLoaderCtxContext, routeLoaderCtx);
|
|
994
|
+
useContextProvider(RouteActionContext, actionState);
|
|
1019
995
|
};
|
|
1020
996
|
/** @public This is a wrapper around the `useQwikRouter()` hook. We recommend using the hook instead of this component, unless you have a good reason to make your root component reactive. */
|
|
1021
997
|
function initializeSPA(goto, scroller) {
|
|
@@ -1052,7 +1028,7 @@ function initializeSPA(goto, scroller) {
|
|
|
1052
1028
|
};
|
|
1053
1029
|
}
|
|
1054
1030
|
document.addEventListener("click", (event) => {
|
|
1055
|
-
if (event.defaultPrevented) return;
|
|
1031
|
+
if (event.defaultPrevented || !isPlainPrimaryClick(event)) return;
|
|
1056
1032
|
const target = event.target.closest("a[href]");
|
|
1057
1033
|
if (target && !target.hasAttribute("preventdefault:click")) {
|
|
1058
1034
|
const href = target.getAttribute("href");
|
|
@@ -1220,6 +1196,7 @@ function routeActionQrl(actionQrl, ...rest) {
|
|
|
1220
1196
|
function action() {
|
|
1221
1197
|
const loc = useLocation();
|
|
1222
1198
|
const currentAction = useAction();
|
|
1199
|
+
const runAction = useContext(RouteActionRunnerContext, null);
|
|
1223
1200
|
const initialState = {
|
|
1224
1201
|
actionPath: `?${QACTION_KEY}=${id}`,
|
|
1225
1202
|
submitted: false,
|
|
@@ -1242,7 +1219,7 @@ function routeActionQrl(actionQrl, ...rest) {
|
|
|
1242
1219
|
return initialState;
|
|
1243
1220
|
});
|
|
1244
1221
|
initialState.submit = /* @__PURE__ */ inlinedQrl((input = {}) => {
|
|
1245
|
-
let currentAction = _capturesObj._[0], id = _capturesObj._[1], latestSubmission = _capturesObj._[2], loc = _capturesObj._[3],
|
|
1222
|
+
let currentAction = _capturesObj._[0], id = _capturesObj._[1], latestSubmission = _capturesObj._[2], loc = _capturesObj._[3], runAction = _capturesObj._[4], state = _capturesObj._[5];
|
|
1246
1223
|
if (isServer) throw new Error(`Actions can not be invoked within the server during SSR.
|
|
1247
1224
|
Action.run() can only be called on the browser, for example when a user clicks a button, or submits a form.`);
|
|
1248
1225
|
let data;
|
|
@@ -1272,6 +1249,7 @@ Action.run() can only be called on the browser, for example when a user clicks a
|
|
|
1272
1249
|
resolve: noSerialize(resolve),
|
|
1273
1250
|
resolveDispatch: noSerialize(resolveDispatch)
|
|
1274
1251
|
};
|
|
1252
|
+
runAction?.(RUN_PENDING_ACTION);
|
|
1275
1253
|
})).then(({ result, status }) => {
|
|
1276
1254
|
const isLatestSubmission = latestSubmission.current === submission;
|
|
1277
1255
|
if (isLatestSubmission) {
|
|
@@ -1302,6 +1280,7 @@ Action.run() can only be called on the browser, for example when a user clicks a
|
|
|
1302
1280
|
id,
|
|
1303
1281
|
{ current: void 0 },
|
|
1304
1282
|
loc,
|
|
1283
|
+
runAction,
|
|
1305
1284
|
state
|
|
1306
1285
|
]);
|
|
1307
1286
|
return state;
|
|
@@ -1580,8 +1559,8 @@ var ServiceWorkerRegister = (props) => /*#__PURE__*/ _jsxSorted("script", {
|
|
|
1580
1559
|
dangerouslySetInnerHTML: _getServiceWorkerScript(_getServiceWorkerUrl()),
|
|
1581
1560
|
nonce: _wrapProp(props, "nonce")
|
|
1582
1561
|
}, { type: "module" }, null, 3, "UM_0");
|
|
1583
|
-
var _hf0 = (p0) => p0.spaReset ? "true" : void 0;
|
|
1584
|
-
var _hf0_str = "p0.spaReset?\"true\":undefined";
|
|
1562
|
+
var _hf0$1 = (p0) => p0.spaReset ? "true" : void 0;
|
|
1563
|
+
var _hf0_str$1 = "p0.spaReset?\"true\":undefined";
|
|
1585
1564
|
/** @public */
|
|
1586
1565
|
var Form = ({ action, spaReset, reloadDocument, onSubmit$, ...rest }, key) => {
|
|
1587
1566
|
if (action) {
|
|
@@ -1604,13 +1583,11 @@ var Form = ({ action, spaReset, reloadDocument, onSubmit$, ...rest }, key) => {
|
|
|
1604
1583
|
"q-e:submit": [onSubmit$, !reloadDocument ? action.submit : void 0],
|
|
1605
1584
|
["data-spa-reset"]: spaReset ? "true" : void 0
|
|
1606
1585
|
}, { method: "post" }, null, 0, key);
|
|
1607
|
-
} else return /*#__PURE__*/
|
|
1608
|
-
...rest,
|
|
1586
|
+
} else return /*#__PURE__*/ _jsxSplit(GetForm, {
|
|
1609
1587
|
spaReset,
|
|
1610
1588
|
reloadDocument,
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
});
|
|
1589
|
+
...rest
|
|
1590
|
+
}, { onSubmit$ }, null, 0, key);
|
|
1614
1591
|
};
|
|
1615
1592
|
var GetForm = /*#__PURE__*/ componentQrl(/*#__PURE__*/ inlinedQrl((_rawProps) => {
|
|
1616
1593
|
const rest = _restProps(_rawProps, [
|
|
@@ -1622,7 +1599,7 @@ var GetForm = /*#__PURE__*/ componentQrl(/*#__PURE__*/ inlinedQrl((_rawProps) =>
|
|
|
1622
1599
|
const nav = useNavigate();
|
|
1623
1600
|
return /*#__PURE__*/ _jsxSplit("form", {
|
|
1624
1601
|
action: "get",
|
|
1625
|
-
"data-spa-reset": _fnSignal(_hf0, [_rawProps], _hf0_str),
|
|
1602
|
+
"data-spa-reset": _fnSignal(_hf0$1, [_rawProps], _hf0_str$1),
|
|
1626
1603
|
..._getVarProps(rest),
|
|
1627
1604
|
"q-e:submit": [
|
|
1628
1605
|
...Array.isArray(_rawProps.onSubmit$) ? _rawProps.onSubmit$ : [_rawProps.onSubmit$],
|
|
@@ -1729,6 +1706,12 @@ var createRenderer = (getOptions) => {
|
|
|
1729
1706
|
return renderToStream(jsx, renderOptions);
|
|
1730
1707
|
});
|
|
1731
1708
|
};
|
|
1709
|
+
var _hf0 = (p0, p1) => p1 || p0.dangerouslySetInnerHTML;
|
|
1710
|
+
var _hf0_str = "p1||p0.dangerouslySetInnerHTML";
|
|
1711
|
+
var trackWholeStore = (store) => {
|
|
1712
|
+
Object.keys(store);
|
|
1713
|
+
return untrack(() => ({ ...store }));
|
|
1714
|
+
};
|
|
1732
1715
|
/**
|
|
1733
1716
|
* This renders all the tags collected from `head`.
|
|
1734
1717
|
*
|
|
@@ -1752,30 +1735,35 @@ var createRenderer = (getOptions) => {
|
|
|
1752
1735
|
* @public
|
|
1753
1736
|
*/
|
|
1754
1737
|
var DocumentHeadTags = /*#__PURE__*/ componentQrl(/*#__PURE__*/ inlinedQrl((props) => {
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1738
|
+
const documentHead = trackWholeStore(useDocumentHead());
|
|
1739
|
+
const head = {
|
|
1740
|
+
title: props.title ?? documentHead.title,
|
|
1741
|
+
meta: props.meta ?? documentHead.meta,
|
|
1742
|
+
links: props.links ?? documentHead.links,
|
|
1743
|
+
styles: props.styles ?? documentHead.styles,
|
|
1744
|
+
scripts: props.scripts ?? documentHead.scripts
|
|
1759
1745
|
};
|
|
1760
1746
|
return /*#__PURE__*/ _jsxSorted(Fragment, null, null, [
|
|
1761
1747
|
head.title && /*#__PURE__*/ _jsxSorted("title", null, null, head.title, 1, "eL_0"),
|
|
1762
1748
|
head.meta.map((m) => /*#__PURE__*/ _jsxSplit("meta", { ..._getVarProps(m) }, _getConstProps(m), null, 0, "eL_1")),
|
|
1763
1749
|
head.links.map((l) => /*#__PURE__*/ _jsxSplit("link", { ..._getVarProps(l) }, _getConstProps(l), null, 0, "eL_2")),
|
|
1764
1750
|
head.styles.map((s) => {
|
|
1765
|
-
const
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1751
|
+
const { style, key, props: oldProps, ...rest } = trackWholeStore(s);
|
|
1752
|
+
const props = oldProps || rest;
|
|
1753
|
+
return /*#__PURE__*/ _jsxSplit("style", {
|
|
1754
|
+
..._getVarProps(props),
|
|
1755
|
+
..._getConstProps(props),
|
|
1756
|
+
dangerouslySetInnerHTML: _fnSignal(_hf0, [props, style], _hf0_str)
|
|
1757
|
+
}, null, null, 0, key);
|
|
1771
1758
|
}),
|
|
1772
1759
|
head.scripts.map((s) => {
|
|
1773
|
-
const
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1760
|
+
const { script, key, props: oldProps, ...rest } = trackWholeStore(s);
|
|
1761
|
+
const props = oldProps || rest;
|
|
1762
|
+
return /*#__PURE__*/ _jsxSplit("script", {
|
|
1763
|
+
..._getVarProps(props),
|
|
1764
|
+
..._getConstProps(props),
|
|
1765
|
+
dangerouslySetInnerHTML: _fnSignal(_hf0, [props, script], _hf0_str)
|
|
1766
|
+
}, null, null, 0, key);
|
|
1779
1767
|
})
|
|
1780
1768
|
], 1, "eL_3");
|
|
1781
1769
|
}, "DocumentHeadTags_component_9CrWYOoCpgY"));
|