@alepha/react 0.6.10 → 0.7.0

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.
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var core = require('@alepha/core');
4
- var useActive = require('./useActive-4QlZKGbw.cjs');
4
+ var useActive = require('./useActive-DjpZBEuB.cjs');
5
5
  require('react/jsx-runtime');
6
6
  require('react');
7
7
  require('@alepha/server');
@@ -17,6 +17,7 @@ class ReactModule {
17
17
  core.__bind(useActive.$page, ReactModule);
18
18
 
19
19
  exports.$page = useActive.$page;
20
+ exports.ErrorBoundary = useActive.ErrorBoundary;
20
21
  exports.Link = useActive.Link;
21
22
  exports.NestedView = useActive.NestedView;
22
23
  exports.ReactBrowserProvider = useActive.ReactBrowserProvider;
@@ -1 +1 @@
1
- {"version":3,"file":"index.browser.cjs","sources":["../src/index.browser.ts"],"sourcesContent":["import { $inject, Alepha, __bind } from \"@alepha/core\";\nimport { $page } from \"./descriptors/$page.ts\";\nimport { BrowserRouterProvider } from \"./providers/BrowserRouterProvider.ts\";\nimport { PageDescriptorProvider } from \"./providers/PageDescriptorProvider.ts\";\nimport { ReactBrowserProvider } from \"./providers/ReactBrowserProvider.ts\";\n\nexport * from \"./index.shared\";\nexport * from \"./providers/ReactBrowserProvider.ts\";\n\nexport class ReactModule {\n\tprotected readonly alepha = $inject(Alepha);\n\n\tconstructor() {\n\t\tthis.alepha //\n\t\t\t.with(PageDescriptorProvider)\n\t\t\t.with(ReactBrowserProvider)\n\t\t\t.with(BrowserRouterProvider);\n\t}\n}\n\n__bind($page, ReactModule);\n"],"names":["$inject","Alepha","PageDescriptorProvider","ReactBrowserProvider","BrowserRouterProvider","__bind","$page"],"mappings":";;;;;;;;;;AAQO,MAAM,WAAW,CAAC;AACzB,EAAE,MAAM,GAAGA,YAAO,CAACC,WAAM,CAAC;AAC1B,EAAE,WAAW,GAAG;AAChB,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAACC,gCAAsB,CAAC,CAAC,IAAI,CAACC,8BAAoB,CAAC,CAAC,IAAI,CAACC,+BAAqB,CAAC;AACnG;AACA;AACAC,WAAM,CAACC,eAAK,EAAE,WAAW,CAAC;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.browser.cjs","sources":["../src/index.browser.ts"],"sourcesContent":["import { $inject, Alepha, __bind } from \"@alepha/core\";\nimport { $page } from \"./descriptors/$page.ts\";\nimport { BrowserRouterProvider } from \"./providers/BrowserRouterProvider.ts\";\nimport { PageDescriptorProvider } from \"./providers/PageDescriptorProvider.ts\";\nimport { ReactBrowserProvider } from \"./providers/ReactBrowserProvider.ts\";\n\nexport * from \"./index.shared\";\nexport * from \"./providers/ReactBrowserProvider.ts\";\n\nexport class ReactModule {\n\tprotected readonly alepha = $inject(Alepha);\n\n\tconstructor() {\n\t\tthis.alepha //\n\t\t\t.with(PageDescriptorProvider)\n\t\t\t.with(ReactBrowserProvider)\n\t\t\t.with(BrowserRouterProvider);\n\t}\n}\n\n__bind($page, ReactModule);\n"],"names":["$inject","Alepha","PageDescriptorProvider","ReactBrowserProvider","BrowserRouterProvider","__bind","$page"],"mappings":";;;;;;;;;;AAQO,MAAM,WAAW,CAAC;AACzB,EAAE,MAAM,GAAGA,YAAO,CAACC,WAAM,CAAC;AAC1B,EAAE,WAAW,GAAG;AAChB,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAACC,gCAAsB,CAAC,CAAC,IAAI,CAACC,8BAAoB,CAAC,CAAC,IAAI,CAACC,+BAAqB,CAAC;AACnG;AACA;AACAC,WAAM,CAACC,eAAK,EAAE,WAAW,CAAC;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,6 +1,6 @@
1
1
  import { __bind, $inject, Alepha } from '@alepha/core';
2
- import { $ as $page, P as PageDescriptorProvider, l as ReactBrowserProvider, B as BrowserRouterProvider } from './useActive-ClUsghB5.js';
3
- export { L as Link, N as NestedView, j as RedirectionError, R as RouterContext, b as RouterHookApi, a as RouterLayerContext, i as useActive, d as useApi, c as useClient, u as useInject, e as useQueryParams, f as useRouter, g as useRouterEvents, h as useRouterState } from './useActive-ClUsghB5.js';
2
+ import { $ as $page, P as PageDescriptorProvider, l as ReactBrowserProvider, B as BrowserRouterProvider } from './useActive-BX41CqY8.js';
3
+ export { E as ErrorBoundary, L as Link, N as NestedView, j as RedirectionError, R as RouterContext, b as RouterHookApi, a as RouterLayerContext, i as useActive, d as useApi, c as useClient, u as useInject, e as useQueryParams, f as useRouter, g as useRouterEvents, h as useRouterState } from './useActive-BX41CqY8.js';
4
4
  import 'react/jsx-runtime';
5
5
  import 'react';
6
6
  import '@alepha/server';
package/dist/index.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  var core = require('@alepha/core');
4
4
  var server = require('@alepha/server');
5
- var useActive = require('./useActive-4QlZKGbw.cjs');
5
+ var useActive = require('./useActive-DjpZBEuB.cjs');
6
6
  var node_fs = require('node:fs');
7
7
  var promises = require('node:fs/promises');
8
8
  var node_path = require('node:path');
@@ -161,16 +161,24 @@ class ReactServerProvider {
161
161
  () => fetch(templateUrl).then((it) => it.text()).catch(() => void 0)
162
162
  );
163
163
  }
164
+ /**
165
+ * For testing purposes, creates a render function that can be used.
166
+ */
164
167
  createRenderFunction(name) {
165
168
  return async (options = {}) => {
166
169
  const page = this.pageDescriptorProvider.page(name);
167
- const state = await this.pageDescriptorProvider.createLayers(page, {
170
+ const context = {
168
171
  url: new URL("http://localhost"),
169
172
  params: options.params ?? {},
170
173
  query: options.query ?? {},
171
- head: {}
172
- });
173
- return server$1.renderToString(this.pageDescriptorProvider.root(state));
174
+ head: {},
175
+ onError: () => null
176
+ };
177
+ const state = await this.pageDescriptorProvider.createLayers(
178
+ page,
179
+ context
180
+ );
181
+ return server$1.renderToString(this.pageDescriptorProvider.root(state, context));
174
182
  };
175
183
  }
176
184
  createHandler(page, templateLoader) {
@@ -180,22 +188,27 @@ class ReactServerProvider {
180
188
  if (!template) {
181
189
  throw new Error("Template not found");
182
190
  }
183
- const request = {
191
+ const context = {
184
192
  url,
185
193
  params,
186
194
  query,
187
- head: {}
195
+ // plugins
196
+ head: {},
197
+ onError: () => null
188
198
  };
189
199
  if (this.alepha.has(server.ServerLinksProvider)) {
190
200
  const srv = this.alepha.get(server.ServerLinksProvider);
191
- request.links = await srv.links();
192
- this.alepha.als.set("links", request.links);
201
+ context.links = await srv.getLinks({
202
+ user: serverRequest.user,
203
+ authorization: serverRequest.headers.authorization
204
+ });
205
+ this.alepha.als.set("links", context.links);
193
206
  }
194
207
  await this.alepha.emit(
195
208
  "react:server:render",
196
209
  {
197
210
  request: serverRequest,
198
- pageRequest: request
211
+ pageRequest: context
199
212
  },
200
213
  {
201
214
  log: false
@@ -203,15 +216,15 @@ class ReactServerProvider {
203
216
  );
204
217
  const state = await this.pageDescriptorProvider.createLayers(
205
218
  page,
206
- request
219
+ context
207
220
  );
208
221
  if (state.redirect) {
209
222
  return reply.redirect(state.redirect);
210
223
  }
211
- const element = this.pageDescriptorProvider.root(state, request);
224
+ const element = this.pageDescriptorProvider.root(state, context);
212
225
  const app = server$1.renderToString(element);
213
- const script = `<script>window.__ssr=${JSON.stringify({
214
- links: request.links,
226
+ const hydrationData = {
227
+ links: context.links,
215
228
  layers: state.layers.map((it) => ({
216
229
  ...it,
217
230
  error: it.error ? {
@@ -225,7 +238,8 @@ class ReactServerProvider {
225
238
  path: void 0,
226
239
  element: void 0
227
240
  }))
228
- })}<\/script>`;
241
+ };
242
+ const script = `<script>window.__ssr=${JSON.stringify(hydrationData)}<\/script>`;
229
243
  const response = {
230
244
  html: template
231
245
  };
@@ -235,8 +249,11 @@ class ReactServerProvider {
235
249
  reply.headers.pragma = "no-cache";
236
250
  reply.headers.expires = "0";
237
251
  this.fillTemplate(response, app, script);
238
- if (state.head) {
239
- response.html = this.headProvider.renderHead(response.html, state.head);
252
+ if (context.head) {
253
+ response.html = this.headProvider.renderHead(
254
+ response.html,
255
+ context.head
256
+ );
240
257
  }
241
258
  return response.html;
242
259
  };
@@ -278,6 +295,7 @@ class ReactModule {
278
295
  core.__bind(useActive.$page, ReactModule);
279
296
 
280
297
  exports.$page = useActive.$page;
298
+ exports.ErrorBoundary = useActive.ErrorBoundary;
281
299
  exports.Link = useActive.Link;
282
300
  exports.NestedView = useActive.NestedView;
283
301
  exports.PageDescriptorProvider = useActive.PageDescriptorProvider;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/providers/ServerHeadProvider.ts","../src/providers/ReactServerProvider.ts","../src/index.ts"],"sourcesContent":["export interface Head {\n\ttitle?: string;\n\thtmlAttributes?: Record<string, string>;\n\tbodyAttributes?: Record<string, string>;\n\tmeta?: Array<{ name: string; content: string }>;\n}\n\nexport class ServerHeadProvider {\n\trenderHead(template: string, head: Head): string {\n\t\tlet result = template;\n\n\t\t// Inject htmlAttributes\n\t\tconst htmlAttributes = head.htmlAttributes;\n\t\tif (htmlAttributes) {\n\t\t\tresult = result.replace(\n\t\t\t\t/<html([^>]*)>/i,\n\t\t\t\t(_, existingAttrs) =>\n\t\t\t\t\t`<html${this.mergeAttributes(existingAttrs, htmlAttributes)}>`,\n\t\t\t);\n\t\t}\n\n\t\t// Inject bodyAttributes\n\t\tconst bodyAttributes = head.bodyAttributes;\n\t\tif (bodyAttributes) {\n\t\t\tresult = result.replace(\n\t\t\t\t/<body([^>]*)>/i,\n\t\t\t\t(_, existingAttrs) =>\n\t\t\t\t\t`<body${this.mergeAttributes(existingAttrs, bodyAttributes)}>`,\n\t\t\t);\n\t\t}\n\n\t\t// Build head content\n\t\tlet headContent = \"\";\n\t\tconst title = head.title;\n\t\tif (title) {\n\t\t\tif (template.includes(\"<title>\")) {\n\t\t\t\tresult = result.replace(\n\t\t\t\t\t/<title>(.*?)<\\/title>/i,\n\t\t\t\t\t() => `<title>${this.escapeHtml(title)}</title>`,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\theadContent += `<title>${this.escapeHtml(title)}</title>\\n`;\n\t\t\t}\n\t\t}\n\n\t\tif (head.meta) {\n\t\t\tfor (const meta of head.meta) {\n\t\t\t\theadContent += `<meta name=\"${this.escapeHtml(meta.name)}\" content=\"${this.escapeHtml(meta.content)}\">\\n`;\n\t\t\t}\n\t\t}\n\n\t\t// Inject into <head>...</head>\n\t\tresult = result.replace(\n\t\t\t/<head([^>]*)>(.*?)<\\/head>/is,\n\t\t\t(_, existingAttrs, existingHead) =>\n\t\t\t\t`<head${existingAttrs}>${existingHead}${headContent}</head>`,\n\t\t);\n\n\t\treturn result.trim();\n\t}\n\n\tmergeAttributes(existing: string, attrs: Record<string, string>): string {\n\t\tconst existingAttrs = this.parseAttributes(existing);\n\t\tconst merged = { ...existingAttrs, ...attrs };\n\t\treturn Object.entries(merged)\n\t\t\t.map(([k, v]) => ` ${k}=\"${this.escapeHtml(v)}\"`)\n\t\t\t.join(\"\");\n\t}\n\n\tparseAttributes(attrStr: string): Record<string, string> {\n\t\tconst attrs: Record<string, string> = {};\n\t\tconst attrRegex = /([^\\s=]+)(?:=\"([^\"]*)\")?/g;\n\t\tlet match: RegExpExecArray | null = attrRegex.exec(attrStr);\n\n\t\twhile (match) {\n\t\t\tattrs[match[1]] = match[2] ?? \"\";\n\t\t\tmatch = attrRegex.exec(attrStr);\n\t\t}\n\n\t\treturn attrs;\n\t}\n\n\tescapeHtml(str: string): string {\n\t\treturn str\n\t\t\t.replace(/&/g, \"&amp;\")\n\t\t\t.replace(/</g, \"&lt;\")\n\t\t\t.replace(/>/g, \"&gt;\")\n\t\t\t.replace(/\"/g, \"&quot;\")\n\t\t\t.replace(/'/g, \"&#039;\");\n\t}\n}\n","import { existsSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport {\n\t$hook,\n\t$inject,\n\t$logger,\n\tAlepha,\n\tOPTIONS,\n\ttype Static,\n\tt,\n} from \"@alepha/core\";\nimport {\n\ttype ServerHandler,\n\tServerLinksProvider,\n\tServerRouterProvider,\n} from \"@alepha/server\";\nimport { ServerStaticProvider } from \"@alepha/server-static\";\nimport { renderToString } from \"react-dom/server\";\nimport { $page } from \"../descriptors/$page.ts\";\nimport {\n\tPageDescriptorProvider,\n\ttype PageRequest,\n\ttype PageRoute,\n} from \"./PageDescriptorProvider.ts\";\nimport { ServerHeadProvider } from \"./ServerHeadProvider.ts\";\n\nexport const envSchema = t.object({\n\tREACT_SERVER_DIST: t.string({ default: \"client\" }),\n\tREACT_SERVER_PREFIX: t.string({ default: \"\" }),\n\tREACT_SSR_ENABLED: t.boolean({ default: false }),\n\tREACT_ROOT_ID: t.string({ default: \"root\" }),\n});\n\ndeclare module \"@alepha/core\" {\n\tinterface Env extends Partial<Static<typeof envSchema>> {}\n\tinterface State {\n\t\t\"ReactServerProvider.template\"?: string;\n\t\t\"ReactServerProvider.ssr\"?: boolean;\n\t}\n}\n\nexport class ReactServerProvider {\n\tprotected readonly log = $logger();\n\tprotected readonly alepha = $inject(Alepha);\n\tprotected readonly pageDescriptorProvider = $inject(PageDescriptorProvider);\n\tprotected readonly serverStaticProvider = $inject(ServerStaticProvider);\n\tprotected readonly serverRouterProvider = $inject(ServerRouterProvider);\n\tprotected readonly headProvider = $inject(ServerHeadProvider);\n\tprotected readonly env = $inject(envSchema);\n\tprotected readonly ROOT_DIV_REGEX = new RegExp(\n\t\t`<div([^>]*)\\\\s+id=[\"']${this.env.REACT_ROOT_ID}[\"']([^>]*)>(.*?)<\\\\/div>`,\n\t\t\"is\",\n\t);\n\n\tprotected readonly configure = $hook({\n\t\tname: \"configure\",\n\t\thandler: async () => {\n\t\t\tconst pages = this.alepha.getDescriptorValues($page);\n\t\t\tif (pages.length === 0) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tfor (const { key, instance, value } of pages) {\n\t\t\t\tconst name = value[OPTIONS].name ?? key;\n\n\t\t\t\tif (this.alepha.isTest()) {\n\t\t\t\t\tinstance[key].render = this.createRenderFunction(name);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (this.alepha.isServerless() === \"vite\") {\n\t\t\t\tawait this.configureVite();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet root = \"\";\n\t\t\tif (!this.alepha.isServerless()) {\n\t\t\t\troot = this.getPublicDirectory();\n\n\t\t\t\tif (!root) {\n\t\t\t\t\tthis.log.warn(\"Missing static files, SSR will be disabled\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tawait this.configureStaticServer(root);\n\t\t\t}\n\n\t\t\tconst template =\n\t\t\t\tthis.alepha.state(\"ReactServerProvider.template\") ??\n\t\t\t\t(await readFile(join(root, \"index.html\"), \"utf-8\"));\n\n\t\t\tawait this.registerPages(async () => template);\n\n\t\t\tthis.alepha.state(\"ReactServerProvider.ssr\", true);\n\t\t},\n\t});\n\n\tprotected async registerPages(\n\t\ttemplateLoader: () => Promise<string | undefined>,\n\t) {\n\t\tfor (const page of this.pageDescriptorProvider.getPages()) {\n\t\t\tthis.log.debug(`+ ${page.match} -> ${page.name}`);\n\t\t\tawait this.serverRouterProvider.route({\n\t\t\t\tmethod: \"GET\",\n\t\t\t\tpath: page.match,\n\t\t\t\thandler: this.createHandler(page, templateLoader),\n\t\t\t});\n\t\t}\n\t}\n\n\tprotected getPublicDirectory(): string {\n\t\tconst maybe = [\n\t\t\tjoin(process.cwd(), this.env.REACT_SERVER_DIST),\n\t\t\tjoin(process.cwd(), \"..\", this.env.REACT_SERVER_DIST),\n\t\t];\n\n\t\tfor (const it of maybe) {\n\t\t\tif (existsSync(it)) {\n\t\t\t\treturn it;\n\t\t\t}\n\t\t}\n\n\t\treturn \"\";\n\t}\n\n\tprotected async configureStaticServer(root: string) {\n\t\tawait this.serverStaticProvider.serve({\n\t\t\troot,\n\t\t\tpath: this.env.REACT_SERVER_PREFIX,\n\t\t});\n\t}\n\n\tprotected async configureVite() {\n\t\tconst url = `http://${process.env.SERVER_HOST}:${process.env.SERVER_PORT}`;\n\t\tthis.log.info(\"SSR (vite) OK\");\n\t\tthis.alepha.state(\"ReactServerProvider.ssr\", true);\n\t\tconst templateUrl = `${url}/index.html`;\n\n\t\tawait this.registerPages(() =>\n\t\t\tfetch(templateUrl)\n\t\t\t\t.then((it) => it.text())\n\t\t\t\t.catch(() => undefined),\n\t\t);\n\t}\n\n\tprotected createRenderFunction(name: string) {\n\t\treturn async (\n\t\t\toptions: {\n\t\t\t\tparams?: Record<string, string>;\n\t\t\t\tquery?: Record<string, string>;\n\t\t\t} = {},\n\t\t) => {\n\t\t\tconst page = this.pageDescriptorProvider.page(name);\n\n\t\t\tconst state = await this.pageDescriptorProvider.createLayers(page, {\n\t\t\t\turl: new URL(\"http://localhost\"),\n\t\t\t\tparams: options.params ?? {},\n\t\t\t\tquery: options.query ?? {},\n\t\t\t\thead: {},\n\t\t\t});\n\n\t\t\treturn renderToString(this.pageDescriptorProvider.root(state));\n\t\t};\n\t}\n\n\tprotected createHandler(\n\t\tpage: PageRoute,\n\t\ttemplateLoader: () => Promise<string | undefined>,\n\t): ServerHandler {\n\t\treturn async (serverRequest) => {\n\t\t\tconst { url, reply, query, params } = serverRequest;\n\t\t\tconst template = await templateLoader();\n\t\t\tif (!template) {\n\t\t\t\tthrow new Error(\"Template not found\");\n\t\t\t}\n\n\t\t\tconst request: PageRequest = {\n\t\t\t\turl,\n\t\t\t\tparams,\n\t\t\t\tquery,\n\t\t\t\thead: {},\n\t\t\t};\n\n\t\t\t// -- links\n\t\t\tif (this.alepha.has(ServerLinksProvider)) {\n\t\t\t\tconst srv = this.alepha.get(ServerLinksProvider);\n\t\t\t\trequest.links = (await srv.links()) as any;\n\t\t\t\tthis.alepha.als.set(\"links\", request.links);\n\t\t\t}\n\n\t\t\tawait this.alepha.emit(\n\t\t\t\t\"react:server:render\",\n\t\t\t\t{\n\t\t\t\t\trequest: serverRequest,\n\t\t\t\t\tpageRequest: request,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tlog: false,\n\t\t\t\t},\n\t\t\t);\n\n\t\t\tconst state = await this.pageDescriptorProvider.createLayers(\n\t\t\t\tpage,\n\t\t\t\trequest,\n\t\t\t);\n\n\t\t\tif (state.redirect) {\n\t\t\t\treturn reply.redirect(state.redirect);\n\t\t\t}\n\n\t\t\tconst element = this.pageDescriptorProvider.root(state, request);\n\t\t\tconst app = renderToString(element);\n\n\t\t\t// create hydration data\n\t\t\tconst script = `<script>window.__ssr=${JSON.stringify({\n\t\t\t\tlinks: request.links,\n\t\t\t\tlayers: state.layers.map((it) => ({\n\t\t\t\t\t...it,\n\t\t\t\t\terror: it.error\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t...it.error,\n\t\t\t\t\t\t\t\tname: it.error.name,\n\t\t\t\t\t\t\t\tmessage: it.error.message,\n\t\t\t\t\t\t\t\tstack: it.error.stack, // TODO: Hide stack in production ?\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: undefined,\n\t\t\t\t\tindex: undefined,\n\t\t\t\t\tpath: undefined,\n\t\t\t\t\telement: undefined,\n\t\t\t\t})),\n\t\t\t})}</script>`;\n\n\t\t\tconst response = {\n\t\t\t\thtml: template,\n\t\t\t};\n\n\t\t\treply.status = 200;\n\t\t\treply.headers[\"content-type\"] = \"text/html\";\n\t\t\treply.headers[\"cache-control\"] =\n\t\t\t\t\"no-store, no-cache, must-revalidate, proxy-revalidate\";\n\t\t\treply.headers.pragma = \"no-cache\";\n\t\t\treply.headers.expires = \"0\";\n\n\t\t\t// inject app into template\n\t\t\tthis.fillTemplate(response, app, script);\n\n\t\t\t// inject head meta\n\t\t\tif (state.head) {\n\t\t\t\tresponse.html = this.headProvider.renderHead(response.html, state.head);\n\t\t\t}\n\n\t\t\t// TODO: hook for plugins \"react:server:template\"\n\t\t\t// { response: { html: string }, request, state }\n\n\t\t\treturn response.html;\n\t\t};\n\t}\n\n\tfillTemplate(response: { html: string }, app: string, script: string) {\n\t\tif (this.ROOT_DIV_REGEX.test(response.html)) {\n\t\t\t// replace contents of the existing <div id=\"root\">\n\t\t\tresponse.html = response.html.replace(\n\t\t\t\tthis.ROOT_DIV_REGEX,\n\t\t\t\t(_match, beforeId, afterId) => {\n\t\t\t\t\treturn `<div${beforeId} id=\"${this.env.REACT_ROOT_ID}\"${afterId}>${app}</div>`;\n\t\t\t\t},\n\t\t\t);\n\t\t} else {\n\t\t\tconst bodyOpenTag = /<body([^>]*)>/i;\n\t\t\tif (bodyOpenTag.test(response.html)) {\n\t\t\t\tresponse.html = response.html.replace(bodyOpenTag, (match) => {\n\t\t\t\t\treturn `${match}\\n<div id=\"${this.env.REACT_ROOT_ID}\">${app}</div>`;\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tconst bodyCloseTagRegex = /<\\/body>/i;\n\t\tif (bodyCloseTagRegex.test(response.html)) {\n\t\t\tresponse.html = response.html.replace(\n\t\t\t\tbodyCloseTagRegex,\n\t\t\t\t`${script}\\n</body>`,\n\t\t\t);\n\t\t}\n\t}\n}\n","import { $inject, Alepha, __bind } from \"@alepha/core\";\nimport {\n\tServerLinksProvider,\n\tServerModule,\n\ttype ServerRequest,\n} from \"@alepha/server\";\nimport { $page } from \"./descriptors/$page.ts\";\nimport {\n\tPageDescriptorProvider,\n\ttype PageReactContext,\n\ttype PageRequest,\n\ttype RouterState,\n} from \"./providers/PageDescriptorProvider.ts\";\nimport type { ReactHydrationState } from \"./providers/ReactBrowserProvider.ts\";\nimport { ReactServerProvider } from \"./providers/ReactServerProvider.ts\";\nexport { default as NestedView } from \"./components/NestedView.tsx\";\n\nexport * from \"./index.shared.ts\";\nexport * from \"./providers/PageDescriptorProvider.ts\";\nexport * from \"./providers/ReactBrowserProvider.ts\";\nexport * from \"./providers/ReactServerProvider.ts\";\nexport * from \"./errors/RedirectionError.ts\";\n\ndeclare module \"@alepha/core\" {\n\tinterface Hooks {\n\t\t\"react:browser:render\": {\n\t\t\tcontext: PageReactContext;\n\t\t\thydration?: ReactHydrationState;\n\t\t};\n\t\t\"react:server:render\": {\n\t\t\trequest: ServerRequest;\n\t\t\tpageRequest: PageRequest;\n\t\t};\n\n\t\t\"react:transition:begin\": {\n\t\t\tstate: RouterState;\n\t\t};\n\t\t\"react:transition:success\": {\n\t\t\tstate: RouterState;\n\t\t};\n\t\t\"react:transition:error\": {\n\t\t\terror: Error;\n\t\t\tstate: RouterState;\n\t\t};\n\t\t\"react:transition:end\": {\n\t\t\tstate: RouterState;\n\t\t};\n\t}\n}\n\nexport class ReactModule {\n\tprotected readonly alepha = $inject(Alepha);\n\n\tconstructor() {\n\t\tthis.alepha //\n\t\t\t.with(ServerModule)\n\t\t\t.with(ServerLinksProvider)\n\t\t\t.with(PageDescriptorProvider)\n\t\t\t.with(ReactServerProvider);\n\t}\n}\n\n__bind($page, ReactModule);\n"],"names":["t","$logger","$inject","Alepha","PageDescriptorProvider","ServerStaticProvider","ServerRouterProvider","$hook","$page","OPTIONS","readFile","join","existsSync","renderToString","ServerLinksProvider","ServerModule","__bind"],"mappings":";;;;;;;;;;;;;;;AACO,MAAM,kBAAkB,CAAC;AAChC,EAAE,UAAU,CAAC,QAAQ,EAAE,IAAI,EAAE;AAC7B,IAAI,IAAI,MAAM,GAAG,QAAQ;AACzB,IAAI,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc;AAC9C,IAAI,IAAI,cAAc,EAAE;AACxB,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO;AAC7B,QAAQ,gBAAgB;AACxB,QAAQ,CAAC,CAAC,EAAE,aAAa,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,eAAe,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC,CAAC;AAC3F,OAAO;AACP;AACA,IAAI,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc;AAC9C,IAAI,IAAI,cAAc,EAAE;AACxB,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO;AAC7B,QAAQ,gBAAgB;AACxB,QAAQ,CAAC,CAAC,EAAE,aAAa,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,eAAe,CAAC,aAAa,EAAE,cAA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AC1C,MAAM,IAAI,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;AAC3C,QAAQ,QAAQ,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,KAAK,KAAK;AACtE,UAAU,OAAO,CAAC,EAAE,KAAK;AACzB,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,EAAE,GAAG,CAAC,MAAM,CAAC;AACjD,SAAS,CAAC;AACV;AACA;AACA,IAAI,MAAM,iBAAiB,GAAG,WAAW;AACzC,IAAI,IAAI,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;AAC/C,MAAM,QAAQ,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO;AAC3C,QAAQ,iBAAiB;AACzB,QAAQ,CAAC,EAAE,MAAM;AACjB,OAAO;AACP,OAAO;AACP;AACA;AACA;;ACtMO,MAAM,WAAW,CAAC;AACzB,EAAE,MAAM,GAAGX,YAAO,CAACC,WAAM,CAAC;AAC1B,EAAE,WAAW,GAAG;AAChB,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAACY,mBAAY,CAAC,CAAC,IAAI,CAACD,0BAAmB,CAAC,CAAC,IAAI,CAACV,gCAAsB,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC;AACnH;AACA;AACAY,WAAM,CAACR,eAAK,EAAE,WAAW,CAAC;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/providers/ServerHeadProvider.ts","../src/providers/ReactServerProvider.ts","../src/index.ts"],"sourcesContent":["export interface Head {\n\ttitle?: string;\n\thtmlAttributes?: Record<string, string>;\n\tbodyAttributes?: Record<string, string>;\n\tmeta?: Array<{ name: string; content: string }>;\n}\n\nexport class ServerHeadProvider {\n\trenderHead(template: string, head: Head): string {\n\t\tlet result = template;\n\n\t\t// Inject htmlAttributes\n\t\tconst htmlAttributes = head.htmlAttributes;\n\t\tif (htmlAttributes) {\n\t\t\tresult = result.replace(\n\t\t\t\t/<html([^>]*)>/i,\n\t\t\t\t(_, existingAttrs) =>\n\t\t\t\t\t`<html${this.mergeAttributes(existingAttrs, htmlAttributes)}>`,\n\t\t\t);\n\t\t}\n\n\t\t// Inject bodyAttributes\n\t\tconst bodyAttributes = head.bodyAttributes;\n\t\tif (bodyAttributes) {\n\t\t\tresult = result.replace(\n\t\t\t\t/<body([^>]*)>/i,\n\t\t\t\t(_, existingAttrs) =>\n\t\t\t\t\t`<body${this.mergeAttributes(existingAttrs, bodyAttributes)}>`,\n\t\t\t);\n\t\t}\n\n\t\t// Build head content\n\t\tlet headContent = \"\";\n\t\tconst title = head.title;\n\t\tif (title) {\n\t\t\tif (template.includes(\"<title>\")) {\n\t\t\t\tresult = result.replace(\n\t\t\t\t\t/<title>(.*?)<\\/title>/i,\n\t\t\t\t\t() => `<title>${this.escapeHtml(title)}</title>`,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\theadContent += `<title>${this.escapeHtml(title)}</title>\\n`;\n\t\t\t}\n\t\t}\n\n\t\tif (head.meta) {\n\t\t\tfor (const meta of head.meta) {\n\t\t\t\theadContent += `<meta name=\"${this.escapeHtml(meta.name)}\" content=\"${this.escapeHtml(meta.content)}\">\\n`;\n\t\t\t}\n\t\t}\n\n\t\t// Inject into <head>...</head>\n\t\tresult = result.replace(\n\t\t\t/<head([^>]*)>(.*?)<\\/head>/is,\n\t\t\t(_, existingAttrs, existingHead) =>\n\t\t\t\t`<head${existingAttrs}>${existingHead}${headContent}</head>`,\n\t\t);\n\n\t\treturn result.trim();\n\t}\n\n\tmergeAttributes(existing: string, attrs: Record<string, string>): string {\n\t\tconst existingAttrs = this.parseAttributes(existing);\n\t\tconst merged = { ...existingAttrs, ...attrs };\n\t\treturn Object.entries(merged)\n\t\t\t.map(([k, v]) => ` ${k}=\"${this.escapeHtml(v)}\"`)\n\t\t\t.join(\"\");\n\t}\n\n\tparseAttributes(attrStr: string): Record<string, string> {\n\t\tconst attrs: Record<string, string> = {};\n\t\tconst attrRegex = /([^\\s=]+)(?:=\"([^\"]*)\")?/g;\n\t\tlet match: RegExpExecArray | null = attrRegex.exec(attrStr);\n\n\t\twhile (match) {\n\t\t\tattrs[match[1]] = match[2] ?? \"\";\n\t\t\tmatch = attrRegex.exec(attrStr);\n\t\t}\n\n\t\treturn attrs;\n\t}\n\n\tescapeHtml(str: string): string {\n\t\treturn str\n\t\t\t.replace(/&/g, \"&amp;\")\n\t\t\t.replace(/</g, \"&lt;\")\n\t\t\t.replace(/>/g, \"&gt;\")\n\t\t\t.replace(/\"/g, \"&quot;\")\n\t\t\t.replace(/'/g, \"&#039;\");\n\t}\n}\n","import { existsSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport {\n\t$hook,\n\t$inject,\n\t$logger,\n\tAlepha,\n\tOPTIONS,\n\ttype Static,\n\tt,\n} from \"@alepha/core\";\nimport {\n\ttype ServerHandler,\n\tServerLinksProvider,\n\tServerRouterProvider,\n} from \"@alepha/server\";\nimport { ServerStaticProvider } from \"@alepha/server-static\";\nimport { renderToString } from \"react-dom/server\";\nimport { $page } from \"../descriptors/$page.ts\";\nimport {\n\tPageDescriptorProvider,\n\ttype PageRequest,\n\ttype PageRoute,\n} from \"./PageDescriptorProvider.ts\";\nimport { ServerHeadProvider } from \"./ServerHeadProvider.ts\";\n\nexport const envSchema = t.object({\n\tREACT_SERVER_DIST: t.string({ default: \"client\" }),\n\tREACT_SERVER_PREFIX: t.string({ default: \"\" }),\n\tREACT_SSR_ENABLED: t.boolean({ default: false }),\n\tREACT_ROOT_ID: t.string({ default: \"root\" }),\n});\n\ndeclare module \"@alepha/core\" {\n\tinterface Env extends Partial<Static<typeof envSchema>> {}\n\tinterface State {\n\t\t\"ReactServerProvider.template\"?: string;\n\t\t\"ReactServerProvider.ssr\"?: boolean;\n\t}\n}\n\nexport class ReactServerProvider {\n\tprotected readonly log = $logger();\n\tprotected readonly alepha = $inject(Alepha);\n\tprotected readonly pageDescriptorProvider = $inject(PageDescriptorProvider);\n\tprotected readonly serverStaticProvider = $inject(ServerStaticProvider);\n\tprotected readonly serverRouterProvider = $inject(ServerRouterProvider);\n\tprotected readonly headProvider = $inject(ServerHeadProvider);\n\tprotected readonly env = $inject(envSchema);\n\tprotected readonly ROOT_DIV_REGEX = new RegExp(\n\t\t`<div([^>]*)\\\\s+id=[\"']${this.env.REACT_ROOT_ID}[\"']([^>]*)>(.*?)<\\\\/div>`,\n\t\t\"is\",\n\t);\n\n\tprotected readonly configure = $hook({\n\t\tname: \"configure\",\n\t\thandler: async () => {\n\t\t\tconst pages = this.alepha.getDescriptorValues($page);\n\t\t\tif (pages.length === 0) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tfor (const { key, instance, value } of pages) {\n\t\t\t\tconst name = value[OPTIONS].name ?? key;\n\n\t\t\t\tif (this.alepha.isTest()) {\n\t\t\t\t\tinstance[key].render = this.createRenderFunction(name);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (this.alepha.isServerless() === \"vite\") {\n\t\t\t\tawait this.configureVite();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet root = \"\";\n\t\t\tif (!this.alepha.isServerless()) {\n\t\t\t\troot = this.getPublicDirectory();\n\n\t\t\t\tif (!root) {\n\t\t\t\t\tthis.log.warn(\"Missing static files, SSR will be disabled\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tawait this.configureStaticServer(root);\n\t\t\t}\n\n\t\t\tconst template =\n\t\t\t\tthis.alepha.state(\"ReactServerProvider.template\") ??\n\t\t\t\t(await readFile(join(root, \"index.html\"), \"utf-8\"));\n\n\t\t\tawait this.registerPages(async () => template);\n\n\t\t\tthis.alepha.state(\"ReactServerProvider.ssr\", true);\n\t\t},\n\t});\n\n\tprotected async registerPages(\n\t\ttemplateLoader: () => Promise<string | undefined>,\n\t) {\n\t\tfor (const page of this.pageDescriptorProvider.getPages()) {\n\t\t\tthis.log.debug(`+ ${page.match} -> ${page.name}`);\n\t\t\tawait this.serverRouterProvider.route({\n\t\t\t\tmethod: \"GET\",\n\t\t\t\tpath: page.match,\n\t\t\t\thandler: this.createHandler(page, templateLoader),\n\t\t\t});\n\t\t}\n\t}\n\n\tprotected getPublicDirectory(): string {\n\t\tconst maybe = [\n\t\t\tjoin(process.cwd(), this.env.REACT_SERVER_DIST),\n\t\t\tjoin(process.cwd(), \"..\", this.env.REACT_SERVER_DIST),\n\t\t];\n\n\t\tfor (const it of maybe) {\n\t\t\tif (existsSync(it)) {\n\t\t\t\treturn it;\n\t\t\t}\n\t\t}\n\n\t\treturn \"\";\n\t}\n\n\tprotected async configureStaticServer(root: string) {\n\t\tawait this.serverStaticProvider.serve({\n\t\t\troot,\n\t\t\tpath: this.env.REACT_SERVER_PREFIX,\n\t\t});\n\t}\n\n\tprotected async configureVite() {\n\t\tconst url = `http://${process.env.SERVER_HOST}:${process.env.SERVER_PORT}`;\n\t\tthis.log.info(\"SSR (vite) OK\");\n\t\tthis.alepha.state(\"ReactServerProvider.ssr\", true);\n\t\tconst templateUrl = `${url}/index.html`;\n\n\t\tawait this.registerPages(() =>\n\t\t\tfetch(templateUrl)\n\t\t\t\t.then((it) => it.text())\n\t\t\t\t.catch(() => undefined),\n\t\t);\n\t}\n\n\t/**\n\t * For testing purposes, creates a render function that can be used.\n\t */\n\tprotected createRenderFunction(name: string) {\n\t\treturn async (\n\t\t\toptions: {\n\t\t\t\tparams?: Record<string, string>;\n\t\t\t\tquery?: Record<string, string>;\n\t\t\t} = {},\n\t\t) => {\n\t\t\tconst page = this.pageDescriptorProvider.page(name);\n\t\t\tconst context: PageRequest = {\n\t\t\t\turl: new URL(\"http://localhost\"),\n\t\t\t\tparams: options.params ?? {},\n\t\t\t\tquery: options.query ?? {},\n\t\t\t\thead: {},\n\t\t\t\tonError: () => null,\n\t\t\t};\n\n\t\t\t// for testing\n\t\t\tconst state = await this.pageDescriptorProvider.createLayers(\n\t\t\t\tpage,\n\t\t\t\tcontext,\n\t\t\t);\n\n\t\t\treturn renderToString(this.pageDescriptorProvider.root(state, context));\n\t\t};\n\t}\n\n\tprotected createHandler(\n\t\tpage: PageRoute,\n\t\ttemplateLoader: () => Promise<string | undefined>,\n\t): ServerHandler {\n\t\treturn async (serverRequest) => {\n\t\t\tconst { url, reply, query, params } = serverRequest;\n\t\t\tconst template = await templateLoader();\n\t\t\tif (!template) {\n\t\t\t\tthrow new Error(\"Template not found\");\n\t\t\t}\n\n\t\t\tconst context: PageRequest = {\n\t\t\t\turl,\n\t\t\t\tparams,\n\t\t\t\tquery,\n\t\t\t\t// plugins\n\t\t\t\thead: {},\n\t\t\t\tonError: () => null,\n\t\t\t};\n\n\t\t\t// -- links\n\t\t\tif (this.alepha.has(ServerLinksProvider)) {\n\t\t\t\tconst srv = this.alepha.get(ServerLinksProvider);\n\n\t\t\t\tcontext.links = await srv.getLinks({\n\t\t\t\t\tuser: serverRequest.user,\n\t\t\t\t\tauthorization: serverRequest.headers.authorization,\n\t\t\t\t});\n\n\t\t\t\tthis.alepha.als.set(\"links\", context.links);\n\t\t\t}\n\n\t\t\tawait this.alepha.emit(\n\t\t\t\t\"react:server:render\",\n\t\t\t\t{\n\t\t\t\t\trequest: serverRequest,\n\t\t\t\t\tpageRequest: context,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tlog: false,\n\t\t\t\t},\n\t\t\t);\n\n\t\t\tconst state = await this.pageDescriptorProvider.createLayers(\n\t\t\t\tpage,\n\t\t\t\tcontext,\n\t\t\t);\n\n\t\t\tif (state.redirect) {\n\t\t\t\treturn reply.redirect(state.redirect);\n\t\t\t}\n\n\t\t\tconst element = this.pageDescriptorProvider.root(state, context);\n\t\t\tconst app = renderToString(element);\n\n\t\t\tconst hydrationData = {\n\t\t\t\tlinks: context.links,\n\t\t\t\tlayers: state.layers.map((it) => ({\n\t\t\t\t\t...it,\n\t\t\t\t\terror: it.error\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t...it.error,\n\t\t\t\t\t\t\t\tname: it.error.name,\n\t\t\t\t\t\t\t\tmessage: it.error.message,\n\t\t\t\t\t\t\t\tstack: it.error.stack, // TODO: Hide stack in production ?\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: undefined,\n\t\t\t\t\tindex: undefined,\n\t\t\t\t\tpath: undefined,\n\t\t\t\t\telement: undefined,\n\t\t\t\t})),\n\t\t\t};\n\n\t\t\t// create hydration data\n\t\t\tconst script = `<script>window.__ssr=${JSON.stringify(hydrationData)}</script>`;\n\n\t\t\tconst response = {\n\t\t\t\thtml: template,\n\t\t\t};\n\n\t\t\treply.status = 200;\n\t\t\treply.headers[\"content-type\"] = \"text/html\";\n\t\t\treply.headers[\"cache-control\"] =\n\t\t\t\t\"no-store, no-cache, must-revalidate, proxy-revalidate\";\n\t\t\treply.headers.pragma = \"no-cache\";\n\t\t\treply.headers.expires = \"0\";\n\n\t\t\t// inject app into template\n\t\t\tthis.fillTemplate(response, app, script);\n\n\t\t\t// inject head meta\n\t\t\tif (context.head) {\n\t\t\t\tresponse.html = this.headProvider.renderHead(\n\t\t\t\t\tresponse.html,\n\t\t\t\t\tcontext.head,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// TODO: hook for plugins \"react:server:template\"\n\t\t\t// { response: { html: string }, request, state }\n\n\t\t\treturn response.html;\n\t\t};\n\t}\n\n\tfillTemplate(response: { html: string }, app: string, script: string) {\n\t\tif (this.ROOT_DIV_REGEX.test(response.html)) {\n\t\t\t// replace contents of the existing <div id=\"root\">\n\t\t\tresponse.html = response.html.replace(\n\t\t\t\tthis.ROOT_DIV_REGEX,\n\t\t\t\t(_match, beforeId, afterId) => {\n\t\t\t\t\treturn `<div${beforeId} id=\"${this.env.REACT_ROOT_ID}\"${afterId}>${app}</div>`;\n\t\t\t\t},\n\t\t\t);\n\t\t} else {\n\t\t\tconst bodyOpenTag = /<body([^>]*)>/i;\n\t\t\tif (bodyOpenTag.test(response.html)) {\n\t\t\t\tresponse.html = response.html.replace(bodyOpenTag, (match) => {\n\t\t\t\t\treturn `${match}\\n<div id=\"${this.env.REACT_ROOT_ID}\">${app}</div>`;\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tconst bodyCloseTagRegex = /<\\/body>/i;\n\t\tif (bodyCloseTagRegex.test(response.html)) {\n\t\t\tresponse.html = response.html.replace(\n\t\t\t\tbodyCloseTagRegex,\n\t\t\t\t`${script}\\n</body>`,\n\t\t\t);\n\t\t}\n\t}\n}\n","import { $inject, Alepha, __bind } from \"@alepha/core\";\nimport {\n\tServerLinksProvider,\n\tServerModule,\n\ttype ServerRequest,\n} from \"@alepha/server\";\nimport { $page } from \"./descriptors/$page.ts\";\nimport {\n\tPageDescriptorProvider,\n\ttype PageReactContext,\n\ttype PageRequest,\n\ttype RouterState,\n} from \"./providers/PageDescriptorProvider.ts\";\nimport type { ReactHydrationState } from \"./providers/ReactBrowserProvider.ts\";\nimport { ReactServerProvider } from \"./providers/ReactServerProvider.ts\";\nexport { default as NestedView } from \"./components/NestedView.tsx\";\n\nexport * from \"./index.shared.ts\";\nexport * from \"./providers/PageDescriptorProvider.ts\";\nexport * from \"./providers/ReactBrowserProvider.ts\";\nexport * from \"./providers/ReactServerProvider.ts\";\nexport * from \"./errors/RedirectionError.ts\";\n\ndeclare module \"@alepha/core\" {\n\tinterface Hooks {\n\t\t\"react:browser:render\": {\n\t\t\tstate: RouterState;\n\t\t\tcontext: PageReactContext;\n\t\t\thydration?: ReactHydrationState;\n\t\t};\n\t\t\"react:server:render\": {\n\t\t\trequest: ServerRequest;\n\t\t\tpageRequest: PageRequest;\n\t\t};\n\n\t\t\"react:transition:begin\": {\n\t\t\tstate: RouterState;\n\t\t\tcontext: PageReactContext;\n\t\t};\n\t\t\"react:transition:success\": {\n\t\t\tstate: RouterState;\n\t\t};\n\t\t\"react:transition:error\": {\n\t\t\terror: Error;\n\t\t\tstate: RouterState;\n\t\t\tcontext: PageReactContext;\n\t\t};\n\t\t\"react:transition:end\": {\n\t\t\tstate: RouterState;\n\t\t\tcontext: PageReactContext;\n\t\t};\n\t}\n}\n\nexport class ReactModule {\n\tprotected readonly alepha = $inject(Alepha);\n\n\tconstructor() {\n\t\tthis.alepha //\n\t\t\t.with(ServerModule)\n\t\t\t.with(ServerLinksProvider)\n\t\t\t.with(PageDescriptorProvider)\n\t\t\t.with(ReactServerProvider);\n\t}\n}\n\n__bind($page, ReactModule);\n"],"names":["t","$logger","$inject","Alepha","PageDescriptorProvider","ServerStaticProvider","ServerRouterProvider","$hook","$page","OPTIONS","readFile","join","existsSync","renderToString","ServerLinksProvider","ServerModule","__bind"],"mappings":";;;;;;;;;;;;;;;AACO,MAAM,kBAAkB,CAAC;AAChC,EAAE,UAAU,CAAC,QAAQ,EAAE,IAAI,EAAE;AAC7B,IAAI,IAAI,MAAM,GAAG,QAAQ;AACzB,IAAI,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc;AAC9C,IAAI,IAAI,cAAc,EAAE;AACxB,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO;AAC7B,QAAQ,gBAAgB;AACxB,QAAQ,CAAC,CAAC,EAAE,aAAa,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,eAAe,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC,CAAC;AAC3F,OAAO;AACP;AACA,IAAI,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc;AAC9C,IAAI,IAAI,cAAc,EAAE;AACxB,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO;AAC7B,QAAQ,gBAAgB;AACxB,QAAQ,CAAC,CAAC,EAAE,aAAa,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,eAAe,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC,CAAC;AAC3F,OAAO;AACP;AACA,IAAI,IAAI,WAAW,GAAG,EAAE;AACxB,IAAI,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK;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Static$1, TSchema as TSchema$1, KIND, OPTIONS, Async, Class, TObject as TObject$1 } from '@alepha/core';
3
3
  import * as _alepha_server from '@alepha/server';
4
- import { HttpClientLink, HttpClient, ServerRouterProvider, ServerHandler, ServerRequest } from '@alepha/server';
5
- import * as react from 'react';
6
- import react__default, { ReactNode, FC, AnchorHTMLAttributes } from 'react';
4
+ import { HttpClientLink, HttpClient, ApiLinksResponse, ServerRouterProvider, ServerHandler, ServerRequest } from '@alepha/server';
5
+ import * as React from 'react';
6
+ import React__default, { ReactNode, FC, AnchorHTMLAttributes, PropsWithChildren, ErrorInfo } from 'react';
7
7
  import { Root } from 'react-dom/client';
8
8
  import { RouterProvider, Route } from '@alepha/router';
9
9
  import * as react_jsx_runtime from 'react/jsx-runtime';
@@ -156,7 +156,7 @@ declare class BrowserRouterProvider extends RouterProvider<BrowserRoute> {
156
156
  add(entry: PageRouteEntry): void;
157
157
  protected readonly configure: _alepha_core.HookDescriptor<"configure">;
158
158
  transition(url: URL, options?: TransitionOptions): Promise<RouterRenderResult>;
159
- root(state: RouterState, context?: PageReactContext): ReactNode;
159
+ root(state: RouterState, context: PageReactContext): ReactNode;
160
160
  }
161
161
 
162
162
  declare const envSchema$1: _alepha_core.TObject<{
@@ -193,10 +193,7 @@ declare class ReactBrowserProvider {
193
193
  protected render(options?: {
194
194
  url?: string;
195
195
  previous?: PreviousLayerData[];
196
- }): Promise<{
197
- url: string;
198
- head: Head;
199
- }>;
196
+ }): Promise<RouterRenderResult>;
200
197
  /**
201
198
  * Get embedded layers from the server.
202
199
  *
@@ -218,6 +215,7 @@ declare class ReactBrowserProvider {
218
215
  interface RouterGoOptions {
219
216
  replace?: boolean;
220
217
  match?: TransitionOptions;
218
+ params?: Record<string, string>;
221
219
  }
222
220
  interface ReactHydrationState {
223
221
  layers?: PreviousLayerData[];
@@ -265,28 +263,16 @@ declare class RouterHookApi {
265
263
  createHref(pathname: HrefLike, layer?: {
266
264
  path: string;
267
265
  }): string;
268
- /**
269
- *
270
- * @param path
271
- * @param options
272
- */
273
- go(path: HrefLike, options?: RouterGoOptions): Promise<void>;
274
- /**
275
- *
276
- * @param path
277
- */
278
- createAnchorProps(path: string): AnchorProps;
266
+ go(path: string, options?: RouterGoOptions): Promise<void>;
267
+ go<T extends object>(path: keyof VirtualRouter<T>, options?: RouterGoOptions): Promise<void>;
268
+ anchor(path: string): AnchorProps;
279
269
  /**
280
270
  * Set query params.
281
271
  *
282
272
  * @param record
283
273
  * @param options
284
274
  */
285
- setQueryParams(record: Record<string, any>, options?: {
286
- /**
287
- * If true, this will merge current query params with the new ones.
288
- */
289
- merge?: boolean;
275
+ setQueryParams(record: Record<string, any> | ((queryParams: Record<string, any>) => Record<string, any>), options?: {
290
276
  /**
291
277
  * If true, this will add a new entry to the history stack.
292
278
  */
@@ -299,6 +285,9 @@ type HrefLike = string | {
299
285
  name?: string;
300
286
  };
301
287
  };
288
+ type VirtualRouter<T> = {
289
+ [K in keyof T as T[K] extends PageDescriptor ? K : never]: T[K];
290
+ };
302
291
 
303
292
  declare const KEY = "PAGE";
304
293
  interface PageConfigSchema {
@@ -324,10 +313,7 @@ interface PageDescriptorOptions<TConfig extends PageConfigSchema = PageConfigSch
324
313
  };
325
314
  can?: () => boolean;
326
315
  head?: Head | ((props: TProps, previous?: Head) => Head);
327
- errorHandler?: FC<{
328
- error: Error;
329
- url: string;
330
- }>;
316
+ errorHandler?: (error: Error) => ReactNode;
331
317
  }
332
318
  interface PageDescriptor<TConfig extends PageConfigSchema = PageConfigSchema, TProps extends object = TPropsDefault, TPropsParent extends object = TPropsParentDefault> {
333
319
  [KIND]: typeof KEY;
@@ -361,11 +347,7 @@ interface PageRequestConfig<TConfig extends PageConfigSchema = PageConfigSchema>
361
347
  params: TConfig["params"] extends TSchema$1 ? Static$1<TConfig["params"]> : Record<string, string>;
362
348
  query: TConfig["query"] extends TSchema$1 ? Static$1<TConfig["query"]> : Record<string, string>;
363
349
  }
364
- type PageResolve<TConfig extends PageConfigSchema = PageConfigSchema, TPropsParent extends object = TPropsParentDefault> = PageRequestConfig<TConfig> & TPropsParent & PageResolveContext;
365
- interface PageResolveContext {
366
- url: URL;
367
- head: Head;
368
- }
350
+ type PageResolve<TConfig extends PageConfigSchema = PageConfigSchema, TPropsParent extends object = TPropsParentDefault> = PageRequestConfig<TConfig> & TPropsParent & PageReactContext;
369
351
 
370
352
  declare class PageDescriptorProvider {
371
353
  protected readonly log: _alepha_core.Logger;
@@ -373,12 +355,9 @@ declare class PageDescriptorProvider {
373
355
  protected readonly pages: PageRoute[];
374
356
  getPages(): PageRoute[];
375
357
  page(name: string): PageRoute;
376
- root(state: RouterState, context?: PageReactContext): ReactNode;
358
+ root(state: RouterState, context: PageReactContext): ReactNode;
377
359
  createLayers(route: PageRoute, request: PageRequest): Promise<CreateLayersResult>;
378
- protected getErrorHandler(route: PageRoute): react.FC<{
379
- error: Error;
380
- url: string;
381
- }> | undefined;
360
+ protected getErrorHandler(route: PageRoute): ((error: Error) => ReactNode) | undefined;
382
361
  protected createElement(page: PageRoute, props: Record<string, any>): Promise<ReactNode>;
383
362
  protected fillHead(page: PageRoute, ctx: PageRequest, props: Record<string, any>): void;
384
363
  renderError(e: Error): ReactNode;
@@ -429,14 +408,13 @@ interface Layer {
429
408
  }
430
409
  type PreviousLayerData = Omit<Layer, "element">;
431
410
  interface AnchorProps {
432
- href?: string;
433
- onClick?: (ev: any) => any;
411
+ href: string;
412
+ onClick: (ev: any) => any;
434
413
  }
435
414
  interface RouterState {
436
415
  pathname: string;
437
416
  search: string;
438
417
  layers: Array<Layer>;
439
- head: Head;
440
418
  }
441
419
  interface TransitionOptions {
442
420
  state?: RouterState;
@@ -450,23 +428,27 @@ interface RouterStackItem {
450
428
  error?: Error;
451
429
  }
452
430
  interface RouterRenderResult {
431
+ state: RouterState;
432
+ context: PageReactContext;
453
433
  redirect?: string;
454
- layers: Layer[];
455
- head: Head;
456
- element: ReactNode;
457
434
  }
458
435
  interface PageRequest extends PageReactContext {
459
- url: URL;
460
436
  params: Record<string, any>;
461
437
  query: Record<string, string>;
462
- head: Head;
463
438
  previous?: PreviousLayerData[];
464
439
  }
465
440
  interface CreateLayersResult extends RouterState {
466
441
  redirect?: string;
467
442
  }
443
+ /**
444
+ * It's like RouterState, but publicly available in React context.
445
+ * This is where we store all plugin data!
446
+ */
468
447
  interface PageReactContext {
469
- links?: HttpClientLink[];
448
+ url: URL;
449
+ head: Head;
450
+ onError: (error: Error) => ReactNode;
451
+ links?: ApiLinksResponse;
470
452
  }
471
453
 
472
454
  interface NestedViewProps {
@@ -478,26 +460,65 @@ interface NestedViewProps {
478
460
  * @param props
479
461
  * @constructor
480
462
  */
481
- declare const NestedView: (props: NestedViewProps) => string | number | bigint | boolean | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<ReactNode> | Promise<string | number | bigint | boolean | react.ReactPortal | react.ReactElement<unknown, string | react.JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | null;
463
+ declare const NestedView: (props: NestedViewProps) => react_jsx_runtime.JSX.Element;
482
464
 
483
465
  interface LinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
484
466
  to: string | PageDescriptor;
485
- children?: react__default.ReactNode;
467
+ children?: React__default.ReactNode;
486
468
  }
487
469
  declare const Link: (props: LinkProps) => react_jsx_runtime.JSX.Element | null;
488
470
 
471
+ /**
472
+ * Props for the ErrorBoundary component.
473
+ */
474
+ interface ErrorBoundaryProps {
475
+ /**
476
+ * Fallback React node to render when an error is caught.
477
+ * If not provided, a default error message will be shown.
478
+ */
479
+ fallback: (error: Error) => ReactNode;
480
+ /**
481
+ * Optional callback that receives the error and error info.
482
+ * Use this to log errors to a monitoring service.
483
+ */
484
+ onError?: (error: Error, info: ErrorInfo) => void;
485
+ }
486
+ /**
487
+ * State of the ErrorBoundary component.
488
+ */
489
+ interface ErrorBoundaryState {
490
+ error?: Error;
491
+ }
492
+ /**
493
+ * A reusable error boundary for catching rendering errors
494
+ * in any part of the React component tree.
495
+ */
496
+ declare class ErrorBoundary extends React__default.Component<PropsWithChildren<ErrorBoundaryProps>, ErrorBoundaryState> {
497
+ constructor(props: ErrorBoundaryProps);
498
+ /**
499
+ * Update state so the next render shows the fallback UI.
500
+ */
501
+ static getDerivedStateFromError(error: Error): ErrorBoundaryState;
502
+ /**
503
+ * Lifecycle method called when an error is caught.
504
+ * You can log the error or perform side effects here.
505
+ */
506
+ componentDidCatch(error: Error, info: ErrorInfo): void;
507
+ render(): ReactNode;
508
+ }
509
+
489
510
  interface RouterContextValue {
490
511
  alepha: Alepha;
491
512
  state: RouterState;
492
513
  context: PageReactContext;
493
514
  }
494
- declare const RouterContext: react.Context<RouterContextValue | undefined>;
515
+ declare const RouterContext: React.Context<RouterContextValue | undefined>;
495
516
 
496
517
  interface RouterLayerContextValue {
497
518
  index: number;
498
519
  path: string;
499
520
  }
500
- declare const RouterLayerContext: react.Context<RouterLayerContextValue | undefined>;
521
+ declare const RouterLayerContext: React.Context<RouterLayerContextValue | undefined>;
501
522
 
502
523
  declare const useInject: <T extends object>(clazz: Class<T>) => T;
503
524
 
@@ -574,6 +595,9 @@ declare class ReactServerProvider {
574
595
  protected getPublicDirectory(): string;
575
596
  protected configureStaticServer(root: string): Promise<void>;
576
597
  protected configureVite(): Promise<void>;
598
+ /**
599
+ * For testing purposes, creates a render function that can be used.
600
+ */
577
601
  protected createRenderFunction(name: string): (options?: {
578
602
  params?: Record<string, string>;
579
603
  query?: Record<string, string>;
@@ -587,6 +611,7 @@ declare class ReactServerProvider {
587
611
  declare module "@alepha/core" {
588
612
  interface Hooks {
589
613
  "react:browser:render": {
614
+ state: RouterState;
590
615
  context: PageReactContext;
591
616
  hydration?: ReactHydrationState;
592
617
  };
@@ -596,6 +621,7 @@ declare module "@alepha/core" {
596
621
  };
597
622
  "react:transition:begin": {
598
623
  state: RouterState;
624
+ context: PageReactContext;
599
625
  };
600
626
  "react:transition:success": {
601
627
  state: RouterState;
@@ -603,9 +629,11 @@ declare module "@alepha/core" {
603
629
  "react:transition:error": {
604
630
  error: Error;
605
631
  state: RouterState;
632
+ context: PageReactContext;
606
633
  };
607
634
  "react:transition:end": {
608
635
  state: RouterState;
636
+ context: PageReactContext;
609
637
  };
610
638
  }
611
639
  }
@@ -614,4 +642,4 @@ declare class ReactModule {
614
642
  constructor();
615
643
  }
616
644
 
617
- export { $page, type AnchorProps, type CreateLayersResult, type Head, type HrefLike, type Layer, Link, NestedView, type PageConfigSchema, type PageDescriptor, type PageDescriptorOptions, PageDescriptorProvider, type PageReactContext, type PageRequest, type PageRequestConfig, type PageResolve, type PageResolveContext, type PageRoute, type PageRouteEntry, type PreviousLayerData, ReactBrowserProvider, type ReactHydrationState, ReactModule, ReactServerProvider, RedirectionError, RouterContext, type RouterContextValue, type RouterGoOptions, RouterHookApi, RouterLayerContext, type RouterLayerContextValue, type RouterRenderResult, type RouterStackItem, type RouterState, type TPropsDefault, type TPropsParentDefault, type TransitionOptions, type UseActiveHook, type UseQueryParamsHookOptions, envSchema, isPageRoute, useActive, useApi, useClient, useInject, useQueryParams, useRouter, useRouterEvents, useRouterState };
645
+ export { $page, type AnchorProps, type CreateLayersResult, ErrorBoundary, type Head, type HrefLike, type Layer, Link, NestedView, type PageConfigSchema, type PageDescriptor, type PageDescriptorOptions, PageDescriptorProvider, type PageReactContext, type PageRequest, type PageRequestConfig, type PageResolve, type PageRoute, type PageRouteEntry, type PreviousLayerData, ReactBrowserProvider, type ReactHydrationState, ReactModule, ReactServerProvider, RedirectionError, RouterContext, type RouterContextValue, type RouterGoOptions, RouterHookApi, RouterLayerContext, type RouterLayerContextValue, type RouterRenderResult, type RouterStackItem, type RouterState, type TPropsDefault, type TPropsParentDefault, type TransitionOptions, type UseActiveHook, type UseQueryParamsHookOptions, type VirtualRouter, envSchema, isPageRoute, useActive, useApi, useClient, useInject, useQueryParams, useRouter, useRouterEvents, useRouterState };