@alepha/react 0.6.4 → 0.6.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.
@@ -2,8 +2,8 @@
2
2
 
3
3
  var jsxRuntime = require('react/jsx-runtime');
4
4
  var React = require('react');
5
- var server = require('@alepha/server');
6
5
  var core = require('@alepha/core');
6
+ var server = require('@alepha/server');
7
7
  var client = require('react-dom/client');
8
8
  var router = require('@alepha/router');
9
9
 
@@ -12,20 +12,20 @@ const $page = (options) => {
12
12
  core.__descriptor(KEY);
13
13
  if (options.children) {
14
14
  for (const child of options.children) {
15
- child.options.parent = {
16
- options
15
+ child[core.OPTIONS].parent = {
16
+ [core.OPTIONS]: options
17
17
  };
18
18
  }
19
19
  }
20
20
  if (options.parent) {
21
- options.parent.options.children ??= [];
22
- options.parent.options.children.push({
23
- options
21
+ options.parent[core.OPTIONS].children ??= [];
22
+ options.parent[core.OPTIONS].children.push({
23
+ [core.OPTIONS]: options
24
24
  });
25
25
  }
26
26
  return {
27
27
  [core.KIND]: KEY,
28
- options,
28
+ [core.OPTIONS]: options,
29
29
  render: () => {
30
30
  throw new core.NotImplementedError(KEY);
31
31
  },
@@ -51,6 +51,48 @@ const RouterContext = React.createContext(
51
51
 
52
52
  const RouterLayerContext = React.createContext(void 0);
53
53
 
54
+ const useRouterEvents = (opts = {}, deps = []) => {
55
+ const ctx = React.useContext(RouterContext);
56
+ if (!ctx) {
57
+ throw new Error("useRouter must be used within a RouterProvider");
58
+ }
59
+ React.useEffect(() => {
60
+ if (!ctx.alepha.isBrowser()) {
61
+ return;
62
+ }
63
+ const subs = [];
64
+ const onBegin = opts.onBegin;
65
+ const onEnd = opts.onEnd;
66
+ const onError = opts.onError;
67
+ if (onBegin) {
68
+ subs.push(
69
+ ctx.alepha.on("react:transition:begin", {
70
+ callback: onBegin
71
+ })
72
+ );
73
+ }
74
+ if (onEnd) {
75
+ subs.push(
76
+ ctx.alepha.on("react:transition:end", {
77
+ callback: onEnd
78
+ })
79
+ );
80
+ }
81
+ if (onError) {
82
+ subs.push(
83
+ ctx.alepha.on("react:transition:error", {
84
+ callback: onError
85
+ })
86
+ );
87
+ }
88
+ return () => {
89
+ for (const sub of subs) {
90
+ sub();
91
+ }
92
+ };
93
+ }, deps);
94
+ };
95
+
54
96
  const NestedView = (props) => {
55
97
  const app = React.useContext(RouterContext);
56
98
  const layer = React.useContext(RouterLayerContext);
@@ -58,13 +100,14 @@ const NestedView = (props) => {
58
100
  const [view, setView] = React.useState(
59
101
  app?.state.layers[index]?.element
60
102
  );
61
- React.useEffect(() => {
62
- if (app?.alepha.isBrowser()) {
63
- return app?.events.on("end", (state) => {
103
+ useRouterEvents(
104
+ {
105
+ onEnd: ({ state }) => {
64
106
  setView(state.layers[index]?.element);
65
- });
66
- }
67
- }, [app]);
107
+ }
108
+ },
109
+ [app]
110
+ );
68
111
  return view ?? props.children ?? null;
69
112
  };
70
113
 
@@ -90,15 +133,14 @@ class PageDescriptorProvider {
90
133
  }
91
134
  throw new Error(`Page ${name} not found`);
92
135
  }
93
- root(state, context = {}, events) {
136
+ root(state, context = {}) {
94
137
  return React.createElement(
95
138
  RouterContext.Provider,
96
139
  {
97
140
  value: {
98
141
  alepha: this.alepha,
99
142
  state,
100
- context,
101
- events: events ?? new core.EventEmitter()
143
+ context
102
144
  }
103
145
  },
104
146
  React.createElement(NestedView, {}, state.layers[0]?.element)
@@ -334,8 +376,8 @@ class PageDescriptorProvider {
334
376
  handler: () => {
335
377
  const pages = this.alepha.getDescriptorValues($page);
336
378
  for (const { value, key } of pages) {
337
- value.options.name ??= key;
338
- if (value.options.parent) {
379
+ value[core.OPTIONS].name ??= key;
380
+ if (value[core.OPTIONS].parent) {
339
381
  continue;
340
382
  }
341
383
  this.add(this.map(pages, value));
@@ -343,14 +385,14 @@ class PageDescriptorProvider {
343
385
  }
344
386
  });
345
387
  map(pages, target) {
346
- const children = target.options.children ?? [];
388
+ const children = target[core.OPTIONS].children ?? [];
347
389
  for (const it of pages) {
348
- if (it.value.options.parent === target) {
390
+ if (it.value[core.OPTIONS].parent === target) {
349
391
  children.push(it.value);
350
392
  }
351
393
  }
352
394
  return {
353
- ...target.options,
395
+ ...target[core.OPTIONS],
354
396
  parent: void 0,
355
397
  children: children.map((it) => this.map(pages, it))
356
398
  };
@@ -436,7 +478,6 @@ class BrowserRouterProvider extends router.RouterProvider {
436
478
  log = core.$logger();
437
479
  alepha = core.$inject(core.Alepha);
438
480
  pageDescriptorProvider = core.$inject(PageDescriptorProvider);
439
- events = new core.EventEmitter();
440
481
  add(entry) {
441
482
  this.pageDescriptorProvider.add(entry);
442
483
  }
@@ -461,7 +502,7 @@ class BrowserRouterProvider extends router.RouterProvider {
461
502
  layers: [],
462
503
  head: {}
463
504
  };
464
- await this.events.emit("begin", void 0);
505
+ await this.alepha.emit("react:transition:begin", { state });
465
506
  try {
466
507
  const previous = options.previous;
467
508
  const { route, params } = this.match(pathname);
@@ -503,7 +544,7 @@ class BrowserRouterProvider extends router.RouterProvider {
503
544
  path: "/"
504
545
  });
505
546
  }
506
- await this.events.emit("success", void 0);
547
+ await this.alepha.emit("react:transition:success", { state });
507
548
  } catch (e) {
508
549
  this.log.error(e);
509
550
  state.layers = [
@@ -514,10 +555,15 @@ class BrowserRouterProvider extends router.RouterProvider {
514
555
  path: "/"
515
556
  }
516
557
  ];
517
- await this.events.emit("error", e);
558
+ await this.alepha.emit("react:transition:error", {
559
+ error: e,
560
+ state
561
+ });
518
562
  }
519
563
  if (!options.state) {
520
- await this.events.emit("end", state);
564
+ await this.alepha.emit("react:transition:end", {
565
+ state
566
+ });
521
567
  return {
522
568
  element: this.root(state, options.context),
523
569
  layers: state.layers,
@@ -528,7 +574,9 @@ class BrowserRouterProvider extends router.RouterProvider {
528
574
  options.state.pathname = state.pathname;
529
575
  options.state.search = state.search;
530
576
  options.state.head = state.head;
531
- await this.events.emit("end", options.state);
577
+ await this.alepha.emit("react:transition:end", {
578
+ state: options.state
579
+ });
532
580
  return {
533
581
  element: this.root(state, options.context),
534
582
  layers: options.state.layers,
@@ -536,7 +584,7 @@ class BrowserRouterProvider extends router.RouterProvider {
536
584
  };
537
585
  }
538
586
  root(state, context = {}) {
539
- return this.pageDescriptorProvider.root(state, context, this.events);
587
+ return this.pageDescriptorProvider.root(state, context);
540
588
  }
541
589
  }
542
590
 
@@ -686,11 +734,19 @@ class ReactBrowserProvider {
686
734
  window.addEventListener("popstate", () => {
687
735
  this.render();
688
736
  });
689
- this.router.events.on("end", ({ head: head2 }) => {
690
- this.headProvider.renderHead(this.document, head2);
737
+ this.alepha.on("react:transition:end", {
738
+ callback: ({ state }) => {
739
+ this.headProvider.renderHead(this.document, state.head);
740
+ }
691
741
  });
692
742
  }
693
743
  });
744
+ onTransitionEnd = core.$hook({
745
+ name: "react:transition:end",
746
+ handler: async ({ state }) => {
747
+ this.headProvider.renderHead(this.document, state.head);
748
+ }
749
+ });
694
750
  }
695
751
 
696
752
  class RouterHookApi {
@@ -819,15 +875,15 @@ const useRouter = () => {
819
875
 
820
876
  const Link = (props) => {
821
877
  React.useContext(RouterContext);
822
- const to = typeof props.to === "string" ? props.to : props.to.options.path;
878
+ const to = typeof props.to === "string" ? props.to : props.to[core.OPTIONS].path;
823
879
  if (!to) {
824
880
  return null;
825
881
  }
826
- const can = typeof props.to === "string" ? void 0 : props.to.options.can;
882
+ const can = typeof props.to === "string" ? void 0 : props.to[core.OPTIONS].can;
827
883
  if (can && !can()) {
828
884
  return null;
829
885
  }
830
- const name = typeof props.to === "string" ? void 0 : props.to.options.name;
886
+ const name = typeof props.to === "string" ? void 0 : props.to[core.OPTIONS].name;
831
887
  const router = useRouter();
832
888
  return /* @__PURE__ */ jsxRuntime.jsx("a", { ...router.createAnchorProps(to), ...props, children: props.children ?? name });
833
889
  };
@@ -884,34 +940,6 @@ const decode = (alepha, schema, data) => {
884
940
  }
885
941
  };
886
942
 
887
- const useRouterEvents = (opts = {}) => {
888
- const ctx = React.useContext(RouterContext);
889
- const layer = React.useContext(RouterLayerContext);
890
- if (!ctx || !layer) {
891
- throw new Error("useRouter must be used within a RouterProvider");
892
- }
893
- React.useEffect(() => {
894
- const subs = [];
895
- const onBegin = opts.onBegin;
896
- const onEnd = opts.onEnd;
897
- const onError = opts.onError;
898
- if (onBegin) {
899
- subs.push(ctx.events.on("begin", onBegin));
900
- }
901
- if (onEnd) {
902
- subs.push(ctx.events.on("end", onEnd));
903
- }
904
- if (onError) {
905
- subs.push(ctx.events.on("error", onError));
906
- }
907
- return () => {
908
- for (const sub of subs) {
909
- sub();
910
- }
911
- };
912
- }, []);
913
- };
914
-
915
943
  const useRouterState = () => {
916
944
  const ctx = React.useContext(RouterContext);
917
945
  const layer = React.useContext(RouterLayerContext);
@@ -919,12 +947,9 @@ const useRouterState = () => {
919
947
  throw new Error("useRouter must be used within a RouterProvider");
920
948
  }
921
949
  const [state, setState] = React.useState(ctx.state);
922
- React.useEffect(
923
- () => ctx.events.on("end", (it) => {
924
- setState({ ...it });
925
- }),
926
- []
927
- );
950
+ useRouterEvents({
951
+ onEnd: ({ state: state2 }) => setState({ ...state2 })
952
+ });
928
953
  return state;
929
954
  };
930
955
 
@@ -943,10 +968,9 @@ const useActive = (path) => {
943
968
  const href = React.useMemo(() => router.createHref(path, layer), [path, layer]);
944
969
  const [isPending, setPending] = React.useState(false);
945
970
  const isActive = current === href;
946
- React.useEffect(
947
- () => ctx.events.on("end", ({ pathname }) => setCurrent(pathname)),
948
- []
949
- );
971
+ useRouterEvents({
972
+ onEnd: ({ state }) => setCurrent(state.pathname)
973
+ });
950
974
  return {
951
975
  name,
952
976
  isPending,
@@ -985,4 +1009,4 @@ exports.useQueryParams = useQueryParams;
985
1009
  exports.useRouter = useRouter;
986
1010
  exports.useRouterEvents = useRouterEvents;
987
1011
  exports.useRouterState = useRouterState;
988
- //# sourceMappingURL=useActive-BGtt_RNQ.cjs.map
1012
+ //# sourceMappingURL=useActive-Ce3Xvs5V.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useActive-Ce3Xvs5V.cjs","sources":["../src/descriptors/$page.ts","../src/contexts/RouterContext.ts","../src/contexts/RouterLayerContext.ts","../src/hooks/useRouterEvents.ts","../src/components/NestedView.tsx","../src/errors/RedirectionError.ts","../src/providers/PageDescriptorProvider.ts","../src/providers/BrowserHeadProvider.ts","../src/providers/BrowserRouterProvider.ts","../src/providers/ReactBrowserProvider.ts","../src/hooks/RouterHookApi.ts","../src/hooks/useRouter.ts","../src/components/Link.tsx","../src/hooks/useInject.ts","../src/hooks/useClient.ts","../src/hooks/useQueryParams.ts","../src/hooks/useRouterState.ts","../src/hooks/useActive.ts"],"sourcesContent":["import { type Async, OPTIONS, type Static, type TSchema } from \"@alepha/core\";\nimport { KIND, NotImplementedError, __descriptor } from \"@alepha/core\";\nimport type { FC } from \"react\";\nimport type { RouterHookApi } from \"../hooks/RouterHookApi.ts\";\n\nconst KEY = \"PAGE\";\n\nexport interface PageConfigSchema {\n\tquery?: TSchema;\n\tparams?: TSchema;\n}\n\nexport type TPropsDefault = any;\n\nexport type TPropsParentDefault = object;\n\nexport interface PageDescriptorOptions<\n\tTConfig extends PageConfigSchema = PageConfigSchema,\n\tTProps extends object = TPropsDefault,\n\tTPropsParent extends object = TPropsParentDefault,\n> {\n\tname?: string;\n\n\tpath?: string;\n\n\tschema?: TConfig;\n\n\tresolve?: (config: PageResolve<TConfig, TPropsParent>) => Async<TProps>;\n\n\tcomponent?: FC<TProps & TPropsParent>;\n\n\tlazy?: () => Promise<{ default: FC<TProps & TPropsParent> }>;\n\n\tchildren?: Array<{ [OPTIONS]: PageDescriptorOptions }>;\n\n\tparent?: { [OPTIONS]: PageDescriptorOptions<any, TPropsParent> };\n\n\tcan?: () => boolean;\n\n\thead?: Head | ((props: TProps, previous?: Head) => Head);\n\n\terrorHandler?: FC<{ error: Error; url: string }>;\n}\n\nexport interface PageDescriptor<\n\tTConfig extends PageConfigSchema = PageConfigSchema,\n\tTProps extends object = TPropsDefault,\n\tTPropsParent extends object = TPropsParentDefault,\n> {\n\t[KIND]: typeof KEY;\n\t[OPTIONS]: PageDescriptorOptions<TConfig, TProps, TPropsParent>;\n\n\trender: (options?: {\n\t\tparams?: Record<string, string>;\n\t\tquery?: Record<string, string>;\n\t}) => Promise<string>;\n\tgo: () => void;\n\tcreateAnchorProps: (routerHook: RouterHookApi) => {\n\t\thref: string;\n\t\tonClick: () => void;\n\t};\n\tcan: () => boolean;\n}\n\nexport const $page = <\n\tTConfig extends PageConfigSchema = PageConfigSchema,\n\tTProps extends object = TPropsDefault,\n\tTPropsParent extends object = TPropsParentDefault,\n>(\n\toptions: PageDescriptorOptions<TConfig, TProps, TPropsParent>,\n): PageDescriptor<TConfig, TProps, TPropsParent> => {\n\t__descriptor(KEY);\n\n\tif (options.children) {\n\t\tfor (const child of options.children) {\n\t\t\tchild[OPTIONS].parent = {\n\t\t\t\t[OPTIONS]: options as PageDescriptorOptions<any, any, any>,\n\t\t\t};\n\t\t}\n\t}\n\n\tif (options.parent) {\n\t\toptions.parent[OPTIONS].children ??= [];\n\t\toptions.parent[OPTIONS].children.push({\n\t\t\t[OPTIONS]: options as PageDescriptorOptions<any, any, any>,\n\t\t});\n\t}\n\n\treturn {\n\t\t[KIND]: KEY,\n\t\t[OPTIONS]: options,\n\t\trender: () => {\n\t\t\tthrow new NotImplementedError(KEY);\n\t\t},\n\t\tgo: () => {\n\t\t\tthrow new NotImplementedError(KEY);\n\t\t},\n\t\tcreateAnchorProps: () => {\n\t\t\tthrow new NotImplementedError(KEY);\n\t\t},\n\t\tcan: () => {\n\t\t\tif (options.can) {\n\t\t\t\treturn options.can();\n\t\t\t}\n\t\t\treturn true;\n\t\t},\n\t};\n};\n\n$page[KIND] = KEY;\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport interface Head {\n\ttitle?: string;\n\ttitleSeparator?: string;\n\thtmlAttributes?: Record<string, string>;\n\tbodyAttributes?: Record<string, string>;\n\tmeta?: Array<{ name: string; content: string }>;\n}\n\nexport interface PageRequestConfig<\n\tTConfig extends PageConfigSchema = PageConfigSchema,\n> {\n\tparams: TConfig[\"params\"] extends TSchema\n\t\t? Static<TConfig[\"params\"]>\n\t\t: Record<string, string>;\n\n\tquery: TConfig[\"query\"] extends TSchema\n\t\t? Static<TConfig[\"query\"]>\n\t\t: Record<string, string>;\n}\n\nexport type PageResolve<\n\tTConfig extends PageConfigSchema = PageConfigSchema,\n\tTPropsParent extends object = TPropsParentDefault,\n> = PageRequestConfig<TConfig> & TPropsParent & PageResolveContext;\n\nexport interface PageResolveContext {\n\turl: URL;\n\thead: Head;\n}\n","import type { Alepha } from \"@alepha/core\";\nimport { createContext } from \"react\";\nimport type {\n\tPageReactContext,\n\tRouterState,\n} from \"../providers/PageDescriptorProvider.ts\";\n\nexport interface RouterContextValue {\n\talepha: Alepha;\n\tstate: RouterState;\n\tcontext: PageReactContext;\n}\n\nexport const RouterContext = createContext<RouterContextValue | undefined>(\n\tundefined,\n);\n","import { createContext } from \"react\";\n\nexport interface RouterLayerContextValue {\n\tindex: number;\n\tpath: string;\n}\n\nexport const RouterLayerContext = createContext<\n\tRouterLayerContextValue | undefined\n>(undefined);\n","import { useContext, useEffect } from \"react\";\nimport { RouterContext } from \"../contexts/RouterContext.ts\";\nimport type { RouterState } from \"../providers/PageDescriptorProvider.ts\";\n\nexport const useRouterEvents = (\n\topts: {\n\t\tonBegin?: (ev: { state: RouterState }) => void;\n\t\tonEnd?: (ev: { state: RouterState }) => void;\n\t\tonError?: (ev: { state: RouterState; error: Error }) => void;\n\t} = {},\n\tdeps: any[] = [],\n) => {\n\tconst ctx = useContext(RouterContext);\n\tif (!ctx) {\n\t\tthrow new Error(\"useRouter must be used within a RouterProvider\");\n\t}\n\n\tuseEffect(() => {\n\t\tif (!ctx.alepha.isBrowser()) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst subs: Function[] = [];\n\t\tconst onBegin = opts.onBegin;\n\t\tconst onEnd = opts.onEnd;\n\t\tconst onError = opts.onError;\n\n\t\tif (onBegin) {\n\t\t\tsubs.push(\n\t\t\t\tctx.alepha.on(\"react:transition:begin\", {\n\t\t\t\t\tcallback: onBegin,\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\tif (onEnd) {\n\t\t\tsubs.push(\n\t\t\t\tctx.alepha.on(\"react:transition:end\", {\n\t\t\t\t\tcallback: onEnd,\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\tif (onError) {\n\t\t\tsubs.push(\n\t\t\t\tctx.alepha.on(\"react:transition:error\", {\n\t\t\t\t\tcallback: onError,\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\treturn () => {\n\t\t\tfor (const sub of subs) {\n\t\t\t\tsub();\n\t\t\t}\n\t\t};\n\t}, deps);\n};\n","import type { ReactNode } from \"react\";\nimport { useContext, useState } from \"react\";\nimport { RouterContext } from \"../contexts/RouterContext.ts\";\nimport { RouterLayerContext } from \"../contexts/RouterLayerContext.ts\";\nimport { useRouterEvents } from \"../hooks/useRouterEvents.ts\";\n\nexport interface NestedViewProps {\n\tchildren?: ReactNode;\n}\n\n/**\n * Nested view component\n *\n * @param props\n * @constructor\n */\nconst NestedView = (props: NestedViewProps) => {\n\tconst app = useContext(RouterContext);\n\tconst layer = useContext(RouterLayerContext);\n\tconst index = layer?.index ?? 0;\n\n\tconst [view, setView] = useState<ReactNode | undefined>(\n\t\tapp?.state.layers[index]?.element,\n\t);\n\n\tuseRouterEvents(\n\t\t{\n\t\t\tonEnd: ({ state }) => {\n\t\t\t\tsetView(state.layers[index]?.element);\n\t\t\t},\n\t\t},\n\t\t[app],\n\t);\n\n\treturn view ?? props.children ?? null;\n};\n\nexport default NestedView;\n","import type { HrefLike } from \"../hooks/RouterHookApi.ts\";\n\nexport class RedirectionError extends Error {\n\tconstructor(public readonly page: HrefLike) {\n\t\tsuper(\"Redirection\");\n\t}\n}\n","import { $hook, $inject, $logger, Alepha, OPTIONS } from \"@alepha/core\";\nimport type { HttpClientLink } from \"@alepha/server\";\nimport { type ReactNode, createElement } from \"react\";\nimport NestedView from \"../components/NestedView.tsx\";\nimport { RouterContext } from \"../contexts/RouterContext.ts\";\nimport { RouterLayerContext } from \"../contexts/RouterLayerContext.ts\";\nimport {\n\t$page,\n\ttype Head,\n\ttype PageDescriptorOptions,\n} from \"../descriptors/$page.ts\";\nimport { RedirectionError } from \"../errors/RedirectionError.ts\";\n\nexport class PageDescriptorProvider {\n\tprotected readonly log = $logger();\n\tprotected readonly alepha = $inject(Alepha);\n\tprotected readonly pages: PageRoute[] = [];\n\n\tpublic getPages(): PageRoute[] {\n\t\treturn this.pages;\n\t}\n\n\tpublic page(name: string): PageRoute {\n\t\tfor (const page of this.pages) {\n\t\t\tif (page.name === name) {\n\t\t\t\treturn page;\n\t\t\t}\n\t\t}\n\n\t\tthrow new Error(`Page ${name} not found`);\n\t}\n\n\tpublic root(state: RouterState, context: PageReactContext = {}): ReactNode {\n\t\treturn createElement(\n\t\t\tRouterContext.Provider,\n\t\t\t{\n\t\t\t\tvalue: {\n\t\t\t\t\talepha: this.alepha,\n\t\t\t\t\tstate,\n\t\t\t\t\tcontext,\n\t\t\t\t},\n\t\t\t},\n\t\t\tcreateElement(NestedView, {}, state.layers[0]?.element),\n\t\t);\n\t}\n\n\tpublic async createLayers(\n\t\troute: PageRoute,\n\t\trequest: PageRequest,\n\t): Promise<CreateLayersResult> {\n\t\tconst { pathname, search } = request.url;\n\t\tconst layers: Layer[] = []; // result layers\n\t\tlet context: Record<string, any> = {}; // all props\n\t\tconst stack: Array<RouterStackItem> = [{ route }]; // stack of routes\n\n\t\tlet parent = route.parent;\n\t\twhile (parent) {\n\t\t\tstack.unshift({ route: parent });\n\t\t\tparent = parent.parent;\n\t\t}\n\n\t\tlet forceRefresh = false;\n\n\t\tfor (let i = 0; i < stack.length; i++) {\n\t\t\tconst it = stack[i];\n\t\t\tconst route = it.route;\n\t\t\tconst config: Record<string, any> = {};\n\n\t\t\ttry {\n\t\t\t\tconfig.query = route.schema?.query\n\t\t\t\t\t? this.alepha.parse(route.schema.query, request.query)\n\t\t\t\t\t: request.query;\n\t\t\t} catch (e) {\n\t\t\t\tit.error = e as Error;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tconfig.params = route.schema?.params\n\t\t\t\t\t? this.alepha.parse(route.schema.params, request.params)\n\t\t\t\t\t: request.params;\n\t\t\t} catch (e) {\n\t\t\t\tit.error = e as Error;\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\t// save config\n\t\t\tit.config = {\n\t\t\t\t...config,\n\t\t\t};\n\n\t\t\t// no resolve, render a basic view by default\n\t\t\tif (!route.resolve) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// check if previous layer is the same, reuse if possible\n\t\t\tconst previous = request.previous;\n\t\t\tif (previous?.[i] && !forceRefresh && previous[i].name === route.name) {\n\t\t\t\tconst url = (str?: string) => (str ? str.replace(/\\/\\/+/g, \"/\") : \"/\");\n\n\t\t\t\tconst prev = JSON.stringify({\n\t\t\t\t\tpart: url(previous[i].part),\n\t\t\t\t\tparams: previous[i].config?.params ?? {},\n\t\t\t\t});\n\n\t\t\t\tconst curr = JSON.stringify({\n\t\t\t\t\tpart: url(route.path),\n\t\t\t\t\tparams: config.params ?? {},\n\t\t\t\t});\n\n\t\t\t\tif (prev === curr) {\n\t\t\t\t\t// part is the same, reuse previous layer\n\t\t\t\t\tit.props = previous[i].props;\n\t\t\t\t\tit.error = previous[i].error;\n\t\t\t\t\tcontext = {\n\t\t\t\t\t\t...context,\n\t\t\t\t\t\t...it.props,\n\t\t\t\t\t};\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t// part is different, force refresh of next layers\n\t\t\t\tforceRefresh = true;\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tconst props =\n\t\t\t\t\t(await route.resolve?.({\n\t\t\t\t\t\t...request, // request\n\t\t\t\t\t\t...config, // params, query\n\t\t\t\t\t\t...context, // previous props\n\t\t\t\t\t} as any)) ?? {};\n\n\t\t\t\t// save props\n\t\t\t\tit.props = {\n\t\t\t\t\t...props,\n\t\t\t\t};\n\n\t\t\t\t// add props to context\n\t\t\t\tcontext = {\n\t\t\t\t\t...context,\n\t\t\t\t\t...props,\n\t\t\t\t};\n\t\t\t} catch (e) {\n\t\t\t\t// check if we need to redirect\n\t\t\t\tif (e instanceof RedirectionError) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tlayers: [],\n\t\t\t\t\t\tredirect: typeof e.page === \"string\" ? e.page : this.href(e.page),\n\t\t\t\t\t\thead: request.head,\n\t\t\t\t\t\tpathname,\n\t\t\t\t\t\tsearch,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tthis.log.error(e);\n\n\t\t\t\tit.error = e as Error;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tlet acc = \"\";\n\t\tfor (let i = 0; i < stack.length; i++) {\n\t\t\tconst it = stack[i];\n\t\t\tconst props = it.props ?? {};\n\n\t\t\tconst params = { ...it.config?.params };\n\t\t\tfor (const key of Object.keys(params)) {\n\t\t\t\tparams[key] = String(params[key]);\n\t\t\t}\n\n\t\t\tif (it.route.head && !it.error) {\n\t\t\t\tthis.fillHead(it.route, request, {\n\t\t\t\t\t...props,\n\t\t\t\t\t...context,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tacc += \"/\";\n\t\t\tacc += it.route.path ? this.compile(it.route.path, params) : \"\";\n\t\t\tconst path = acc.replace(/\\/+/, \"/\");\n\n\t\t\t// handler has thrown an error, render an error view\n\t\t\tif (it.error) {\n\t\t\t\tconst errorHandler = this.getErrorHandler(it.route);\n\t\t\t\tconst element = await (errorHandler\n\t\t\t\t\t? errorHandler({\n\t\t\t\t\t\t\t...it.config,\n\t\t\t\t\t\t\terror: it.error,\n\t\t\t\t\t\t\turl: \"\",\n\t\t\t\t\t\t})\n\t\t\t\t\t: this.renderError(it.error));\n\n\t\t\t\tlayers.push({\n\t\t\t\t\tprops,\n\t\t\t\t\terror: it.error,\n\t\t\t\t\tname: it.route.name,\n\t\t\t\t\tpart: it.route.path,\n\t\t\t\t\tconfig: it.config,\n\t\t\t\t\telement: this.renderView(i + 1, path, element),\n\t\t\t\t\tindex: i + 1,\n\t\t\t\t\tpath,\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\t// normal use case\n\n\t\t\tconst layer = await this.createElement(it.route, {\n\t\t\t\t...props,\n\t\t\t\t...context,\n\t\t\t});\n\n\t\t\tlayers.push({\n\t\t\t\tname: it.route.name,\n\t\t\t\tprops,\n\t\t\t\tpart: it.route.path,\n\t\t\t\tconfig: it.config,\n\t\t\t\telement: this.renderView(i + 1, path, layer),\n\t\t\t\tindex: i + 1,\n\t\t\t\tpath,\n\t\t\t});\n\t\t}\n\n\t\treturn { layers, head: request.head, pathname, search };\n\t}\n\n\tprotected getErrorHandler(route: PageRoute) {\n\t\tif (route.errorHandler) return route.errorHandler;\n\t\tlet parent = route.parent;\n\t\twhile (parent) {\n\t\t\tif (parent.errorHandler) return parent.errorHandler;\n\t\t\tparent = parent.parent;\n\t\t}\n\t}\n\n\tprotected async createElement(\n\t\tpage: PageRoute,\n\t\tprops: Record<string, any>,\n\t): Promise<ReactNode> {\n\t\tif (page.lazy) {\n\t\t\tconst component = await page.lazy(); // load component\n\t\t\treturn createElement(component.default, props);\n\t\t}\n\n\t\tif (page.component) {\n\t\t\treturn createElement(page.component, props);\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\tprotected fillHead(\n\t\tpage: PageRoute,\n\t\tctx: PageRequest,\n\t\tprops: Record<string, any>,\n\t): void {\n\t\tif (!page.head) {\n\t\t\treturn;\n\t\t}\n\n\t\tctx.head ??= {};\n\n\t\tconst head =\n\t\t\ttypeof page.head === \"function\" ? page.head(props, ctx.head) : page.head;\n\n\t\tif (head.title) {\n\t\t\tctx.head ??= {};\n\n\t\t\tif (ctx.head.titleSeparator) {\n\t\t\t\tctx.head.title = `${head.title}${ctx.head.titleSeparator}${ctx.head.title}`;\n\t\t\t} else {\n\t\t\t\tctx.head.title = head.title;\n\t\t\t}\n\n\t\t\tctx.head.titleSeparator = head.titleSeparator;\n\t\t}\n\n\t\tif (head.htmlAttributes) {\n\t\t\tctx.head.htmlAttributes = {\n\t\t\t\t...ctx.head.htmlAttributes,\n\t\t\t\t...head.htmlAttributes,\n\t\t\t};\n\t\t}\n\n\t\tif (head.bodyAttributes) {\n\t\t\tctx.head.bodyAttributes = {\n\t\t\t\t...ctx.head.bodyAttributes,\n\t\t\t\t...head.bodyAttributes,\n\t\t\t};\n\t\t}\n\n\t\tif (head.meta) {\n\t\t\tctx.head.meta = [...(ctx.head.meta ?? []), ...(head.meta ?? [])];\n\t\t}\n\t}\n\n\tpublic renderError(e: Error): ReactNode {\n\t\treturn createElement(\"pre\", { style: { overflow: \"auto\" } }, `${e.stack}`);\n\t}\n\n\tpublic renderEmptyView(): ReactNode {\n\t\treturn createElement(NestedView, {});\n\t}\n\n\tpublic href(\n\t\tpage: { options: { name?: string } },\n\t\tparams: Record<string, any> = {},\n\t): string {\n\t\tconst found = this.pages.find((it) => it.name === page.options.name);\n\t\tif (!found) {\n\t\t\tthrow new Error(`Page ${page.options.name} not found`);\n\t\t}\n\n\t\tlet url = found.path ?? \"\";\n\t\tlet parent = found.parent;\n\t\twhile (parent) {\n\t\t\turl = `${parent.path ?? \"\"}/${url}`;\n\t\t\tparent = parent.parent;\n\t\t}\n\n\t\turl = this.compile(url, params);\n\n\t\treturn url.replace(/\\/\\/+/g, \"/\") || \"/\";\n\t}\n\n\tpublic compile(path: string, params: Record<string, string> = {}) {\n\t\tfor (const [key, value] of Object.entries(params)) {\n\t\t\tpath = path.replace(`:${key}`, value);\n\t\t}\n\t\treturn path;\n\t}\n\n\tprotected renderView(\n\t\tindex: number,\n\t\tpath: string,\n\t\tview: ReactNode = this.renderEmptyView(),\n\t): ReactNode {\n\t\treturn createElement(\n\t\t\tRouterLayerContext.Provider,\n\t\t\t{\n\t\t\t\tvalue: {\n\t\t\t\t\tindex,\n\t\t\t\t\tpath,\n\t\t\t\t},\n\t\t\t},\n\t\t\tview,\n\t\t);\n\t}\n\n\tprotected readonly configure = $hook({\n\t\tname: \"configure\",\n\t\thandler: () => {\n\t\t\tconst pages = this.alepha.getDescriptorValues($page);\n\t\t\tfor (const { value, key } of pages) {\n\t\t\t\tvalue[OPTIONS].name ??= key;\n\n\t\t\t\t// skip children, we only want root pages\n\t\t\t\tif (value[OPTIONS].parent) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tthis.add(this.map(pages, value));\n\t\t\t}\n\t\t},\n\t});\n\n\tprotected map(\n\t\tpages: Array<{ value: { [OPTIONS]: PageDescriptorOptions } }>,\n\t\ttarget: { [OPTIONS]: PageDescriptorOptions },\n\t): PageRouteEntry {\n\t\tconst children = target[OPTIONS].children ?? [];\n\n\t\tfor (const it of pages) {\n\t\t\tif (it.value[OPTIONS].parent === target) {\n\t\t\t\tchildren.push(it.value);\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\t...target[OPTIONS],\n\t\t\tparent: undefined,\n\t\t\tchildren: children.map((it) => this.map(pages, it)),\n\t\t} as PageRoute;\n\t}\n\n\tpublic add(entry: PageRouteEntry) {\n\t\tif (this.alepha.isReady()) {\n\t\t\tthrow new Error(\"Router is already initialized\");\n\t\t}\n\n\t\tentry.name ??= this.nextId();\n\t\tconst page = entry as PageRoute;\n\n\t\tpage.match = this.createMatch(page);\n\t\tthis.pages.push(page);\n\n\t\tif (page.children) {\n\t\t\tfor (const child of page.children) {\n\t\t\t\t(child as PageRoute).parent = page;\n\t\t\t\tthis.add(child);\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected createMatch(page: PageRoute): string {\n\t\tlet url = page.path ?? \"/\";\n\t\tlet target = page.parent;\n\t\twhile (target) {\n\t\t\turl = `${target.path ?? \"\"}/${url}`;\n\t\t\ttarget = target.parent;\n\t\t}\n\n\t\tlet path = url.replace(/\\/\\/+/g, \"/\");\n\n\t\tif (path.endsWith(\"/\") && path !== \"/\") {\n\t\t\t// remove trailing slash\n\t\t\tpath = path.slice(0, -1);\n\t\t}\n\n\t\treturn path;\n\t}\n\n\tprotected _next = 0;\n\n\tprotected nextId(): string {\n\t\tthis._next += 1;\n\t\treturn `P${this._next}`;\n\t}\n}\n\nexport const isPageRoute = (it: any): it is PageRoute => {\n\treturn (\n\t\tit &&\n\t\ttypeof it === \"object\" &&\n\t\ttypeof it.path === \"string\" &&\n\t\ttypeof it.page === \"object\"\n\t);\n};\n\nexport interface PageRouteEntry\n\textends Omit<PageDescriptorOptions, \"children\" | \"parent\"> {\n\tchildren?: PageRouteEntry[];\n}\n\nexport interface PageRoute extends PageRouteEntry {\n\ttype: \"page\";\n\tname: string;\n\tparent?: PageRoute;\n\tmatch: string;\n}\n\nexport interface Layer {\n\tconfig?: {\n\t\tquery?: Record<string, any>;\n\t\tparams?: Record<string, any>;\n\t\t// stack of resolved props\n\t\tcontext?: Record<string, any>;\n\t};\n\n\tname: string;\n\tprops?: Record<string, any>;\n\terror?: Error;\n\tpart?: string;\n\telement: ReactNode;\n\tindex: number;\n\tpath: string;\n}\n\nexport type PreviousLayerData = Omit<Layer, \"element\">;\n\nexport interface AnchorProps {\n\thref?: string;\n\tonClick?: (ev: any) => any;\n}\n\nexport interface RouterState {\n\tpathname: string;\n\tsearch: string;\n\tlayers: Array<Layer>;\n\thead: Head;\n}\n\nexport interface TransitionOptions {\n\tstate?: RouterState;\n\tprevious?: PreviousLayerData[];\n\tcontext?: PageReactContext;\n}\n\nexport interface RouterStackItem {\n\troute: PageRoute;\n\tconfig?: Record<string, any>;\n\tprops?: Record<string, any>;\n\terror?: Error;\n}\n\nexport interface RouterRenderResult {\n\tredirect?: string;\n\tlayers: Layer[];\n\thead: Head;\n\telement: ReactNode;\n}\n\nexport interface PageRequest extends PageReactContext {\n\turl: URL;\n\tparams: Record<string, any>;\n\tquery: Record<string, string>;\n\thead: Head;\n\n\t// previous layers (browser history or browser hydration, always null on server)\n\tprevious?: PreviousLayerData[];\n}\n\nexport interface CreateLayersResult extends RouterState {\n\tredirect?: string;\n}\n\n// will be passed to ReactContext\nexport interface PageReactContext {\n\tlinks?: HttpClientLink[];\n}\n","import type { Head } from \"./ServerHeadProvider.ts\";\n\nexport class BrowserHeadProvider {\n\trenderHead(document: Document, head: Head): void {\n\t\tif (head.title) {\n\t\t\tdocument.title = head.title;\n\t\t}\n\n\t\tif (head.bodyAttributes) {\n\t\t\tfor (const [key, value] of Object.entries(head.bodyAttributes)) {\n\t\t\t\tif (value) {\n\t\t\t\t\tdocument.body.setAttribute(key, value);\n\t\t\t\t} else {\n\t\t\t\t\tdocument.body.removeAttribute(key);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (head.htmlAttributes) {\n\t\t\tfor (const [key, value] of Object.entries(head.htmlAttributes)) {\n\t\t\t\tif (value) {\n\t\t\t\t\tdocument.documentElement.setAttribute(key, value);\n\t\t\t\t} else {\n\t\t\t\t\tdocument.documentElement.removeAttribute(key);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (head.meta) {\n\t\t\tfor (const [key, value] of Object.entries(head.meta)) {\n\t\t\t\tconst meta = document.querySelector(`meta[name=\"${key}\"]`);\n\t\t\t\tif (meta) {\n\t\t\t\t\tmeta.setAttribute(\"content\", value.content);\n\t\t\t\t} else {\n\t\t\t\t\tconst newMeta = document.createElement(\"meta\");\n\t\t\t\t\tnewMeta.setAttribute(\"name\", key);\n\t\t\t\t\tnewMeta.setAttribute(\"content\", value.content);\n\t\t\t\t\tdocument.head.appendChild(newMeta);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n","import { $hook, $inject, $logger, Alepha } from \"@alepha/core\";\nimport { type Route, RouterProvider } from \"@alepha/router\";\nimport type { ReactNode } from \"react\";\nimport {\n\tPageDescriptorProvider,\n\ttype PageReactContext,\n\ttype PageRoute,\n\ttype PageRouteEntry,\n\ttype RouterRenderResult,\n\ttype RouterState,\n\ttype TransitionOptions,\n\tisPageRoute,\n} from \"./PageDescriptorProvider.ts\";\n\nexport interface BrowserRoute extends Route {\n\tpage: PageRoute;\n}\n\nexport class BrowserRouterProvider extends RouterProvider<BrowserRoute> {\n\tprotected readonly log = $logger();\n\tprotected readonly alepha = $inject(Alepha);\n\tprotected readonly pageDescriptorProvider = $inject(PageDescriptorProvider);\n\n\tpublic add(entry: PageRouteEntry) {\n\t\tthis.pageDescriptorProvider.add(entry);\n\t}\n\n\tprotected readonly configure = $hook({\n\t\tname: \"configure\",\n\t\thandler: async () => {\n\t\t\tfor (const page of this.pageDescriptorProvider.getPages()) {\n\t\t\t\t// mount only if a view is provided\n\t\t\t\tif (page.component || page.lazy) {\n\t\t\t\t\tthis.push({\n\t\t\t\t\t\tpath: page.match,\n\t\t\t\t\t\tpage,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t});\n\n\tpublic async transition(\n\t\turl: URL,\n\t\toptions: TransitionOptions = {},\n\t): Promise<RouterRenderResult> {\n\t\tconst { pathname, search } = url;\n\t\tconst state: RouterState = {\n\t\t\tpathname,\n\t\t\tsearch,\n\t\t\tlayers: [],\n\t\t\thead: {},\n\t\t};\n\n\t\tawait this.alepha.emit(\"react:transition:begin\", { state });\n\n\t\ttry {\n\t\t\tconst previous = options.previous;\n\t\t\tconst { route, params } = this.match(pathname);\n\n\t\t\tconst query: Record<string, string> = {};\n\t\t\tif (search) {\n\t\t\t\tfor (const [key, value] of new URLSearchParams(search).entries()) {\n\t\t\t\t\tquery[key] = String(value);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (isPageRoute(route)) {\n\t\t\t\tconst result = await this.pageDescriptorProvider.createLayers(\n\t\t\t\t\troute.page,\n\t\t\t\t\t{\n\t\t\t\t\t\turl,\n\t\t\t\t\t\tparams: params ?? {},\n\t\t\t\t\t\tquery,\n\t\t\t\t\t\tprevious,\n\t\t\t\t\t\t...state,\n\t\t\t\t\t\thead: state.head,\n\t\t\t\t\t\t...(options.context ?? {}),\n\t\t\t\t\t},\n\t\t\t\t);\n\n\t\t\t\tif (result.redirect) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\telement: null,\n\t\t\t\t\t\tlayers: [],\n\t\t\t\t\t\tredirect: result.redirect,\n\t\t\t\t\t\thead: state.head,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tstate.layers = result.layers;\n\t\t\t\tstate.head = result.head;\n\t\t\t}\n\n\t\t\tif (state.layers.length === 0) {\n\t\t\t\tstate.layers.push({\n\t\t\t\t\tname: \"not-found\",\n\t\t\t\t\telement: \"Not Found\",\n\t\t\t\t\tindex: 0,\n\t\t\t\t\tpath: \"/\",\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tawait this.alepha.emit(\"react:transition:success\", { state });\n\t\t} catch (e) {\n\t\t\tthis.log.error(e);\n\t\t\tstate.layers = [\n\t\t\t\t{\n\t\t\t\t\tname: \"error\",\n\t\t\t\t\telement: this.pageDescriptorProvider.renderError(e as Error),\n\t\t\t\t\tindex: 0,\n\t\t\t\t\tpath: \"/\",\n\t\t\t\t},\n\t\t\t];\n\n\t\t\tawait this.alepha.emit(\"react:transition:error\", {\n\t\t\t\terror: e as Error,\n\t\t\t\tstate,\n\t\t\t});\n\t\t}\n\n\t\tif (!options.state) {\n\t\t\tawait this.alepha.emit(\"react:transition:end\", {\n\t\t\t\tstate,\n\t\t\t});\n\t\t\treturn {\n\t\t\t\telement: this.root(state, options.context),\n\t\t\t\tlayers: state.layers,\n\t\t\t\thead: state.head,\n\t\t\t};\n\t\t}\n\n\t\toptions.state.layers = state.layers;\n\t\toptions.state.pathname = state.pathname;\n\t\toptions.state.search = state.search;\n\t\toptions.state.head = state.head;\n\n\t\tawait this.alepha.emit(\"react:transition:end\", {\n\t\t\tstate: options.state,\n\t\t});\n\n\t\treturn {\n\t\t\telement: this.root(state, options.context),\n\t\t\tlayers: options.state.layers,\n\t\t\thead: state.head,\n\t\t};\n\t}\n\n\tpublic root(state: RouterState, context: PageReactContext = {}): ReactNode {\n\t\treturn this.pageDescriptorProvider.root(state, context);\n\t}\n}\n","import { $hook, $inject, $logger, Alepha, type Static, t } from \"@alepha/core\";\nimport { HttpClient, type HttpClientLink } from \"@alepha/server\";\nimport type { Root } from \"react-dom/client\";\nimport { createRoot, hydrateRoot } from \"react-dom/client\";\nimport type { Head } from \"../descriptors/$page.ts\";\nimport { BrowserHeadProvider } from \"./BrowserHeadProvider.ts\";\nimport { BrowserRouterProvider } from \"./BrowserRouterProvider.ts\";\nimport type {\n\tPreviousLayerData,\n\tRouterState,\n\tTransitionOptions,\n} from \"./PageDescriptorProvider.ts\";\n\nconst envSchema = t.object({\n\tREACT_ROOT_ID: t.string({ default: \"root\" }),\n});\n\ndeclare module \"@alepha/core\" {\n\tinterface Env extends Partial<Static<typeof envSchema>> {}\n}\n\nexport class ReactBrowserProvider {\n\tprotected readonly log = $logger();\n\tprotected readonly client = $inject(HttpClient);\n\tprotected readonly alepha = $inject(Alepha);\n\tprotected readonly router = $inject(BrowserRouterProvider);\n\tprotected readonly headProvider = $inject(BrowserHeadProvider);\n\tprotected readonly env = $inject(envSchema);\n\tprotected root!: Root;\n\n\tpublic transitioning?: {\n\t\tto: string;\n\t};\n\n\tpublic state: RouterState = {\n\t\tlayers: [],\n\t\tpathname: \"\",\n\t\tsearch: \"\",\n\t\thead: {},\n\t};\n\n\tpublic get document() {\n\t\treturn window.document;\n\t}\n\n\tpublic get history() {\n\t\treturn window.history;\n\t}\n\n\tpublic get url(): string {\n\t\treturn window.location.pathname + window.location.search;\n\t}\n\n\tpublic async invalidate(props?: Record<string, any>) {\n\t\tconst previous: PreviousLayerData[] = [];\n\n\t\tif (props) {\n\t\t\tconst [key] = Object.keys(props);\n\t\t\tconst value = props[key];\n\n\t\t\tfor (const layer of this.state.layers) {\n\t\t\t\tif (layer.props?.[key]) {\n\t\t\t\t\tprevious.push({\n\t\t\t\t\t\t...layer,\n\t\t\t\t\t\tprops: {\n\t\t\t\t\t\t\t...layer.props,\n\t\t\t\t\t\t\t[key]: value,\n\t\t\t\t\t\t},\n\t\t\t\t\t});\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tprevious.push(layer);\n\t\t\t}\n\t\t}\n\n\t\tawait this.render({ previous });\n\t}\n\n\t/**\n\t *\n\t * @param url\n\t * @param options\n\t */\n\tpublic async go(url: string, options: RouterGoOptions = {}): Promise<void> {\n\t\tconst result = await this.render({\n\t\t\turl,\n\t\t});\n\n\t\tif (result.url !== url) {\n\t\t\tthis.history.replaceState({}, \"\", result.url);\n\t\t\treturn;\n\t\t}\n\n\t\tif (options.replace) {\n\t\t\tthis.history.replaceState({}, \"\", url);\n\t\t\treturn;\n\t\t}\n\n\t\tthis.history.pushState({}, \"\", url);\n\t}\n\n\tprotected async render(\n\t\toptions: {\n\t\t\turl?: string;\n\t\t\tprevious?: PreviousLayerData[];\n\t\t} = {},\n\t): Promise<{ url: string; head: Head }> {\n\t\tconst previous = options.previous ?? this.state.layers;\n\t\tconst url = options.url ?? this.url;\n\n\t\tthis.transitioning = { to: url };\n\n\t\tconst result = await this.router.transition(\n\t\t\tnew URL(`http://localhost${url}`),\n\t\t\t{\n\t\t\t\tprevious,\n\t\t\t\tstate: this.state,\n\t\t\t},\n\t\t);\n\n\t\tif (result.redirect) {\n\t\t\treturn await this.render({ url: result.redirect });\n\t\t}\n\n\t\tthis.transitioning = undefined;\n\n\t\treturn { url, head: result.head };\n\t}\n\n\t/**\n\t * Get embedded layers from the server.\n\t *\n\t * @protected\n\t */\n\tprotected getHydrationState(): ReactHydrationState | undefined {\n\t\ttry {\n\t\t\tif (\"__ssr\" in window && typeof window.__ssr === \"object\") {\n\t\t\t\treturn window.__ssr as ReactHydrationState;\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsole.error(error);\n\t\t}\n\t}\n\n\t/**\n\t *\n\t * @protected\n\t */\n\tprotected getRootElement() {\n\t\tconst root = this.document.getElementById(this.env.REACT_ROOT_ID);\n\t\tif (root) {\n\t\t\treturn root;\n\t\t}\n\n\t\tconst div = this.document.createElement(\"div\");\n\t\tdiv.id = this.env.REACT_ROOT_ID;\n\n\t\tthis.document.body.prepend(div);\n\n\t\treturn div;\n\t}\n\n\t// -------------------------------------------------------------------------------------------------------------------\n\n\t/**\n\t *\n\t * @protected\n\t */\n\tpublic readonly ready = $hook({\n\t\tname: \"ready\",\n\t\thandler: async () => {\n\t\t\tconst hydration = this.getHydrationState();\n\t\t\tconst previous = hydration?.layers ?? [];\n\n\t\t\tif (hydration?.links) {\n\t\t\t\tthis.client.links = hydration.links as HttpClientLink[];\n\t\t\t}\n\n\t\t\tconst { head } = await this.render({ previous });\n\t\t\tif (head) {\n\t\t\t\tthis.headProvider.renderHead(this.document, head);\n\t\t\t}\n\n\t\t\tconst context = {};\n\n\t\t\tawait this.alepha.emit(\"react:browser:render\", {\n\t\t\t\tcontext,\n\t\t\t\thydration,\n\t\t\t});\n\n\t\t\tconst element = this.router.root(this.state, context);\n\n\t\t\tif (previous.length > 0) {\n\t\t\t\tthis.root = hydrateRoot(this.getRootElement(), element);\n\t\t\t\tthis.log.info(\"Hydrated root element\");\n\t\t\t} else {\n\t\t\t\tthis.root ??= createRoot(this.getRootElement());\n\t\t\t\tthis.root.render(element);\n\t\t\t\tthis.log.info(\"Created root element\");\n\t\t\t}\n\n\t\t\twindow.addEventListener(\"popstate\", () => {\n\t\t\t\tthis.render();\n\t\t\t});\n\n\t\t\tthis.alepha.on(\"react:transition:end\", {\n\t\t\t\tcallback: ({ state }) => {\n\t\t\t\t\tthis.headProvider.renderHead(this.document, state.head);\n\t\t\t\t},\n\t\t\t});\n\t\t},\n\t});\n\n\tpublic readonly onTransitionEnd = $hook({\n\t\tname: \"react:transition:end\",\n\t\thandler: async ({ state }) => {\n\t\t\tthis.headProvider.renderHead(this.document, state.head);\n\t\t},\n\t});\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport interface RouterGoOptions {\n\treplace?: boolean;\n\tmatch?: TransitionOptions;\n}\n\nexport interface ReactHydrationState {\n\tlayers?: PreviousLayerData[];\n\tlinks?: HttpClientLink[];\n}\n","import type {\n\tAnchorProps,\n\tRouterState,\n} from \"../providers/PageDescriptorProvider.ts\";\nimport type {\n\tReactBrowserProvider,\n\tRouterGoOptions,\n} from \"../providers/ReactBrowserProvider.ts\";\n\nexport class RouterHookApi {\n\tconstructor(\n\t\tprivate readonly state: RouterState,\n\t\tprivate readonly layer: {\n\t\t\tpath: string;\n\t\t},\n\t\tprivate readonly browser?: ReactBrowserProvider,\n\t) {}\n\n\t/**\n\t *\n\t */\n\tpublic get current(): RouterState {\n\t\treturn this.state;\n\t}\n\n\t/**\n\t *\n\t */\n\tpublic get pathname(): string {\n\t\treturn this.state.pathname;\n\t}\n\n\t/**\n\t *\n\t */\n\tpublic get query(): Record<string, string> {\n\t\tconst query: Record<string, string> = {};\n\n\t\tfor (const [key, value] of new URLSearchParams(\n\t\t\tthis.state.search,\n\t\t).entries()) {\n\t\t\tquery[key] = String(value);\n\t\t}\n\n\t\treturn query;\n\t}\n\n\t/**\n\t *\n\t */\n\tpublic async back() {\n\t\tthis.browser?.history.back();\n\t}\n\n\t/**\n\t *\n\t */\n\tpublic async forward() {\n\t\tthis.browser?.history.forward();\n\t}\n\n\t/**\n\t *\n\t * @param props\n\t */\n\tpublic async invalidate(props?: Record<string, any>) {\n\t\tawait this.browser?.invalidate(props);\n\t}\n\n\t/**\n\t * Create a valid href for the given pathname.\n\t *\n\t * @param pathname\n\t * @param layer\n\t */\n\tpublic createHref(pathname: HrefLike, layer: { path: string } = this.layer) {\n\t\tif (typeof pathname === \"object\") {\n\t\t\tpathname = pathname.options.path ?? \"\";\n\t\t}\n\n\t\treturn pathname.startsWith(\"/\")\n\t\t\t? pathname\n\t\t\t: `${layer.path}/${pathname}`.replace(/\\/\\/+/g, \"/\");\n\t}\n\n\t/**\n\t *\n\t * @param path\n\t * @param options\n\t */\n\tpublic async go(\n\t\tpath: HrefLike,\n\t\toptions: RouterGoOptions = {},\n\t): Promise<void> {\n\t\treturn await this.browser?.go(this.createHref(path, this.layer), options);\n\t}\n\n\t/**\n\t *\n\t * @param path\n\t */\n\tpublic createAnchorProps(path: string): AnchorProps {\n\t\tconst href = this.createHref(path, this.layer);\n\t\treturn {\n\t\t\thref,\n\t\t\tonClick: (ev: any) => {\n\t\t\t\tev.stopPropagation();\n\t\t\t\tev.preventDefault();\n\n\t\t\t\tthis.go(path).catch(console.error);\n\t\t\t},\n\t\t};\n\t}\n\n\t/**\n\t * Set query params.\n\t *\n\t * @param record\n\t * @param options\n\t */\n\tpublic setQueryParams(\n\t\trecord: Record<string, any>,\n\t\toptions: {\n\t\t\t/**\n\t\t\t * If true, this will merge current query params with the new ones.\n\t\t\t */\n\t\t\tmerge?: boolean;\n\n\t\t\t/**\n\t\t\t * If true, this will add a new entry to the history stack.\n\t\t\t */\n\t\t\tpush?: boolean;\n\t\t} = {},\n\t) {\n\t\tconst search = new URLSearchParams(\n\t\t\toptions.merge\n\t\t\t\t? {\n\t\t\t\t\t\t...this.query,\n\t\t\t\t\t\t...record,\n\t\t\t\t\t}\n\t\t\t\t: {\n\t\t\t\t\t\t...record,\n\t\t\t\t\t},\n\t\t).toString();\n\n\t\tconst state = search ? `${this.pathname}?${search}` : this.pathname;\n\n\t\tif (options.push) {\n\t\t\twindow.history.pushState({}, \"\", state);\n\t\t} else {\n\t\t\twindow.history.replaceState({}, \"\", state);\n\t\t}\n\t}\n}\n\nexport type HrefLike = string | { options: { path?: string; name?: string } };\n","import { useContext, useMemo } from \"react\";\nimport { RouterContext } from \"../contexts/RouterContext.ts\";\nimport { RouterLayerContext } from \"../contexts/RouterLayerContext.ts\";\nimport { ReactBrowserProvider } from \"../providers/ReactBrowserProvider.ts\";\nimport { RouterHookApi } from \"./RouterHookApi.ts\";\n\nexport const useRouter = (): RouterHookApi => {\n\tconst ctx = useContext(RouterContext);\n\tconst layer = useContext(RouterLayerContext);\n\tif (!ctx || !layer) {\n\t\tthrow new Error(\"useRouter must be used within a RouterProvider\");\n\t}\n\n\treturn useMemo(\n\t\t() =>\n\t\t\tnew RouterHookApi(\n\t\t\t\tctx.state,\n\t\t\t\tlayer,\n\t\t\t\tctx.alepha.isBrowser()\n\t\t\t\t\t? ctx.alepha.get(ReactBrowserProvider)\n\t\t\t\t\t: undefined,\n\t\t\t),\n\t\t[layer],\n\t);\n};\n","import React from \"react\";\nimport type { AnchorHTMLAttributes } from \"react\";\nimport { RouterContext } from \"../contexts/RouterContext.ts\";\nimport type { PageDescriptor } from \"../descriptors/$page.ts\";\nimport { useRouter } from \"../hooks/useRouter.ts\";\nimport { OPTIONS } from \"@alepha/core\";\n\nexport interface LinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {\n\tto: string | PageDescriptor;\n\tchildren?: React.ReactNode;\n}\n\nconst Link = (props: LinkProps) => {\n\tReact.useContext(RouterContext);\n\n\tconst to = typeof props.to === \"string\" ? props.to : props.to[OPTIONS].path;\n\tif (!to) {\n\t\treturn null;\n\t}\n\n\tconst can = typeof props.to === \"string\" ? undefined : props.to[OPTIONS].can;\n\tif (can && !can()) {\n\t\treturn null;\n\t}\n\n\tconst name =\n\t\ttypeof props.to === \"string\" ? undefined : props.to[OPTIONS].name;\n\n\tconst router = useRouter();\n\treturn (\n\t\t<a {...router.createAnchorProps(to)} {...props}>\n\t\t\t{props.children ?? name}\n\t\t</a>\n\t);\n};\n\nexport default Link;\n","import type { Class } from \"@alepha/core\";\nimport { useContext } from \"react\";\nimport { RouterContext } from \"../contexts/RouterContext.ts\";\n\nexport const useInject = <T extends object>(clazz: Class<T>): T => {\n\tconst ctx = useContext(RouterContext);\n\tif (!ctx) {\n\t\tthrow new Error(\"useRouter must be used within a <RouterProvider>\");\n\t}\n\n\treturn ctx.alepha.get(clazz, {\n\t\tskipRegistration: true,\n\t});\n};\n","import { HttpClient } from \"@alepha/server\";\nimport { useInject } from \"./useInject.ts\";\n\nexport const useClient = (): HttpClient => {\n\treturn useInject(HttpClient);\n};\n","import type { Alepha, Static, TObject } from \"@alepha/core\";\nimport { useContext, useEffect, useState } from \"react\";\nimport { RouterContext } from \"../contexts/RouterContext.ts\";\nimport { useRouter } from \"./useRouter.ts\";\n\nexport interface UseQueryParamsHookOptions {\n\tformat?: \"base64\" | \"querystring\";\n\tkey?: string;\n\tpush?: boolean;\n}\n\nexport const useQueryParams = <T extends TObject>(\n\tschema: T,\n\toptions: UseQueryParamsHookOptions = {},\n): [Static<T>, (data: Static<T>) => void] => {\n\tconst ctx = useContext(RouterContext);\n\tif (!ctx) {\n\t\tthrow new Error(\"useQueryParams must be used within a RouterProvider\");\n\t}\n\n\tconst key = options.key ?? \"q\";\n\tconst router = useRouter();\n\tconst querystring = router.query[key];\n\n\tconst [queryParams, setQueryParams] = useState(\n\t\tdecode(ctx.alepha, schema, router.query[key]),\n\t);\n\n\tuseEffect(() => {\n\t\tsetQueryParams(decode(ctx.alepha, schema, querystring));\n\t}, [querystring]);\n\n\treturn [\n\t\tqueryParams,\n\t\t(queryParams: Static<T>) => {\n\t\t\tsetQueryParams(queryParams);\n\t\t\trouter.setQueryParams(\n\t\t\t\t{ [key]: encode(ctx.alepha, schema, queryParams) },\n\t\t\t\t{\n\t\t\t\t\tmerge: true,\n\t\t\t\t},\n\t\t\t);\n\t\t},\n\t];\n};\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nconst encode = (alepha: Alepha, schema: TObject, data: any) => {\n\treturn btoa(JSON.stringify(alepha.parse(schema, data)));\n};\n\nconst decode = (alepha: Alepha, schema: TObject, data: any) => {\n\ttry {\n\t\treturn alepha.parse(schema, JSON.parse(atob(decodeURIComponent(data))));\n\t} catch (error) {\n\t\treturn {};\n\t}\n};\n","import { useContext, useState } from \"react\";\nimport { RouterContext } from \"../contexts/RouterContext.ts\";\nimport { RouterLayerContext } from \"../contexts/RouterLayerContext.ts\";\nimport type { RouterState } from \"../providers/PageDescriptorProvider.ts\";\nimport { useRouterEvents } from \"./useRouterEvents.ts\";\n\nexport const useRouterState = (): RouterState => {\n\tconst ctx = useContext(RouterContext);\n\tconst layer = useContext(RouterLayerContext);\n\tif (!ctx || !layer) {\n\t\tthrow new Error(\"useRouter must be used within a RouterProvider\");\n\t}\n\n\tconst [state, setState] = useState(ctx.state);\n\n\tuseRouterEvents({\n\t\tonEnd: ({ state }) => setState({ ...state }),\n\t});\n\n\treturn state;\n};\n","import { useContext, useMemo, useState } from \"react\";\nimport { RouterContext } from \"../contexts/RouterContext.ts\";\nimport { RouterLayerContext } from \"../contexts/RouterLayerContext.ts\";\nimport type { AnchorProps } from \"../providers/PageDescriptorProvider.ts\";\nimport type { HrefLike } from \"./RouterHookApi.ts\";\nimport { useRouter } from \"./useRouter.ts\";\nimport { useRouterEvents } from \"./useRouterEvents.ts\";\n\nexport const useActive = (path: HrefLike): UseActiveHook => {\n\tconst router = useRouter();\n\tconst ctx = useContext(RouterContext);\n\tconst layer = useContext(RouterLayerContext);\n\tif (!ctx || !layer) {\n\t\tthrow new Error(\"useRouter must be used within a RouterProvider\");\n\t}\n\n\tlet name: string | undefined;\n\tif (typeof path === \"object\" && path.options.name) {\n\t\tname = path.options.name;\n\t}\n\n\tconst [current, setCurrent] = useState(ctx.state.pathname);\n\tconst href = useMemo(() => router.createHref(path, layer), [path, layer]);\n\tconst [isPending, setPending] = useState(false);\n\tconst isActive = current === href;\n\n\tuseRouterEvents({\n\t\tonEnd: ({ state }) => setCurrent(state.pathname),\n\t});\n\n\treturn {\n\t\tname,\n\t\tisPending,\n\t\tisActive,\n\t\tanchorProps: {\n\t\t\thref,\n\t\t\tonClick: (ev: any) => {\n\t\t\t\tev.stopPropagation();\n\t\t\t\tev.preventDefault();\n\t\t\t\tif (isActive) return;\n\t\t\t\tif (isPending) return;\n\n\t\t\t\tsetPending(true);\n\t\t\t\trouter.go(href).then(() => {\n\t\t\t\t\tsetPending(false);\n\t\t\t\t});\n\t\t\t},\n\t\t},\n\t};\n};\n\nexport interface UseActiveHook {\n\tisActive: boolean;\n\tanchorProps: AnchorProps;\n\tisPending: boolean;\n\tname?: string;\n}\n"],"names":["__descriptor","OPTIONS","KIND","NotImplementedError","createContext","useContext","useEffect","useState","$logger","$inject","Alepha","createElement","$hook","RouterProvider","t","HttpClient","hydrateRoot","createRoot","useMemo","jsx"],"mappings":";;;;;;;;;AAGA,MAAM,GAAG,GAAG,MAAM;AACN,MAAC,KAAK,GAAG,CAAC,OAAO,KAAK;AAClC,EAAEA,iBAAY,CAAC,GAAG,CAAC;AACnB,EAAE,IAAI,OAAO,CAAC,QAAQ,EAAE;AACxB,IAAI,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,QAAQ,EAAE;AAC1C,MAAM,KAAK,CAACC,YAAO,CAAC,CAAC,MAAM,GAAG;AAC9B,QAAQ,CAACA,YAAO,GAAG;AACnB,OAAO;AACP;AACA;AACA,EAAE,IAAI,OAAO,CAAC,MAAM,EAAE;AACtB,IAAI,OAAO,CAAC,MAAM,CAACA,YAAO,CAAC,CAAC,QAAQ,KAAK,EAAE;AAC3C,IAAI,OAAO,CAAC,MAAM,CAACA,YAAO,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;AAC1C,MAAM,CAACA,YAAO,GAAG;AACjB,KAAK,CAAC;AACN;AACA,EAAE,OAAO;AACT,IAAI,CAACC,SAAI,GAAG,GAAG;AACf,IAAI,CAACD,YAAO,GAAG,OAAO;AACtB,IAAI,MAAM,EAAE,MAAM;AAClB,MAAM,MAAM,IAAIE,wBAAmB,CAAC,GAAG,CAAC;AACxC,KAAK;AACL,IAAI,EAAE,EAAE,MAAM;AACd,MAAM,MAAM,IAAIA,wBAAmB,CAAC,GAAG,CAAC;AACxC,KAAK;AACL,IAAI,iBAAiB,EAAE,MAAM;AAC7B,MAAM,MAAM,IAAIA,wBAAmB,CAAC,GAAG,CAAC;AACxC,KAAK;AACL,IAAI,GAAG,EAAE,MAAM;AACf,MAAM,IAAI,OAAO,CAAC,GAAG,EAAE;AACvB,QAAQ,OAAO,OAAO,C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,CAAC;AACV;AACA;AACA,GAAG;AACH;;;;;;;;;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,44 +1,48 @@
1
1
  {
2
- "name": "@alepha/react",
3
- "version": "0.6.4",
4
- "type": "module",
5
- "license": "MIT",
6
- "main": "./dist/index.js",
7
- "types": "./dist/index.d.ts",
8
- "browser": {
9
- "./dist/index.js": "./dist/index.browser.js"
10
- },
11
- "files": [
12
- "dist",
13
- "src"
14
- ],
15
- "dependencies": {
16
- "@alepha/core": "0.6.4",
17
- "@alepha/router": "0.6.4",
18
- "@alepha/server": "0.6.4",
19
- "@alepha/server-static": "0.6.4",
20
- "react-dom": "^19.1.0"
21
- },
22
- "devDependencies": {
23
- "@types/react": "^19.1.3",
24
- "@types/react-dom": "^19.1.3",
25
- "pkgroll": "^2.12.2",
26
- "react": "^19.1.0",
27
- "vitest": "^3.1.3"
28
- },
29
- "peerDependencies": {
30
- "@types/react": "^19",
31
- "react": "^19"
32
- },
33
- "scripts": {
34
- "build": "pkgroll --clean-dist --sourcemap"
35
- },
36
- "exports": {
37
- ".": {
38
- "import": "./dist/index.js",
39
- "require": "./dist/index.cjs",
40
- "types": "./dist/index.d.ts",
41
- "browser": "./dist/index.browser.js"
42
- }
43
- }
2
+ "name": "@alepha/react",
3
+ "version": "0.6.5",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "main": "./src/index.ts",
7
+ "types": "./src/index.ts",
8
+ "browser": "./src/index.browser.ts",
9
+ "files": [
10
+ "dist",
11
+ "src"
12
+ ],
13
+ "dependencies": {
14
+ "@alepha/core": "0.6.5",
15
+ "@alepha/router": "0.6.5",
16
+ "@alepha/server": "0.6.5",
17
+ "@alepha/server-static": "0.6.5",
18
+ "react-dom": "^19.1.0"
19
+ },
20
+ "devDependencies": {
21
+ "@types/react": "^19.1.4",
22
+ "@types/react-dom": "^19.1.5",
23
+ "pkgroll": "^2.12.2",
24
+ "react": "^19.1.0",
25
+ "vitest": "^3.1.3"
26
+ },
27
+ "peerDependencies": {
28
+ "@types/react": "^19",
29
+ "react": "^19"
30
+ },
31
+ "scripts": {
32
+ "build": "pkgroll --clean-dist --sourcemap"
33
+ },
34
+ "publishConfig": {
35
+ "main": "./dist/index.cjs",
36
+ "types": "./dist/index.d.ts",
37
+ "browser": "./dist/index.browser.js",
38
+ "module": "./dist/index.js",
39
+ "exports": {
40
+ ".": {
41
+ "import": "./dist/index.js",
42
+ "require": "./dist/index.cjs",
43
+ "types": "./dist/index.d.ts",
44
+ "browser": "./dist/index.browser.js"
45
+ }
46
+ }
47
+ }
44
48
  }
@@ -3,6 +3,7 @@ import type { AnchorHTMLAttributes } from "react";
3
3
  import { RouterContext } from "../contexts/RouterContext.ts";
4
4
  import type { PageDescriptor } from "../descriptors/$page.ts";
5
5
  import { useRouter } from "../hooks/useRouter.ts";
6
+ import { OPTIONS } from "@alepha/core";
6
7
 
7
8
  export interface LinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
8
9
  to: string | PageDescriptor;
@@ -12,17 +13,18 @@ export interface LinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
12
13
  const Link = (props: LinkProps) => {
13
14
  React.useContext(RouterContext);
14
15
 
15
- const to = typeof props.to === "string" ? props.to : props.to.options.path;
16
+ const to = typeof props.to === "string" ? props.to : props.to[OPTIONS].path;
16
17
  if (!to) {
17
18
  return null;
18
19
  }
19
20
 
20
- const can = typeof props.to === "string" ? undefined : props.to.options.can;
21
+ const can = typeof props.to === "string" ? undefined : props.to[OPTIONS].can;
21
22
  if (can && !can()) {
22
23
  return null;
23
24
  }
24
25
 
25
- const name = typeof props.to === "string" ? undefined : props.to.options.name;
26
+ const name =
27
+ typeof props.to === "string" ? undefined : props.to[OPTIONS].name;
26
28
 
27
29
  const router = useRouter();
28
30
  return (
@@ -1,7 +1,8 @@
1
1
  import type { ReactNode } from "react";
2
- import { useContext, useEffect, useState } from "react";
2
+ import { useContext, useState } from "react";
3
3
  import { RouterContext } from "../contexts/RouterContext.ts";
4
4
  import { RouterLayerContext } from "../contexts/RouterLayerContext.ts";
5
+ import { useRouterEvents } from "../hooks/useRouterEvents.ts";
5
6
 
6
7
  export interface NestedViewProps {
7
8
  children?: ReactNode;
@@ -22,13 +23,14 @@ const NestedView = (props: NestedViewProps) => {
22
23
  app?.state.layers[index]?.element,
23
24
  );
24
25
 
25
- useEffect(() => {
26
- if (app?.alepha.isBrowser()) {
27
- return app?.events.on("end", (state) => {
26
+ useRouterEvents(
27
+ {
28
+ onEnd: ({ state }) => {
28
29
  setView(state.layers[index]?.element);
29
- });
30
- }
31
- }, [app]);
30
+ },
31
+ },
32
+ [app],
33
+ );
32
34
 
33
35
  return view ?? props.children ?? null;
34
36
  };