@qwik.dev/router 2.0.0-beta.11 → 2.0.0-beta.14
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/azure-swa/vite/index.mjs +28 -207
- package/lib/adapters/bun-server/vite/index.mjs +16 -202
- package/lib/adapters/cloud-run/vite/index.mjs +15 -201
- package/lib/adapters/cloudflare-pages/vite/index.mjs +65 -6
- package/lib/adapters/deno-server/vite/index.mjs +18 -204
- package/lib/adapters/netlify-edge/vite/index.mjs +58 -246
- package/lib/adapters/node-server/vite/index.mjs +16 -202
- package/lib/adapters/shared/vite/index.d.ts +4 -4
- package/lib/adapters/shared/vite/index.mjs +250 -149
- package/lib/adapters/ssg/vite/index.mjs +12 -199
- package/lib/adapters/vercel-edge/vite/index.d.ts +1 -1
- package/lib/adapters/vercel-edge/vite/index.mjs +50 -235
- package/lib/chunks/error-handler.mjs +57 -0
- package/lib/chunks/format-error.mjs +137 -0
- package/lib/chunks/fs.mjs +254 -0
- package/lib/chunks/index.mjs +884 -0
- package/lib/chunks/mime-types.mjs +52 -0
- package/lib/chunks/routing.qwik.mjs +429 -0
- package/lib/chunks/types.qwik.mjs +22 -0
- package/lib/index.d.ts +11 -4
- package/lib/index.qwik.mjs +533 -1019
- package/lib/middleware/aws-lambda/index.mjs +38 -28
- package/lib/middleware/azure-swa/index.mjs +65 -48
- package/lib/middleware/bun/index.mjs +104 -119
- package/lib/middleware/cloudflare-pages/index.mjs +69 -49
- package/lib/middleware/deno/index.mjs +94 -114
- package/lib/middleware/firebase/index.mjs +26 -18
- package/lib/middleware/netlify-edge/index.mjs +53 -38
- package/lib/middleware/node/index.mjs +184 -167
- package/lib/middleware/request-handler/index.d.ts +22 -4
- package/lib/middleware/request-handler/index.mjs +1203 -877
- package/lib/middleware/vercel-edge/index.mjs +72 -49
- package/lib/service-worker/index.mjs +4 -0
- package/lib/ssg/index.mjs +14 -22
- package/lib/vite/index.d.ts +13 -7
- package/lib/vite/index.mjs +1609 -1217
- package/package.json +27 -44
- package/lib/adapters/azure-swa/vite/index-BqUeglYs.cjs +0 -1
- package/lib/adapters/azure-swa/vite/index-CBIchDYq.js +0 -651
- package/lib/adapters/azure-swa/vite/index-ClHGw5z1.js +0 -6
- package/lib/adapters/azure-swa/vite/index-CrwlB95_.js +0 -22
- package/lib/adapters/azure-swa/vite/index-DTIOTwZo.cjs +0 -11
- package/lib/adapters/azure-swa/vite/index-vQuPcef3.cjs +0 -1
- package/lib/adapters/azure-swa/vite/index.cjs +0 -5
- package/lib/adapters/bun-server/vite/index-BqUeglYs.cjs +0 -1
- package/lib/adapters/bun-server/vite/index-CBIchDYq.js +0 -651
- package/lib/adapters/bun-server/vite/index-ClHGw5z1.js +0 -6
- package/lib/adapters/bun-server/vite/index-CrwlB95_.js +0 -22
- package/lib/adapters/bun-server/vite/index-DTIOTwZo.cjs +0 -11
- package/lib/adapters/bun-server/vite/index-vQuPcef3.cjs +0 -1
- package/lib/adapters/bun-server/vite/index.cjs +0 -5
- package/lib/adapters/cloud-run/vite/index-BqUeglYs.cjs +0 -1
- package/lib/adapters/cloud-run/vite/index-CBIchDYq.js +0 -651
- package/lib/adapters/cloud-run/vite/index-ClHGw5z1.js +0 -6
- package/lib/adapters/cloud-run/vite/index-CrwlB95_.js +0 -22
- package/lib/adapters/cloud-run/vite/index-DTIOTwZo.cjs +0 -11
- package/lib/adapters/cloud-run/vite/index-vQuPcef3.cjs +0 -1
- package/lib/adapters/cloud-run/vite/index.cjs +0 -5
- package/lib/adapters/cloudflare-pages/vite/index-Bg_9YkM5.js +0 -22
- package/lib/adapters/cloudflare-pages/vite/index-C1aDmh1S.cjs +0 -1
- package/lib/adapters/cloudflare-pages/vite/index-CHT9Y93A.js +0 -254
- package/lib/adapters/cloudflare-pages/vite/index-Ck7KvpK1.cjs +0 -11
- package/lib/adapters/cloudflare-pages/vite/index-ClHGw5z1.js +0 -6
- package/lib/adapters/cloudflare-pages/vite/index-Cp1cjAds.js +0 -645
- package/lib/adapters/cloudflare-pages/vite/index-D9RL9dvJ.cjs +0 -5
- package/lib/adapters/cloudflare-pages/vite/index-vQuPcef3.cjs +0 -1
- package/lib/adapters/cloudflare-pages/vite/index.cjs +0 -1
- package/lib/adapters/deno-server/vite/index-BqUeglYs.cjs +0 -1
- package/lib/adapters/deno-server/vite/index-CBIchDYq.js +0 -651
- package/lib/adapters/deno-server/vite/index-ClHGw5z1.js +0 -6
- package/lib/adapters/deno-server/vite/index-CrwlB95_.js +0 -22
- package/lib/adapters/deno-server/vite/index-DTIOTwZo.cjs +0 -11
- package/lib/adapters/deno-server/vite/index-vQuPcef3.cjs +0 -1
- package/lib/adapters/deno-server/vite/index.cjs +0 -5
- package/lib/adapters/netlify-edge/vite/index-BqUeglYs.cjs +0 -1
- package/lib/adapters/netlify-edge/vite/index-CBIchDYq.js +0 -651
- package/lib/adapters/netlify-edge/vite/index-ClHGw5z1.js +0 -6
- package/lib/adapters/netlify-edge/vite/index-CrwlB95_.js +0 -22
- package/lib/adapters/netlify-edge/vite/index-DTIOTwZo.cjs +0 -11
- package/lib/adapters/netlify-edge/vite/index-vQuPcef3.cjs +0 -1
- package/lib/adapters/netlify-edge/vite/index.cjs +0 -6
- package/lib/adapters/node-server/vite/index-BqUeglYs.cjs +0 -1
- package/lib/adapters/node-server/vite/index-CBIchDYq.js +0 -651
- package/lib/adapters/node-server/vite/index-ClHGw5z1.js +0 -6
- package/lib/adapters/node-server/vite/index-CrwlB95_.js +0 -22
- package/lib/adapters/node-server/vite/index-DTIOTwZo.cjs +0 -11
- package/lib/adapters/node-server/vite/index-vQuPcef3.cjs +0 -1
- package/lib/adapters/node-server/vite/index.cjs +0 -5
- package/lib/adapters/shared/vite/index-BqUeglYs.cjs +0 -1
- package/lib/adapters/shared/vite/index-CBIchDYq.js +0 -651
- package/lib/adapters/shared/vite/index-ClHGw5z1.js +0 -6
- package/lib/adapters/shared/vite/index-CrwlB95_.js +0 -22
- package/lib/adapters/shared/vite/index-DTIOTwZo.cjs +0 -11
- package/lib/adapters/shared/vite/index-vQuPcef3.cjs +0 -1
- package/lib/adapters/shared/vite/index.cjs +0 -5
- package/lib/adapters/ssg/vite/index-BqUeglYs.cjs +0 -1
- package/lib/adapters/ssg/vite/index-CBIchDYq.js +0 -651
- package/lib/adapters/ssg/vite/index-ClHGw5z1.js +0 -6
- package/lib/adapters/ssg/vite/index-CrwlB95_.js +0 -22
- package/lib/adapters/ssg/vite/index-DTIOTwZo.cjs +0 -11
- package/lib/adapters/ssg/vite/index-vQuPcef3.cjs +0 -1
- package/lib/adapters/ssg/vite/index.cjs +0 -5
- package/lib/adapters/vercel-edge/vite/index-BqUeglYs.cjs +0 -1
- package/lib/adapters/vercel-edge/vite/index-CBIchDYq.js +0 -651
- package/lib/adapters/vercel-edge/vite/index-ClHGw5z1.js +0 -6
- package/lib/adapters/vercel-edge/vite/index-CrwlB95_.js +0 -22
- package/lib/adapters/vercel-edge/vite/index-DTIOTwZo.cjs +0 -11
- package/lib/adapters/vercel-edge/vite/index-vQuPcef3.cjs +0 -1
- package/lib/adapters/vercel-edge/vite/index.cjs +0 -5
- package/lib/index.qwik.cjs +0 -2126
- package/lib/middleware/aws-lambda/index.cjs +0 -1
- package/lib/middleware/azure-swa/index.cjs +0 -1
- package/lib/middleware/bun/index.cjs +0 -1
- package/lib/middleware/cloudflare-pages/index.cjs +0 -1
- package/lib/middleware/deno/index.cjs +0 -1
- package/lib/middleware/firebase/index.cjs +0 -1
- package/lib/middleware/netlify-edge/index.cjs +0 -1
- package/lib/middleware/node/index.cjs +0 -1
- package/lib/middleware/request-handler/index.cjs +0 -18
- package/lib/middleware/vercel-edge/index.cjs +0 -1
- package/lib/service-worker.cjs +0 -1
- package/lib/service-worker.mjs +0 -5
- package/lib/ssg/deno.cjs +0 -1
- package/lib/ssg/deno.mjs +0 -6
- package/lib/ssg/index-CBIchDYq.js +0 -651
- package/lib/ssg/index-ClHGw5z1.js +0 -6
- package/lib/ssg/index-DTIOTwZo.cjs +0 -11
- package/lib/ssg/index-vQuPcef3.cjs +0 -1
- package/lib/ssg/index.cjs +0 -1
- package/lib/ssg/node.cjs +0 -11
- package/lib/ssg/node.mjs +0 -651
- package/lib/vite/index.cjs +0 -42
package/lib/index.qwik.mjs
CHANGED
|
@@ -1,237 +1,31 @@
|
|
|
1
|
-
import { jsx, Fragment, jsxs } from
|
|
2
|
-
import { component$, useErrorBoundary, useOnWindow, $, Slot,
|
|
3
|
-
import { p } from
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
|
|
1
|
+
import { jsx, Fragment, jsxs } from '@qwik.dev/core/jsx-runtime';
|
|
2
|
+
import { component$, useErrorBoundary, useOnWindow, $, Slot, createContextId, useContext, implicit$FirstArg, noSerialize, useVisibleTask$, useServerData, useSignal, untrack, sync$, isDev, withLocale, event$, isServer, useStyles$, useStore, isBrowser, useContextProvider, useTask$, getLocale, jsx as jsx$1, SkipRender, createElement } from '@qwik.dev/core';
|
|
3
|
+
import { g as getClientNavPath, s as shouldPreload, p as preloadRouteBundles, l as loadClientData, i as isPromise, a as isSamePath, c as createLoaderSignal, t as toUrl, b as isSameOrigin, d as loadRoute, D as DEFAULT_LOADERS_SERIALIZATION_STRATEGY, C as CLIENT_DATA_CACHE, Q as Q_ROUTE, e as clientNavigate, f as deepFreeze, h as QFN_KEY, j as QACTION_KEY, k as QDATA_KEY } from './chunks/routing.qwik.mjs';
|
|
4
|
+
import * as qwikRouterConfig from '@qwik-router-config';
|
|
5
|
+
import { _getContextContainer, SerializerSymbol, _UNINITIALIZED, _getContextElement, _hasStoreEffects, _getQContainerElement, forceStoreEffects, _waitUntilRendered, _getContextEvent, _serialize, _deserialize, _resolveContextWithoutSequentialScope } from '@qwik.dev/core/internal';
|
|
6
|
+
import { _asyncRequestStore } from '@qwik.dev/router/middleware/request-handler';
|
|
7
|
+
import * as v from 'valibot';
|
|
8
|
+
import * as z from 'zod';
|
|
9
|
+
export { z } from 'zod';
|
|
10
|
+
import swRegister from '@qwik-router-sw-register';
|
|
11
|
+
import { renderToStream } from '@qwik.dev/core/server';
|
|
12
|
+
import '@qwik.dev/core/preloader';
|
|
13
|
+
import './chunks/types.qwik.mjs';
|
|
14
|
+
|
|
10
15
|
const ErrorBoundary = component$((props) => {
|
|
11
|
-
const
|
|
12
|
-
useOnWindow(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
const store = useErrorBoundary();
|
|
17
|
+
useOnWindow(
|
|
18
|
+
"qerror",
|
|
19
|
+
$((e) => {
|
|
20
|
+
store.error = e.detail.error;
|
|
21
|
+
})
|
|
22
|
+
);
|
|
23
|
+
if (store.error && props.fallback$) {
|
|
24
|
+
return /* @__PURE__ */ jsx(Fragment, { children: props.fallback$(store.error) });
|
|
19
25
|
}
|
|
20
26
|
return /* @__PURE__ */ jsx(Slot, {});
|
|
21
27
|
});
|
|
22
|
-
|
|
23
|
-
const CLIENT_DATA_CACHE = /* @__PURE__ */ new Map();
|
|
24
|
-
const QACTION_KEY = "qaction";
|
|
25
|
-
const QLOADER_KEY = "qloaders";
|
|
26
|
-
const QFN_KEY = "qfunc";
|
|
27
|
-
const QDATA_KEY = "qdata";
|
|
28
|
-
const Q_ROUTE = "q:route";
|
|
29
|
-
const DEFAULT_LOADERS_SERIALIZATION_STRATEGY = globalThis.__DEFAULT_LOADERS_SERIALIZATION_STRATEGY__ || "never";
|
|
30
|
-
const MAX_Q_DATA_RETRY_COUNT = 3;
|
|
31
|
-
const loadClientData = async (url, element, opts, retryCount = 0) => {
|
|
32
|
-
const pagePathname = url.pathname;
|
|
33
|
-
const pageSearch = url.search;
|
|
34
|
-
const clientDataPath = getClientDataPath(pagePathname, pageSearch, {
|
|
35
|
-
actionId: opts?.action?.id,
|
|
36
|
-
loaderIds: opts?.loaderIds
|
|
37
|
-
});
|
|
38
|
-
let qData;
|
|
39
|
-
if (!opts?.action) {
|
|
40
|
-
qData = CLIENT_DATA_CACHE.get(clientDataPath);
|
|
41
|
-
}
|
|
42
|
-
if (opts?.preloadRouteBundles !== false) {
|
|
43
|
-
preloadRouteBundles(pagePathname, 0.8);
|
|
44
|
-
}
|
|
45
|
-
let resolveFn;
|
|
46
|
-
if (!qData) {
|
|
47
|
-
const fetchOptions = getFetchOptions(opts?.action, opts?.clearCache);
|
|
48
|
-
if (opts?.action) {
|
|
49
|
-
opts.action.data = void 0;
|
|
50
|
-
}
|
|
51
|
-
qData = fetch(clientDataPath, fetchOptions).then((rsp) => {
|
|
52
|
-
if (rsp.status === 404 && opts?.loaderIds && retryCount < MAX_Q_DATA_RETRY_COUNT) {
|
|
53
|
-
opts.loaderIds = void 0;
|
|
54
|
-
return loadClientData(url, element, opts, retryCount + 1);
|
|
55
|
-
}
|
|
56
|
-
if (rsp.redirected) {
|
|
57
|
-
const redirectedURL = new URL(rsp.url);
|
|
58
|
-
const isQData = redirectedURL.pathname.endsWith("/q-data.json");
|
|
59
|
-
if (!isQData || redirectedURL.origin !== location.origin) {
|
|
60
|
-
if (!opts?.isPrefetch) {
|
|
61
|
-
location.href = redirectedURL.href;
|
|
62
|
-
}
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if ((rsp.headers.get("content-type") || "").includes("json")) {
|
|
67
|
-
return rsp.text().then((text) => {
|
|
68
|
-
const [clientData] = _deserialize(text, element);
|
|
69
|
-
if (!clientData) {
|
|
70
|
-
location.href = url.href;
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
if (opts?.clearCache) {
|
|
74
|
-
CLIENT_DATA_CACHE.delete(clientDataPath);
|
|
75
|
-
}
|
|
76
|
-
if (clientData.redirect) {
|
|
77
|
-
location.href = clientData.redirect;
|
|
78
|
-
} else if (opts?.action) {
|
|
79
|
-
const { action } = opts;
|
|
80
|
-
const actionData = clientData.loaders[action.id];
|
|
81
|
-
resolveFn = () => {
|
|
82
|
-
action.resolve({
|
|
83
|
-
status: rsp.status,
|
|
84
|
-
result: actionData
|
|
85
|
-
});
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
return clientData;
|
|
89
|
-
});
|
|
90
|
-
} else {
|
|
91
|
-
if (opts?.isPrefetch !== true) {
|
|
92
|
-
location.href = url.href;
|
|
93
|
-
}
|
|
94
|
-
return void 0;
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
if (!opts?.action) {
|
|
98
|
-
CLIENT_DATA_CACHE.set(clientDataPath, qData);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return qData.then((v) => {
|
|
102
|
-
if (!v) {
|
|
103
|
-
CLIENT_DATA_CACHE.delete(clientDataPath);
|
|
104
|
-
}
|
|
105
|
-
resolveFn && resolveFn();
|
|
106
|
-
return v;
|
|
107
|
-
});
|
|
108
|
-
};
|
|
109
|
-
const getFetchOptions = (action, noCache) => {
|
|
110
|
-
const actionData = action?.data;
|
|
111
|
-
if (!actionData) {
|
|
112
|
-
if (noCache) {
|
|
113
|
-
return {
|
|
114
|
-
cache: "no-cache",
|
|
115
|
-
headers: {
|
|
116
|
-
"Cache-Control": "no-cache",
|
|
117
|
-
Pragma: "no-cache"
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
return void 0;
|
|
122
|
-
}
|
|
123
|
-
if (actionData instanceof FormData) {
|
|
124
|
-
return {
|
|
125
|
-
method: "POST",
|
|
126
|
-
body: actionData
|
|
127
|
-
};
|
|
128
|
-
} else {
|
|
129
|
-
return {
|
|
130
|
-
method: "POST",
|
|
131
|
-
body: JSON.stringify(actionData),
|
|
132
|
-
headers: {
|
|
133
|
-
"Content-Type": "application/json; charset=UTF-8"
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
const toPath = (url) => url.pathname + url.search + url.hash;
|
|
139
|
-
const toUrl = (url, baseUrl) => new URL(url, baseUrl.href);
|
|
140
|
-
const isSameOrigin = (a, b) => a.origin === b.origin;
|
|
141
|
-
const withSlash = (path) => path.endsWith("/") ? path : path + "/";
|
|
142
|
-
const isSamePathname = ({ pathname: a }, { pathname: b }) => {
|
|
143
|
-
const lDiff = Math.abs(a.length - b.length);
|
|
144
|
-
return lDiff === 0 ? a === b : lDiff === 1 && withSlash(a) === withSlash(b);
|
|
145
|
-
};
|
|
146
|
-
const isSameSearchQuery = (a, b) => a.search === b.search;
|
|
147
|
-
const isSamePath = (a, b) => isSameSearchQuery(a, b) && isSamePathname(a, b);
|
|
148
|
-
const getClientDataPath = (pathname, pageSearch, options) => {
|
|
149
|
-
let search = pageSearch ?? "";
|
|
150
|
-
if (options?.actionId) {
|
|
151
|
-
search += (search ? "&" : "?") + QACTION_KEY + "=" + encodeURIComponent(options.actionId);
|
|
152
|
-
}
|
|
153
|
-
if (options?.loaderIds) {
|
|
154
|
-
for (const loaderId of options.loaderIds) {
|
|
155
|
-
search += (search ? "&" : "?") + QLOADER_KEY + "=" + encodeURIComponent(loaderId);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return pathname + (pathname.endsWith("/") ? "" : "/") + "q-data.json" + search;
|
|
159
|
-
};
|
|
160
|
-
const getClientNavPath = (props, baseUrl) => {
|
|
161
|
-
const href = props.href;
|
|
162
|
-
if (typeof href === "string" && typeof props.target !== "string" && !props.reload) {
|
|
163
|
-
try {
|
|
164
|
-
const linkUrl = toUrl(href.trim(), baseUrl.url);
|
|
165
|
-
const currentUrl = toUrl("", baseUrl.url);
|
|
166
|
-
if (isSameOrigin(linkUrl, currentUrl)) {
|
|
167
|
-
return toPath(linkUrl);
|
|
168
|
-
}
|
|
169
|
-
} catch (e) {
|
|
170
|
-
console.error(e);
|
|
171
|
-
}
|
|
172
|
-
} else if (props.reload) {
|
|
173
|
-
return toPath(toUrl("", baseUrl.url));
|
|
174
|
-
}
|
|
175
|
-
return null;
|
|
176
|
-
};
|
|
177
|
-
const shouldPreload = (clientNavPath, currentLoc) => {
|
|
178
|
-
if (clientNavPath) {
|
|
179
|
-
const prefetchUrl = toUrl(clientNavPath, currentLoc.url);
|
|
180
|
-
const currentUrl = toUrl("", currentLoc.url);
|
|
181
|
-
return !isSamePathname(prefetchUrl, currentUrl);
|
|
182
|
-
}
|
|
183
|
-
return false;
|
|
184
|
-
};
|
|
185
|
-
const isPromise = (value) => {
|
|
186
|
-
return value && typeof value.then === "function";
|
|
187
|
-
};
|
|
188
|
-
const createLoaderSignal = (loadersObject, loaderId, url, serializationStrategy, container) => {
|
|
189
|
-
return createAsyncComputed$(async () => {
|
|
190
|
-
if (isBrowser && loadersObject[loaderId] === _UNINITIALIZED) {
|
|
191
|
-
const data = await loadClientData(url, void 0, {
|
|
192
|
-
loaderIds: [
|
|
193
|
-
loaderId
|
|
194
|
-
]
|
|
195
|
-
});
|
|
196
|
-
loadersObject[loaderId] = data?.loaders[loaderId] ?? _UNINITIALIZED;
|
|
197
|
-
}
|
|
198
|
-
return loadersObject[loaderId];
|
|
199
|
-
}, {
|
|
200
|
-
container,
|
|
201
|
-
serializationStrategy
|
|
202
|
-
});
|
|
203
|
-
};
|
|
204
|
-
const clientNavigate = (win, navType, fromURL, toURL, replaceState = false) => {
|
|
205
|
-
if (navType !== "popstate") {
|
|
206
|
-
const samePath = isSamePath(fromURL, toURL);
|
|
207
|
-
const sameHash = fromURL.hash === toURL.hash;
|
|
208
|
-
if (!samePath || !sameHash) {
|
|
209
|
-
const newState = {
|
|
210
|
-
_qRouterScroll: newScrollState()
|
|
211
|
-
};
|
|
212
|
-
if (replaceState) {
|
|
213
|
-
win.history.replaceState(newState, "", toPath(toURL));
|
|
214
|
-
} else {
|
|
215
|
-
win.history.pushState(newState, "", toPath(toURL));
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
};
|
|
220
|
-
const newScrollState = () => {
|
|
221
|
-
return {
|
|
222
|
-
x: 0,
|
|
223
|
-
y: 0,
|
|
224
|
-
w: 0,
|
|
225
|
-
h: 0
|
|
226
|
-
};
|
|
227
|
-
};
|
|
228
|
-
const preloadRouteBundles = (path, probability = 0.8) => {
|
|
229
|
-
if (isBrowser) {
|
|
230
|
-
path = path.endsWith("/") ? path : path + "/";
|
|
231
|
-
path = path.length > 1 && path.startsWith("/") ? path.slice(1) : path;
|
|
232
|
-
p(path, probability);
|
|
233
|
-
}
|
|
234
|
-
};
|
|
28
|
+
|
|
235
29
|
const RouteStateContext = /* @__PURE__ */ createContextId("qc-s");
|
|
236
30
|
const ContentContext = /* @__PURE__ */ createContextId("qc-c");
|
|
237
31
|
const ContentInternalContext = /* @__PURE__ */ createContextId("qc-ic");
|
|
@@ -239,15 +33,17 @@ const DocumentHeadContext = /* @__PURE__ */ createContextId("qc-h");
|
|
|
239
33
|
const RouteLocationContext = /* @__PURE__ */ createContextId("qc-l");
|
|
240
34
|
const RouteNavigateContext = /* @__PURE__ */ createContextId("qc-n");
|
|
241
35
|
const RouteActionContext = /* @__PURE__ */ createContextId("qc-a");
|
|
242
|
-
const RouteInternalContext = /* @__PURE__ */ createContextId("qc-ir");
|
|
243
36
|
const RoutePreventNavigateContext = /* @__PURE__ */ createContextId("qc-p");
|
|
37
|
+
|
|
244
38
|
const useContent = () => useContext(ContentContext);
|
|
245
39
|
const useDocumentHead = () => useContext(DocumentHeadContext);
|
|
246
40
|
const useLocation = () => useContext(RouteLocationContext);
|
|
247
41
|
const useNavigate = () => useContext(RouteNavigateContext);
|
|
248
42
|
const usePreventNavigateQrl = (fn) => {
|
|
249
43
|
if (!__EXPERIMENTAL__.preventNavigate) {
|
|
250
|
-
throw new Error(
|
|
44
|
+
throw new Error(
|
|
45
|
+
'usePreventNavigate$ is experimental and must be enabled with `experimental: ["preventNavigate"]` in the `qwikVite` plugin.'
|
|
46
|
+
);
|
|
251
47
|
}
|
|
252
48
|
const registerPreventNav = useContext(RoutePreventNavigateContext);
|
|
253
49
|
useVisibleTask$(() => registerPreventNav(fn));
|
|
@@ -255,19 +51,28 @@ const usePreventNavigateQrl = (fn) => {
|
|
|
255
51
|
const usePreventNavigate$ = implicit$FirstArg(usePreventNavigateQrl);
|
|
256
52
|
const useAction = () => useContext(RouteActionContext);
|
|
257
53
|
const useQwikRouterEnv = () => noSerialize(useServerData("qwikrouter"));
|
|
54
|
+
|
|
258
55
|
const Link = component$((props) => {
|
|
259
56
|
const nav = useNavigate();
|
|
260
57
|
const loc = useLocation();
|
|
261
58
|
const originalHref = props.href;
|
|
262
59
|
const anchorRef = useSignal();
|
|
263
|
-
const {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
reload
|
|
267
|
-
|
|
60
|
+
const {
|
|
61
|
+
onClick$,
|
|
62
|
+
prefetch: prefetchProp,
|
|
63
|
+
reload,
|
|
64
|
+
replaceState,
|
|
65
|
+
scroll,
|
|
66
|
+
...linkProps
|
|
67
|
+
} = /* @__PURE__ */ (() => props)();
|
|
68
|
+
const clientNavPath = untrack(() => getClientNavPath({ ...linkProps, reload }, loc));
|
|
268
69
|
linkProps.href = clientNavPath || originalHref;
|
|
269
|
-
const prefetchData = untrack(
|
|
270
|
-
|
|
70
|
+
const prefetchData = untrack(
|
|
71
|
+
() => !!clientNavPath && prefetchProp !== false && prefetchProp !== "js" || void 0
|
|
72
|
+
);
|
|
73
|
+
const prefetch = untrack(
|
|
74
|
+
() => prefetchData || !!clientNavPath && prefetchProp !== false && shouldPreload(clientNavPath, loc)
|
|
75
|
+
);
|
|
271
76
|
const handlePrefetch = prefetch ? $((_, elm) => {
|
|
272
77
|
if (navigator.connection?.saveData) {
|
|
273
78
|
return;
|
|
@@ -292,11 +97,7 @@ const Link = component$((props) => {
|
|
|
292
97
|
if (event.defaultPrevented) {
|
|
293
98
|
if (elm.href) {
|
|
294
99
|
elm.setAttribute("aria-pressed", "true");
|
|
295
|
-
nav(elm.href, {
|
|
296
|
-
forceReload: reload,
|
|
297
|
-
replaceState,
|
|
298
|
-
scroll
|
|
299
|
-
}).then(() => {
|
|
100
|
+
nav(elm.href, { forceReload: reload, replaceState, scroll }).then(() => {
|
|
300
101
|
elm.removeAttribute("aria-pressed");
|
|
301
102
|
});
|
|
302
103
|
}
|
|
@@ -312,7 +113,9 @@ const Link = component$((props) => {
|
|
|
312
113
|
if (handler) {
|
|
313
114
|
const event = new CustomEvent("qvisible");
|
|
314
115
|
if (Array.isArray(handler)) {
|
|
315
|
-
handler.flat(10).forEach(
|
|
116
|
+
handler.flat(10).forEach(
|
|
117
|
+
(handler2) => handler2?.(event, anchorRef.value)
|
|
118
|
+
);
|
|
316
119
|
} else {
|
|
317
120
|
handler?.(event, anchorRef.value);
|
|
318
121
|
}
|
|
@@ -321,37 +124,37 @@ const Link = component$((props) => {
|
|
|
321
124
|
handlePrefetch?.(void 0, anchorRef.value);
|
|
322
125
|
}
|
|
323
126
|
});
|
|
324
|
-
return /* @__PURE__ */ jsx(
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
onQVisible$: [],
|
|
345
|
-
children: /* @__PURE__ */ jsx(Slot, {})
|
|
346
|
-
});
|
|
127
|
+
return /* @__PURE__ */ jsx(
|
|
128
|
+
"a",
|
|
129
|
+
{
|
|
130
|
+
ref: anchorRef,
|
|
131
|
+
...{ "q:link": !!clientNavPath },
|
|
132
|
+
...linkProps,
|
|
133
|
+
onClick$: [
|
|
134
|
+
preventDefault,
|
|
135
|
+
handlePreload,
|
|
136
|
+
// needs to be in between preventDefault and onClick$ to ensure it starts asap.
|
|
137
|
+
onClick$,
|
|
138
|
+
handleClientSideNavigation
|
|
139
|
+
],
|
|
140
|
+
"data-prefetch": prefetchData,
|
|
141
|
+
onMouseOver$: [linkProps.onMouseOver$, handlePrefetch],
|
|
142
|
+
onFocus$: [linkProps.onFocus$, handlePrefetch],
|
|
143
|
+
onQVisible$: [],
|
|
144
|
+
children: /* @__PURE__ */ jsx(Slot, {})
|
|
145
|
+
}
|
|
146
|
+
);
|
|
347
147
|
});
|
|
348
|
-
|
|
148
|
+
|
|
149
|
+
const resolveHead = (endpoint, routeLocation, contentModules, locale, defaults) => withLocale(locale, () => {
|
|
349
150
|
const head = createDocumentHead(defaults);
|
|
350
|
-
const getData = (loaderOrAction) => {
|
|
151
|
+
const getData = ((loaderOrAction) => {
|
|
351
152
|
const id = loaderOrAction.__id;
|
|
352
153
|
if (loaderOrAction.__brand === "server_loader") {
|
|
353
154
|
if (!(id in endpoint.loaders)) {
|
|
354
|
-
throw new Error(
|
|
155
|
+
throw new Error(
|
|
156
|
+
"You can not get the returned data of a loader that has not been executed for this request."
|
|
157
|
+
);
|
|
355
158
|
}
|
|
356
159
|
}
|
|
357
160
|
const data = endpoint.loaders[id];
|
|
@@ -359,7 +162,7 @@ const resolveHead = (endpoint, routeLocation, contentModules, locale, defaults)
|
|
|
359
162
|
throw new Error("Loaders returning a promise can not be resolved for the head function.");
|
|
360
163
|
}
|
|
361
164
|
return data;
|
|
362
|
-
};
|
|
165
|
+
});
|
|
363
166
|
const fns = [];
|
|
364
167
|
for (const contentModule of contentModules) {
|
|
365
168
|
const contentModuleHead = contentModule?.head;
|
|
@@ -374,18 +177,16 @@ const resolveHead = (endpoint, routeLocation, contentModules, locale, defaults)
|
|
|
374
177
|
if (fns.length) {
|
|
375
178
|
const headProps = {
|
|
376
179
|
head,
|
|
377
|
-
withLocale: (fn) =>
|
|
180
|
+
withLocale: (fn) => fn(),
|
|
378
181
|
resolveValue: getData,
|
|
379
182
|
...routeLocation
|
|
380
183
|
};
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
}
|
|
385
|
-
});
|
|
184
|
+
for (const fn of fns) {
|
|
185
|
+
resolveDocumentHead(head, fn(headProps));
|
|
186
|
+
}
|
|
386
187
|
}
|
|
387
188
|
return head;
|
|
388
|
-
};
|
|
189
|
+
});
|
|
389
190
|
const resolveDocumentHead = (resolvedHead, updatedHead) => {
|
|
390
191
|
if (typeof updatedHead.title === "string") {
|
|
391
192
|
resolvedHead.title = updatedHead.title;
|
|
@@ -412,244 +213,35 @@ const mergeArray = (existingArr, newArr) => {
|
|
|
412
213
|
};
|
|
413
214
|
const createDocumentHead = (defaults) => ({
|
|
414
215
|
title: defaults?.title || "",
|
|
415
|
-
meta: [
|
|
416
|
-
|
|
417
|
-
],
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
],
|
|
421
|
-
styles: [
|
|
422
|
-
...defaults?.styles || []
|
|
423
|
-
],
|
|
424
|
-
scripts: [
|
|
425
|
-
...defaults?.scripts || []
|
|
426
|
-
],
|
|
427
|
-
frontmatter: {
|
|
428
|
-
...defaults?.frontmatter
|
|
429
|
-
}
|
|
216
|
+
meta: [...defaults?.meta || []],
|
|
217
|
+
links: [...defaults?.links || []],
|
|
218
|
+
styles: [...defaults?.styles || []],
|
|
219
|
+
scripts: [...defaults?.scripts || []],
|
|
220
|
+
frontmatter: { ...defaults?.frontmatter }
|
|
430
221
|
});
|
|
431
|
-
|
|
432
|
-
const routeIdx = startIdxSkipSlash(route);
|
|
433
|
-
const routeLength = lengthNoTrailingSlash(route);
|
|
434
|
-
const pathIdx = startIdxSkipSlash(path);
|
|
435
|
-
const pathLength = lengthNoTrailingSlash(path);
|
|
436
|
-
return matchRoutePart(route, routeIdx, routeLength, path, pathIdx, pathLength);
|
|
437
|
-
}
|
|
438
|
-
function matchRoutePart(route, routeIdx, routeLength, path, pathIdx, pathLength) {
|
|
439
|
-
if (path.startsWith("/build/")) {
|
|
440
|
-
return null;
|
|
441
|
-
}
|
|
442
|
-
let params = null;
|
|
443
|
-
while (routeIdx < routeLength) {
|
|
444
|
-
const routeCh = route.charCodeAt(routeIdx++);
|
|
445
|
-
const pathCh = path.charCodeAt(pathIdx++);
|
|
446
|
-
if (routeCh === 91) {
|
|
447
|
-
const isMany = isThreeDots(route, routeIdx);
|
|
448
|
-
const paramNameStart = routeIdx + (isMany ? 3 : 0);
|
|
449
|
-
const paramNameEnd = scan(route, paramNameStart, routeLength, 93);
|
|
450
|
-
const paramName = route.substring(paramNameStart, paramNameEnd);
|
|
451
|
-
const paramSuffixEnd = scan(route, paramNameEnd + 1, routeLength, 47);
|
|
452
|
-
const suffix = route.substring(paramNameEnd + 1, paramSuffixEnd);
|
|
453
|
-
routeIdx = paramNameEnd + 1;
|
|
454
|
-
const paramValueStart = pathIdx - 1;
|
|
455
|
-
if (isMany) {
|
|
456
|
-
const match = recursiveScan(paramName, suffix, path, paramValueStart, pathLength, route, routeIdx + suffix.length + 1, routeLength);
|
|
457
|
-
if (match) {
|
|
458
|
-
return Object.assign(params || (params = {}), match);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
const paramValueEnd = scan(path, paramValueStart, pathLength, 47, suffix);
|
|
462
|
-
if (paramValueEnd == -1) {
|
|
463
|
-
return null;
|
|
464
|
-
}
|
|
465
|
-
const paramValue = path.substring(paramValueStart, paramValueEnd);
|
|
466
|
-
if (!isMany && !suffix && !paramValue) {
|
|
467
|
-
return null;
|
|
468
|
-
}
|
|
469
|
-
pathIdx = paramValueEnd;
|
|
470
|
-
(params || (params = {}))[paramName] = decodeURIComponent(paramValue);
|
|
471
|
-
} else if (routeCh !== pathCh) {
|
|
472
|
-
if (!(isNaN(pathCh) && isRestParameter(route, routeIdx))) {
|
|
473
|
-
return null;
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
if (allConsumed(route, routeIdx) && allConsumed(path, pathIdx)) {
|
|
478
|
-
return params || {};
|
|
479
|
-
} else {
|
|
480
|
-
return null;
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
function isRestParameter(text, idx) {
|
|
484
|
-
return text.charCodeAt(idx) === 91 && isThreeDots(text, idx + 1);
|
|
485
|
-
}
|
|
486
|
-
function lengthNoTrailingSlash(text) {
|
|
487
|
-
const length = text.length;
|
|
488
|
-
return length > 1 && text.charCodeAt(length - 1) === 47 ? length - 1 : length;
|
|
489
|
-
}
|
|
490
|
-
function allConsumed(text, idx) {
|
|
491
|
-
const length = text.length;
|
|
492
|
-
return idx >= length || idx == length - 1 && text.charCodeAt(idx) === 47;
|
|
493
|
-
}
|
|
494
|
-
function startIdxSkipSlash(text) {
|
|
495
|
-
return text.charCodeAt(0) === 47 ? 1 : 0;
|
|
496
|
-
}
|
|
497
|
-
function isThreeDots(text, idx) {
|
|
498
|
-
return text.charCodeAt(idx) === 46 && text.charCodeAt(idx + 1) === 46 && text.charCodeAt(idx + 2) === 46;
|
|
499
|
-
}
|
|
500
|
-
function scan(text, idx, end, ch, suffix = "") {
|
|
501
|
-
while (idx < end && text.charCodeAt(idx) !== ch) {
|
|
502
|
-
idx++;
|
|
503
|
-
}
|
|
504
|
-
const suffixLength = suffix.length;
|
|
505
|
-
for (let i = 0; i < suffixLength; i++) {
|
|
506
|
-
if (text.charCodeAt(idx - suffixLength + i) !== suffix.charCodeAt(i)) {
|
|
507
|
-
return -1;
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
return idx - suffixLength;
|
|
511
|
-
}
|
|
512
|
-
function recursiveScan(paramName, suffix, path, pathStart, pathLength, route, routeStart, routeLength) {
|
|
513
|
-
if (path.charCodeAt(pathStart) === 47) {
|
|
514
|
-
pathStart++;
|
|
515
|
-
}
|
|
516
|
-
let pathIdx = pathLength;
|
|
517
|
-
const sep = suffix + "/";
|
|
518
|
-
while (pathIdx >= pathStart) {
|
|
519
|
-
const match = matchRoutePart(route, routeStart, routeLength, path, pathIdx, pathLength);
|
|
520
|
-
if (match) {
|
|
521
|
-
let value = path.substring(pathStart, Math.min(pathIdx, pathLength));
|
|
522
|
-
if (value.endsWith(sep)) {
|
|
523
|
-
value = value.substring(0, value.length - sep.length);
|
|
524
|
-
}
|
|
525
|
-
match[paramName] = decodeURIComponent(value);
|
|
526
|
-
return match;
|
|
527
|
-
}
|
|
528
|
-
const newPathIdx = lastIndexOf(path, pathStart, sep, pathIdx, pathStart - 1) + sep.length;
|
|
529
|
-
if (pathIdx === newPathIdx) {
|
|
530
|
-
break;
|
|
531
|
-
}
|
|
532
|
-
pathIdx = newPathIdx;
|
|
533
|
-
}
|
|
534
|
-
return null;
|
|
535
|
-
}
|
|
536
|
-
function lastIndexOf(text, start, match, searchIdx, notFoundIdx) {
|
|
537
|
-
let idx = text.lastIndexOf(match, searchIdx);
|
|
538
|
-
if (idx == searchIdx - match.length) {
|
|
539
|
-
idx = text.lastIndexOf(match, searchIdx - match.length - 1);
|
|
540
|
-
}
|
|
541
|
-
return idx > start ? idx : notFoundIdx;
|
|
542
|
-
}
|
|
543
|
-
var RouteDataProp = /* @__PURE__ */ (function(RouteDataProp2) {
|
|
544
|
-
RouteDataProp2[RouteDataProp2["RouteName"] = 0] = "RouteName";
|
|
545
|
-
RouteDataProp2[RouteDataProp2["Loaders"] = 1] = "Loaders";
|
|
546
|
-
RouteDataProp2[RouteDataProp2["OriginalPathname"] = 2] = "OriginalPathname";
|
|
547
|
-
RouteDataProp2[RouteDataProp2["RouteBundleNames"] = 3] = "RouteBundleNames";
|
|
548
|
-
return RouteDataProp2;
|
|
549
|
-
})({});
|
|
550
|
-
var MenuDataProp = /* @__PURE__ */ (function(MenuDataProp2) {
|
|
551
|
-
MenuDataProp2[MenuDataProp2["Pathname"] = 0] = "Pathname";
|
|
552
|
-
MenuDataProp2[MenuDataProp2["MenuLoader"] = 1] = "MenuLoader";
|
|
553
|
-
return MenuDataProp2;
|
|
554
|
-
})({});
|
|
555
|
-
const deepFreeze = (obj) => {
|
|
556
|
-
if (obj == null) {
|
|
557
|
-
return obj;
|
|
558
|
-
}
|
|
559
|
-
Object.getOwnPropertyNames(obj).forEach((prop) => {
|
|
560
|
-
const value = obj[prop];
|
|
561
|
-
if (value && typeof value === "object" && !Object.isFrozen(value)) {
|
|
562
|
-
deepFreeze(value);
|
|
563
|
-
}
|
|
564
|
-
});
|
|
565
|
-
return Object.freeze(obj);
|
|
566
|
-
};
|
|
567
|
-
const loadRoute = async (routes, menus, cacheModules, pathname, isInternal) => {
|
|
568
|
-
if (!Array.isArray(routes)) {
|
|
569
|
-
return null;
|
|
570
|
-
}
|
|
571
|
-
for (const routeData of routes) {
|
|
572
|
-
const routeName = routeData[RouteDataProp.RouteName];
|
|
573
|
-
const params = matchRoute(routeName, pathname);
|
|
574
|
-
if (!params) {
|
|
575
|
-
continue;
|
|
576
|
-
}
|
|
577
|
-
const loaders = routeData[RouteDataProp.Loaders];
|
|
578
|
-
const routeBundleNames = routeData[RouteDataProp.RouteBundleNames];
|
|
579
|
-
const modules = new Array(loaders.length);
|
|
580
|
-
const pendingLoads = [];
|
|
581
|
-
loaders.forEach((moduleLoader, i) => {
|
|
582
|
-
loadModule(moduleLoader, pendingLoads, (routeModule) => modules[i] = routeModule, cacheModules);
|
|
583
|
-
});
|
|
584
|
-
let menu = void 0;
|
|
585
|
-
{
|
|
586
|
-
const menuLoader = getMenuLoader(menus, pathname);
|
|
587
|
-
loadModule(menuLoader, pendingLoads, (menuModule) => menu = menuModule?.default, cacheModules);
|
|
588
|
-
}
|
|
589
|
-
if (pendingLoads.length > 0) {
|
|
590
|
-
await Promise.all(pendingLoads);
|
|
591
|
-
}
|
|
592
|
-
return [
|
|
593
|
-
routeName,
|
|
594
|
-
params,
|
|
595
|
-
modules,
|
|
596
|
-
deepFreeze(menu),
|
|
597
|
-
routeBundleNames
|
|
598
|
-
];
|
|
599
|
-
}
|
|
600
|
-
return null;
|
|
601
|
-
};
|
|
602
|
-
const loadModule = (moduleLoader, pendingLoads, moduleSetter, cacheModules) => {
|
|
603
|
-
if (typeof moduleLoader === "function") {
|
|
604
|
-
const loadedModule = MODULE_CACHE.get(moduleLoader);
|
|
605
|
-
if (loadedModule) {
|
|
606
|
-
moduleSetter(loadedModule);
|
|
607
|
-
} else {
|
|
608
|
-
const moduleOrPromise = moduleLoader();
|
|
609
|
-
if (typeof moduleOrPromise.then === "function") {
|
|
610
|
-
pendingLoads.push(moduleOrPromise.then((loadedModule2) => {
|
|
611
|
-
if (cacheModules !== false) {
|
|
612
|
-
MODULE_CACHE.set(moduleLoader, loadedModule2);
|
|
613
|
-
}
|
|
614
|
-
moduleSetter(loadedModule2);
|
|
615
|
-
}));
|
|
616
|
-
} else if (moduleOrPromise) {
|
|
617
|
-
moduleSetter(moduleOrPromise);
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
};
|
|
622
|
-
const getMenuLoader = (menus, pathname) => {
|
|
623
|
-
if (menus) {
|
|
624
|
-
pathname = pathname.endsWith("/") ? pathname : pathname + "/";
|
|
625
|
-
const menu = menus.find((m) => m[MenuDataProp.Pathname] === pathname || pathname.startsWith(m[MenuDataProp.Pathname]));
|
|
626
|
-
if (menu) {
|
|
627
|
-
return menu[MenuDataProp.MenuLoader];
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
};
|
|
222
|
+
|
|
631
223
|
function callRestoreScrollOnDocument() {
|
|
632
224
|
if (document.__q_scroll_restore__) {
|
|
633
225
|
document.__q_scroll_restore__();
|
|
634
226
|
document.__q_scroll_restore__ = void 0;
|
|
635
227
|
}
|
|
636
228
|
}
|
|
637
|
-
const restoreScroll = (type,
|
|
229
|
+
const restoreScroll = (type, toUrl, fromUrl, scroller, scrollState) => {
|
|
638
230
|
if (type === "popstate" && scrollState) {
|
|
639
231
|
scroller.scrollTo(scrollState.x, scrollState.y);
|
|
640
232
|
} else if (type === "link" || type === "form") {
|
|
641
|
-
if (!hashScroll(
|
|
233
|
+
if (!hashScroll(toUrl, fromUrl)) {
|
|
642
234
|
scroller.scrollTo(0, 0);
|
|
643
235
|
}
|
|
644
236
|
}
|
|
645
237
|
};
|
|
646
|
-
const hashScroll = (
|
|
647
|
-
const elmId =
|
|
238
|
+
const hashScroll = (toUrl, fromUrl) => {
|
|
239
|
+
const elmId = toUrl.hash.slice(1);
|
|
648
240
|
const elm = elmId && document.getElementById(elmId);
|
|
649
241
|
if (elm) {
|
|
650
242
|
elm.scrollIntoView();
|
|
651
243
|
return true;
|
|
652
|
-
} else if (!elm &&
|
|
244
|
+
} else if (!elm && toUrl.hash && isSamePath(toUrl, fromUrl)) {
|
|
653
245
|
return true;
|
|
654
246
|
}
|
|
655
247
|
return false;
|
|
@@ -671,25 +263,16 @@ const saveScrollHistory = (scrollState) => {
|
|
|
671
263
|
state._qRouterScroll = scrollState;
|
|
672
264
|
history.replaceState(state, "");
|
|
673
265
|
};
|
|
266
|
+
|
|
674
267
|
const spaInit = event$((_, el) => {
|
|
675
|
-
|
|
676
|
-
const spa = "_qRouterSPA";
|
|
677
|
-
const initPopstate = "_qRouterInitPopstate";
|
|
678
|
-
const initAnchors = "_qRouterInitAnchors";
|
|
679
|
-
const initVisibility = "_qRouterInitVisibility";
|
|
680
|
-
const initScroll = "_qRouterInitScroll";
|
|
681
|
-
if (!win[spa] && !win[initPopstate] && !win[initAnchors] && !win[initVisibility] && !win[initScroll]) {
|
|
268
|
+
if (!window._qRouterSPA && !window._qRouterInitPopstate) {
|
|
682
269
|
const currentPath = location.pathname + location.search;
|
|
683
|
-
const historyPatch = "_qRouterHistoryPatch";
|
|
684
|
-
const scrollEnabled = "_qRouterScrollEnabled";
|
|
685
|
-
const debounceTimeout = "_qRouterScrollDebounce";
|
|
686
|
-
const scrollHistory = "_qRouterScroll";
|
|
687
270
|
const checkAndScroll = (scrollState) => {
|
|
688
271
|
if (scrollState) {
|
|
689
|
-
|
|
272
|
+
window.scrollTo(scrollState.x, scrollState.y);
|
|
690
273
|
}
|
|
691
274
|
};
|
|
692
|
-
const
|
|
275
|
+
const currentScrollState = () => {
|
|
693
276
|
const elm = document.documentElement;
|
|
694
277
|
return {
|
|
695
278
|
x: elm.scrollLeft,
|
|
@@ -700,16 +283,16 @@ const spaInit = event$((_, el) => {
|
|
|
700
283
|
};
|
|
701
284
|
const saveScrollState = (scrollState) => {
|
|
702
285
|
const state = history.state || {};
|
|
703
|
-
state
|
|
286
|
+
state._qRouterScroll = scrollState || currentScrollState();
|
|
704
287
|
history.replaceState(state, "");
|
|
705
288
|
};
|
|
706
289
|
saveScrollState();
|
|
707
|
-
|
|
708
|
-
if (
|
|
290
|
+
window._qRouterInitPopstate = () => {
|
|
291
|
+
if (window._qRouterSPA) {
|
|
709
292
|
return;
|
|
710
293
|
}
|
|
711
|
-
|
|
712
|
-
clearTimeout(
|
|
294
|
+
window._qRouterScrollEnabled = false;
|
|
295
|
+
clearTimeout(window._qRouterScrollDebounce);
|
|
713
296
|
if (currentPath !== location.pathname + location.search) {
|
|
714
297
|
const getContainer = (el2) => el2.closest("[q\\:container]:not([q\\:container=html]):not([q\\:container=text])");
|
|
715
298
|
const container = getContainer(el);
|
|
@@ -719,36 +302,34 @@ const spaInit = event$((_, el) => {
|
|
|
719
302
|
id: "qc--n"
|
|
720
303
|
});
|
|
721
304
|
if (nav) {
|
|
722
|
-
nav(location.href, {
|
|
723
|
-
type: "popstate"
|
|
724
|
-
});
|
|
305
|
+
nav(location.href, { type: "popstate" });
|
|
725
306
|
} else {
|
|
726
307
|
location.reload();
|
|
727
308
|
}
|
|
728
309
|
} else {
|
|
729
310
|
if (history.scrollRestoration === "manual") {
|
|
730
|
-
const scrollState = history.state?.
|
|
311
|
+
const scrollState = history.state?._qRouterScroll;
|
|
731
312
|
checkAndScroll(scrollState);
|
|
732
|
-
|
|
313
|
+
window._qRouterScrollEnabled = true;
|
|
733
314
|
}
|
|
734
315
|
}
|
|
735
316
|
};
|
|
736
|
-
if (!
|
|
737
|
-
|
|
317
|
+
if (!window._qRouterHistoryPatch) {
|
|
318
|
+
window._qRouterHistoryPatch = true;
|
|
738
319
|
const pushState = history.pushState;
|
|
739
320
|
const replaceState = history.replaceState;
|
|
740
321
|
const prepareState = (state) => {
|
|
741
322
|
if (state === null || typeof state === "undefined") {
|
|
742
323
|
state = {};
|
|
743
324
|
} else if (state?.constructor !== Object) {
|
|
744
|
-
state = {
|
|
745
|
-
_data: state
|
|
746
|
-
};
|
|
325
|
+
state = { _data: state };
|
|
747
326
|
if (isDev) {
|
|
748
|
-
console.warn(
|
|
327
|
+
console.warn(
|
|
328
|
+
"In a Qwik SPA context, `history.state` is used to store scroll state. Direct calls to `pushState()` and `replaceState()` must supply an actual Object type. We need to be able to automatically attach the scroll state to your state object. A new state object has been created, your data has been moved to: `history.state._data`"
|
|
329
|
+
);
|
|
749
330
|
}
|
|
750
331
|
}
|
|
751
|
-
state._qRouterScroll = state._qRouterScroll ||
|
|
332
|
+
state._qRouterScroll = state._qRouterScroll || currentScrollState();
|
|
752
333
|
return state;
|
|
753
334
|
};
|
|
754
335
|
history.pushState = (state, title, url) => {
|
|
@@ -760,8 +341,8 @@ const spaInit = event$((_, el) => {
|
|
|
760
341
|
return replaceState.call(history, state, title, url);
|
|
761
342
|
};
|
|
762
343
|
}
|
|
763
|
-
|
|
764
|
-
if (
|
|
344
|
+
window._qRouterInitAnchors = (event) => {
|
|
345
|
+
if (window._qRouterSPA || event.defaultPrevented) {
|
|
765
346
|
return;
|
|
766
347
|
}
|
|
767
348
|
const target = event.target.closest("a[href]");
|
|
@@ -780,13 +361,9 @@ const spaInit = event$((_, el) => {
|
|
|
780
361
|
if (dest.href.endsWith("#")) {
|
|
781
362
|
window.scrollTo(0, 0);
|
|
782
363
|
} else {
|
|
783
|
-
|
|
784
|
-
clearTimeout(
|
|
785
|
-
saveScrollState({
|
|
786
|
-
...currentScrollState2(),
|
|
787
|
-
x: 0,
|
|
788
|
-
y: 0
|
|
789
|
-
});
|
|
364
|
+
window._qRouterScrollEnabled = false;
|
|
365
|
+
clearTimeout(window._qRouterScrollDebounce);
|
|
366
|
+
saveScrollState({ ...currentScrollState(), x: 0, y: 0 });
|
|
790
367
|
location.reload();
|
|
791
368
|
}
|
|
792
369
|
} else {
|
|
@@ -799,36 +376,35 @@ const spaInit = event$((_, el) => {
|
|
|
799
376
|
}
|
|
800
377
|
}
|
|
801
378
|
};
|
|
802
|
-
|
|
803
|
-
if (!
|
|
379
|
+
window._qRouterInitVisibility = () => {
|
|
380
|
+
if (!window._qRouterSPA && window._qRouterScrollEnabled && document.visibilityState === "hidden") {
|
|
804
381
|
saveScrollState();
|
|
805
382
|
}
|
|
806
383
|
};
|
|
807
|
-
|
|
808
|
-
if (
|
|
384
|
+
window._qRouterInitScroll = () => {
|
|
385
|
+
if (window._qRouterSPA || !window._qRouterScrollEnabled) {
|
|
809
386
|
return;
|
|
810
387
|
}
|
|
811
|
-
clearTimeout(
|
|
812
|
-
|
|
388
|
+
clearTimeout(window._qRouterScrollDebounce);
|
|
389
|
+
window._qRouterScrollDebounce = setTimeout(() => {
|
|
813
390
|
saveScrollState();
|
|
814
|
-
|
|
391
|
+
window._qRouterScrollDebounce = void 0;
|
|
815
392
|
}, 200);
|
|
816
393
|
};
|
|
817
|
-
|
|
394
|
+
window._qRouterScrollEnabled = true;
|
|
818
395
|
setTimeout(() => {
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
if (!win.navigation) {
|
|
825
|
-
document.addEventListener("visibilitychange", win[initVisibility], {
|
|
396
|
+
window.addEventListener("popstate", window._qRouterInitPopstate);
|
|
397
|
+
window.addEventListener("scroll", window._qRouterInitScroll, { passive: true });
|
|
398
|
+
document.addEventListener("click", window._qRouterInitAnchors);
|
|
399
|
+
if (!window.navigation) {
|
|
400
|
+
document.addEventListener("visibilitychange", window._qRouterInitVisibility, {
|
|
826
401
|
passive: true
|
|
827
402
|
});
|
|
828
403
|
}
|
|
829
404
|
}, 0);
|
|
830
405
|
}
|
|
831
406
|
});
|
|
407
|
+
|
|
832
408
|
const startViewTransition = (params) => {
|
|
833
409
|
if (!params.update) {
|
|
834
410
|
return;
|
|
@@ -840,37 +416,42 @@ const startViewTransition = (params) => {
|
|
|
840
416
|
} catch {
|
|
841
417
|
transition = document.startViewTransition(params.update);
|
|
842
418
|
}
|
|
843
|
-
const event = new CustomEvent("qviewtransition", {
|
|
844
|
-
detail: transition
|
|
845
|
-
});
|
|
419
|
+
const event = new CustomEvent("qviewtransition", { detail: transition });
|
|
846
420
|
document.dispatchEvent(event);
|
|
847
421
|
return transition;
|
|
848
422
|
} else {
|
|
849
423
|
params.update?.();
|
|
850
424
|
}
|
|
851
425
|
};
|
|
852
|
-
|
|
426
|
+
|
|
427
|
+
const transitionCss = "@layer qwik{@supports selector(html:active-view-transition-type(type)){html:active-view-transition-type(qwik-navigation){:root{view-transition-name:none}}}@supports not selector(html:active-view-transition-type(type)){:root{view-transition-name:none}}}";
|
|
428
|
+
|
|
853
429
|
const QWIK_CITY_SCROLLER = "_qCityScroller";
|
|
854
430
|
const QWIK_ROUTER_SCROLLER = "_qRouterScroller";
|
|
855
431
|
const preventNav = {};
|
|
856
|
-
const internalState = {
|
|
857
|
-
navCount: 0
|
|
858
|
-
};
|
|
432
|
+
const internalState = { navCount: 0 };
|
|
859
433
|
const useQwikRouter = (props) => {
|
|
434
|
+
if (!isServer) {
|
|
435
|
+
throw new Error(
|
|
436
|
+
"useQwikRouter can only run during SSR on the server. If you are seeing this, it means you are re-rendering the root of your application. Fix that or use the <QwikRouterProvider> component around the root of your application."
|
|
437
|
+
);
|
|
438
|
+
}
|
|
860
439
|
useStyles$(transitionCss);
|
|
861
440
|
const env = useQwikRouterEnv();
|
|
862
441
|
if (!env?.params) {
|
|
863
|
-
throw new Error(
|
|
442
|
+
throw new Error(
|
|
443
|
+
`Missing Qwik Router Env Data for help visit https://github.com/QwikDev/qwik/issues/6237`
|
|
444
|
+
);
|
|
864
445
|
}
|
|
865
446
|
const urlEnv = useServerData("url");
|
|
866
447
|
if (!urlEnv) {
|
|
867
448
|
throw new Error(`Missing Qwik URL Env Data`);
|
|
868
449
|
}
|
|
869
450
|
const serverHead = useServerData("documentHead");
|
|
870
|
-
if (
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
451
|
+
if (env.ev.originalUrl.pathname !== env.ev.url.pathname && !__EXPERIMENTAL__.enableRequestRewrite) {
|
|
452
|
+
throw new Error(
|
|
453
|
+
`enableRequestRewrite is an experimental feature and is not enabled. Please enable the feature flag by adding \`experimental: ["enableRequestRewrite"]\` to your qwikVite plugin options.`
|
|
454
|
+
);
|
|
874
455
|
}
|
|
875
456
|
const url = new URL(urlEnv);
|
|
876
457
|
const routeLocationTarget = {
|
|
@@ -879,9 +460,7 @@ const useQwikRouter = (props) => {
|
|
|
879
460
|
isNavigating: false,
|
|
880
461
|
prevUrl: void 0
|
|
881
462
|
};
|
|
882
|
-
const routeLocation = useStore(routeLocationTarget, {
|
|
883
|
-
deep: false
|
|
884
|
-
});
|
|
463
|
+
const routeLocation = useStore(routeLocationTarget, { deep: false });
|
|
885
464
|
const navResolver = {};
|
|
886
465
|
const container = _getContextContainer();
|
|
887
466
|
const getSerializationStrategy = (loaderId) => {
|
|
@@ -891,7 +470,13 @@ const useQwikRouter = (props) => {
|
|
|
891
470
|
const loaderState = {};
|
|
892
471
|
for (const [key, value] of Object.entries(env.response.loaders)) {
|
|
893
472
|
loadersObject[key] = value;
|
|
894
|
-
loaderState[key] = createLoaderSignal(
|
|
473
|
+
loaderState[key] = createLoaderSignal(
|
|
474
|
+
loadersObject,
|
|
475
|
+
key,
|
|
476
|
+
url,
|
|
477
|
+
getSerializationStrategy(key),
|
|
478
|
+
container
|
|
479
|
+
);
|
|
895
480
|
}
|
|
896
481
|
loadersObject[SerializerSymbol] = (obj) => {
|
|
897
482
|
const loadersSerializationObject = {};
|
|
@@ -903,11 +488,11 @@ const useQwikRouter = (props) => {
|
|
|
903
488
|
const routeInternal = useSignal({
|
|
904
489
|
type: "initial",
|
|
905
490
|
dest: url,
|
|
906
|
-
forceReload: false,
|
|
907
|
-
replaceState: false,
|
|
908
491
|
scroll: true
|
|
909
492
|
});
|
|
910
|
-
const documentHead = useStore(
|
|
493
|
+
const documentHead = useStore(
|
|
494
|
+
() => createDocumentHead(serverHead)
|
|
495
|
+
);
|
|
911
496
|
const content = useStore({
|
|
912
497
|
headings: void 0,
|
|
913
498
|
menu: void 0
|
|
@@ -915,32 +500,34 @@ const useQwikRouter = (props) => {
|
|
|
915
500
|
const contentInternal = useSignal();
|
|
916
501
|
const currentActionId = env.response.action;
|
|
917
502
|
const currentAction = currentActionId ? env.response.loaders[currentActionId] : void 0;
|
|
918
|
-
const actionState = useSignal(
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
503
|
+
const actionState = useSignal(
|
|
504
|
+
currentAction ? {
|
|
505
|
+
id: currentActionId,
|
|
506
|
+
data: env.response.formData,
|
|
507
|
+
output: {
|
|
508
|
+
result: currentAction,
|
|
509
|
+
status: env.response.status
|
|
510
|
+
}
|
|
511
|
+
} : void 0
|
|
512
|
+
);
|
|
926
513
|
const registerPreventNav = $((fn$) => {
|
|
927
514
|
if (!isBrowser) {
|
|
928
515
|
return;
|
|
929
516
|
}
|
|
930
|
-
preventNav.$handler$
|
|
517
|
+
preventNav.$handler$ ||= (event) => {
|
|
931
518
|
internalState.navCount++;
|
|
932
519
|
if (!preventNav.$cbs$) {
|
|
933
520
|
return;
|
|
934
521
|
}
|
|
935
|
-
const prevents = [
|
|
936
|
-
|
|
937
|
-
|
|
522
|
+
const prevents = [...preventNav.$cbs$.values()].map(
|
|
523
|
+
(cb) => cb.resolved ? cb.resolved() : cb()
|
|
524
|
+
);
|
|
938
525
|
if (prevents.some(Boolean)) {
|
|
939
526
|
event.preventDefault();
|
|
940
527
|
event.returnValue = true;
|
|
941
528
|
}
|
|
942
|
-
}
|
|
943
|
-
(preventNav.$cbs$
|
|
529
|
+
};
|
|
530
|
+
(preventNav.$cbs$ ||= /* @__PURE__ */ new Set()).add(fn$);
|
|
944
531
|
fn$.resolve();
|
|
945
532
|
window.addEventListener("beforeunload", preventNav.$handler$);
|
|
946
533
|
return () => {
|
|
@@ -954,17 +541,22 @@ const useQwikRouter = (props) => {
|
|
|
954
541
|
};
|
|
955
542
|
});
|
|
956
543
|
const goto = $(async (path, opt) => {
|
|
957
|
-
const {
|
|
958
|
-
|
|
959
|
-
|
|
544
|
+
const {
|
|
545
|
+
type = "link",
|
|
546
|
+
forceReload = path === void 0,
|
|
547
|
+
// Hack for nav() because this API is already set.
|
|
548
|
+
replaceState = false,
|
|
549
|
+
scroll = true
|
|
550
|
+
} = typeof opt === "object" ? opt : { forceReload: opt };
|
|
960
551
|
internalState.navCount++;
|
|
552
|
+
if (isBrowser && type === "link" && routeInternal.value.type === "initial") {
|
|
553
|
+
routeInternal.value.dest = new URL(window.location.href);
|
|
554
|
+
}
|
|
961
555
|
const lastDest = routeInternal.value.dest;
|
|
962
556
|
const dest = path === void 0 ? lastDest : typeof path === "number" ? path : toUrl(path, routeLocation.url);
|
|
963
557
|
if (preventNav.$cbs$ && (forceReload || typeof dest === "number" || !isSamePath(dest, lastDest) || !isSameOrigin(dest, lastDest))) {
|
|
964
558
|
const ourNavId = internalState.navCount;
|
|
965
|
-
const prevents = await Promise.all([
|
|
966
|
-
...preventNav.$cbs$.values()
|
|
967
|
-
].map((cb) => cb(dest)));
|
|
559
|
+
const prevents = await Promise.all([...preventNav.$cbs$.values()].map((cb) => cb(dest)));
|
|
968
560
|
if (ourNavId !== internalState.navCount || prevents.some(Boolean)) {
|
|
969
561
|
if (ourNavId === internalState.navCount && type === "popstate") {
|
|
970
562
|
history.pushState(null, "", lastDest);
|
|
@@ -993,7 +585,9 @@ const useQwikRouter = (props) => {
|
|
|
993
585
|
if (!scroller) {
|
|
994
586
|
scroller = document.getElementById(QWIK_CITY_SCROLLER);
|
|
995
587
|
if (scroller && isDev) {
|
|
996
|
-
console.warn(
|
|
588
|
+
console.warn(
|
|
589
|
+
`Please update your scroller ID to "${QWIK_ROUTER_SCROLLER}" as "${QWIK_CITY_SCROLLER}" is deprecated and will be removed in V3`
|
|
590
|
+
);
|
|
997
591
|
}
|
|
998
592
|
}
|
|
999
593
|
if (!scroller) {
|
|
@@ -1015,7 +609,12 @@ const useQwikRouter = (props) => {
|
|
|
1015
609
|
};
|
|
1016
610
|
if (isBrowser) {
|
|
1017
611
|
loadClientData(dest, _getContextElement());
|
|
1018
|
-
loadRoute(
|
|
612
|
+
loadRoute(
|
|
613
|
+
qwikRouterConfig.routes,
|
|
614
|
+
qwikRouterConfig.menus,
|
|
615
|
+
qwikRouterConfig.cacheModules,
|
|
616
|
+
dest.pathname
|
|
617
|
+
);
|
|
1019
618
|
}
|
|
1020
619
|
actionState.value = void 0;
|
|
1021
620
|
routeLocation.isNavigating = true;
|
|
@@ -1030,14 +629,11 @@ const useQwikRouter = (props) => {
|
|
|
1030
629
|
useContextProvider(RouteNavigateContext, goto);
|
|
1031
630
|
useContextProvider(RouteStateContext, loaderState);
|
|
1032
631
|
useContextProvider(RouteActionContext, actionState);
|
|
1033
|
-
useContextProvider(RouteInternalContext, routeInternal);
|
|
1034
632
|
useContextProvider(RoutePreventNavigateContext, registerPreventNav);
|
|
1035
633
|
useTask$(({ track }) => {
|
|
1036
634
|
async function run() {
|
|
1037
|
-
const
|
|
1038
|
-
|
|
1039
|
-
actionState.value
|
|
1040
|
-
]);
|
|
635
|
+
const navigation = track(routeInternal);
|
|
636
|
+
const action = track(actionState);
|
|
1041
637
|
const locale = getLocale("");
|
|
1042
638
|
const prevUrl = routeLocation.url;
|
|
1043
639
|
const navType = action ? "form" : navigation.type;
|
|
@@ -1059,17 +655,19 @@ const useQwikRouter = (props) => {
|
|
|
1059
655
|
} else if (!globalThis.__NO_TRAILING_SLASH__) {
|
|
1060
656
|
trackUrl.pathname += "/";
|
|
1061
657
|
}
|
|
1062
|
-
let loadRoutePromise = loadRoute(
|
|
658
|
+
let loadRoutePromise = loadRoute(
|
|
659
|
+
qwikRouterConfig.routes,
|
|
660
|
+
qwikRouterConfig.menus,
|
|
661
|
+
qwikRouterConfig.cacheModules,
|
|
662
|
+
trackUrl.pathname
|
|
663
|
+
);
|
|
1063
664
|
elm = _getContextElement();
|
|
1064
665
|
const pageData = clientPageData = await loadClientData(trackUrl, elm, {
|
|
1065
666
|
action,
|
|
1066
667
|
clearCache: true
|
|
1067
668
|
});
|
|
1068
669
|
if (!pageData) {
|
|
1069
|
-
routeInternal.untrackedValue = {
|
|
1070
|
-
type: navType,
|
|
1071
|
-
dest: trackUrl
|
|
1072
|
-
};
|
|
670
|
+
routeInternal.untrackedValue = { type: navType, dest: trackUrl };
|
|
1073
671
|
return;
|
|
1074
672
|
}
|
|
1075
673
|
const newHref = pageData.href;
|
|
@@ -1122,11 +720,14 @@ const useQwikRouter = (props) => {
|
|
|
1122
720
|
}
|
|
1123
721
|
routeLocationTarget.params = params;
|
|
1124
722
|
}
|
|
1125
|
-
routeInternal.untrackedValue = {
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
723
|
+
routeInternal.untrackedValue = { type: navType, dest: trackUrl };
|
|
724
|
+
const resolvedHead = resolveHead(
|
|
725
|
+
clientPageData,
|
|
726
|
+
routeLocation,
|
|
727
|
+
contentModules,
|
|
728
|
+
locale,
|
|
729
|
+
serverHead
|
|
730
|
+
);
|
|
1130
731
|
content.headings = pageModule.headings;
|
|
1131
732
|
content.menu = menu;
|
|
1132
733
|
contentInternal.untrackedValue = noSerialize(contentModules);
|
|
@@ -1142,7 +743,8 @@ const useQwikRouter = (props) => {
|
|
|
1142
743
|
scrollState = getScrollHistory();
|
|
1143
744
|
}
|
|
1144
745
|
const scroller = document.getElementById(QWIK_ROUTER_SCROLLER) ?? document.documentElement;
|
|
1145
|
-
if (navigation.scroll && (!navigation.forceReload || !isSamePath(trackUrl, prevUrl)) && (navType === "link" || navType === "popstate") ||
|
|
746
|
+
if (navigation.scroll && (!navigation.forceReload || !isSamePath(trackUrl, prevUrl)) && (navType === "link" || navType === "popstate") || // Action might have responded with a redirect.
|
|
747
|
+
navType === "form" && !isSamePath(trackUrl, prevUrl)) {
|
|
1146
748
|
document.__q_scroll_restore__ = () => restoreScroll(navType, trackUrl, prevUrl, scroller, scrollState);
|
|
1147
749
|
}
|
|
1148
750
|
const loaders = clientPageData?.loaders;
|
|
@@ -1153,39 +755,44 @@ const useQwikRouter = (props) => {
|
|
|
1153
755
|
const awaitedValue = await value;
|
|
1154
756
|
loadersObject[key] = awaitedValue;
|
|
1155
757
|
if (!signal) {
|
|
1156
|
-
loaderState[key] = createLoaderSignal(
|
|
758
|
+
loaderState[key] = createLoaderSignal(
|
|
759
|
+
loadersObject,
|
|
760
|
+
key,
|
|
761
|
+
trackUrl,
|
|
762
|
+
DEFAULT_LOADERS_SERIALIZATION_STRATEGY,
|
|
763
|
+
container2
|
|
764
|
+
);
|
|
1157
765
|
} else {
|
|
1158
766
|
signal.invalidate();
|
|
1159
767
|
}
|
|
1160
768
|
}
|
|
1161
769
|
}
|
|
1162
770
|
CLIENT_DATA_CACHE.clear();
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
win._qRouterSPA = true;
|
|
771
|
+
if (!window._qRouterSPA) {
|
|
772
|
+
window._qRouterSPA = true;
|
|
1166
773
|
history.scrollRestoration = "manual";
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
clearTimeout(
|
|
774
|
+
window.addEventListener("popstate", () => {
|
|
775
|
+
window._qRouterScrollEnabled = false;
|
|
776
|
+
clearTimeout(window._qRouterScrollDebounce);
|
|
1170
777
|
goto(location.href, {
|
|
1171
778
|
type: "popstate"
|
|
1172
779
|
});
|
|
1173
780
|
});
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
if (!
|
|
1177
|
-
|
|
781
|
+
window.removeEventListener("popstate", window._qRouterInitPopstate);
|
|
782
|
+
window._qRouterInitPopstate = void 0;
|
|
783
|
+
if (!window._qRouterHistoryPatch) {
|
|
784
|
+
window._qRouterHistoryPatch = true;
|
|
1178
785
|
const pushState = history.pushState;
|
|
1179
786
|
const replaceState2 = history.replaceState;
|
|
1180
787
|
const prepareState = (state) => {
|
|
1181
788
|
if (state === null || typeof state === "undefined") {
|
|
1182
789
|
state = {};
|
|
1183
790
|
} else if (state?.constructor !== Object) {
|
|
1184
|
-
state = {
|
|
1185
|
-
_data: state
|
|
1186
|
-
};
|
|
791
|
+
state = { _data: state };
|
|
1187
792
|
if (isDev) {
|
|
1188
|
-
console.warn(
|
|
793
|
+
console.warn(
|
|
794
|
+
"In a Qwik SPA context, `history.state` is used to store scroll state. Direct calls to `pushState()` and `replaceState()` must supply an actual Object type. We need to be able to automatically attach the scroll state to your state object. A new state object has been created, your data has been moved to: `history.state._data`"
|
|
795
|
+
);
|
|
1189
796
|
}
|
|
1190
797
|
}
|
|
1191
798
|
state._qRouterScroll = state._qRouterScroll || currentScrollState(scroller);
|
|
@@ -1200,7 +807,7 @@ const useQwikRouter = (props) => {
|
|
|
1200
807
|
return replaceState2.call(history, state, title, url2);
|
|
1201
808
|
};
|
|
1202
809
|
}
|
|
1203
|
-
document.
|
|
810
|
+
document.addEventListener("click", (event) => {
|
|
1204
811
|
if (event.defaultPrevented) {
|
|
1205
812
|
return;
|
|
1206
813
|
}
|
|
@@ -1215,8 +822,8 @@ const useQwikRouter = (props) => {
|
|
|
1215
822
|
if (dest.href !== prev.href) {
|
|
1216
823
|
history.pushState(null, "", dest);
|
|
1217
824
|
}
|
|
1218
|
-
|
|
1219
|
-
clearTimeout(
|
|
825
|
+
window._qRouterScrollEnabled = false;
|
|
826
|
+
clearTimeout(window._qRouterScrollDebounce);
|
|
1220
827
|
saveScrollHistory({
|
|
1221
828
|
...currentScrollState(scroller),
|
|
1222
829
|
x: 0,
|
|
@@ -1229,43 +836,49 @@ const useQwikRouter = (props) => {
|
|
|
1229
836
|
}
|
|
1230
837
|
}
|
|
1231
838
|
});
|
|
1232
|
-
document.
|
|
1233
|
-
|
|
839
|
+
document.removeEventListener("click", window._qRouterInitAnchors);
|
|
840
|
+
window._qRouterInitAnchors = void 0;
|
|
1234
841
|
if (!window.navigation) {
|
|
1235
|
-
document.addEventListener(
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
842
|
+
document.addEventListener(
|
|
843
|
+
"visibilitychange",
|
|
844
|
+
() => {
|
|
845
|
+
if ((window._qRouterScrollEnabled || window._qCityScrollEnabled) && document.visibilityState === "hidden") {
|
|
846
|
+
if (window._qCityScrollEnabled) {
|
|
847
|
+
console.warn(
|
|
848
|
+
'"_qCityScrollEnabled" is deprecated. Use "_qRouterScrollEnabled" instead.'
|
|
849
|
+
);
|
|
850
|
+
}
|
|
851
|
+
const scrollState2 = currentScrollState(scroller);
|
|
852
|
+
saveScrollHistory(scrollState2);
|
|
1239
853
|
}
|
|
854
|
+
},
|
|
855
|
+
{ passive: true }
|
|
856
|
+
);
|
|
857
|
+
document.removeEventListener("visibilitychange", window._qRouterInitVisibility);
|
|
858
|
+
window._qRouterInitVisibility = void 0;
|
|
859
|
+
}
|
|
860
|
+
window.addEventListener(
|
|
861
|
+
"scroll",
|
|
862
|
+
() => {
|
|
863
|
+
if (!window._qRouterScrollEnabled && !window._qCityScrollEnabled) {
|
|
864
|
+
return;
|
|
865
|
+
}
|
|
866
|
+
clearTimeout(window._qRouterScrollDebounce);
|
|
867
|
+
window._qRouterScrollDebounce = setTimeout(() => {
|
|
1240
868
|
const scrollState2 = currentScrollState(scroller);
|
|
1241
869
|
saveScrollHistory(scrollState2);
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
}
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
win.addEventListener("scroll", () => {
|
|
1250
|
-
if (!win._qRouterScrollEnabled && !win._qCityScrollEnabled) {
|
|
1251
|
-
return;
|
|
1252
|
-
}
|
|
1253
|
-
clearTimeout(win._qRouterScrollDebounce);
|
|
1254
|
-
win._qRouterScrollDebounce = setTimeout(() => {
|
|
1255
|
-
const scrollState2 = currentScrollState(scroller);
|
|
1256
|
-
saveScrollHistory(scrollState2);
|
|
1257
|
-
win._qRouterScrollDebounce = void 0;
|
|
1258
|
-
}, 200);
|
|
1259
|
-
}, {
|
|
1260
|
-
passive: true
|
|
1261
|
-
});
|
|
1262
|
-
removeEventListener("scroll", win._qRouterInitScroll);
|
|
1263
|
-
win._qRouterInitScroll = void 0;
|
|
870
|
+
window._qRouterScrollDebounce = void 0;
|
|
871
|
+
}, 200);
|
|
872
|
+
},
|
|
873
|
+
{ passive: true }
|
|
874
|
+
);
|
|
875
|
+
removeEventListener("scroll", window._qRouterInitScroll);
|
|
876
|
+
window._qRouterInitScroll = void 0;
|
|
1264
877
|
spaInit.resolve();
|
|
1265
878
|
}
|
|
1266
879
|
if (navType !== "popstate") {
|
|
1267
|
-
|
|
1268
|
-
clearTimeout(
|
|
880
|
+
window._qRouterScrollEnabled = false;
|
|
881
|
+
clearTimeout(window._qRouterScrollDebounce);
|
|
1269
882
|
const scrollState2 = currentScrollState(scroller);
|
|
1270
883
|
saveScrollHistory(scrollState2);
|
|
1271
884
|
}
|
|
@@ -1280,9 +893,7 @@ const useQwikRouter = (props) => {
|
|
|
1280
893
|
} else {
|
|
1281
894
|
const viewTransition = startViewTransition({
|
|
1282
895
|
update: navigate,
|
|
1283
|
-
types: [
|
|
1284
|
-
"qwik-navigation"
|
|
1285
|
-
]
|
|
896
|
+
types: ["qwik-navigation"]
|
|
1286
897
|
});
|
|
1287
898
|
if (!viewTransition) {
|
|
1288
899
|
return Promise.resolve();
|
|
@@ -1295,7 +906,7 @@ const useQwikRouter = (props) => {
|
|
|
1295
906
|
container2.setAttribute(Q_ROUTE, routeName);
|
|
1296
907
|
const scrollState2 = currentScrollState(scroller);
|
|
1297
908
|
saveScrollHistory(scrollState2);
|
|
1298
|
-
|
|
909
|
+
window._qRouterScrollEnabled = true;
|
|
1299
910
|
if (isBrowser) {
|
|
1300
911
|
callRestoreScrollOnDocument();
|
|
1301
912
|
}
|
|
@@ -1329,31 +940,27 @@ const QwikCityProvider = QwikRouterProvider;
|
|
|
1329
940
|
const useQwikMockRouter = (props) => {
|
|
1330
941
|
const urlEnv = props.url ?? "http://localhost/";
|
|
1331
942
|
const url = new URL(urlEnv);
|
|
1332
|
-
const routeLocation = useStore(
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
943
|
+
const routeLocation = useStore(
|
|
944
|
+
{
|
|
945
|
+
url,
|
|
946
|
+
params: props.params ?? {},
|
|
947
|
+
isNavigating: false,
|
|
948
|
+
prevUrl: void 0
|
|
949
|
+
},
|
|
950
|
+
{ deep: false }
|
|
951
|
+
);
|
|
1340
952
|
const loaderState = {};
|
|
1341
|
-
const routeInternal = useSignal({
|
|
1342
|
-
type: "initial",
|
|
1343
|
-
dest: url
|
|
1344
|
-
});
|
|
1345
953
|
const goto = props.goto ?? $(async () => {
|
|
1346
954
|
console.warn("QwikRouterMockProvider: goto not provided");
|
|
1347
955
|
});
|
|
1348
|
-
const documentHead = useStore(createDocumentHead, {
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
});
|
|
956
|
+
const documentHead = useStore(createDocumentHead, { deep: false });
|
|
957
|
+
const content = useStore(
|
|
958
|
+
{
|
|
959
|
+
headings: void 0,
|
|
960
|
+
menu: void 0
|
|
961
|
+
},
|
|
962
|
+
{ deep: false }
|
|
963
|
+
);
|
|
1357
964
|
const contentInternal = useSignal();
|
|
1358
965
|
const actionState = useSignal();
|
|
1359
966
|
useContextProvider(ContentContext, content);
|
|
@@ -1363,13 +970,13 @@ const useQwikMockRouter = (props) => {
|
|
|
1363
970
|
useContextProvider(RouteNavigateContext, goto);
|
|
1364
971
|
useContextProvider(RouteStateContext, loaderState);
|
|
1365
972
|
useContextProvider(RouteActionContext, actionState);
|
|
1366
|
-
useContextProvider(RouteInternalContext, routeInternal);
|
|
1367
973
|
};
|
|
1368
974
|
const QwikRouterMockProvider = component$((props) => {
|
|
1369
975
|
useQwikMockRouter(props);
|
|
1370
976
|
return /* @__PURE__ */ jsx(Slot, {});
|
|
1371
977
|
});
|
|
1372
978
|
const QwikCityMockProvider = QwikRouterMockProvider;
|
|
979
|
+
|
|
1373
980
|
const RouterOutlet = component$(() => {
|
|
1374
981
|
const serverData = useServerData("containerAttributes");
|
|
1375
982
|
if (!serverData) {
|
|
@@ -1387,10 +994,11 @@ const RouterOutlet = component$(() => {
|
|
|
1387
994
|
});
|
|
1388
995
|
}
|
|
1389
996
|
}
|
|
1390
|
-
return /* @__PURE__ */ jsxs(Fragment, {
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
997
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
998
|
+
cmp,
|
|
999
|
+
!__EXPERIMENTAL__.noSPA && /* @__PURE__ */ jsx(
|
|
1000
|
+
"script",
|
|
1001
|
+
{
|
|
1394
1002
|
"document:onQCInit$": spaInit,
|
|
1395
1003
|
"document:onQInit$": sync$(() => {
|
|
1396
1004
|
((w, h) => {
|
|
@@ -1404,87 +1012,14 @@ const RouterOutlet = component$(() => {
|
|
|
1404
1012
|
}
|
|
1405
1013
|
})(window, history);
|
|
1406
1014
|
})
|
|
1407
|
-
}
|
|
1408
|
-
|
|
1409
|
-
});
|
|
1015
|
+
}
|
|
1016
|
+
)
|
|
1017
|
+
] });
|
|
1410
1018
|
}
|
|
1411
1019
|
return SkipRender;
|
|
1412
1020
|
});
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
function getGlobalConfig(config2) {
|
|
1416
|
-
return {
|
|
1417
|
-
lang: config2?.lang ?? store?.lang,
|
|
1418
|
-
message: config2?.message,
|
|
1419
|
-
abortEarly: config2?.abortEarly ?? store?.abortEarly,
|
|
1420
|
-
abortPipeEarly: config2?.abortPipeEarly ?? store?.abortPipeEarly
|
|
1421
|
-
};
|
|
1422
|
-
}
|
|
1423
|
-
// @__NO_SIDE_EFFECTS__
|
|
1424
|
-
function getDotPath(issue) {
|
|
1425
|
-
if (issue.path) {
|
|
1426
|
-
let key = "";
|
|
1427
|
-
for (const item of issue.path) {
|
|
1428
|
-
if (typeof item.key === "string" || typeof item.key === "number") {
|
|
1429
|
-
if (key) {
|
|
1430
|
-
key += `.${item.key}`;
|
|
1431
|
-
} else {
|
|
1432
|
-
key += item.key;
|
|
1433
|
-
}
|
|
1434
|
-
} else {
|
|
1435
|
-
return null;
|
|
1436
|
-
}
|
|
1437
|
-
}
|
|
1438
|
-
return key;
|
|
1439
|
-
}
|
|
1440
|
-
return null;
|
|
1441
|
-
}
|
|
1442
|
-
// @__NO_SIDE_EFFECTS__
|
|
1443
|
-
function flatten(issues) {
|
|
1444
|
-
const flatErrors = {};
|
|
1445
|
-
for (const issue of issues) {
|
|
1446
|
-
if (issue.path) {
|
|
1447
|
-
const dotPath = /* @__PURE__ */ getDotPath(issue);
|
|
1448
|
-
if (dotPath) {
|
|
1449
|
-
if (!flatErrors.nested) {
|
|
1450
|
-
flatErrors.nested = {};
|
|
1451
|
-
}
|
|
1452
|
-
if (flatErrors.nested[dotPath]) {
|
|
1453
|
-
flatErrors.nested[dotPath].push(issue.message);
|
|
1454
|
-
} else {
|
|
1455
|
-
flatErrors.nested[dotPath] = [issue.message];
|
|
1456
|
-
}
|
|
1457
|
-
} else {
|
|
1458
|
-
if (flatErrors.other) {
|
|
1459
|
-
flatErrors.other.push(issue.message);
|
|
1460
|
-
} else {
|
|
1461
|
-
flatErrors.other = [issue.message];
|
|
1462
|
-
}
|
|
1463
|
-
}
|
|
1464
|
-
} else {
|
|
1465
|
-
if (flatErrors.root) {
|
|
1466
|
-
flatErrors.root.push(issue.message);
|
|
1467
|
-
} else {
|
|
1468
|
-
flatErrors.root = [issue.message];
|
|
1469
|
-
}
|
|
1470
|
-
}
|
|
1471
|
-
}
|
|
1472
|
-
return flatErrors;
|
|
1473
|
-
}
|
|
1474
|
-
// @__NO_SIDE_EFFECTS__
|
|
1475
|
-
async function safeParseAsync(schema, input, config2) {
|
|
1476
|
-
const dataset = await schema["~run"](
|
|
1477
|
-
{ value: input },
|
|
1478
|
-
/* @__PURE__ */ getGlobalConfig(config2)
|
|
1479
|
-
);
|
|
1480
|
-
return {
|
|
1481
|
-
typed: dataset.typed,
|
|
1482
|
-
success: !dataset.issues,
|
|
1483
|
-
output: dataset.value,
|
|
1484
|
-
issues: dataset.issues
|
|
1485
|
-
};
|
|
1486
|
-
}
|
|
1487
|
-
const routeActionQrl = (actionQrl, ...rest) => {
|
|
1021
|
+
|
|
1022
|
+
const routeActionQrl = ((actionQrl, ...rest) => {
|
|
1488
1023
|
const { id, validators } = getValidators(rest, actionQrl);
|
|
1489
1024
|
function action() {
|
|
1490
1025
|
const loc = useLocation();
|
|
@@ -1550,16 +1085,15 @@ Action.run() can only be called on the browser, for example when a user clicks a
|
|
|
1550
1085
|
if (form.getAttribute("data-spa-reset") === "true") {
|
|
1551
1086
|
form.reset();
|
|
1552
1087
|
}
|
|
1553
|
-
const detail = {
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
}));
|
|
1088
|
+
const detail = { status, value: result };
|
|
1089
|
+
form.dispatchEvent(
|
|
1090
|
+
new CustomEvent("submitcompleted", {
|
|
1091
|
+
bubbles: false,
|
|
1092
|
+
cancelable: false,
|
|
1093
|
+
composed: false,
|
|
1094
|
+
detail
|
|
1095
|
+
})
|
|
1096
|
+
);
|
|
1563
1097
|
}
|
|
1564
1098
|
return {
|
|
1565
1099
|
status,
|
|
@@ -1576,8 +1110,8 @@ Action.run() can only be called on the browser, for example when a user clicks a
|
|
|
1576
1110
|
action.__id = id;
|
|
1577
1111
|
Object.freeze(action);
|
|
1578
1112
|
return action;
|
|
1579
|
-
};
|
|
1580
|
-
const globalActionQrl = (actionQrl, ...rest) => {
|
|
1113
|
+
});
|
|
1114
|
+
const globalActionQrl = ((actionQrl, ...rest) => {
|
|
1581
1115
|
const action = routeActionQrl(actionQrl, ...rest);
|
|
1582
1116
|
if (isServer) {
|
|
1583
1117
|
if (typeof globalThis._qwikActionsMap === "undefined") {
|
|
@@ -1586,10 +1120,14 @@ const globalActionQrl = (actionQrl, ...rest) => {
|
|
|
1586
1120
|
globalThis._qwikActionsMap.set(action.__id, action);
|
|
1587
1121
|
}
|
|
1588
1122
|
return action;
|
|
1589
|
-
};
|
|
1590
|
-
const routeAction$ = /* @__PURE__ */ implicit$FirstArg(
|
|
1591
|
-
|
|
1592
|
-
|
|
1123
|
+
});
|
|
1124
|
+
const routeAction$ = /* @__PURE__ */ implicit$FirstArg(
|
|
1125
|
+
routeActionQrl
|
|
1126
|
+
);
|
|
1127
|
+
const globalAction$ = /* @__PURE__ */ implicit$FirstArg(
|
|
1128
|
+
globalActionQrl
|
|
1129
|
+
);
|
|
1130
|
+
const routeLoaderQrl = ((loaderQrl, ...rest) => {
|
|
1593
1131
|
const { id, validators, serializationStrategy } = getValidators(rest, loaderQrl);
|
|
1594
1132
|
function loader() {
|
|
1595
1133
|
const state = _resolveContextWithoutSequentialScope(RouteStateContext);
|
|
@@ -1609,18 +1147,19 @@ const routeLoaderQrl = (loaderQrl, ...rest) => {
|
|
|
1609
1147
|
loader.__validators = validators;
|
|
1610
1148
|
loader.__id = id;
|
|
1611
1149
|
loader.__serializationStrategy = serializationStrategy;
|
|
1150
|
+
loader.__expires = -1;
|
|
1612
1151
|
Object.freeze(loader);
|
|
1613
1152
|
return loader;
|
|
1614
|
-
};
|
|
1153
|
+
});
|
|
1615
1154
|
const routeLoader$ = /* @__PURE__ */ implicit$FirstArg(routeLoaderQrl);
|
|
1616
|
-
const validatorQrl = (validator) => {
|
|
1155
|
+
const validatorQrl = ((validator) => {
|
|
1617
1156
|
if (isServer) {
|
|
1618
1157
|
return {
|
|
1619
1158
|
validate: validator
|
|
1620
1159
|
};
|
|
1621
1160
|
}
|
|
1622
1161
|
return void 0;
|
|
1623
|
-
};
|
|
1162
|
+
});
|
|
1624
1163
|
const validator$ = /* @__PURE__ */ implicit$FirstArg(validatorQrl);
|
|
1625
1164
|
const flattenValibotIssues = (issues) => {
|
|
1626
1165
|
return issues.reduce((acc, issue) => {
|
|
@@ -1643,7 +1182,9 @@ const flattenValibotIssues = (issues) => {
|
|
|
1643
1182
|
};
|
|
1644
1183
|
const valibotQrl = (qrl) => {
|
|
1645
1184
|
if (!__EXPERIMENTAL__.valibot) {
|
|
1646
|
-
throw new Error(
|
|
1185
|
+
throw new Error(
|
|
1186
|
+
'Valibot is an experimental feature and is not enabled. Please enable the feature flag by adding `experimental: ["valibot"]` to your qwikVite plugin options.'
|
|
1187
|
+
);
|
|
1647
1188
|
}
|
|
1648
1189
|
if (isServer) {
|
|
1649
1190
|
return {
|
|
@@ -1651,7 +1192,7 @@ const valibotQrl = (qrl) => {
|
|
|
1651
1192
|
async validate(ev, inputData) {
|
|
1652
1193
|
const schema = await qrl.resolve().then((obj) => typeof obj === "function" ? obj(ev) : obj);
|
|
1653
1194
|
const data = inputData ?? await ev.parseBody();
|
|
1654
|
-
const result = await
|
|
1195
|
+
const result = await v.safeParseAsync(schema, data);
|
|
1655
1196
|
if (result.success) {
|
|
1656
1197
|
return {
|
|
1657
1198
|
success: true,
|
|
@@ -1665,7 +1206,7 @@ const valibotQrl = (qrl) => {
|
|
|
1665
1206
|
success: false,
|
|
1666
1207
|
status: 400,
|
|
1667
1208
|
error: {
|
|
1668
|
-
formErrors:
|
|
1209
|
+
formErrors: v.flatten(result.issues).root ?? [],
|
|
1669
1210
|
fieldErrors: flattenValibotIssues(result.issues)
|
|
1670
1211
|
}
|
|
1671
1212
|
};
|
|
@@ -1677,9 +1218,7 @@ const valibotQrl = (qrl) => {
|
|
|
1677
1218
|
};
|
|
1678
1219
|
const valibot$ = /* @__PURE__ */ implicit$FirstArg(valibotQrl);
|
|
1679
1220
|
const flattenZodIssues = (issues) => {
|
|
1680
|
-
issues = Array.isArray(issues) ? issues : [
|
|
1681
|
-
issues
|
|
1682
|
-
];
|
|
1221
|
+
issues = Array.isArray(issues) ? issues : [issues];
|
|
1683
1222
|
return issues.reduce((acc, issue) => {
|
|
1684
1223
|
const isExpectingArray = "expected" in issue && issue.expected === "array";
|
|
1685
1224
|
const hasArrayType = issue.path.some((path) => typeof path === "number") || isExpectingArray;
|
|
@@ -1746,93 +1285,96 @@ const serverQrl = (qrl, options) => {
|
|
|
1746
1285
|
const headers = options?.headers || {};
|
|
1747
1286
|
const origin = options?.origin || "";
|
|
1748
1287
|
const fetchOptions = options?.fetchOptions || {};
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1288
|
+
return $(async function(...args) {
|
|
1289
|
+
const abortSignal = args.length > 0 && args[0] instanceof AbortSignal ? args.shift() : void 0;
|
|
1290
|
+
if (isServer) {
|
|
1291
|
+
let requestEvent = _asyncRequestStore?.getStore();
|
|
1292
|
+
if (!requestEvent) {
|
|
1293
|
+
const contexts = [useQwikRouterEnv()?.ev, this, _getContextEvent()];
|
|
1294
|
+
requestEvent = contexts.find(
|
|
1295
|
+
(v2) => v2 && Object.prototype.hasOwnProperty.call(v2, "sharedMap") && Object.prototype.hasOwnProperty.call(v2, "cookie")
|
|
1296
|
+
);
|
|
1297
|
+
}
|
|
1298
|
+
return qrl.apply(requestEvent, isDev ? deepFreeze(args) : args);
|
|
1299
|
+
} else {
|
|
1300
|
+
const ctxElm = _getContextElement();
|
|
1301
|
+
const filteredArgs = args.map((arg) => {
|
|
1302
|
+
if (arg instanceof SubmitEvent && arg.target instanceof HTMLFormElement) {
|
|
1303
|
+
return new FormData(arg.target);
|
|
1304
|
+
} else if (arg instanceof Event) {
|
|
1305
|
+
return null;
|
|
1306
|
+
} else if (arg instanceof Node) {
|
|
1307
|
+
return null;
|
|
1761
1308
|
}
|
|
1762
|
-
return
|
|
1309
|
+
return arg;
|
|
1310
|
+
});
|
|
1311
|
+
const qrlHash = qrl.getHash();
|
|
1312
|
+
let query = "";
|
|
1313
|
+
const config = {
|
|
1314
|
+
...fetchOptions,
|
|
1315
|
+
method,
|
|
1316
|
+
headers: {
|
|
1317
|
+
...headers,
|
|
1318
|
+
"Content-Type": "application/qwik-json",
|
|
1319
|
+
Accept: "application/json, application/qwik-json, text/qwik-json-stream, text/plain",
|
|
1320
|
+
// Required so we don't call accidentally
|
|
1321
|
+
"X-QRL": qrlHash
|
|
1322
|
+
},
|
|
1323
|
+
signal: abortSignal
|
|
1324
|
+
};
|
|
1325
|
+
const captured = qrl.getCaptured();
|
|
1326
|
+
let toSend;
|
|
1327
|
+
if (captured?.length) {
|
|
1328
|
+
toSend = [filteredArgs, captured];
|
|
1763
1329
|
} else {
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
signal: abortSignal
|
|
1788
|
-
};
|
|
1789
|
-
const body = await _serialize([
|
|
1790
|
-
qrl,
|
|
1791
|
-
...filteredArgs
|
|
1792
|
-
]);
|
|
1793
|
-
if (method === "GET") {
|
|
1794
|
-
query += `&${QDATA_KEY}=${encodeURIComponent(body)}`;
|
|
1795
|
-
} else {
|
|
1796
|
-
config.body = body;
|
|
1797
|
-
}
|
|
1798
|
-
const res = await fetch(`${origin}?${QFN_KEY}=${qrlHash}${query}`, config);
|
|
1799
|
-
const contentType = res.headers.get("Content-Type");
|
|
1800
|
-
if (res.ok && contentType === "text/qwik-json-stream" && res.body) {
|
|
1801
|
-
return (async function* () {
|
|
1802
|
-
try {
|
|
1803
|
-
for await (const result of deserializeStream(res.body, ctxElm ?? document.documentElement, abortSignal)) {
|
|
1804
|
-
yield result;
|
|
1805
|
-
}
|
|
1806
|
-
} finally {
|
|
1807
|
-
if (!abortSignal?.aborted) {
|
|
1808
|
-
await res.body.cancel();
|
|
1809
|
-
}
|
|
1330
|
+
toSend = filteredArgs.length ? [filteredArgs] : [];
|
|
1331
|
+
}
|
|
1332
|
+
const body = await _serialize(toSend);
|
|
1333
|
+
if (method === "GET") {
|
|
1334
|
+
query += `&${QDATA_KEY}=${encodeURIComponent(body)}`;
|
|
1335
|
+
} else {
|
|
1336
|
+
config.body = body;
|
|
1337
|
+
}
|
|
1338
|
+
const res = await fetch(`${origin}?${QFN_KEY}=${qrlHash}${query}`, config);
|
|
1339
|
+
const contentType = res.headers.get("Content-Type");
|
|
1340
|
+
if (res.ok && contentType === "text/qwik-json-stream" && res.body) {
|
|
1341
|
+
return (async function* () {
|
|
1342
|
+
try {
|
|
1343
|
+
for await (const result of deserializeStream(
|
|
1344
|
+
res.body,
|
|
1345
|
+
ctxElm ?? document.documentElement,
|
|
1346
|
+
abortSignal
|
|
1347
|
+
)) {
|
|
1348
|
+
yield result;
|
|
1349
|
+
}
|
|
1350
|
+
} finally {
|
|
1351
|
+
if (!abortSignal?.aborted) {
|
|
1352
|
+
await res.body.cancel();
|
|
1810
1353
|
}
|
|
1811
|
-
})();
|
|
1812
|
-
} else if (contentType === "application/qwik-json") {
|
|
1813
|
-
const str = await res.text();
|
|
1814
|
-
const [obj] = _deserialize(str, ctxElm ?? document.documentElement);
|
|
1815
|
-
if (res.status >= 400) {
|
|
1816
|
-
throw obj;
|
|
1817
|
-
}
|
|
1818
|
-
return obj;
|
|
1819
|
-
} else if (contentType === "application/json") {
|
|
1820
|
-
const obj = await res.json();
|
|
1821
|
-
if (res.status >= 400) {
|
|
1822
|
-
throw obj;
|
|
1823
|
-
}
|
|
1824
|
-
return obj;
|
|
1825
|
-
} else if (contentType === "text/plain" || contentType === "text/html") {
|
|
1826
|
-
const str = await res.text();
|
|
1827
|
-
if (res.status >= 400) {
|
|
1828
|
-
throw str;
|
|
1829
1354
|
}
|
|
1830
|
-
|
|
1355
|
+
})();
|
|
1356
|
+
} else if (contentType === "application/qwik-json") {
|
|
1357
|
+
const str = await res.text();
|
|
1358
|
+
const [obj] = _deserialize(str, ctxElm ?? document.documentElement);
|
|
1359
|
+
if (res.status >= 400) {
|
|
1360
|
+
throw obj;
|
|
1361
|
+
}
|
|
1362
|
+
return obj;
|
|
1363
|
+
} else if (contentType === "application/json") {
|
|
1364
|
+
const obj = await res.json();
|
|
1365
|
+
if (res.status >= 400) {
|
|
1366
|
+
throw obj;
|
|
1367
|
+
}
|
|
1368
|
+
return obj;
|
|
1369
|
+
} else if (contentType === "text/plain" || contentType === "text/html") {
|
|
1370
|
+
const str = await res.text();
|
|
1371
|
+
if (res.status >= 400) {
|
|
1372
|
+
throw str;
|
|
1831
1373
|
}
|
|
1374
|
+
return str;
|
|
1832
1375
|
}
|
|
1833
|
-
}
|
|
1834
|
-
}
|
|
1835
|
-
return rpc();
|
|
1376
|
+
}
|
|
1377
|
+
});
|
|
1836
1378
|
};
|
|
1837
1379
|
const server$ = /* @__PURE__ */ implicit$FirstArg(serverQrl);
|
|
1838
1380
|
const getValidators = (rest, qrl) => {
|
|
@@ -1883,9 +1425,7 @@ const deserializeStream = async function* (stream, ctxElm, abortSignal) {
|
|
|
1883
1425
|
if (result.done) {
|
|
1884
1426
|
break;
|
|
1885
1427
|
}
|
|
1886
|
-
buffer += decoder.decode(result.value, {
|
|
1887
|
-
stream: true
|
|
1888
|
-
});
|
|
1428
|
+
buffer += decoder.decode(result.value, { stream: true });
|
|
1889
1429
|
const lines = buffer.split(/\n/);
|
|
1890
1430
|
buffer = lines.pop();
|
|
1891
1431
|
for (const line of lines) {
|
|
@@ -1897,95 +1437,109 @@ const deserializeStream = async function* (stream, ctxElm, abortSignal) {
|
|
|
1897
1437
|
reader.releaseLock();
|
|
1898
1438
|
}
|
|
1899
1439
|
};
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
nonce: props.nonce
|
|
1904
|
-
});
|
|
1440
|
+
|
|
1441
|
+
const ServiceWorkerRegister = (props) => /* @__PURE__ */ jsx("script", { type: "module", dangerouslySetInnerHTML: swRegister, nonce: props.nonce });
|
|
1442
|
+
|
|
1905
1443
|
const Form = ({ action, spaReset, reloadDocument, onSubmit$, ...rest }, key) => {
|
|
1906
1444
|
if (action) {
|
|
1907
1445
|
const isArrayApi = Array.isArray(onSubmit$);
|
|
1908
1446
|
if (isArrayApi) {
|
|
1909
|
-
return jsx$1(
|
|
1447
|
+
return jsx$1(
|
|
1448
|
+
"form",
|
|
1449
|
+
{
|
|
1450
|
+
...rest,
|
|
1451
|
+
action: action.actionPath,
|
|
1452
|
+
"preventdefault:submit": !reloadDocument,
|
|
1453
|
+
onSubmit$: [
|
|
1454
|
+
...onSubmit$,
|
|
1455
|
+
// action.submit "submitcompleted" event for onSubmitCompleted$ events
|
|
1456
|
+
!reloadDocument ? $((evt) => {
|
|
1457
|
+
if (!action.submitted) {
|
|
1458
|
+
return action.submit(evt);
|
|
1459
|
+
}
|
|
1460
|
+
}) : void 0
|
|
1461
|
+
],
|
|
1462
|
+
method: "post",
|
|
1463
|
+
["data-spa-reset"]: spaReset ? "true" : void 0
|
|
1464
|
+
},
|
|
1465
|
+
key
|
|
1466
|
+
);
|
|
1467
|
+
}
|
|
1468
|
+
return jsx$1(
|
|
1469
|
+
"form",
|
|
1470
|
+
{
|
|
1910
1471
|
...rest,
|
|
1911
1472
|
action: action.actionPath,
|
|
1912
1473
|
"preventdefault:submit": !reloadDocument,
|
|
1913
1474
|
onSubmit$: [
|
|
1914
|
-
|
|
1475
|
+
// Since v2, this fires before the action is executed so it can be prevented
|
|
1476
|
+
onSubmit$,
|
|
1915
1477
|
// action.submit "submitcompleted" event for onSubmitCompleted$ events
|
|
1916
|
-
!reloadDocument ?
|
|
1917
|
-
if (!action.submitted) {
|
|
1918
|
-
return action.submit(evt);
|
|
1919
|
-
}
|
|
1920
|
-
}) : void 0
|
|
1478
|
+
!reloadDocument ? action.submit : void 0
|
|
1921
1479
|
],
|
|
1922
1480
|
method: "post",
|
|
1923
1481
|
["data-spa-reset"]: spaReset ? "true" : void 0
|
|
1924
|
-
},
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
...rest,
|
|
1928
|
-
action: action.actionPath,
|
|
1929
|
-
"preventdefault:submit": !reloadDocument,
|
|
1930
|
-
onSubmit$: [
|
|
1931
|
-
// Since v2, this fires before the action is executed so it can be prevented
|
|
1932
|
-
onSubmit$,
|
|
1933
|
-
// action.submit "submitcompleted" event for onSubmitCompleted$ events
|
|
1934
|
-
!reloadDocument ? action.submit : void 0
|
|
1935
|
-
],
|
|
1936
|
-
method: "post",
|
|
1937
|
-
["data-spa-reset"]: spaReset ? "true" : void 0
|
|
1938
|
-
}, key);
|
|
1482
|
+
},
|
|
1483
|
+
key
|
|
1484
|
+
);
|
|
1939
1485
|
} else {
|
|
1940
|
-
return /* @__PURE__ */ jsx(
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1486
|
+
return /* @__PURE__ */ jsx(
|
|
1487
|
+
GetForm,
|
|
1488
|
+
{
|
|
1489
|
+
spaReset,
|
|
1490
|
+
reloadDocument,
|
|
1491
|
+
onSubmit$,
|
|
1492
|
+
...rest
|
|
1493
|
+
},
|
|
1494
|
+
key
|
|
1495
|
+
);
|
|
1946
1496
|
}
|
|
1947
1497
|
};
|
|
1948
|
-
const GetForm = component$(
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
}
|
|
1498
|
+
const GetForm = component$(
|
|
1499
|
+
({ action: _0, spaReset, reloadDocument, onSubmit$, ...rest }) => {
|
|
1500
|
+
const nav = useNavigate();
|
|
1501
|
+
return /* @__PURE__ */ jsx(
|
|
1502
|
+
"form",
|
|
1503
|
+
{
|
|
1504
|
+
action: "get",
|
|
1505
|
+
"preventdefault:submit": !reloadDocument,
|
|
1506
|
+
"data-spa-reset": spaReset ? "true" : void 0,
|
|
1507
|
+
...rest,
|
|
1508
|
+
onSubmit$: [
|
|
1509
|
+
...Array.isArray(onSubmit$) ? onSubmit$ : [onSubmit$],
|
|
1510
|
+
$(async (_evt, form) => {
|
|
1511
|
+
const formData = new FormData(form);
|
|
1512
|
+
const params = new URLSearchParams();
|
|
1513
|
+
formData.forEach((value, key) => {
|
|
1514
|
+
if (typeof value === "string") {
|
|
1515
|
+
params.append(key, value);
|
|
1516
|
+
}
|
|
1517
|
+
});
|
|
1518
|
+
await nav("?" + params.toString(), { type: "form", forceReload: true });
|
|
1519
|
+
}),
|
|
1520
|
+
$((_evt, form) => {
|
|
1521
|
+
if (form.getAttribute("data-spa-reset") === "true") {
|
|
1522
|
+
form.reset();
|
|
1523
|
+
}
|
|
1524
|
+
form.dispatchEvent(
|
|
1525
|
+
new CustomEvent("submitcompleted", {
|
|
1526
|
+
bubbles: false,
|
|
1527
|
+
cancelable: false,
|
|
1528
|
+
composed: false,
|
|
1529
|
+
detail: {
|
|
1530
|
+
status: 200
|
|
1531
|
+
}
|
|
1532
|
+
})
|
|
1533
|
+
);
|
|
1534
|
+
})
|
|
1535
|
+
// end of array
|
|
1536
|
+
],
|
|
1537
|
+
children: /* @__PURE__ */ jsx(Slot, {})
|
|
1538
|
+
}
|
|
1539
|
+
);
|
|
1540
|
+
}
|
|
1541
|
+
);
|
|
1542
|
+
|
|
1989
1543
|
const untypedAppUrl = function appUrl(route, params, paramsPrefix = "") {
|
|
1990
1544
|
const path = route.split("/");
|
|
1991
1545
|
for (let i = 0; i < path.length; i++) {
|
|
@@ -2022,86 +1576,46 @@ function omitProps(obj, keys) {
|
|
|
2022
1576
|
}
|
|
2023
1577
|
return omittedObj;
|
|
2024
1578
|
}
|
|
1579
|
+
|
|
2025
1580
|
const createRenderer = (getOptions) => {
|
|
2026
|
-
return (opts) => {
|
|
2027
|
-
const { jsx
|
|
2028
|
-
return renderToStream(
|
|
2029
|
-
};
|
|
1581
|
+
return ((opts) => {
|
|
1582
|
+
const { jsx, options } = getOptions(opts);
|
|
1583
|
+
return renderToStream(jsx, options);
|
|
1584
|
+
});
|
|
2030
1585
|
};
|
|
1586
|
+
|
|
2031
1587
|
const DocumentHeadTags = component$((props) => {
|
|
2032
1588
|
let head = useDocumentHead();
|
|
2033
1589
|
if (props) {
|
|
2034
|
-
head = {
|
|
2035
|
-
...head,
|
|
2036
|
-
...props
|
|
2037
|
-
};
|
|
1590
|
+
head = { ...head, ...props };
|
|
2038
1591
|
}
|
|
2039
|
-
return /* @__PURE__ */ jsxs(Fragment, {
|
|
2040
|
-
children:
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
...l
|
|
2049
|
-
})),
|
|
2050
|
-
head.styles.map((s) => {
|
|
2051
|
-
const props2 = s.props || s;
|
|
2052
|
-
return /* @__PURE__ */ createElement("style", {
|
|
1592
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1593
|
+
head.title && /* @__PURE__ */ jsx("title", { children: head.title }),
|
|
1594
|
+
head.meta.map((m) => /* @__PURE__ */ jsx("meta", { ...m })),
|
|
1595
|
+
head.links.map((l) => /* @__PURE__ */ jsx("link", { ...l })),
|
|
1596
|
+
head.styles.map((s) => {
|
|
1597
|
+
const props2 = s.props || s;
|
|
1598
|
+
return /* @__PURE__ */ createElement(
|
|
1599
|
+
"style",
|
|
1600
|
+
{
|
|
2053
1601
|
...props2,
|
|
2054
1602
|
dangerouslySetInnerHTML: s.style || props2.dangerouslySetInnerHTML,
|
|
2055
1603
|
key: s.key
|
|
2056
|
-
}
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
1604
|
+
}
|
|
1605
|
+
);
|
|
1606
|
+
}),
|
|
1607
|
+
head.scripts.map((s) => {
|
|
1608
|
+
const props2 = s.props || s;
|
|
1609
|
+
return /* @__PURE__ */ createElement(
|
|
1610
|
+
"script",
|
|
1611
|
+
{
|
|
2061
1612
|
...props2,
|
|
2062
1613
|
dangerouslySetInnerHTML: s.script || props2.dangerouslySetInnerHTML,
|
|
2063
1614
|
key: s.key
|
|
2064
|
-
}
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
});
|
|
1615
|
+
}
|
|
1616
|
+
);
|
|
1617
|
+
})
|
|
1618
|
+
] });
|
|
2068
1619
|
});
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
ErrorBoundary,
|
|
2072
|
-
Form,
|
|
2073
|
-
Link,
|
|
2074
|
-
QWIK_CITY_SCROLLER,
|
|
2075
|
-
QWIK_ROUTER_SCROLLER,
|
|
2076
|
-
QwikCityMockProvider,
|
|
2077
|
-
QwikCityProvider,
|
|
2078
|
-
QwikRouterMockProvider,
|
|
2079
|
-
QwikRouterProvider,
|
|
2080
|
-
RouterOutlet,
|
|
2081
|
-
ServiceWorkerRegister,
|
|
2082
|
-
createRenderer,
|
|
2083
|
-
globalAction$,
|
|
2084
|
-
globalActionQrl,
|
|
2085
|
-
omitProps,
|
|
2086
|
-
routeAction$,
|
|
2087
|
-
routeActionQrl,
|
|
2088
|
-
routeLoader$,
|
|
2089
|
-
routeLoaderQrl,
|
|
2090
|
-
server$,
|
|
2091
|
-
serverQrl,
|
|
2092
|
-
untypedAppUrl,
|
|
2093
|
-
useContent,
|
|
2094
|
-
useDocumentHead,
|
|
2095
|
-
useLocation,
|
|
2096
|
-
useNavigate,
|
|
2097
|
-
usePreventNavigate$,
|
|
2098
|
-
usePreventNavigateQrl,
|
|
2099
|
-
useQwikRouter,
|
|
2100
|
-
valibot$,
|
|
2101
|
-
valibotQrl,
|
|
2102
|
-
validator$,
|
|
2103
|
-
validatorQrl,
|
|
2104
|
-
z2 as z,
|
|
2105
|
-
zod$,
|
|
2106
|
-
zodQrl
|
|
2107
|
-
};
|
|
1620
|
+
|
|
1621
|
+
export { DocumentHeadTags, ErrorBoundary, Form, Link, QWIK_CITY_SCROLLER, QWIK_ROUTER_SCROLLER, QwikCityMockProvider, QwikCityProvider, QwikRouterMockProvider, QwikRouterProvider, RouterOutlet, ServiceWorkerRegister, createRenderer, globalAction$, globalActionQrl, omitProps, routeAction$, routeActionQrl, routeLoader$, routeLoaderQrl, server$, serverQrl, untypedAppUrl, useContent, useDocumentHead, useLocation, useNavigate, usePreventNavigate$, usePreventNavigateQrl, useQwikRouter, valibot$, valibotQrl, validator$, validatorQrl, zod$, zodQrl };
|