@alepha/react 0.7.4 → 0.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.browser.cjs +28 -11
- package/dist/index.browser.js +5 -5
- package/dist/index.cjs +27 -256
- package/dist/index.d.ts +62 -60
- package/dist/index.js +6 -235
- package/dist/{ReactBrowserProvider-CXDElhnK.cjs → useRouterState-BTmuHxkM.cjs} +241 -18
- package/dist/{ReactBrowserProvider-ufHSOTmv.js → useRouterState-cCucJfTC.js} +234 -19
- package/package.json +6 -6
- package/src/components/NotFound.tsx +0 -10
- package/src/descriptors/$page.ts +5 -2
- package/src/index.browser.ts +1 -0
- package/src/index.shared.ts +0 -4
- package/src/index.ts +0 -2
package/dist/index.browser.cjs
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var core = require('@alepha/core');
|
|
4
|
-
var
|
|
4
|
+
var useRouterState = require('./useRouterState-BTmuHxkM.cjs');
|
|
5
5
|
var client = require('react-dom/client');
|
|
6
|
+
require('react/jsx-runtime');
|
|
7
|
+
require('react');
|
|
6
8
|
require('@alepha/server');
|
|
7
9
|
require('@alepha/router');
|
|
8
|
-
require('react');
|
|
9
|
-
require('react/jsx-runtime');
|
|
10
10
|
|
|
11
11
|
const envSchema = core.t.object({
|
|
12
12
|
REACT_ROOT_ID: core.t.string({ default: "root" })
|
|
13
13
|
});
|
|
14
14
|
class ReactBrowserRenderer {
|
|
15
|
-
browserProvider = core.$inject(
|
|
16
|
-
browserRouterProvider = core.$inject(
|
|
15
|
+
browserProvider = core.$inject(useRouterState.ReactBrowserProvider);
|
|
16
|
+
browserRouterProvider = core.$inject(useRouterState.BrowserRouterProvider);
|
|
17
17
|
env = core.$inject(envSchema);
|
|
18
18
|
log = core.$logger();
|
|
19
19
|
root;
|
|
@@ -47,12 +47,29 @@ class ReactBrowserRenderer {
|
|
|
47
47
|
|
|
48
48
|
class AlephaReact {
|
|
49
49
|
name = "alepha.react";
|
|
50
|
-
$services = (alepha) => alepha.with(
|
|
50
|
+
$services = (alepha) => alepha.with(useRouterState.PageDescriptorProvider).with(useRouterState.ReactBrowserProvider).with(useRouterState.BrowserRouterProvider).with(ReactBrowserRenderer);
|
|
51
51
|
}
|
|
52
|
-
core.__bind(
|
|
52
|
+
core.__bind(useRouterState.$page, AlephaReact);
|
|
53
53
|
|
|
54
|
-
exports
|
|
55
|
-
exports.
|
|
56
|
-
exports.
|
|
57
|
-
exports.
|
|
54
|
+
exports.$page = useRouterState.$page;
|
|
55
|
+
exports.BrowserRouterProvider = useRouterState.BrowserRouterProvider;
|
|
56
|
+
exports.ClientOnly = useRouterState.ClientOnly;
|
|
57
|
+
exports.ErrorBoundary = useRouterState.ErrorBoundary;
|
|
58
|
+
exports.Link = useRouterState.Link;
|
|
59
|
+
exports.NestedView = useRouterState.NestedView;
|
|
60
|
+
exports.PageDescriptorProvider = useRouterState.PageDescriptorProvider;
|
|
61
|
+
exports.ReactBrowserProvider = useRouterState.ReactBrowserProvider;
|
|
62
|
+
exports.RedirectionError = useRouterState.RedirectionError;
|
|
63
|
+
exports.RouterContext = useRouterState.RouterContext;
|
|
64
|
+
exports.RouterHookApi = useRouterState.RouterHookApi;
|
|
65
|
+
exports.RouterLayerContext = useRouterState.RouterLayerContext;
|
|
66
|
+
exports.isPageRoute = useRouterState.isPageRoute;
|
|
67
|
+
exports.useActive = useRouterState.useActive;
|
|
68
|
+
exports.useAlepha = useRouterState.useAlepha;
|
|
69
|
+
exports.useClient = useRouterState.useClient;
|
|
70
|
+
exports.useInject = useRouterState.useInject;
|
|
71
|
+
exports.useQueryParams = useRouterState.useQueryParams;
|
|
72
|
+
exports.useRouter = useRouterState.useRouter;
|
|
73
|
+
exports.useRouterEvents = useRouterState.useRouterEvents;
|
|
74
|
+
exports.useRouterState = useRouterState.useRouterState;
|
|
58
75
|
exports.AlephaReact = AlephaReact;
|
package/dist/index.browser.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { t, $inject, $logger, $hook, __bind } from '@alepha/core';
|
|
2
|
-
import {
|
|
3
|
-
export {
|
|
2
|
+
import { l as ReactBrowserProvider, B as BrowserRouterProvider, $ as $page, P as PageDescriptorProvider } from './useRouterState-cCucJfTC.js';
|
|
3
|
+
export { C as ClientOnly, E as ErrorBoundary, L as Link, N as NestedView, b as RedirectionError, R as RouterContext, c as RouterHookApi, a as RouterLayerContext, k as isPageRoute, u as useActive, d as useAlepha, e as useClient, f as useInject, g as useQueryParams, h as useRouter, i as useRouterEvents, j as useRouterState } from './useRouterState-cCucJfTC.js';
|
|
4
4
|
import { hydrateRoot, createRoot } from 'react-dom/client';
|
|
5
|
+
import 'react/jsx-runtime';
|
|
6
|
+
import 'react';
|
|
5
7
|
import '@alepha/server';
|
|
6
8
|
import '@alepha/router';
|
|
7
|
-
import 'react';
|
|
8
|
-
import 'react/jsx-runtime';
|
|
9
9
|
|
|
10
10
|
const envSchema = t.object({
|
|
11
11
|
REACT_ROOT_ID: t.string({ default: "root" })
|
|
@@ -50,4 +50,4 @@ class AlephaReact {
|
|
|
50
50
|
}
|
|
51
51
|
__bind($page, AlephaReact);
|
|
52
52
|
|
|
53
|
-
export { AlephaReact, BrowserRouterProvider, PageDescriptorProvider, ReactBrowserProvider };
|
|
53
|
+
export { $page, AlephaReact, BrowserRouterProvider, PageDescriptorProvider, ReactBrowserProvider };
|
package/dist/index.cjs
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
var core = require('@alepha/core');
|
|
4
4
|
var server = require('@alepha/server');
|
|
5
5
|
var serverCache = require('@alepha/server-cache');
|
|
6
|
-
var
|
|
6
|
+
var useRouterState = require('./useRouterState-BTmuHxkM.cjs');
|
|
7
7
|
var node_fs = require('node:fs');
|
|
8
8
|
var node_path = require('node:path');
|
|
9
9
|
var serverStatic = require('@alepha/server-static');
|
|
10
10
|
var server$1 = require('react-dom/server');
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
require('react/jsx-runtime');
|
|
12
|
+
require('react');
|
|
13
13
|
require('@alepha/router');
|
|
14
14
|
|
|
15
15
|
class ServerHeadProvider {
|
|
@@ -83,7 +83,7 @@ const envSchema = core.t.object({
|
|
|
83
83
|
class ReactServerProvider {
|
|
84
84
|
log = core.$logger();
|
|
85
85
|
alepha = core.$inject(core.Alepha);
|
|
86
|
-
pageDescriptorProvider = core.$inject(
|
|
86
|
+
pageDescriptorProvider = core.$inject(useRouterState.PageDescriptorProvider);
|
|
87
87
|
serverStaticProvider = core.$inject(serverStatic.ServerStaticProvider);
|
|
88
88
|
serverRouterProvider = core.$inject(server.ServerRouterProvider);
|
|
89
89
|
headProvider = core.$inject(ServerHeadProvider);
|
|
@@ -96,7 +96,7 @@ class ReactServerProvider {
|
|
|
96
96
|
onConfigure = core.$hook({
|
|
97
97
|
name: "configure",
|
|
98
98
|
handler: async () => {
|
|
99
|
-
const pages = this.alepha.getDescriptorValues(
|
|
99
|
+
const pages = this.alepha.getDescriptorValues(useRouterState.$page);
|
|
100
100
|
const ssrEnabled = pages.length > 0 && this.env.REACT_SSR_ENABLED !== false;
|
|
101
101
|
this.alepha.state("ReactServerProvider.ssr", ssrEnabled);
|
|
102
102
|
for (const { key, instance, value } of pages) {
|
|
@@ -354,260 +354,31 @@ class ReactServerProvider {
|
|
|
354
354
|
}
|
|
355
355
|
}
|
|
356
356
|
|
|
357
|
-
class RouterHookApi {
|
|
358
|
-
constructor(pages, state, layer, browser) {
|
|
359
|
-
this.pages = pages;
|
|
360
|
-
this.state = state;
|
|
361
|
-
this.layer = layer;
|
|
362
|
-
this.browser = browser;
|
|
363
|
-
}
|
|
364
|
-
get current() {
|
|
365
|
-
return this.state;
|
|
366
|
-
}
|
|
367
|
-
get pathname() {
|
|
368
|
-
return this.state.pathname;
|
|
369
|
-
}
|
|
370
|
-
get query() {
|
|
371
|
-
const query = {};
|
|
372
|
-
for (const [key, value] of new URLSearchParams(
|
|
373
|
-
this.state.search
|
|
374
|
-
).entries()) {
|
|
375
|
-
query[key] = String(value);
|
|
376
|
-
}
|
|
377
|
-
return query;
|
|
378
|
-
}
|
|
379
|
-
async back() {
|
|
380
|
-
this.browser?.history.back();
|
|
381
|
-
}
|
|
382
|
-
async forward() {
|
|
383
|
-
this.browser?.history.forward();
|
|
384
|
-
}
|
|
385
|
-
async invalidate(props) {
|
|
386
|
-
await this.browser?.invalidate(props);
|
|
387
|
-
}
|
|
388
|
-
/**
|
|
389
|
-
* Create a valid href for the given pathname.
|
|
390
|
-
*
|
|
391
|
-
* @param pathname
|
|
392
|
-
* @param layer
|
|
393
|
-
*/
|
|
394
|
-
createHref(pathname, layer = this.layer, options = {}) {
|
|
395
|
-
if (typeof pathname === "object") {
|
|
396
|
-
pathname = pathname.options.path ?? "";
|
|
397
|
-
}
|
|
398
|
-
if (options.params) {
|
|
399
|
-
for (const [key, value] of Object.entries(options.params)) {
|
|
400
|
-
pathname = pathname.replace(`:${key}`, String(value));
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
return pathname.startsWith("/") ? pathname : `${layer.path}/${pathname}`.replace(/\/\/+/g, "/");
|
|
404
|
-
}
|
|
405
|
-
async go(path, options) {
|
|
406
|
-
for (const page of this.pages) {
|
|
407
|
-
if (page.name === path) {
|
|
408
|
-
path = page.path ?? "";
|
|
409
|
-
break;
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
await this.browser?.go(this.createHref(path, this.layer, options), options);
|
|
413
|
-
}
|
|
414
|
-
anchor(path, options = {}) {
|
|
415
|
-
for (const page of this.pages) {
|
|
416
|
-
if (page.name === path) {
|
|
417
|
-
path = page.path ?? "";
|
|
418
|
-
break;
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
const href = this.createHref(path, this.layer, options);
|
|
422
|
-
return {
|
|
423
|
-
href,
|
|
424
|
-
onClick: (ev) => {
|
|
425
|
-
ev.stopPropagation();
|
|
426
|
-
ev.preventDefault();
|
|
427
|
-
this.go(path, options).catch(console.error);
|
|
428
|
-
}
|
|
429
|
-
};
|
|
430
|
-
}
|
|
431
|
-
/**
|
|
432
|
-
* Set query params.
|
|
433
|
-
*
|
|
434
|
-
* @param record
|
|
435
|
-
* @param options
|
|
436
|
-
*/
|
|
437
|
-
setQueryParams(record, options = {}) {
|
|
438
|
-
const func = typeof record === "function" ? record : () => record;
|
|
439
|
-
const search = new URLSearchParams(func(this.query)).toString();
|
|
440
|
-
const state = search ? `${this.pathname}?${search}` : this.pathname;
|
|
441
|
-
if (options.push) {
|
|
442
|
-
window.history.pushState({}, "", state);
|
|
443
|
-
} else {
|
|
444
|
-
window.history.replaceState({}, "", state);
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
const useRouter = () => {
|
|
450
|
-
const ctx = React.useContext(ReactBrowserProvider.RouterContext);
|
|
451
|
-
const layer = React.useContext(ReactBrowserProvider.RouterLayerContext);
|
|
452
|
-
if (!ctx || !layer) {
|
|
453
|
-
throw new Error("useRouter must be used within a RouterProvider");
|
|
454
|
-
}
|
|
455
|
-
const pages = React.useMemo(() => {
|
|
456
|
-
return ctx.alepha.get(ReactBrowserProvider.PageDescriptorProvider).getPages();
|
|
457
|
-
}, []);
|
|
458
|
-
return React.useMemo(
|
|
459
|
-
() => new RouterHookApi(
|
|
460
|
-
pages,
|
|
461
|
-
ctx.state,
|
|
462
|
-
layer,
|
|
463
|
-
ctx.alepha.isBrowser() ? ctx.alepha.get(ReactBrowserProvider.ReactBrowserProvider) : void 0
|
|
464
|
-
),
|
|
465
|
-
[layer]
|
|
466
|
-
);
|
|
467
|
-
};
|
|
468
|
-
|
|
469
|
-
const Link = (props) => {
|
|
470
|
-
React.useContext(ReactBrowserProvider.RouterContext);
|
|
471
|
-
const router = useRouter();
|
|
472
|
-
const to = typeof props.to === "string" ? props.to : props.to[core.OPTIONS].path;
|
|
473
|
-
if (!to) {
|
|
474
|
-
return null;
|
|
475
|
-
}
|
|
476
|
-
const can = typeof props.to === "string" ? void 0 : props.to[core.OPTIONS].can;
|
|
477
|
-
if (can && !can()) {
|
|
478
|
-
return null;
|
|
479
|
-
}
|
|
480
|
-
const name = typeof props.to === "string" ? void 0 : props.to[core.OPTIONS].name;
|
|
481
|
-
const anchorProps = {
|
|
482
|
-
...props,
|
|
483
|
-
to: void 0
|
|
484
|
-
};
|
|
485
|
-
return /* @__PURE__ */ jsxRuntime.jsx("a", { ...router.anchor(to), ...anchorProps, children: props.children ?? name });
|
|
486
|
-
};
|
|
487
|
-
|
|
488
|
-
const useActive = (path) => {
|
|
489
|
-
const router = useRouter();
|
|
490
|
-
const ctx = React.useContext(ReactBrowserProvider.RouterContext);
|
|
491
|
-
const layer = React.useContext(ReactBrowserProvider.RouterLayerContext);
|
|
492
|
-
if (!ctx || !layer) {
|
|
493
|
-
throw new Error("useRouter must be used within a RouterProvider");
|
|
494
|
-
}
|
|
495
|
-
let name;
|
|
496
|
-
if (typeof path === "object" && path.options.name) {
|
|
497
|
-
name = path.options.name;
|
|
498
|
-
}
|
|
499
|
-
const [current, setCurrent] = React.useState(ctx.state.pathname);
|
|
500
|
-
const href = React.useMemo(() => router.createHref(path, layer), [path, layer]);
|
|
501
|
-
const [isPending, setPending] = React.useState(false);
|
|
502
|
-
const isActive = current === href;
|
|
503
|
-
ReactBrowserProvider.useRouterEvents({
|
|
504
|
-
onEnd: ({ state }) => setCurrent(state.pathname)
|
|
505
|
-
});
|
|
506
|
-
return {
|
|
507
|
-
name,
|
|
508
|
-
isPending,
|
|
509
|
-
isActive,
|
|
510
|
-
anchorProps: {
|
|
511
|
-
href,
|
|
512
|
-
onClick: (ev) => {
|
|
513
|
-
ev.stopPropagation();
|
|
514
|
-
ev.preventDefault();
|
|
515
|
-
if (isActive) return;
|
|
516
|
-
if (isPending) return;
|
|
517
|
-
setPending(true);
|
|
518
|
-
router.go(href).then(() => {
|
|
519
|
-
setPending(false);
|
|
520
|
-
});
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
};
|
|
524
|
-
};
|
|
525
|
-
|
|
526
|
-
const useInject = (clazz) => {
|
|
527
|
-
const ctx = React.useContext(ReactBrowserProvider.RouterContext);
|
|
528
|
-
if (!ctx) {
|
|
529
|
-
throw new Error("useRouter must be used within a <RouterProvider>");
|
|
530
|
-
}
|
|
531
|
-
return React.useMemo(() => ctx.alepha.get(clazz), []);
|
|
532
|
-
};
|
|
533
|
-
|
|
534
|
-
const useClient = (_scope) => {
|
|
535
|
-
return useInject(server.HttpClient).of();
|
|
536
|
-
};
|
|
537
|
-
|
|
538
|
-
const useQueryParams = (schema, options = {}) => {
|
|
539
|
-
const ctx = React.useContext(ReactBrowserProvider.RouterContext);
|
|
540
|
-
if (!ctx) {
|
|
541
|
-
throw new Error("useQueryParams must be used within a RouterProvider");
|
|
542
|
-
}
|
|
543
|
-
const key = options.key ?? "q";
|
|
544
|
-
const router = useRouter();
|
|
545
|
-
const querystring = router.query[key];
|
|
546
|
-
const [queryParams, setQueryParams] = React.useState(
|
|
547
|
-
decode(ctx.alepha, schema, router.query[key])
|
|
548
|
-
);
|
|
549
|
-
React.useEffect(() => {
|
|
550
|
-
setQueryParams(decode(ctx.alepha, schema, querystring));
|
|
551
|
-
}, [querystring]);
|
|
552
|
-
return [
|
|
553
|
-
queryParams,
|
|
554
|
-
(queryParams2) => {
|
|
555
|
-
setQueryParams(queryParams2);
|
|
556
|
-
router.setQueryParams((data) => {
|
|
557
|
-
return { ...data, [key]: encode(ctx.alepha, schema, queryParams2) };
|
|
558
|
-
});
|
|
559
|
-
}
|
|
560
|
-
];
|
|
561
|
-
};
|
|
562
|
-
const encode = (alepha, schema, data) => {
|
|
563
|
-
return btoa(JSON.stringify(alepha.parse(schema, data)));
|
|
564
|
-
};
|
|
565
|
-
const decode = (alepha, schema, data) => {
|
|
566
|
-
try {
|
|
567
|
-
return alepha.parse(schema, JSON.parse(atob(decodeURIComponent(data))));
|
|
568
|
-
} catch (_error) {
|
|
569
|
-
return {};
|
|
570
|
-
}
|
|
571
|
-
};
|
|
572
|
-
|
|
573
|
-
const useRouterState = () => {
|
|
574
|
-
const ctx = React.useContext(ReactBrowserProvider.RouterContext);
|
|
575
|
-
const layer = React.useContext(ReactBrowserProvider.RouterLayerContext);
|
|
576
|
-
if (!ctx || !layer) {
|
|
577
|
-
throw new Error("useRouter must be used within a RouterProvider");
|
|
578
|
-
}
|
|
579
|
-
const [state, setState] = React.useState(ctx.state);
|
|
580
|
-
ReactBrowserProvider.useRouterEvents({
|
|
581
|
-
onEnd: ({ state: state2 }) => setState({ ...state2 })
|
|
582
|
-
});
|
|
583
|
-
return state;
|
|
584
|
-
};
|
|
585
|
-
|
|
586
357
|
class AlephaReact {
|
|
587
358
|
name = "alepha.react";
|
|
588
|
-
$services = (alepha) => alepha.with(server.AlephaServer).with(serverCache.AlephaServerCache).with(ReactServerProvider).with(
|
|
359
|
+
$services = (alepha) => alepha.with(server.AlephaServer).with(serverCache.AlephaServerCache).with(ReactServerProvider).with(useRouterState.PageDescriptorProvider);
|
|
589
360
|
}
|
|
590
|
-
core.__bind(
|
|
361
|
+
core.__bind(useRouterState.$page, AlephaReact);
|
|
591
362
|
|
|
592
|
-
exports.$page =
|
|
593
|
-
exports.ClientOnly =
|
|
594
|
-
exports.ErrorBoundary =
|
|
595
|
-
exports.
|
|
596
|
-
exports.
|
|
597
|
-
exports.
|
|
598
|
-
exports.
|
|
599
|
-
exports.
|
|
600
|
-
exports.
|
|
601
|
-
exports.
|
|
602
|
-
exports.
|
|
603
|
-
exports.
|
|
363
|
+
exports.$page = useRouterState.$page;
|
|
364
|
+
exports.ClientOnly = useRouterState.ClientOnly;
|
|
365
|
+
exports.ErrorBoundary = useRouterState.ErrorBoundary;
|
|
366
|
+
exports.Link = useRouterState.Link;
|
|
367
|
+
exports.NestedView = useRouterState.NestedView;
|
|
368
|
+
exports.PageDescriptorProvider = useRouterState.PageDescriptorProvider;
|
|
369
|
+
exports.ReactBrowserProvider = useRouterState.ReactBrowserProvider;
|
|
370
|
+
exports.RedirectionError = useRouterState.RedirectionError;
|
|
371
|
+
exports.RouterContext = useRouterState.RouterContext;
|
|
372
|
+
exports.RouterHookApi = useRouterState.RouterHookApi;
|
|
373
|
+
exports.RouterLayerContext = useRouterState.RouterLayerContext;
|
|
374
|
+
exports.isPageRoute = useRouterState.isPageRoute;
|
|
375
|
+
exports.useActive = useRouterState.useActive;
|
|
376
|
+
exports.useAlepha = useRouterState.useAlepha;
|
|
377
|
+
exports.useClient = useRouterState.useClient;
|
|
378
|
+
exports.useInject = useRouterState.useInject;
|
|
379
|
+
exports.useQueryParams = useRouterState.useQueryParams;
|
|
380
|
+
exports.useRouter = useRouterState.useRouter;
|
|
381
|
+
exports.useRouterEvents = useRouterState.useRouterEvents;
|
|
382
|
+
exports.useRouterState = useRouterState.useRouterState;
|
|
604
383
|
exports.AlephaReact = AlephaReact;
|
|
605
|
-
exports.Link = Link;
|
|
606
384
|
exports.ReactServerProvider = ReactServerProvider;
|
|
607
|
-
exports.RouterHookApi = RouterHookApi;
|
|
608
|
-
exports.useActive = useActive;
|
|
609
|
-
exports.useClient = useClient;
|
|
610
|
-
exports.useInject = useInject;
|
|
611
|
-
exports.useQueryParams = useQueryParams;
|
|
612
|
-
exports.useRouter = useRouter;
|
|
613
|
-
exports.useRouterState = useRouterState;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as _alepha_core from '@alepha/core';
|
|
2
2
|
import { TSchema as TSchema$1, KIND, OPTIONS, Static, Async, Alepha, Service, TObject, Module } from '@alepha/core';
|
|
3
|
-
import {
|
|
3
|
+
import { ServerRequest, ApiLinksResponse, HttpClient, ClientScope, HttpVirtualClient, ServerRouterProvider, ServerTimingProvider, ServerHandler } from '@alepha/server';
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import React__default, { PropsWithChildren, ReactNode, FC, ErrorInfo, AnchorHTMLAttributes } from 'react';
|
|
6
|
+
import { ServerRouteCache } from '@alepha/server-cache';
|
|
6
7
|
import { Root } from 'react-dom/client';
|
|
7
8
|
import { RouterProvider, Route } from '@alepha/router';
|
|
8
9
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
@@ -101,7 +102,7 @@ interface PageConfigSchema {
|
|
|
101
102
|
}
|
|
102
103
|
type TPropsDefault = any;
|
|
103
104
|
type TPropsParentDefault = {};
|
|
104
|
-
interface PageDescriptorOptions<TConfig extends PageConfigSchema = PageConfigSchema, TProps extends object = TPropsDefault, TPropsParent extends object = TPropsParentDefault>
|
|
105
|
+
interface PageDescriptorOptions<TConfig extends PageConfigSchema = PageConfigSchema, TProps extends object = TPropsDefault, TPropsParent extends object = TPropsParentDefault> {
|
|
105
106
|
/**
|
|
106
107
|
* Name your page.
|
|
107
108
|
*
|
|
@@ -181,6 +182,7 @@ interface PageDescriptorOptions<TConfig extends PageConfigSchema = PageConfigSch
|
|
|
181
182
|
*/
|
|
182
183
|
client?: boolean | ClientOnlyProps;
|
|
183
184
|
afterHandler?: (request: ServerRequest) => any;
|
|
185
|
+
cache?: ServerRouteCache;
|
|
184
186
|
}
|
|
185
187
|
interface PageDescriptor<TConfig extends PageConfigSchema = PageConfigSchema, TProps extends object = TPropsDefault, TPropsParent extends object = TPropsParentDefault> {
|
|
186
188
|
[KIND]: typeof KEY;
|
|
@@ -436,6 +438,51 @@ interface ReactHydrationState {
|
|
|
436
438
|
links?: ApiLinksResponse;
|
|
437
439
|
}
|
|
438
440
|
|
|
441
|
+
/**
|
|
442
|
+
* Props for the ErrorBoundary component.
|
|
443
|
+
*/
|
|
444
|
+
interface ErrorBoundaryProps {
|
|
445
|
+
/**
|
|
446
|
+
* Fallback React node to render when an error is caught.
|
|
447
|
+
* If not provided, a default error message will be shown.
|
|
448
|
+
*/
|
|
449
|
+
fallback: (error: Error) => ReactNode;
|
|
450
|
+
/**
|
|
451
|
+
* Optional callback that receives the error and error info.
|
|
452
|
+
* Use this to log errors to a monitoring service.
|
|
453
|
+
*/
|
|
454
|
+
onError?: (error: Error, info: ErrorInfo) => void;
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* State of the ErrorBoundary component.
|
|
458
|
+
*/
|
|
459
|
+
interface ErrorBoundaryState {
|
|
460
|
+
error?: Error;
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* A reusable error boundary for catching rendering errors
|
|
464
|
+
* in any part of the React component tree.
|
|
465
|
+
*/
|
|
466
|
+
declare class ErrorBoundary extends React__default.Component<PropsWithChildren<ErrorBoundaryProps>, ErrorBoundaryState> {
|
|
467
|
+
constructor(props: ErrorBoundaryProps);
|
|
468
|
+
/**
|
|
469
|
+
* Update state so the next render shows the fallback UI.
|
|
470
|
+
*/
|
|
471
|
+
static getDerivedStateFromError(error: Error): ErrorBoundaryState;
|
|
472
|
+
/**
|
|
473
|
+
* Lifecycle method called when an error is caught.
|
|
474
|
+
* You can log the error or perform side effects here.
|
|
475
|
+
*/
|
|
476
|
+
componentDidCatch(error: Error, info: ErrorInfo): void;
|
|
477
|
+
render(): ReactNode;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
interface LinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
|
|
481
|
+
to: string | PageDescriptor;
|
|
482
|
+
children?: React__default.ReactNode;
|
|
483
|
+
}
|
|
484
|
+
declare const Link: (props: LinkProps) => react_jsx_runtime.JSX.Element | null;
|
|
485
|
+
|
|
439
486
|
interface NestedViewProps {
|
|
440
487
|
children?: ReactNode;
|
|
441
488
|
}
|
|
@@ -462,6 +509,19 @@ interface NestedViewProps {
|
|
|
462
509
|
*/
|
|
463
510
|
declare const NestedView: (props: NestedViewProps) => react_jsx_runtime.JSX.Element;
|
|
464
511
|
|
|
512
|
+
interface RouterContextValue {
|
|
513
|
+
alepha: Alepha;
|
|
514
|
+
state: RouterState;
|
|
515
|
+
context: PageReactContext;
|
|
516
|
+
}
|
|
517
|
+
declare const RouterContext: React.Context<RouterContextValue | undefined>;
|
|
518
|
+
|
|
519
|
+
interface RouterLayerContextValue {
|
|
520
|
+
index: number;
|
|
521
|
+
path: string;
|
|
522
|
+
}
|
|
523
|
+
declare const RouterLayerContext: React.Context<RouterLayerContextValue | undefined>;
|
|
524
|
+
|
|
465
525
|
declare class RouterHookApi {
|
|
466
526
|
private readonly pages;
|
|
467
527
|
private readonly state;
|
|
@@ -523,64 +583,6 @@ declare class RedirectionError extends Error {
|
|
|
523
583
|
constructor(page: HrefLike);
|
|
524
584
|
}
|
|
525
585
|
|
|
526
|
-
/**
|
|
527
|
-
* Props for the ErrorBoundary component.
|
|
528
|
-
*/
|
|
529
|
-
interface ErrorBoundaryProps {
|
|
530
|
-
/**
|
|
531
|
-
* Fallback React node to render when an error is caught.
|
|
532
|
-
* If not provided, a default error message will be shown.
|
|
533
|
-
*/
|
|
534
|
-
fallback: (error: Error) => ReactNode;
|
|
535
|
-
/**
|
|
536
|
-
* Optional callback that receives the error and error info.
|
|
537
|
-
* Use this to log errors to a monitoring service.
|
|
538
|
-
*/
|
|
539
|
-
onError?: (error: Error, info: ErrorInfo) => void;
|
|
540
|
-
}
|
|
541
|
-
/**
|
|
542
|
-
* State of the ErrorBoundary component.
|
|
543
|
-
*/
|
|
544
|
-
interface ErrorBoundaryState {
|
|
545
|
-
error?: Error;
|
|
546
|
-
}
|
|
547
|
-
/**
|
|
548
|
-
* A reusable error boundary for catching rendering errors
|
|
549
|
-
* in any part of the React component tree.
|
|
550
|
-
*/
|
|
551
|
-
declare class ErrorBoundary extends React__default.Component<PropsWithChildren<ErrorBoundaryProps>, ErrorBoundaryState> {
|
|
552
|
-
constructor(props: ErrorBoundaryProps);
|
|
553
|
-
/**
|
|
554
|
-
* Update state so the next render shows the fallback UI.
|
|
555
|
-
*/
|
|
556
|
-
static getDerivedStateFromError(error: Error): ErrorBoundaryState;
|
|
557
|
-
/**
|
|
558
|
-
* Lifecycle method called when an error is caught.
|
|
559
|
-
* You can log the error or perform side effects here.
|
|
560
|
-
*/
|
|
561
|
-
componentDidCatch(error: Error, info: ErrorInfo): void;
|
|
562
|
-
render(): ReactNode;
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
interface LinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
|
|
566
|
-
to: string | PageDescriptor;
|
|
567
|
-
children?: React__default.ReactNode;
|
|
568
|
-
}
|
|
569
|
-
declare const Link: (props: LinkProps) => react_jsx_runtime.JSX.Element | null;
|
|
570
|
-
|
|
571
|
-
interface RouterContextValue {
|
|
572
|
-
alepha: Alepha;
|
|
573
|
-
state: RouterState;
|
|
574
|
-
context: PageReactContext;
|
|
575
|
-
}
|
|
576
|
-
declare const RouterContext: React.Context<RouterContextValue | undefined>;
|
|
577
|
-
|
|
578
|
-
interface RouterLayerContextValue {
|
|
579
|
-
index: number;
|
|
580
|
-
path: string;
|
|
581
|
-
}
|
|
582
|
-
declare const RouterLayerContext: React.Context<RouterLayerContextValue | undefined>;
|
|
583
|
-
|
|
584
586
|
declare const useActive: (path: HrefLike) => UseActiveHook;
|
|
585
587
|
interface UseActiveHook {
|
|
586
588
|
isActive: boolean;
|