@alepha/react 0.9.3 → 0.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -0
- package/dist/index.browser.js +315 -320
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +496 -457
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +276 -258
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +274 -256
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +494 -460
- package/dist/index.js.map +1 -1
- package/package.json +13 -10
- package/src/components/NestedView.tsx +15 -13
- package/src/components/NotFound.tsx +1 -1
- package/src/descriptors/$page.ts +16 -4
- package/src/errors/Redirection.ts +8 -5
- package/src/hooks/useActive.ts +25 -34
- package/src/hooks/useAlepha.ts +16 -2
- package/src/hooks/useClient.ts +7 -4
- package/src/hooks/useInject.ts +4 -1
- package/src/hooks/useQueryParams.ts +9 -6
- package/src/hooks/useRouter.ts +18 -31
- package/src/hooks/useRouterEvents.ts +7 -7
- package/src/hooks/useRouterState.ts +8 -20
- package/src/hooks/useSchema.ts +10 -15
- package/src/hooks/useStore.ts +0 -7
- package/src/index.browser.ts +11 -11
- package/src/index.shared.ts +2 -3
- package/src/index.ts +21 -30
- package/src/providers/ReactBrowserProvider.ts +149 -65
- package/src/providers/ReactBrowserRouterProvider.ts +132 -0
- package/src/providers/{PageDescriptorProvider.ts → ReactPageProvider.ts} +84 -112
- package/src/providers/ReactServerProvider.ts +69 -74
- package/src/{hooks/RouterHookApi.ts → services/ReactRouter.ts} +44 -54
- package/src/contexts/RouterContext.ts +0 -14
- package/src/providers/BrowserRouterProvider.ts +0 -155
- package/src/providers/ReactBrowserRenderer.ts +0 -93
package/dist/index.d.ts
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import * as _alepha_core11 from "@alepha/core";
|
|
3
|
-
import * as _alepha_core13 from "@alepha/core";
|
|
4
|
-
import * as _alepha_core1 from "@alepha/core";
|
|
5
|
-
import * as _alepha_core0 from "@alepha/core";
|
|
1
|
+
import * as _alepha_core14 from "@alepha/core";
|
|
6
2
|
import { Alepha, Async, Descriptor, KIND, Service, State, Static, TObject, TSchema } from "@alepha/core";
|
|
7
|
-
import {
|
|
3
|
+
import { RequestConfigSchema, ServerHandler, ServerRequest, ServerRouterProvider, ServerTimingProvider } from "@alepha/server";
|
|
8
4
|
import { ServerRouteCache } from "@alepha/server-cache";
|
|
9
5
|
import { ClientScope, HttpVirtualClient, LinkProvider, VirtualAction } from "@alepha/server-links";
|
|
10
|
-
import * as
|
|
6
|
+
import * as _alepha_logger1 from "@alepha/logger";
|
|
11
7
|
import * as react0 from "react";
|
|
12
|
-
import * as react1 from "react";
|
|
13
8
|
import React, { AnchorHTMLAttributes, CSSProperties, ErrorInfo, FC, PropsWithChildren, ReactNode } from "react";
|
|
14
|
-
import * as react_jsx_runtime0$1 from "react/jsx-runtime";
|
|
15
9
|
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
16
|
-
import * as react_jsx_runtime2 from "react/jsx-runtime";
|
|
17
|
-
import { Route, RouterProvider } from "@alepha/router";
|
|
18
10
|
import { ServerStaticProvider } from "@alepha/server-static";
|
|
11
|
+
import { DateTimeProvider } from "@alepha/datetime";
|
|
19
12
|
import { Root } from "react-dom/client";
|
|
13
|
+
import { Route, RouterProvider } from "@alepha/router";
|
|
20
14
|
|
|
21
15
|
//#region src/components/ClientOnly.d.ts
|
|
22
16
|
interface ClientOnlyProps {
|
|
@@ -35,132 +29,16 @@ interface ClientOnlyProps {
|
|
|
35
29
|
*/
|
|
36
30
|
declare const ClientOnly: (props: PropsWithChildren<ClientOnlyProps>) => ReactNode;
|
|
37
31
|
//#endregion
|
|
38
|
-
//#region src/providers/BrowserRouterProvider.d.ts
|
|
39
|
-
interface BrowserRoute extends Route {
|
|
40
|
-
page: PageRoute;
|
|
41
|
-
}
|
|
42
|
-
declare class BrowserRouterProvider extends RouterProvider<BrowserRoute> {
|
|
43
|
-
protected readonly log: _alepha_core17.Logger;
|
|
44
|
-
protected readonly alepha: Alepha;
|
|
45
|
-
protected readonly pageDescriptorProvider: PageDescriptorProvider;
|
|
46
|
-
add(entry: PageRouteEntry): void;
|
|
47
|
-
protected readonly configure: _alepha_core17.HookDescriptor<"configure">;
|
|
48
|
-
transition(url: URL, options?: TransitionOptions): Promise<RouterRenderResult>;
|
|
49
|
-
root(state: RouterState, context: PageReactContext): ReactNode;
|
|
50
|
-
}
|
|
51
|
-
//# sourceMappingURL=BrowserRouterProvider.d.ts.map
|
|
52
|
-
//#endregion
|
|
53
|
-
//#region src/providers/ReactBrowserProvider.d.ts
|
|
54
|
-
declare class ReactBrowserProvider {
|
|
55
|
-
protected readonly log: _alepha_core11.Logger;
|
|
56
|
-
protected readonly client: LinkProvider;
|
|
57
|
-
protected readonly alepha: Alepha;
|
|
58
|
-
protected readonly router: BrowserRouterProvider;
|
|
59
|
-
protected root: Root;
|
|
60
|
-
transitioning?: {
|
|
61
|
-
to: string;
|
|
62
|
-
};
|
|
63
|
-
state: RouterState;
|
|
64
|
-
get document(): Document;
|
|
65
|
-
get history(): History;
|
|
66
|
-
get location(): Location;
|
|
67
|
-
get url(): string;
|
|
68
|
-
pushState(url: string, replace?: boolean): void;
|
|
69
|
-
invalidate(props?: Record<string, any>): Promise<void>;
|
|
70
|
-
go(url: string, options?: RouterGoOptions): Promise<void>;
|
|
71
|
-
protected render(options?: {
|
|
72
|
-
url?: string;
|
|
73
|
-
previous?: PreviousLayerData[];
|
|
74
|
-
}): Promise<RouterRenderResult>;
|
|
75
|
-
/**
|
|
76
|
-
* Get embedded layers from the server.
|
|
77
|
-
*/
|
|
78
|
-
protected getHydrationState(): ReactHydrationState | undefined;
|
|
79
|
-
readonly ready: _alepha_core11.HookDescriptor<"ready">;
|
|
80
|
-
}
|
|
81
|
-
interface RouterGoOptions {
|
|
82
|
-
replace?: boolean;
|
|
83
|
-
match?: TransitionOptions;
|
|
84
|
-
params?: Record<string, string>;
|
|
85
|
-
query?: Record<string, string>;
|
|
86
|
-
}
|
|
87
|
-
interface ReactHydrationState {
|
|
88
|
-
layers?: Array<PreviousLayerData>;
|
|
89
|
-
links?: ApiLinksResponse;
|
|
90
|
-
}
|
|
91
|
-
//# sourceMappingURL=ReactBrowserProvider.d.ts.map
|
|
92
|
-
//#endregion
|
|
93
|
-
//#region src/hooks/RouterHookApi.d.ts
|
|
94
|
-
declare class RouterHookApi<T extends object> {
|
|
95
|
-
private readonly pages;
|
|
96
|
-
private readonly context;
|
|
97
|
-
private readonly state;
|
|
98
|
-
private readonly layer;
|
|
99
|
-
private readonly pageApi;
|
|
100
|
-
private readonly browser?;
|
|
101
|
-
constructor(pages: PageRoute[], context: PageReactContext, state: RouterState, layer: {
|
|
102
|
-
path: string;
|
|
103
|
-
}, pageApi: PageDescriptorProvider, browser?: ReactBrowserProvider | undefined);
|
|
104
|
-
path(name: keyof VirtualRouter<T>, config?: {
|
|
105
|
-
params?: Record<string, string>;
|
|
106
|
-
query?: Record<string, string>;
|
|
107
|
-
}): string;
|
|
108
|
-
getURL(): URL;
|
|
109
|
-
get location(): Location;
|
|
110
|
-
get current(): RouterState;
|
|
111
|
-
get pathname(): string;
|
|
112
|
-
get query(): Record<string, string>;
|
|
113
|
-
back(): Promise<void>;
|
|
114
|
-
forward(): Promise<void>;
|
|
115
|
-
invalidate(props?: Record<string, any>): Promise<void>;
|
|
116
|
-
/**
|
|
117
|
-
* Create a valid href for the given pathname.
|
|
118
|
-
*
|
|
119
|
-
* @param pathname
|
|
120
|
-
* @param layer
|
|
121
|
-
*/
|
|
122
|
-
createHref(pathname: HrefLike, layer?: {
|
|
123
|
-
path: string;
|
|
124
|
-
}, options?: {
|
|
125
|
-
params?: Record<string, any>;
|
|
126
|
-
}): string;
|
|
127
|
-
go(path: string, options?: RouterGoOptions): Promise<void>;
|
|
128
|
-
go(path: keyof VirtualRouter<T>, options?: RouterGoOptions): Promise<void>;
|
|
129
|
-
anchor(path: string, options?: {
|
|
130
|
-
params?: Record<string, any>;
|
|
131
|
-
}): AnchorProps;
|
|
132
|
-
anchor(path: keyof VirtualRouter<T>, options?: {
|
|
133
|
-
params?: Record<string, any>;
|
|
134
|
-
}): AnchorProps;
|
|
135
|
-
/**
|
|
136
|
-
* Set query params.
|
|
137
|
-
*
|
|
138
|
-
* @param record
|
|
139
|
-
* @param options
|
|
140
|
-
*/
|
|
141
|
-
setQueryParams(record: Record<string, any> | ((queryParams: Record<string, any>) => Record<string, any>), options?: {
|
|
142
|
-
/**
|
|
143
|
-
* If true, this will add a new entry to the history stack.
|
|
144
|
-
*/
|
|
145
|
-
push?: boolean;
|
|
146
|
-
}): void;
|
|
147
|
-
}
|
|
148
|
-
type HrefLike = string | {
|
|
149
|
-
options: {
|
|
150
|
-
path?: string;
|
|
151
|
-
name?: string;
|
|
152
|
-
};
|
|
153
|
-
};
|
|
154
|
-
type VirtualRouter<T> = { [K in keyof T as T[K] extends PageDescriptor ? K : never]: T[K] };
|
|
155
|
-
//# sourceMappingURL=RouterHookApi.d.ts.map
|
|
156
|
-
//#endregion
|
|
157
32
|
//#region src/errors/Redirection.d.ts
|
|
33
|
+
/**
|
|
34
|
+
* Used for Redirection during the page loading.
|
|
35
|
+
*
|
|
36
|
+
* Depends on the context, it can be thrown or just returned.
|
|
37
|
+
*/
|
|
158
38
|
declare class Redirection extends Error {
|
|
159
|
-
readonly
|
|
160
|
-
constructor(
|
|
39
|
+
readonly redirect: string;
|
|
40
|
+
constructor(redirect: string);
|
|
161
41
|
}
|
|
162
|
-
//# sourceMappingURL=Redirection.d.ts.map
|
|
163
|
-
|
|
164
42
|
//#endregion
|
|
165
43
|
//#region src/descriptors/$page.d.ts
|
|
166
44
|
/**
|
|
@@ -300,7 +178,7 @@ interface PageDescriptorOptions<TConfig extends PageConfigSchema = PageConfigSch
|
|
|
300
178
|
*/
|
|
301
179
|
onLeave?: () => void;
|
|
302
180
|
}
|
|
303
|
-
type ErrorHandler = (error: Error,
|
|
181
|
+
type ErrorHandler = (error: Error, state: ReactRouterState) => ReactNode | Redirection | undefined;
|
|
304
182
|
declare class PageDescriptor<TConfig extends PageConfigSchema = PageConfigSchema, TProps extends object = TPropsDefault, TPropsParent extends object = TPropsParentDefault> extends Descriptor<PageDescriptorOptions<TConfig, TProps, TPropsParent>> {
|
|
305
183
|
protected onInit(): void;
|
|
306
184
|
get name(): string;
|
|
@@ -309,6 +187,8 @@ declare class PageDescriptor<TConfig extends PageConfigSchema = PageConfigSchema
|
|
|
309
187
|
* Only valid for server-side rendering, it will throw an error if called on the client-side.
|
|
310
188
|
*/
|
|
311
189
|
render(options?: PageDescriptorRenderOptions): Promise<PageDescriptorRenderResult>;
|
|
190
|
+
match(url: string): boolean;
|
|
191
|
+
pathname(config: any): string;
|
|
312
192
|
}
|
|
313
193
|
interface PageConfigSchema {
|
|
314
194
|
query?: TSchema;
|
|
@@ -324,24 +204,23 @@ interface PageDescriptorRenderOptions {
|
|
|
324
204
|
}
|
|
325
205
|
interface PageDescriptorRenderResult {
|
|
326
206
|
html: string;
|
|
327
|
-
|
|
207
|
+
state: ReactRouterState;
|
|
328
208
|
}
|
|
329
209
|
interface PageRequestConfig<TConfig extends PageConfigSchema = PageConfigSchema> {
|
|
330
210
|
params: TConfig["params"] extends TSchema ? Static<TConfig["params"]> : Record<string, string>;
|
|
331
211
|
query: TConfig["query"] extends TSchema ? Static<TConfig["query"]> : Record<string, string>;
|
|
332
212
|
}
|
|
333
|
-
type PageResolve<TConfig extends PageConfigSchema = PageConfigSchema, TPropsParent extends object = TPropsParentDefault> = PageRequestConfig<TConfig> & TPropsParent &
|
|
334
|
-
//# sourceMappingURL=$page.d.ts.map
|
|
213
|
+
type PageResolve<TConfig extends PageConfigSchema = PageConfigSchema, TPropsParent extends object = TPropsParentDefault> = PageRequestConfig<TConfig> & TPropsParent & Omit<ReactRouterState, "layers" | "onError">;
|
|
335
214
|
//#endregion
|
|
336
|
-
//#region src/providers/
|
|
337
|
-
declare const envSchema$
|
|
338
|
-
REACT_STRICT_MODE:
|
|
215
|
+
//#region src/providers/ReactPageProvider.d.ts
|
|
216
|
+
declare const envSchema$2: _alepha_core14.TObject<{
|
|
217
|
+
REACT_STRICT_MODE: _alepha_core14.TBoolean;
|
|
339
218
|
}>;
|
|
340
219
|
declare module "@alepha/core" {
|
|
341
|
-
interface Env extends Partial<Static<typeof envSchema$
|
|
220
|
+
interface Env extends Partial<Static<typeof envSchema$2>> {}
|
|
342
221
|
}
|
|
343
|
-
declare class
|
|
344
|
-
protected readonly log:
|
|
222
|
+
declare class ReactPageProvider {
|
|
223
|
+
protected readonly log: _alepha_logger1.Logger;
|
|
345
224
|
protected readonly env: {
|
|
346
225
|
REACT_STRICT_MODE: boolean;
|
|
347
226
|
};
|
|
@@ -355,19 +234,16 @@ declare class PageDescriptorProvider {
|
|
|
355
234
|
}): string;
|
|
356
235
|
url(name: string, options?: {
|
|
357
236
|
params?: Record<string, string>;
|
|
358
|
-
|
|
237
|
+
host?: string;
|
|
359
238
|
}): URL;
|
|
360
|
-
root(state:
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
pathname: string;
|
|
369
|
-
search: string;
|
|
370
|
-
};
|
|
239
|
+
root(state: ReactRouterState): ReactNode;
|
|
240
|
+
/**
|
|
241
|
+
* Create a new RouterState based on a given route and request.
|
|
242
|
+
* This method resolves the layers for the route, applying any query and params schemas defined in the route.
|
|
243
|
+
* It also handles errors and redirects.
|
|
244
|
+
*/
|
|
245
|
+
createLayers(route: PageRoute, state: ReactRouterState, previous?: PreviousLayerData[]): Promise<CreateLayersResult>;
|
|
246
|
+
protected createRedirectionLayer(redirect: string): CreateLayersResult;
|
|
371
247
|
protected getErrorHandler(route: PageRoute): ErrorHandler | undefined;
|
|
372
248
|
protected createElement(page: PageRoute, props: Record<string, any>): Promise<ReactNode>;
|
|
373
249
|
renderError(error: Error): ReactNode;
|
|
@@ -379,7 +255,7 @@ declare class PageDescriptorProvider {
|
|
|
379
255
|
}, params?: Record<string, any>): string;
|
|
380
256
|
compile(path: string, params?: Record<string, string>): string;
|
|
381
257
|
protected renderView(index: number, path: string, view: ReactNode | undefined, page: PageRoute): ReactNode;
|
|
382
|
-
protected readonly configure:
|
|
258
|
+
protected readonly configure: _alepha_core14.HookDescriptor<"configure">;
|
|
383
259
|
protected map(pages: Array<PageDescriptor>, target: PageDescriptor): PageRouteEntry;
|
|
384
260
|
add(entry: PageRouteEntry): void;
|
|
385
261
|
protected createMatch(page: PageRoute): string;
|
|
@@ -417,15 +293,27 @@ interface AnchorProps {
|
|
|
417
293
|
href: string;
|
|
418
294
|
onClick: (ev?: any) => any;
|
|
419
295
|
}
|
|
420
|
-
interface
|
|
421
|
-
|
|
422
|
-
|
|
296
|
+
interface ReactRouterState {
|
|
297
|
+
/**
|
|
298
|
+
* Stack of layers for the current page.
|
|
299
|
+
*/
|
|
423
300
|
layers: Array<Layer>;
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
301
|
+
/**
|
|
302
|
+
* URL of the current page.
|
|
303
|
+
*/
|
|
304
|
+
url: URL;
|
|
305
|
+
/**
|
|
306
|
+
* Error handler for the current page.
|
|
307
|
+
*/
|
|
308
|
+
onError: ErrorHandler;
|
|
309
|
+
/**
|
|
310
|
+
* Params extracted from the URL for the current page.
|
|
311
|
+
*/
|
|
312
|
+
params: Record<string, any>;
|
|
313
|
+
/**
|
|
314
|
+
* Query parameters extracted from the URL for the current page.
|
|
315
|
+
*/
|
|
316
|
+
query: Record<string, string>;
|
|
429
317
|
}
|
|
430
318
|
interface RouterStackItem {
|
|
431
319
|
route: PageRoute;
|
|
@@ -434,31 +322,99 @@ interface RouterStackItem {
|
|
|
434
322
|
error?: Error;
|
|
435
323
|
cache?: boolean;
|
|
436
324
|
}
|
|
437
|
-
interface
|
|
438
|
-
state: RouterState;
|
|
439
|
-
context: PageReactContext;
|
|
440
|
-
redirect?: string;
|
|
441
|
-
}
|
|
442
|
-
interface PageRequest extends PageReactContext {
|
|
443
|
-
params: Record<string, any>;
|
|
444
|
-
query: Record<string, string>;
|
|
325
|
+
interface TransitionOptions {
|
|
445
326
|
previous?: PreviousLayerData[];
|
|
446
327
|
}
|
|
447
|
-
interface CreateLayersResult
|
|
328
|
+
interface CreateLayersResult {
|
|
448
329
|
redirect?: string;
|
|
330
|
+
state?: ReactRouterState;
|
|
449
331
|
}
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
332
|
+
//#endregion
|
|
333
|
+
//#region src/providers/ReactBrowserRouterProvider.d.ts
|
|
334
|
+
interface BrowserRoute extends Route {
|
|
335
|
+
page: PageRoute;
|
|
336
|
+
}
|
|
337
|
+
declare class ReactBrowserRouterProvider extends RouterProvider<BrowserRoute> {
|
|
338
|
+
protected readonly log: _alepha_logger1.Logger;
|
|
339
|
+
protected readonly alepha: Alepha;
|
|
340
|
+
protected readonly pageApi: ReactPageProvider;
|
|
341
|
+
add(entry: PageRouteEntry): void;
|
|
342
|
+
protected readonly configure: _alepha_core14.HookDescriptor<"configure">;
|
|
343
|
+
transition(url: URL, previous?: PreviousLayerData[]): Promise<string | void>;
|
|
344
|
+
root(state: ReactRouterState): ReactNode;
|
|
460
345
|
}
|
|
461
346
|
//#endregion
|
|
347
|
+
//#region src/providers/ReactBrowserProvider.d.ts
|
|
348
|
+
declare const envSchema$1: _alepha_core14.TObject<{
|
|
349
|
+
REACT_ROOT_ID: _alepha_core14.TString;
|
|
350
|
+
}>;
|
|
351
|
+
declare module "@alepha/core" {
|
|
352
|
+
interface Env extends Partial<Static<typeof envSchema$1>> {}
|
|
353
|
+
}
|
|
354
|
+
interface ReactBrowserRendererOptions {
|
|
355
|
+
scrollRestoration?: "top" | "manual";
|
|
356
|
+
}
|
|
357
|
+
declare class ReactBrowserProvider {
|
|
358
|
+
protected readonly env: {
|
|
359
|
+
REACT_ROOT_ID: string;
|
|
360
|
+
};
|
|
361
|
+
protected readonly log: _alepha_logger1.Logger;
|
|
362
|
+
protected readonly client: LinkProvider;
|
|
363
|
+
protected readonly alepha: Alepha;
|
|
364
|
+
protected readonly router: ReactBrowserRouterProvider;
|
|
365
|
+
protected readonly dateTimeProvider: DateTimeProvider;
|
|
366
|
+
protected root?: Root;
|
|
367
|
+
options: ReactBrowserRendererOptions;
|
|
368
|
+
protected getRootElement(): HTMLElement;
|
|
369
|
+
transitioning?: {
|
|
370
|
+
to: string;
|
|
371
|
+
from?: string;
|
|
372
|
+
};
|
|
373
|
+
get state(): ReactRouterState;
|
|
374
|
+
/**
|
|
375
|
+
* Accessor for Document DOM API.
|
|
376
|
+
*/
|
|
377
|
+
get document(): Document;
|
|
378
|
+
/**
|
|
379
|
+
* Accessor for History DOM API.
|
|
380
|
+
*/
|
|
381
|
+
get history(): History;
|
|
382
|
+
/**
|
|
383
|
+
* Accessor for Location DOM API.
|
|
384
|
+
*/
|
|
385
|
+
get location(): Location;
|
|
386
|
+
get base(): string;
|
|
387
|
+
get url(): string;
|
|
388
|
+
pushState(path: string, replace?: boolean): void;
|
|
389
|
+
invalidate(props?: Record<string, any>): Promise<void>;
|
|
390
|
+
go(url: string, options?: RouterGoOptions): Promise<void>;
|
|
391
|
+
protected render(options?: {
|
|
392
|
+
url?: string;
|
|
393
|
+
previous?: PreviousLayerData[];
|
|
394
|
+
}): Promise<void>;
|
|
395
|
+
/**
|
|
396
|
+
* Get embedded layers from the server.
|
|
397
|
+
*/
|
|
398
|
+
protected getHydrationState(): ReactHydrationState | undefined;
|
|
399
|
+
protected readonly onTransitionEnd: _alepha_core14.HookDescriptor<"react:transition:end">;
|
|
400
|
+
readonly ready: _alepha_core14.HookDescriptor<"ready">;
|
|
401
|
+
}
|
|
402
|
+
interface RouterGoOptions {
|
|
403
|
+
replace?: boolean;
|
|
404
|
+
match?: TransitionOptions;
|
|
405
|
+
params?: Record<string, string>;
|
|
406
|
+
query?: Record<string, string>;
|
|
407
|
+
/**
|
|
408
|
+
* Recreate the whole page, ignoring the current state.
|
|
409
|
+
*/
|
|
410
|
+
force?: boolean;
|
|
411
|
+
}
|
|
412
|
+
type ReactHydrationState = {
|
|
413
|
+
layers?: Array<PreviousLayerData>;
|
|
414
|
+
} & {
|
|
415
|
+
[key: string]: any;
|
|
416
|
+
};
|
|
417
|
+
//#endregion
|
|
462
418
|
//#region src/components/ErrorBoundary.d.ts
|
|
463
419
|
/**
|
|
464
420
|
* Props for the ErrorBoundary component.
|
|
@@ -499,12 +455,22 @@ declare class ErrorBoundary extends React.Component<PropsWithChildren<ErrorBound
|
|
|
499
455
|
render(): ReactNode;
|
|
500
456
|
}
|
|
501
457
|
//#endregion
|
|
458
|
+
//#region src/components/ErrorViewer.d.ts
|
|
459
|
+
interface ErrorViewerProps {
|
|
460
|
+
error: Error;
|
|
461
|
+
alepha: Alepha;
|
|
462
|
+
}
|
|
463
|
+
declare const ErrorViewer: ({
|
|
464
|
+
error,
|
|
465
|
+
alepha
|
|
466
|
+
}: ErrorViewerProps) => react_jsx_runtime0.JSX.Element;
|
|
467
|
+
//#endregion
|
|
502
468
|
//#region src/components/Link.d.ts
|
|
503
469
|
interface LinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
|
|
504
470
|
to: string;
|
|
505
471
|
children?: React.ReactNode;
|
|
506
472
|
}
|
|
507
|
-
declare const Link: (props: LinkProps) => react_jsx_runtime0
|
|
473
|
+
declare const Link: (props: LinkProps) => react_jsx_runtime0.JSX.Element;
|
|
508
474
|
//#endregion
|
|
509
475
|
//#region src/components/NestedView.d.ts
|
|
510
476
|
interface NestedViewProps {
|
|
@@ -536,83 +502,151 @@ declare const NestedView: (props: NestedViewProps) => react_jsx_runtime0.JSX.Ele
|
|
|
536
502
|
//#region src/components/NotFound.d.ts
|
|
537
503
|
declare function NotFoundPage(props: {
|
|
538
504
|
style?: CSSProperties;
|
|
539
|
-
}):
|
|
540
|
-
//# sourceMappingURL=NotFound.d.ts.map
|
|
505
|
+
}): react_jsx_runtime0.JSX.Element;
|
|
541
506
|
//#endregion
|
|
542
507
|
//#region src/contexts/AlephaContext.d.ts
|
|
543
|
-
declare const AlephaContext: react0
|
|
544
|
-
//# sourceMappingURL=AlephaContext.d.ts.map
|
|
545
|
-
//#endregion
|
|
546
|
-
//#region src/contexts/RouterContext.d.ts
|
|
547
|
-
interface RouterContextValue {
|
|
548
|
-
state: RouterState;
|
|
549
|
-
context: PageReactContext;
|
|
550
|
-
}
|
|
551
|
-
declare const RouterContext: react0.Context<RouterContextValue | undefined>;
|
|
552
|
-
//# sourceMappingURL=RouterContext.d.ts.map
|
|
508
|
+
declare const AlephaContext: react0.Context<Alepha | undefined>;
|
|
553
509
|
//#endregion
|
|
554
510
|
//#region src/contexts/RouterLayerContext.d.ts
|
|
555
511
|
interface RouterLayerContextValue {
|
|
556
512
|
index: number;
|
|
557
513
|
path: string;
|
|
558
514
|
}
|
|
559
|
-
declare const RouterLayerContext:
|
|
560
|
-
//# sourceMappingURL=RouterLayerContext.d.ts.map
|
|
515
|
+
declare const RouterLayerContext: react0.Context<RouterLayerContextValue | undefined>;
|
|
561
516
|
//#endregion
|
|
562
517
|
//#region src/hooks/useActive.d.ts
|
|
563
|
-
|
|
518
|
+
interface UseActiveOptions {
|
|
519
|
+
href: string;
|
|
520
|
+
startWith?: boolean;
|
|
521
|
+
}
|
|
522
|
+
declare const useActive: (args: string | UseActiveOptions) => UseActiveHook;
|
|
564
523
|
interface UseActiveHook {
|
|
565
524
|
isActive: boolean;
|
|
566
525
|
anchorProps: AnchorProps;
|
|
567
526
|
isPending: boolean;
|
|
568
527
|
name?: string;
|
|
569
528
|
}
|
|
570
|
-
//# sourceMappingURL=useActive.d.ts.map
|
|
571
529
|
//#endregion
|
|
572
530
|
//#region src/hooks/useAlepha.d.ts
|
|
531
|
+
/**
|
|
532
|
+
* Main Alepha hook.
|
|
533
|
+
*
|
|
534
|
+
* It provides access to the Alepha instance within a React component.
|
|
535
|
+
*
|
|
536
|
+
* With Alepha, you can access the core functionalities of the framework:
|
|
537
|
+
*
|
|
538
|
+
* - alepha.state() for state management
|
|
539
|
+
* - alepha.inject() for dependency injection
|
|
540
|
+
* - alepha.emit() for event handling
|
|
541
|
+
* etc...
|
|
542
|
+
*/
|
|
573
543
|
declare const useAlepha: () => Alepha;
|
|
574
|
-
//# sourceMappingURL=useAlepha.d.ts.map
|
|
575
544
|
//#endregion
|
|
576
545
|
//#region src/hooks/useClient.d.ts
|
|
577
|
-
|
|
578
|
-
|
|
546
|
+
/**
|
|
547
|
+
* Hook to get a virtual client for the specified scope.
|
|
548
|
+
*
|
|
549
|
+
* It's the React-hook version of `$client()`, from `AlephaServerLinks` module.
|
|
550
|
+
*/
|
|
551
|
+
declare const useClient: <T extends object>(scope?: ClientScope) => HttpVirtualClient<T>;
|
|
579
552
|
//#endregion
|
|
580
553
|
//#region src/hooks/useInject.d.ts
|
|
554
|
+
/**
|
|
555
|
+
* Hook to inject a service instance.
|
|
556
|
+
* It's a wrapper of `useAlepha().inject(service)` with a memoization.
|
|
557
|
+
*/
|
|
581
558
|
declare const useInject: <T extends object>(service: Service<T>) => T;
|
|
582
|
-
//# sourceMappingURL=useInject.d.ts.map
|
|
583
559
|
//#endregion
|
|
584
560
|
//#region src/hooks/useQueryParams.d.ts
|
|
561
|
+
/**
|
|
562
|
+
* Not well tested. Use with caution.
|
|
563
|
+
*/
|
|
564
|
+
declare const useQueryParams: <T extends TObject>(schema: T, options?: UseQueryParamsHookOptions) => [Static<T>, (data: Static<T>) => void];
|
|
585
565
|
interface UseQueryParamsHookOptions {
|
|
586
566
|
format?: "base64" | "querystring";
|
|
587
567
|
key?: string;
|
|
588
568
|
push?: boolean;
|
|
589
569
|
}
|
|
590
|
-
|
|
591
|
-
//#
|
|
570
|
+
//#endregion
|
|
571
|
+
//#region src/services/ReactRouter.d.ts
|
|
572
|
+
declare class ReactRouter<T extends object> {
|
|
573
|
+
protected readonly alepha: Alepha;
|
|
574
|
+
protected readonly pageApi: ReactPageProvider;
|
|
575
|
+
get state(): ReactRouterState;
|
|
576
|
+
get pages(): PageRoute[];
|
|
577
|
+
get browser(): ReactBrowserProvider | undefined;
|
|
578
|
+
path(name: keyof VirtualRouter<T>, config?: {
|
|
579
|
+
params?: Record<string, string>;
|
|
580
|
+
query?: Record<string, string>;
|
|
581
|
+
}): string;
|
|
582
|
+
getURL(): URL;
|
|
583
|
+
get location(): Location;
|
|
584
|
+
get current(): ReactRouterState;
|
|
585
|
+
get pathname(): string;
|
|
586
|
+
get query(): Record<string, string>;
|
|
587
|
+
back(): Promise<void>;
|
|
588
|
+
forward(): Promise<void>;
|
|
589
|
+
invalidate(props?: Record<string, any>): Promise<void>;
|
|
590
|
+
go(path: string, options?: RouterGoOptions): Promise<void>;
|
|
591
|
+
go(path: keyof VirtualRouter<T>, options?: RouterGoOptions): Promise<void>;
|
|
592
|
+
anchor(path: string, options?: {
|
|
593
|
+
params?: Record<string, any>;
|
|
594
|
+
}): AnchorProps;
|
|
595
|
+
anchor(path: keyof VirtualRouter<T>, options?: {
|
|
596
|
+
params?: Record<string, any>;
|
|
597
|
+
}): AnchorProps;
|
|
598
|
+
base(path: string): string;
|
|
599
|
+
/**
|
|
600
|
+
* Set query params.
|
|
601
|
+
*
|
|
602
|
+
* @param record
|
|
603
|
+
* @param options
|
|
604
|
+
*/
|
|
605
|
+
setQueryParams(record: Record<string, any> | ((queryParams: Record<string, any>) => Record<string, any>), options?: {
|
|
606
|
+
/**
|
|
607
|
+
* If true, this will add a new entry to the history stack.
|
|
608
|
+
*/
|
|
609
|
+
push?: boolean;
|
|
610
|
+
}): void;
|
|
611
|
+
}
|
|
612
|
+
type VirtualRouter<T> = { [K in keyof T as T[K] extends PageDescriptor ? K : never]: T[K] };
|
|
592
613
|
//#endregion
|
|
593
614
|
//#region src/hooks/useRouter.d.ts
|
|
594
|
-
|
|
595
|
-
|
|
615
|
+
/**
|
|
616
|
+
* Use this hook to access the React Router instance.
|
|
617
|
+
*
|
|
618
|
+
* You can add a type parameter to specify the type of your application.
|
|
619
|
+
* This will allow you to use the router in a typesafe way.
|
|
620
|
+
*
|
|
621
|
+
* @example
|
|
622
|
+
* class App {
|
|
623
|
+
* home = $page();
|
|
624
|
+
* }
|
|
625
|
+
*
|
|
626
|
+
* const router = useRouter<App>();
|
|
627
|
+
* router.go("home"); // typesafe
|
|
628
|
+
*/
|
|
629
|
+
declare const useRouter: <T extends object = any>() => ReactRouter<T>;
|
|
596
630
|
//#endregion
|
|
597
631
|
//#region src/hooks/useRouterEvents.d.ts
|
|
632
|
+
/**
|
|
633
|
+
* Subscribe to various router events.
|
|
634
|
+
*/
|
|
598
635
|
declare const useRouterEvents: (opts?: {
|
|
599
636
|
onBegin?: (ev: {
|
|
600
|
-
state:
|
|
637
|
+
state: ReactRouterState;
|
|
601
638
|
}) => void;
|
|
602
639
|
onEnd?: (ev: {
|
|
603
|
-
state:
|
|
604
|
-
context: PageReactContext;
|
|
640
|
+
state: ReactRouterState;
|
|
605
641
|
}) => void;
|
|
606
642
|
onError?: (ev: {
|
|
607
|
-
state:
|
|
643
|
+
state: ReactRouterState;
|
|
608
644
|
error: Error;
|
|
609
645
|
}) => void;
|
|
610
646
|
}, deps?: any[]) => void;
|
|
611
|
-
//# sourceMappingURL=useRouterEvents.d.ts.map
|
|
612
647
|
//#endregion
|
|
613
648
|
//#region src/hooks/useRouterState.d.ts
|
|
614
|
-
declare const useRouterState: () =>
|
|
615
|
-
//# sourceMappingURL=useRouterState.d.ts.map
|
|
649
|
+
declare const useRouterState: () => ReactRouterState;
|
|
616
650
|
//#endregion
|
|
617
651
|
//#region src/hooks/useSchema.d.ts
|
|
618
652
|
declare const useSchema: <TConfig extends RequestConfigSchema>(action: VirtualAction<TConfig>) => UseSchemaReturn<TConfig>;
|
|
@@ -625,22 +659,20 @@ type UseSchemaReturn<TConfig extends RequestConfigSchema> = TConfig & {
|
|
|
625
659
|
declare const ssrSchemaLoading: (alepha: Alepha, name: string) => RequestConfigSchema | {
|
|
626
660
|
loading: boolean;
|
|
627
661
|
};
|
|
628
|
-
//# sourceMappingURL=useSchema.d.ts.map
|
|
629
662
|
//#endregion
|
|
630
663
|
//#region src/hooks/useStore.d.ts
|
|
631
664
|
/**
|
|
632
665
|
* Hook to access and mutate the Alepha state.
|
|
633
666
|
*/
|
|
634
667
|
declare const useStore: <Key extends keyof State>(key: Key, defaultValue?: State[Key]) => [State[Key], (value: State[Key]) => void];
|
|
635
|
-
//# sourceMappingURL=useStore.d.ts.map
|
|
636
668
|
//#endregion
|
|
637
669
|
//#region src/providers/ReactServerProvider.d.ts
|
|
638
|
-
declare const envSchema:
|
|
639
|
-
REACT_SERVER_DIST:
|
|
640
|
-
REACT_SERVER_PREFIX:
|
|
641
|
-
REACT_SSR_ENABLED:
|
|
642
|
-
REACT_ROOT_ID:
|
|
643
|
-
REACT_SERVER_TEMPLATE:
|
|
670
|
+
declare const envSchema: _alepha_core14.TObject<{
|
|
671
|
+
REACT_SERVER_DIST: _alepha_core14.TString;
|
|
672
|
+
REACT_SERVER_PREFIX: _alepha_core14.TString;
|
|
673
|
+
REACT_SSR_ENABLED: _alepha_core14.TOptional<_alepha_core14.TBoolean>;
|
|
674
|
+
REACT_ROOT_ID: _alepha_core14.TString;
|
|
675
|
+
REACT_SERVER_TEMPLATE: _alepha_core14.TOptional<_alepha_core14.TString>;
|
|
644
676
|
}>;
|
|
645
677
|
declare module "@alepha/core" {
|
|
646
678
|
interface Env extends Partial<Static<typeof envSchema>> {}
|
|
@@ -649,9 +681,9 @@ declare module "@alepha/core" {
|
|
|
649
681
|
}
|
|
650
682
|
}
|
|
651
683
|
declare class ReactServerProvider {
|
|
652
|
-
protected readonly log:
|
|
684
|
+
protected readonly log: _alepha_logger1.Logger;
|
|
653
685
|
protected readonly alepha: Alepha;
|
|
654
|
-
protected readonly
|
|
686
|
+
protected readonly pageApi: ReactPageProvider;
|
|
655
687
|
protected readonly serverStaticProvider: ServerStaticProvider;
|
|
656
688
|
protected readonly serverRouterProvider: ServerRouterProvider;
|
|
657
689
|
protected readonly serverTimingProvider: ServerTimingProvider;
|
|
@@ -663,7 +695,7 @@ declare class ReactServerProvider {
|
|
|
663
695
|
REACT_ROOT_ID: string;
|
|
664
696
|
};
|
|
665
697
|
protected readonly ROOT_DIV_REGEX: RegExp;
|
|
666
|
-
readonly onConfigure:
|
|
698
|
+
readonly onConfigure: _alepha_core14.HookDescriptor<"configure">;
|
|
667
699
|
get template(): string;
|
|
668
700
|
protected registerPages(templateLoader: TemplateLoader): Promise<void>;
|
|
669
701
|
protected getPublicDirectory(): string;
|
|
@@ -673,15 +705,11 @@ declare class ReactServerProvider {
|
|
|
673
705
|
* For testing purposes, creates a render function that can be used.
|
|
674
706
|
*/
|
|
675
707
|
protected createRenderFunction(name: string, withIndex?: boolean): (options?: PageDescriptorRenderOptions) => Promise<{
|
|
676
|
-
|
|
677
|
-
state: CreateLayersResult;
|
|
678
|
-
html: string;
|
|
679
|
-
} | {
|
|
680
|
-
context: PageRequest;
|
|
708
|
+
state: ReactRouterState;
|
|
681
709
|
html: string;
|
|
682
710
|
}>;
|
|
683
|
-
protected createHandler(
|
|
684
|
-
renderToHtml(template: string, state:
|
|
711
|
+
protected createHandler(route: PageRoute, templateLoader: TemplateLoader): ServerHandler;
|
|
712
|
+
renderToHtml(template: string, state: ReactRouterState, hydration?: boolean): string | Redirection;
|
|
685
713
|
protected fillTemplate(response: {
|
|
686
714
|
html: string;
|
|
687
715
|
}, app: string, script: string): void;
|
|
@@ -690,43 +718,35 @@ type TemplateLoader = () => Promise<string | undefined>;
|
|
|
690
718
|
//#endregion
|
|
691
719
|
//#region src/index.d.ts
|
|
692
720
|
declare module "@alepha/core" {
|
|
721
|
+
interface State {
|
|
722
|
+
"react.router.state"?: ReactRouterState;
|
|
723
|
+
}
|
|
693
724
|
interface Hooks {
|
|
694
|
-
"react:router:createLayers": {
|
|
695
|
-
request: ServerRequest;
|
|
696
|
-
context: PageRequest;
|
|
697
|
-
layers: PageRequest[];
|
|
698
|
-
};
|
|
699
725
|
"react:server:render:begin": {
|
|
700
726
|
request?: ServerRequest;
|
|
701
|
-
|
|
727
|
+
state: ReactRouterState;
|
|
702
728
|
};
|
|
703
729
|
"react:server:render:end": {
|
|
704
730
|
request?: ServerRequest;
|
|
705
|
-
|
|
706
|
-
state: RouterState;
|
|
731
|
+
state: ReactRouterState;
|
|
707
732
|
html: string;
|
|
708
733
|
};
|
|
709
734
|
"react:browser:render": {
|
|
710
|
-
state:
|
|
711
|
-
context: PageReactContext;
|
|
735
|
+
state: ReactRouterState;
|
|
712
736
|
hydration?: ReactHydrationState;
|
|
713
737
|
};
|
|
714
738
|
"react:transition:begin": {
|
|
715
|
-
state:
|
|
716
|
-
context: PageReactContext;
|
|
739
|
+
state: ReactRouterState;
|
|
717
740
|
};
|
|
718
741
|
"react:transition:success": {
|
|
719
|
-
state:
|
|
720
|
-
context: PageReactContext;
|
|
742
|
+
state: ReactRouterState;
|
|
721
743
|
};
|
|
722
744
|
"react:transition:error": {
|
|
745
|
+
state: ReactRouterState;
|
|
723
746
|
error: Error;
|
|
724
|
-
state: RouterState;
|
|
725
|
-
context: PageReactContext;
|
|
726
747
|
};
|
|
727
748
|
"react:transition:end": {
|
|
728
|
-
state:
|
|
729
|
-
context: PageReactContext;
|
|
749
|
+
state: ReactRouterState;
|
|
730
750
|
};
|
|
731
751
|
}
|
|
732
752
|
}
|
|
@@ -740,9 +760,7 @@ declare module "@alepha/core" {
|
|
|
740
760
|
* @see {@link $page}
|
|
741
761
|
* @module alepha.react
|
|
742
762
|
*/
|
|
743
|
-
declare const AlephaReact:
|
|
744
|
-
//# sourceMappingURL=index.d.ts.map
|
|
745
|
-
|
|
763
|
+
declare const AlephaReact: _alepha_core14.Service<_alepha_core14.Module>;
|
|
746
764
|
//#endregion
|
|
747
|
-
export { $page, AlephaContext, AlephaReact, AnchorProps, ClientOnly, CreateLayersResult, ErrorBoundary, ErrorHandler,
|
|
765
|
+
export { $page, AlephaContext, AlephaReact, AnchorProps, ClientOnly, CreateLayersResult, ErrorBoundary, ErrorHandler, ErrorViewer, Layer, Link, LinkProps, NestedView, NotFoundPage as NotFound, PageConfigSchema, PageDescriptor, PageDescriptorOptions, PageDescriptorRenderOptions, PageDescriptorRenderResult, PageRequestConfig, PageResolve, PageRoute, PageRouteEntry, PreviousLayerData, ReactBrowserProvider, ReactBrowserRendererOptions, ReactHydrationState, ReactPageProvider, ReactRouter, ReactRouterState, ReactServerProvider, Redirection, RouterGoOptions, RouterLayerContext, RouterLayerContextValue, RouterStackItem, TPropsDefault, TPropsParentDefault, TransitionOptions, UseActiveHook, UseActiveOptions, UseQueryParamsHookOptions, UseSchemaReturn, VirtualRouter, isPageRoute, ssrSchemaLoading, useActive, useAlepha, useClient, useInject, useQueryParams, useRouter, useRouterEvents, useRouterState, useSchema, useStore };
|
|
748
766
|
//# sourceMappingURL=index.d.ts.map
|