@alepha/react 0.13.2 → 0.13.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.
@@ -1192,6 +1192,7 @@ interface ReactRouterState {
1192
1192
  * Optional meta information associated with the current page.
1193
1193
  */
1194
1194
  meta: Record<string, any>;
1195
+ name?: string;
1195
1196
  }
1196
1197
  interface RouterStackItem {
1197
1198
  route: PageRoute;
@@ -2297,6 +2298,35 @@ declare class ReactRouter<T$1 extends object> {
2297
2298
  isActive(href: string, options?: {
2298
2299
  startWith?: boolean;
2299
2300
  }): boolean;
2301
+ node(name: keyof VirtualRouter<T$1> | string, config?: {
2302
+ params?: Record<string, any>;
2303
+ query?: Record<string, any>;
2304
+ }): {
2305
+ label: any;
2306
+ href: string;
2307
+ children: undefined;
2308
+ type: "page";
2309
+ name: string;
2310
+ parent?: PageRoute;
2311
+ match: string;
2312
+ path?: string | undefined;
2313
+ schema?: PageConfigSchema | undefined;
2314
+ resolve?: ((context: PageResolve<PageConfigSchema, TPropsParentDefault>) => any) | undefined;
2315
+ component?: react0.FC<any> | undefined;
2316
+ lazy?: (() => Promise<{
2317
+ default: react0.FC<any>;
2318
+ }>) | undefined;
2319
+ can?: (() => boolean) | undefined;
2320
+ errorHandler?: ErrorHandler | undefined;
2321
+ static?: boolean | {
2322
+ entries?: Partial<PageRequestConfig<PageConfigSchema>>[] | undefined;
2323
+ } | undefined;
2324
+ cache?: ServerRouteCache | undefined;
2325
+ client?: (boolean | ClientOnlyProps) | undefined;
2326
+ onServerResponse?: ((request: ServerRequest) => unknown) | undefined;
2327
+ onLeave?: (() => void) | undefined;
2328
+ animation?: PageAnimation | undefined;
2329
+ };
2300
2330
  path(name: keyof VirtualRouter<T$1> | string, config?: {
2301
2331
  params?: Record<string, any>;
2302
2332
  query?: Record<string, any>;
@@ -487,7 +487,8 @@ const NestedView = (props) => {
487
487
  useEvents({
488
488
  "react:transition:begin": async ({ previous, state: state$1 }) => {
489
489
  const layer = previous.layers[index];
490
- if (`${state$1.url.pathname}/`.startsWith(`${layer?.path}/`)) return;
490
+ if (!layer) return;
491
+ if (`${state$1.url.pathname}/`.startsWith(`${layer.path}/`)) return;
491
492
  const animationExit = parseAnimation(layer.route?.animation, state$1, "exit");
492
493
  if (animationExit) {
493
494
  const duration = animationExit.duration || 200;
@@ -579,25 +580,35 @@ function parseAnimation(animationLike, state, type = "enter") {
579
580
  //#endregion
580
581
  //#region src/core/components/NotFound.tsx
581
582
  function NotFoundPage(props) {
582
- return /* @__PURE__ */ jsx("div", {
583
+ return /* @__PURE__ */ jsxs("div", {
583
584
  style: {
584
- height: "100vh",
585
+ width: "100%",
586
+ minHeight: "90vh",
587
+ boxSizing: "border-box",
585
588
  display: "flex",
586
589
  flexDirection: "column",
587
590
  justifyContent: "center",
588
591
  alignItems: "center",
589
592
  textAlign: "center",
590
- fontFamily: "sans-serif",
591
- padding: "1rem",
593
+ fontFamily: "system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif",
594
+ padding: "2rem",
592
595
  ...props.style
593
596
  },
594
- children: /* @__PURE__ */ jsx("h1", {
597
+ children: [/* @__PURE__ */ jsx("div", {
595
598
  style: {
596
- fontSize: "1rem",
597
- marginBottom: "0.5rem"
599
+ fontSize: "6rem",
600
+ fontWeight: 200,
601
+ lineHeight: 1
598
602
  },
599
- children: "404 - This page does not exist"
600
- })
603
+ children: "404"
604
+ }), /* @__PURE__ */ jsx("div", {
605
+ style: {
606
+ fontSize: "0.875rem",
607
+ marginTop: "1rem",
608
+ opacity: .6
609
+ },
610
+ children: "Page not found"
611
+ })]
601
612
  });
602
613
  }
603
614
 
@@ -1012,8 +1023,7 @@ var ReactServerProvider = class {
1012
1023
  async registerPages(templateLoader) {
1013
1024
  const template = await templateLoader();
1014
1025
  if (template) this.preprocessedTemplate = this.preprocessTemplate(template);
1015
- for (const page of this.pageApi.getPages()) {
1016
- if (page.children?.length) continue;
1026
+ for (const page of this.pageApi.getPages()) if (page.component || page.lazy) {
1017
1027
  this.log.debug(`+ ${page.match} -> ${page.name}`);
1018
1028
  this.serverRouterProvider.createRoute({
1019
1029
  ...page,
@@ -1110,6 +1120,7 @@ var ReactServerProvider = class {
1110
1120
  onError: () => null,
1111
1121
  layers: []
1112
1122
  };
1123
+ state.name = route.name;
1113
1124
  if (this.alepha.has(ServerLinksProvider)) this.alepha.store.set("alepha.server.request.apiLinks", await this.alepha.inject(ServerLinksProvider).getUserApiLinks({
1114
1125
  user: serverRequest.user,
1115
1126
  authorization: serverRequest.headers.authorization
@@ -1117,6 +1128,7 @@ var ReactServerProvider = class {
1117
1128
  let target = route;
1118
1129
  while (target) {
1119
1130
  if (route.can && !route.can()) {
1131
+ this.log.warn(`Access to page '${route.name}' is forbidden by can() check`);
1120
1132
  reply.status = 403;
1121
1133
  reply.headers["content-type"] = "text/plain";
1122
1134
  return "Forbidden";
@@ -1130,7 +1142,10 @@ var ReactServerProvider = class {
1130
1142
  this.serverTimingProvider.beginTiming("createLayers");
1131
1143
  const { redirect } = await this.pageApi.createLayers(route, state);
1132
1144
  this.serverTimingProvider.endTiming("createLayers");
1133
- if (redirect) return reply.redirect(redirect);
1145
+ if (redirect) {
1146
+ this.log.debug("Resolver resulted in redirection", { redirect });
1147
+ return reply.redirect(redirect);
1148
+ }
1134
1149
  reply.headers["content-type"] = "text/html";
1135
1150
  reply.headers["cache-control"] = "no-store, no-cache, must-revalidate, proxy-revalidate";
1136
1151
  reply.headers.pragma = "no-cache";
@@ -1138,8 +1153,10 @@ var ReactServerProvider = class {
1138
1153
  const html = this.renderToHtml(template, state);
1139
1154
  if (html instanceof Redirection) {
1140
1155
  reply.redirect(typeof html.redirect === "string" ? html.redirect : this.pageApi.href(html.redirect));
1156
+ this.log.debug("Rendering resulted in redirection", { redirect: html.redirect });
1141
1157
  return;
1142
1158
  }
1159
+ this.log.trace("Page rendered to HTML successfully");
1143
1160
  const event = {
1144
1161
  request: serverRequest,
1145
1162
  state,
@@ -1292,6 +1309,7 @@ var ReactBrowserRouterProvider = class extends RouterProvider {
1292
1309
  const { route, params } = this.match(pathname);
1293
1310
  const query = {};
1294
1311
  if (search) for (const [key, value] of new URLSearchParams(search).entries()) query[key] = String(value);
1312
+ state.name = route?.page.name;
1295
1313
  state.query = query;
1296
1314
  state.params = params ?? {};
1297
1315
  if (isPageRoute(route)) {
@@ -1524,6 +1542,15 @@ var ReactRouter = class {
1524
1542
  if (options.startWith && !isActive) isActive = current.startsWith(href);
1525
1543
  return isActive;
1526
1544
  }
1545
+ node(name, config = {}) {
1546
+ const page = this.pageApi.page(name);
1547
+ return {
1548
+ ...page,
1549
+ label: page.label ?? page.name,
1550
+ href: this.path(name, config),
1551
+ children: void 0
1552
+ };
1553
+ }
1527
1554
  path(name, config = {}) {
1528
1555
  return this.pageApi.pathname(name, {
1529
1556
  params: {