vorzelajs 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +188 -0
- package/bin/vorzelajs.mjs +2 -0
- package/dist/analytics.d.ts +132 -0
- package/dist/analytics.d.ts.map +1 -0
- package/dist/analytics.js +690 -0
- package/dist/cli/build.d.ts +2 -0
- package/dist/cli/build.d.ts.map +1 -0
- package/dist/cli/build.js +22 -0
- package/dist/cli/dev.d.ts +2 -0
- package/dist/cli/dev.d.ts.map +1 -0
- package/dist/cli/dev.js +93 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +29 -0
- package/dist/cli/serve.d.ts +2 -0
- package/dist/cli/serve.d.ts.map +1 -0
- package/dist/cli/serve.js +43 -0
- package/dist/cookie.d.ts +33 -0
- package/dist/cookie.d.ts.map +1 -0
- package/dist/cookie.js +198 -0
- package/dist/debug/error-stack.d.ts +14 -0
- package/dist/debug/error-stack.d.ts.map +1 -0
- package/dist/debug/error-stack.js +52 -0
- package/dist/internal/document.d.ts +12 -0
- package/dist/internal/document.d.ts.map +1 -0
- package/dist/internal/document.jsx +56 -0
- package/dist/internal/entry-client.d.ts +2 -0
- package/dist/internal/entry-client.d.ts.map +1 -0
- package/dist/internal/entry-client.jsx +8 -0
- package/dist/internal/entry-server.d.ts +14 -0
- package/dist/internal/entry-server.d.ts.map +1 -0
- package/dist/internal/entry-server.jsx +71 -0
- package/dist/runtime/create-route.d.ts +8 -0
- package/dist/runtime/create-route.d.ts.map +1 -0
- package/dist/runtime/create-route.js +18 -0
- package/dist/runtime/head.d.ts +10 -0
- package/dist/runtime/head.d.ts.map +1 -0
- package/dist/runtime/head.js +111 -0
- package/dist/runtime/index.d.ts +6 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.jsx +4 -0
- package/dist/runtime/navigation.d.ts +36 -0
- package/dist/runtime/navigation.d.ts.map +1 -0
- package/dist/runtime/navigation.js +70 -0
- package/dist/runtime/path.d.ts +11 -0
- package/dist/runtime/path.d.ts.map +1 -0
- package/dist/runtime/path.js +80 -0
- package/dist/runtime/resolve.d.ts +11 -0
- package/dist/runtime/resolve.d.ts.map +1 -0
- package/dist/runtime/resolve.js +449 -0
- package/dist/runtime/runtime.d.ts +40 -0
- package/dist/runtime/runtime.d.ts.map +1 -0
- package/dist/runtime/runtime.jsx +779 -0
- package/dist/runtime/search.d.ts +23 -0
- package/dist/runtime/search.d.ts.map +1 -0
- package/dist/runtime/search.js +178 -0
- package/dist/runtime/server.d.ts +10 -0
- package/dist/runtime/server.d.ts.map +1 -0
- package/dist/runtime/server.js +5 -0
- package/dist/runtime/types.d.ts +248 -0
- package/dist/runtime/types.d.ts.map +1 -0
- package/dist/runtime/types.js +1 -0
- package/dist/seo.d.ts +16 -0
- package/dist/seo.d.ts.map +1 -0
- package/dist/seo.js +69 -0
- package/dist/server/index.d.ts +53 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +268 -0
- package/dist/session.d.ts +23 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +58 -0
- package/dist/vite/index.d.ts +13 -0
- package/dist/vite/index.d.ts.map +1 -0
- package/dist/vite/index.js +174 -0
- package/dist/vite/routes-plugin.d.ts +4 -0
- package/dist/vite/routes-plugin.d.ts.map +1 -0
- package/dist/vite/routes-plugin.js +345 -0
- package/dist/vite/server-only.d.ts +3 -0
- package/dist/vite/server-only.d.ts.map +1 -0
- package/dist/vite/server-only.js +342 -0
- package/package.json +76 -0
- package/templates/bare/README.md +22 -0
- package/templates/bare/src/components/counter-card.tsx +19 -0
- package/templates/bare/src/routes/__root.tsx +24 -0
- package/templates/bare/src/routes/index.tsx +36 -0
- package/templates/base/gitignore +4 -0
- package/templates/base/public/favicon.svg +5 -0
- package/templates/base/tsconfig.json +18 -0
- package/templates/modern/README.md +28 -0
- package/templates/modern/src/components/counter-card.tsx +19 -0
- package/templates/modern/src/routes/__root.tsx +42 -0
- package/templates/modern/src/routes/about.tsx +55 -0
- package/templates/modern/src/routes/index.tsx +51 -0
- package/templates/styling/css/styles.css +269 -0
- package/templates/styling/css-modules/styles.css +269 -0
- package/templates/styling/tailwind/styles.css +271 -0
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
import { parseErrorStack } from '../debug/error-stack';
|
|
2
|
+
// @ts-expect-error resolved by vorzelajs vite plugin
|
|
3
|
+
import { routeHydrationManifest } from 'virtual:vorzela/hydration';
|
|
4
|
+
// @ts-expect-error resolved by vorzelajs vite plugin
|
|
5
|
+
import { routeManifest } from 'virtual:vorzela/routes';
|
|
6
|
+
import { mergeHeads } from './head';
|
|
7
|
+
import { isNotFound, isRedirect } from './navigation';
|
|
8
|
+
import { buildRouteBranch, matchPathPattern, normalizePath } from './path';
|
|
9
|
+
const generatedRouteHydrationManifest = routeHydrationManifest;
|
|
10
|
+
const generatedRouteManifest = routeManifest;
|
|
11
|
+
function createResponseStub() {
|
|
12
|
+
return {
|
|
13
|
+
headers: new Headers(),
|
|
14
|
+
status: 200,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function createClientRequest(pathname) {
|
|
18
|
+
if (typeof window === 'undefined') {
|
|
19
|
+
return new Request(`http://localhost${pathname}`);
|
|
20
|
+
}
|
|
21
|
+
return new Request(new URL(pathname, window.location.origin), {
|
|
22
|
+
headers: {
|
|
23
|
+
'X-Vorzela-Navigation': 'client',
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function createRouteLocation(target, pathname, request) {
|
|
28
|
+
const targetUrl = new URL(target, new URL(request.url).origin);
|
|
29
|
+
return {
|
|
30
|
+
href: targetUrl.href,
|
|
31
|
+
pathname,
|
|
32
|
+
search: targetUrl.search,
|
|
33
|
+
searchParams: targetUrl.searchParams,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function createRawSearch(searchParams) {
|
|
37
|
+
const rawSearch = {};
|
|
38
|
+
for (const key of new Set(searchParams.keys())) {
|
|
39
|
+
const values = searchParams.getAll(key);
|
|
40
|
+
rawSearch[key] = values.length <= 1 ? values[0] : values;
|
|
41
|
+
}
|
|
42
|
+
return rawSearch;
|
|
43
|
+
}
|
|
44
|
+
function selectBestMatch(pathname) {
|
|
45
|
+
return generatedRouteManifest
|
|
46
|
+
.filter((entry) => entry.id !== '__root__' && entry.matchPath !== null)
|
|
47
|
+
.map((entry) => ({
|
|
48
|
+
entry,
|
|
49
|
+
result: matchPathPattern(entry.matchPath, pathname),
|
|
50
|
+
}))
|
|
51
|
+
.filter((candidate) => candidate.result.matched)
|
|
52
|
+
.sort((left, right) => {
|
|
53
|
+
if (left.result.score !== right.result.score) {
|
|
54
|
+
return right.result.score - left.result.score;
|
|
55
|
+
}
|
|
56
|
+
return right.entry.fullPath.length - left.entry.fullPath.length;
|
|
57
|
+
})[0];
|
|
58
|
+
}
|
|
59
|
+
async function loadRouteDefinition(entry) {
|
|
60
|
+
const module = await entry.loadRoute();
|
|
61
|
+
return module.Route;
|
|
62
|
+
}
|
|
63
|
+
function resolveNotFoundHandlerId(loadedEntries) {
|
|
64
|
+
for (let index = loadedEntries.length - 1; index >= 0; index -= 1) {
|
|
65
|
+
const candidate = loadedEntries[index];
|
|
66
|
+
if (candidate.route.options.notFoundComponent) {
|
|
67
|
+
return candidate.entry.id;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
function resolveErrorHandlerId(loadedEntries) {
|
|
73
|
+
for (let index = loadedEntries.length - 1; index >= 0; index -= 1) {
|
|
74
|
+
const candidate = loadedEntries[index];
|
|
75
|
+
if (candidate.route.options.errorComponent) {
|
|
76
|
+
return candidate.entry.id;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
function createRouteErrorData(error, phase) {
|
|
82
|
+
const debug = process.env.NODE_ENV !== 'production'
|
|
83
|
+
? parseErrorStack(error)
|
|
84
|
+
: undefined;
|
|
85
|
+
if (error instanceof Error) {
|
|
86
|
+
return {
|
|
87
|
+
debug,
|
|
88
|
+
message: error.message || 'Unexpected route error',
|
|
89
|
+
name: error.name || 'Error',
|
|
90
|
+
phase,
|
|
91
|
+
status: 500,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
debug,
|
|
96
|
+
message: typeof error === 'string' ? error : 'Unexpected route error',
|
|
97
|
+
name: 'Error',
|
|
98
|
+
phase,
|
|
99
|
+
status: 500,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function createRouteErrorState(loadedEntries, targetId, error, phase) {
|
|
103
|
+
return {
|
|
104
|
+
handlerId: resolveErrorHandlerId(loadedEntries),
|
|
105
|
+
targetId,
|
|
106
|
+
error: createRouteErrorData(error, phase),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function resolveMatchHydration(entry, route) {
|
|
110
|
+
const detected = generatedRouteHydrationManifest[entry.id]?.detected ?? 'static';
|
|
111
|
+
const configured = route.options.hydration ?? 'auto';
|
|
112
|
+
return configured === 'auto' ? detected : configured;
|
|
113
|
+
}
|
|
114
|
+
function createResolvedMatch(entry, route, params, loaderData, search) {
|
|
115
|
+
return {
|
|
116
|
+
fullPath: entry.fullPath,
|
|
117
|
+
hydration: resolveMatchHydration(entry, route),
|
|
118
|
+
id: entry.id,
|
|
119
|
+
loaderData,
|
|
120
|
+
params,
|
|
121
|
+
route,
|
|
122
|
+
search,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function validateRouteSearch(route, rawSearch) {
|
|
126
|
+
return route.options.validateSearch
|
|
127
|
+
? route.options.validateSearch(rawSearch)
|
|
128
|
+
: rawSearch;
|
|
129
|
+
}
|
|
130
|
+
async function materializeMatches(matches) {
|
|
131
|
+
const routesById = new Map(generatedRouteManifest.map((entry) => [entry.id, entry]));
|
|
132
|
+
return Promise.all(matches.map(async (match) => {
|
|
133
|
+
const entry = routesById.get(match.id);
|
|
134
|
+
if (!entry) {
|
|
135
|
+
throw new Error(`Unknown route id: ${match.id}`);
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
...match,
|
|
139
|
+
route: await loadRouteDefinition(entry),
|
|
140
|
+
};
|
|
141
|
+
}));
|
|
142
|
+
}
|
|
143
|
+
export async function resolveRoute(target, options = {}) {
|
|
144
|
+
const normalized = normalizePath(target);
|
|
145
|
+
const request = options.request ?? createClientRequest(target);
|
|
146
|
+
const responseStub = createResponseStub();
|
|
147
|
+
const context = options.context ?? {};
|
|
148
|
+
const location = createRouteLocation(target, normalized, request);
|
|
149
|
+
const rawSearch = createRawSearch(location.searchParams);
|
|
150
|
+
const bestMatch = selectBestMatch(normalized);
|
|
151
|
+
if (!bestMatch) {
|
|
152
|
+
const rootEntry = generatedRouteManifest.find((entry) => entry.id === '__root__');
|
|
153
|
+
if (!rootEntry) {
|
|
154
|
+
throw new Error(`No route matched ${normalized}`);
|
|
155
|
+
}
|
|
156
|
+
const rootRoute = await loadRouteDefinition(rootEntry);
|
|
157
|
+
let rootSearch = rawSearch;
|
|
158
|
+
if (rootRoute.options.validateSearch) {
|
|
159
|
+
try {
|
|
160
|
+
rootSearch = validateRouteSearch(rootRoute, rawSearch);
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
if (isRedirect(error)) {
|
|
164
|
+
throw error;
|
|
165
|
+
}
|
|
166
|
+
if (isNotFound(error)) {
|
|
167
|
+
return {
|
|
168
|
+
head: mergeHeads([]),
|
|
169
|
+
matches: [
|
|
170
|
+
createResolvedMatch(rootEntry, rootRoute, {}, undefined, rawSearch),
|
|
171
|
+
],
|
|
172
|
+
notFound: {
|
|
173
|
+
handlerId: rootRoute.options.notFoundComponent ? rootEntry.id : null,
|
|
174
|
+
targetId: rootEntry.id,
|
|
175
|
+
},
|
|
176
|
+
pathname: normalized,
|
|
177
|
+
renderSource: 'component',
|
|
178
|
+
responseHeaders: responseStub.headers,
|
|
179
|
+
search: location.search,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
head: mergeHeads([]),
|
|
184
|
+
matches: [
|
|
185
|
+
createResolvedMatch(rootEntry, rootRoute, {}, undefined, rawSearch),
|
|
186
|
+
],
|
|
187
|
+
pathname: normalized,
|
|
188
|
+
renderSource: 'component',
|
|
189
|
+
responseHeaders: responseStub.headers,
|
|
190
|
+
routeError: createRouteErrorState([{ entry: rootEntry, route: rootRoute }], rootEntry.id, error, 'validateSearch'),
|
|
191
|
+
search: location.search,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
const head = rootRoute.options.head
|
|
196
|
+
? rootRoute.options.head({
|
|
197
|
+
context,
|
|
198
|
+
loaderData: undefined,
|
|
199
|
+
location,
|
|
200
|
+
params: {},
|
|
201
|
+
pathname: normalized,
|
|
202
|
+
search: rootSearch,
|
|
203
|
+
})
|
|
204
|
+
: undefined;
|
|
205
|
+
return {
|
|
206
|
+
head: mergeHeads([head]),
|
|
207
|
+
matches: [
|
|
208
|
+
createResolvedMatch(rootEntry, rootRoute, {}, undefined, rootSearch),
|
|
209
|
+
],
|
|
210
|
+
notFound: {
|
|
211
|
+
handlerId: rootRoute.options.notFoundComponent ? rootEntry.id : null,
|
|
212
|
+
targetId: rootEntry.id,
|
|
213
|
+
},
|
|
214
|
+
pathname: normalized,
|
|
215
|
+
renderSource: 'component',
|
|
216
|
+
responseHeaders: responseStub.headers,
|
|
217
|
+
search: location.search,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
const branchEntries = buildRouteBranch(generatedRouteManifest, bestMatch.entry.id);
|
|
221
|
+
const accumulatedHeads = [];
|
|
222
|
+
const matches = [];
|
|
223
|
+
const loadedEntries = [];
|
|
224
|
+
for (const entry of branchEntries) {
|
|
225
|
+
const route = await loadRouteDefinition(entry);
|
|
226
|
+
const params = bestMatch.result.params;
|
|
227
|
+
loadedEntries.push({ entry, route });
|
|
228
|
+
let validatedSearch = rawSearch;
|
|
229
|
+
if (route.options.validateSearch) {
|
|
230
|
+
try {
|
|
231
|
+
validatedSearch = validateRouteSearch(route, rawSearch);
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
if (isRedirect(error)) {
|
|
235
|
+
throw error;
|
|
236
|
+
}
|
|
237
|
+
if (isNotFound(error)) {
|
|
238
|
+
matches.push(createResolvedMatch(entry, route, params, undefined, rawSearch));
|
|
239
|
+
return {
|
|
240
|
+
head: mergeHeads(accumulatedHeads),
|
|
241
|
+
matches,
|
|
242
|
+
notFound: {
|
|
243
|
+
handlerId: resolveNotFoundHandlerId(loadedEntries),
|
|
244
|
+
targetId: entry.id,
|
|
245
|
+
},
|
|
246
|
+
pathname: normalized,
|
|
247
|
+
renderSource: 'component',
|
|
248
|
+
responseHeaders: responseStub.headers,
|
|
249
|
+
search: location.search,
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
matches.push(createResolvedMatch(entry, route, params, undefined, rawSearch));
|
|
253
|
+
return {
|
|
254
|
+
head: mergeHeads(accumulatedHeads),
|
|
255
|
+
matches,
|
|
256
|
+
pathname: normalized,
|
|
257
|
+
renderSource: 'component',
|
|
258
|
+
responseHeaders: responseStub.headers,
|
|
259
|
+
routeError: createRouteErrorState(loadedEntries, entry.id, error, 'validateSearch'),
|
|
260
|
+
search: location.search,
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
if (route.options.beforeLoad) {
|
|
265
|
+
try {
|
|
266
|
+
const beforeLoadResult = await route.options.beforeLoad({
|
|
267
|
+
context,
|
|
268
|
+
location,
|
|
269
|
+
params: params,
|
|
270
|
+
pathname: normalized,
|
|
271
|
+
request,
|
|
272
|
+
response: responseStub,
|
|
273
|
+
search: validatedSearch,
|
|
274
|
+
});
|
|
275
|
+
if (isRedirect(beforeLoadResult) || isNotFound(beforeLoadResult)) {
|
|
276
|
+
throw beforeLoadResult;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
catch (error) {
|
|
280
|
+
if (isRedirect(error)) {
|
|
281
|
+
throw error;
|
|
282
|
+
}
|
|
283
|
+
if (isNotFound(error)) {
|
|
284
|
+
matches.push(createResolvedMatch(entry, route, params, undefined, validatedSearch));
|
|
285
|
+
return {
|
|
286
|
+
head: mergeHeads(accumulatedHeads),
|
|
287
|
+
matches,
|
|
288
|
+
notFound: {
|
|
289
|
+
handlerId: resolveNotFoundHandlerId(loadedEntries),
|
|
290
|
+
targetId: entry.id,
|
|
291
|
+
},
|
|
292
|
+
pathname: normalized,
|
|
293
|
+
renderSource: 'component',
|
|
294
|
+
responseHeaders: responseStub.headers,
|
|
295
|
+
search: location.search,
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
matches.push(createResolvedMatch(entry, route, params, undefined, validatedSearch));
|
|
299
|
+
return {
|
|
300
|
+
head: mergeHeads(accumulatedHeads),
|
|
301
|
+
matches,
|
|
302
|
+
pathname: normalized,
|
|
303
|
+
renderSource: 'component',
|
|
304
|
+
responseHeaders: responseStub.headers,
|
|
305
|
+
routeError: createRouteErrorState(loadedEntries, entry.id, error, 'beforeLoad'),
|
|
306
|
+
search: location.search,
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
let loaderData;
|
|
311
|
+
if (route.options.loader) {
|
|
312
|
+
try {
|
|
313
|
+
loaderData = await route.options.loader({
|
|
314
|
+
context,
|
|
315
|
+
location,
|
|
316
|
+
params: params,
|
|
317
|
+
pathname: normalized,
|
|
318
|
+
request,
|
|
319
|
+
response: responseStub,
|
|
320
|
+
search: validatedSearch,
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
catch (error) {
|
|
324
|
+
if (isRedirect(error)) {
|
|
325
|
+
throw error;
|
|
326
|
+
}
|
|
327
|
+
if (isNotFound(error)) {
|
|
328
|
+
matches.push(createResolvedMatch(entry, route, params, undefined, validatedSearch));
|
|
329
|
+
return {
|
|
330
|
+
head: mergeHeads(accumulatedHeads),
|
|
331
|
+
matches,
|
|
332
|
+
notFound: {
|
|
333
|
+
handlerId: resolveNotFoundHandlerId(loadedEntries),
|
|
334
|
+
targetId: entry.id,
|
|
335
|
+
},
|
|
336
|
+
pathname: normalized,
|
|
337
|
+
renderSource: 'component',
|
|
338
|
+
responseHeaders: responseStub.headers,
|
|
339
|
+
search: location.search,
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
matches.push(createResolvedMatch(entry, route, params, undefined, validatedSearch));
|
|
343
|
+
return {
|
|
344
|
+
head: mergeHeads(accumulatedHeads),
|
|
345
|
+
matches,
|
|
346
|
+
pathname: normalized,
|
|
347
|
+
renderSource: 'component',
|
|
348
|
+
responseHeaders: responseStub.headers,
|
|
349
|
+
routeError: createRouteErrorState(loadedEntries, entry.id, error, 'loader'),
|
|
350
|
+
search: location.search,
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
let head;
|
|
355
|
+
if (route.options.head) {
|
|
356
|
+
try {
|
|
357
|
+
head = route.options.head({
|
|
358
|
+
context,
|
|
359
|
+
loaderData,
|
|
360
|
+
location,
|
|
361
|
+
params: params,
|
|
362
|
+
pathname: normalized,
|
|
363
|
+
search: validatedSearch,
|
|
364
|
+
});
|
|
365
|
+
if (head) {
|
|
366
|
+
accumulatedHeads.push(head);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
catch (error) {
|
|
370
|
+
matches.push(createResolvedMatch(entry, route, params, loaderData, validatedSearch));
|
|
371
|
+
return {
|
|
372
|
+
head: mergeHeads(accumulatedHeads),
|
|
373
|
+
matches,
|
|
374
|
+
pathname: normalized,
|
|
375
|
+
renderSource: 'component',
|
|
376
|
+
responseHeaders: responseStub.headers,
|
|
377
|
+
routeError: createRouteErrorState(loadedEntries, entry.id, error, 'render'),
|
|
378
|
+
search: location.search,
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
matches.push(createResolvedMatch(entry, route, params, loaderData, validatedSearch));
|
|
383
|
+
}
|
|
384
|
+
return {
|
|
385
|
+
head: mergeHeads(accumulatedHeads),
|
|
386
|
+
matches,
|
|
387
|
+
pathname: normalized,
|
|
388
|
+
renderSource: 'component',
|
|
389
|
+
responseHeaders: responseStub.headers,
|
|
390
|
+
search: location.search,
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
export function serializeRouteState(state) {
|
|
394
|
+
return {
|
|
395
|
+
head: state.head,
|
|
396
|
+
matches: state.matches.map((match) => ({
|
|
397
|
+
fullPath: match.fullPath,
|
|
398
|
+
hydration: match.hydration,
|
|
399
|
+
id: match.id,
|
|
400
|
+
loaderData: match.loaderData,
|
|
401
|
+
params: match.params,
|
|
402
|
+
search: match.search,
|
|
403
|
+
})),
|
|
404
|
+
notFound: state.notFound,
|
|
405
|
+
pathname: state.pathname,
|
|
406
|
+
routeError: state.routeError,
|
|
407
|
+
search: state.search,
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
export async function materializeBootstrapPayload(payload) {
|
|
411
|
+
return {
|
|
412
|
+
head: payload.head,
|
|
413
|
+
matches: await materializeMatches(payload.matches),
|
|
414
|
+
notFound: payload.notFound,
|
|
415
|
+
pathname: payload.pathname,
|
|
416
|
+
renderSource: 'component',
|
|
417
|
+
routeError: payload.routeError,
|
|
418
|
+
search: payload.search,
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
export async function materializePayloadEnvelope(payload) {
|
|
422
|
+
return {
|
|
423
|
+
head: payload.head,
|
|
424
|
+
matches: await materializeMatches(payload.matches),
|
|
425
|
+
notFound: payload.notFound,
|
|
426
|
+
pathname: payload.pathname,
|
|
427
|
+
payloadHtml: payload.html,
|
|
428
|
+
renderSource: 'payload',
|
|
429
|
+
routeError: payload.routeError,
|
|
430
|
+
search: payload.search,
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
export function getResolvedRouteStatus(state) {
|
|
434
|
+
if (state.routeError) {
|
|
435
|
+
return state.routeError.error.status;
|
|
436
|
+
}
|
|
437
|
+
if (state.notFound) {
|
|
438
|
+
return 404;
|
|
439
|
+
}
|
|
440
|
+
const leaf = state.matches[state.matches.length - 1];
|
|
441
|
+
return leaf?.id === '/$' || leaf?.id.endsWith('/$') ? 404 : 200;
|
|
442
|
+
}
|
|
443
|
+
export function isNotFoundState(state) {
|
|
444
|
+
if (state.notFound) {
|
|
445
|
+
return true;
|
|
446
|
+
}
|
|
447
|
+
const leaf = state.matches[state.matches.length - 1];
|
|
448
|
+
return leaf?.id === '/$' || leaf?.id.endsWith('/$');
|
|
449
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Accessor, JSX } from 'solid-js';
|
|
2
|
+
import type { BootstrapPayload, NavigateToOptions, ResolvedRouteState, RouteErrorData, RouterCreateOptions, RouteSearch, SetSearchFunction } from './types';
|
|
3
|
+
type NavigationOptions = {
|
|
4
|
+
force?: boolean;
|
|
5
|
+
replace?: boolean;
|
|
6
|
+
scroll?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export interface VorzelaRouter {
|
|
9
|
+
context: Record<string, unknown>;
|
|
10
|
+
init: () => Promise<void>;
|
|
11
|
+
navigate: (to: string | NavigateToOptions, options?: NavigationOptions) => Promise<void>;
|
|
12
|
+
prefetch: (to: string | NavigateToOptions) => Promise<void>;
|
|
13
|
+
setSearch: SetSearchFunction;
|
|
14
|
+
state: Accessor<ResolvedRouteState>;
|
|
15
|
+
}
|
|
16
|
+
export declare function createRouter(initialPayload: BootstrapPayload, options?: RouterCreateOptions): VorzelaRouter;
|
|
17
|
+
type RenderResolvedMatchesOptions = {
|
|
18
|
+
onRenderError?: (error: RouteErrorData) => void;
|
|
19
|
+
retry?: () => void;
|
|
20
|
+
wrapHydrationBoundaries?: boolean;
|
|
21
|
+
};
|
|
22
|
+
export declare function renderResolvedMatches(state: Pick<ResolvedRouteState, 'matches' | 'notFound' | 'payloadHtml' | 'renderSource' | 'routeError'>, options?: RenderResolvedMatchesOptions): JSX.Element;
|
|
23
|
+
export declare function RouterProvider(props: {
|
|
24
|
+
router: VorzelaRouter;
|
|
25
|
+
}): JSX.Element;
|
|
26
|
+
export declare function Outlet(): number | boolean | Node | JSX.ArrayElement | (string & {}) | null;
|
|
27
|
+
export declare function useRouter(): VorzelaRouter;
|
|
28
|
+
export declare function useNavigate(): (to: string | NavigateToOptions, options?: NavigationOptions) => Promise<void>;
|
|
29
|
+
export declare function useParams<T extends Record<string, string> = Record<string, string>>(): T;
|
|
30
|
+
export declare function useLoaderData<T = unknown>(): T;
|
|
31
|
+
export declare function useSearch<T extends RouteSearch = RouteSearch>(): () => T;
|
|
32
|
+
export declare function useSetSearch<T extends RouteSearch = RouteSearch>(): SetSearchFunction<T>;
|
|
33
|
+
export declare function readBootstrapPayload(): BootstrapPayload;
|
|
34
|
+
type LinkProps = JSX.AnchorHTMLAttributes<HTMLAnchorElement> & {
|
|
35
|
+
replace?: boolean;
|
|
36
|
+
to: string;
|
|
37
|
+
};
|
|
38
|
+
export declare function Link(props: LinkProps): JSX.Element;
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/runtime/runtime.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAa,GAAG,EAAE,MAAM,UAAU,CAAA;AAYxD,OAAO,KAAK,EACV,gBAAgB,EAChB,iBAAiB,EAEjB,kBAAkB,EAIlB,cAAc,EAId,mBAAmB,EAEnB,WAAW,EACX,iBAAiB,EAElB,MAAM,SAAS,CAAA;AAEhB,KAAK,iBAAiB,GAAG;IACvB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB,CAAA;AAaD,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAChC,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IACzB,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,iBAAiB,EAAE,OAAO,CAAC,EAAE,iBAAiB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACxF,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,iBAAiB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC3D,SAAS,EAAE,iBAAiB,CAAA;IAC5B,KAAK,EAAE,QAAQ,CAAC,kBAAkB,CAAC,CAAA;CACpC;AAsUD,wBAAgB,YAAY,CAC1B,cAAc,EAAE,gBAAgB,EAChC,OAAO,GAAE,mBAAwB,GAChC,aAAa,CA6Wf;AAMD,KAAK,4BAA4B,GAAG;IAClC,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAA;IAC/C,KAAK,CAAC,EAAE,MAAM,IAAI,CAAA;IAClB,uBAAuB,CAAC,EAAE,OAAO,CAAA;CAClC,CAAA;AAED,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,IAAI,CAAC,kBAAkB,EAAE,SAAS,GAAG,UAAU,GAAG,aAAa,GAAG,cAAc,GAAG,YAAY,CAAC,EACvG,OAAO,GAAE,4BAAiC,GACzC,GAAG,CAAC,OAAO,CA8Gb;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE;IAAE,MAAM,EAAE,aAAa,CAAA;CAAE,eA2D9D;AAED,wBAAgB,MAAM,sEAErB;AAED,wBAAgB,SAAS,kBAQxB;AAED,wBAAgB,WAAW,KAGjB,IAAI,MAAM,GAAG,iBAAiB,EAAE,UAAU,iBAAiB,mBAOpE;AAED,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAO1D,CAAC,CACzB;AAED,wBAAgB,aAAa,CAAC,CAAC,GAAG,OAAO,KAOZ,CAAC,CAC7B;AAED,wBAAgB,SAAS,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,aAgB5D;AAED,wBAAgB,YAAY,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,KAAK,iBAAiB,CAAC,CAAC,CAAC,CAuBxF;AAED,wBAAgB,oBAAoB,IAAI,gBAAgB,CAQvD;AAED,KAAK,SAAS,GAAG,GAAG,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,GAAG;IAC7D,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,EAAE,EAAE,MAAM,CAAA;CACX,CAAA;AAED,wBAAgB,IAAI,CAAC,KAAK,EAAE,SAAS,eAqFpC"}
|