@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.
- package/dist/index.browser.cjs +2 -1
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +2 -2
- package/dist/index.cjs +35 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +80 -52
- package/dist/index.js +35 -18
- package/dist/index.js.map +1 -1
- package/dist/{useActive-ClUsghB5.js → useActive-BX41CqY8.js} +96 -98
- package/dist/useActive-BX41CqY8.js.map +1 -0
- package/dist/{useActive-4QlZKGbw.cjs → useActive-DjpZBEuB.cjs} +96 -97
- package/dist/useActive-DjpZBEuB.cjs.map +1 -0
- package/package.json +7 -7
- package/src/components/ErrorBoundary.tsx +72 -0
- package/src/components/Link.tsx +2 -2
- package/src/components/NestedView.tsx +10 -1
- package/src/descriptors/$page.ts +4 -8
- package/src/hooks/RouterHookApi.ts +18 -32
- package/src/hooks/useInject.ts +1 -7
- package/src/hooks/useQueryParams.ts +3 -6
- package/src/index.shared.ts +1 -0
- package/src/index.ts +4 -0
- package/src/providers/BrowserRouterProvider.ts +26 -32
- package/src/providers/PageDescriptorProvider.ts +21 -22
- package/src/providers/ReactBrowserProvider.ts +17 -20
- package/src/providers/ReactServerProvider.ts +37 -16
- package/dist/useActive-4QlZKGbw.cjs.map +0 -1
- package/dist/useActive-ClUsghB5.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t, $logger, $inject, Alepha, $hook, OPTIONS, __bind } from '@alepha/core';
|
|
2
2
|
import { ServerRouterProvider, ServerLinksProvider, ServerModule } from '@alepha/server';
|
|
3
|
-
import { P as PageDescriptorProvider, $ as $page } from './useActive-
|
|
4
|
-
export { L as Link, N as NestedView, l as ReactBrowserProvider, j as RedirectionError, R as RouterContext, b as RouterHookApi, a as RouterLayerContext, k as isPageRoute, 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-
|
|
3
|
+
import { P as PageDescriptorProvider, $ as $page } from './useActive-BX41CqY8.js';
|
|
4
|
+
export { E as ErrorBoundary, L as Link, N as NestedView, l as ReactBrowserProvider, j as RedirectionError, R as RouterContext, b as RouterHookApi, a as RouterLayerContext, k as isPageRoute, 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';
|
|
5
5
|
import { existsSync } from 'node:fs';
|
|
6
6
|
import { readFile } from 'node:fs/promises';
|
|
7
7
|
import { join } from 'node:path';
|
|
@@ -160,16 +160,24 @@ class ReactServerProvider {
|
|
|
160
160
|
() => fetch(templateUrl).then((it) => it.text()).catch(() => void 0)
|
|
161
161
|
);
|
|
162
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* For testing purposes, creates a render function that can be used.
|
|
165
|
+
*/
|
|
163
166
|
createRenderFunction(name) {
|
|
164
167
|
return async (options = {}) => {
|
|
165
168
|
const page = this.pageDescriptorProvider.page(name);
|
|
166
|
-
const
|
|
169
|
+
const context = {
|
|
167
170
|
url: new URL("http://localhost"),
|
|
168
171
|
params: options.params ?? {},
|
|
169
172
|
query: options.query ?? {},
|
|
170
|
-
head: {}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
+
head: {},
|
|
174
|
+
onError: () => null
|
|
175
|
+
};
|
|
176
|
+
const state = await this.pageDescriptorProvider.createLayers(
|
|
177
|
+
page,
|
|
178
|
+
context
|
|
179
|
+
);
|
|
180
|
+
return renderToString(this.pageDescriptorProvider.root(state, context));
|
|
173
181
|
};
|
|
174
182
|
}
|
|
175
183
|
createHandler(page, templateLoader) {
|
|
@@ -179,22 +187,27 @@ class ReactServerProvider {
|
|
|
179
187
|
if (!template) {
|
|
180
188
|
throw new Error("Template not found");
|
|
181
189
|
}
|
|
182
|
-
const
|
|
190
|
+
const context = {
|
|
183
191
|
url,
|
|
184
192
|
params,
|
|
185
193
|
query,
|
|
186
|
-
|
|
194
|
+
// plugins
|
|
195
|
+
head: {},
|
|
196
|
+
onError: () => null
|
|
187
197
|
};
|
|
188
198
|
if (this.alepha.has(ServerLinksProvider)) {
|
|
189
199
|
const srv = this.alepha.get(ServerLinksProvider);
|
|
190
|
-
|
|
191
|
-
|
|
200
|
+
context.links = await srv.getLinks({
|
|
201
|
+
user: serverRequest.user,
|
|
202
|
+
authorization: serverRequest.headers.authorization
|
|
203
|
+
});
|
|
204
|
+
this.alepha.als.set("links", context.links);
|
|
192
205
|
}
|
|
193
206
|
await this.alepha.emit(
|
|
194
207
|
"react:server:render",
|
|
195
208
|
{
|
|
196
209
|
request: serverRequest,
|
|
197
|
-
pageRequest:
|
|
210
|
+
pageRequest: context
|
|
198
211
|
},
|
|
199
212
|
{
|
|
200
213
|
log: false
|
|
@@ -202,15 +215,15 @@ class ReactServerProvider {
|
|
|
202
215
|
);
|
|
203
216
|
const state = await this.pageDescriptorProvider.createLayers(
|
|
204
217
|
page,
|
|
205
|
-
|
|
218
|
+
context
|
|
206
219
|
);
|
|
207
220
|
if (state.redirect) {
|
|
208
221
|
return reply.redirect(state.redirect);
|
|
209
222
|
}
|
|
210
|
-
const element = this.pageDescriptorProvider.root(state,
|
|
223
|
+
const element = this.pageDescriptorProvider.root(state, context);
|
|
211
224
|
const app = renderToString(element);
|
|
212
|
-
const
|
|
213
|
-
links:
|
|
225
|
+
const hydrationData = {
|
|
226
|
+
links: context.links,
|
|
214
227
|
layers: state.layers.map((it) => ({
|
|
215
228
|
...it,
|
|
216
229
|
error: it.error ? {
|
|
@@ -224,7 +237,8 @@ class ReactServerProvider {
|
|
|
224
237
|
path: void 0,
|
|
225
238
|
element: void 0
|
|
226
239
|
}))
|
|
227
|
-
}
|
|
240
|
+
};
|
|
241
|
+
const script = `<script>window.__ssr=${JSON.stringify(hydrationData)}<\/script>`;
|
|
228
242
|
const response = {
|
|
229
243
|
html: template
|
|
230
244
|
};
|
|
@@ -234,8 +248,11 @@ class ReactServerProvider {
|
|
|
234
248
|
reply.headers.pragma = "no-cache";
|
|
235
249
|
reply.headers.expires = "0";
|
|
236
250
|
this.fillTemplate(response, app, script);
|
|
237
|
-
if (
|
|
238
|
-
response.html = this.headProvider.renderHead(
|
|
251
|
+
if (context.head) {
|
|
252
|
+
response.html = this.headProvider.renderHead(
|
|
253
|
+
response.html,
|
|
254
|
+
context.head
|
|
255
|
+
);
|
|
239
256
|
}
|
|
240
257
|
return response.html;
|
|
241
258
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","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, \"&\")\n\t\t\t.replace(/</g, \"<\")\n\t\t\t.replace(/>/g, \">\")\n\t\t\t.replace(/\"/g, \""\")\n\t\t\t.replace(/'/g, \"'\");\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":[],"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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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,GAAG,OAAO,CAAC,MAAM,CAAC;AAC1B,EAAE,WAAW,GAAG;AAChB,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC;AACnH;AACA;AACA,MAAM,CAAC,KAAK,EAAE,WAAW,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","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, \"&\")\n\t\t\t.replace(/</g, \"<\")\n\t\t\t.replace(/>/g, \">\")\n\t\t\t.replace(/\"/g, \""\")\n\t\t\t.replace(/'/g, \"'\");\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":[],"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;AAC5B,IAAI,IAAI,KAAK,EAAE;AACf,MAAM,IAAI,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;AACxC,QAAQ,MAAM,GAAG,MAAM,CAAC,OAAO;AAC/B,UAAU,wBAAwB;AAClC,UAAU,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,KAA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I,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;;ACvNO,MAAM,WAAW,CAAC;AACzB,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;AAC1B,EAAE,WAAW,GAAG;AAChB,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC;AACnH;AACA;AACA,MAAM,CAAC,KAAK,EAAE,WAAW,CAAC;;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import React, { createContext, useContext, useEffect, useState, createElement, useMemo } from 'react';
|
|
3
2
|
import { __descriptor, OPTIONS, NotImplementedError, KIND, $logger, $inject, Alepha, $hook, t } from '@alepha/core';
|
|
3
|
+
import React, { createContext, useContext, useEffect, useState, createElement, useMemo } from 'react';
|
|
4
4
|
import { HttpClient } from '@alepha/server';
|
|
5
5
|
import { hydrateRoot, createRoot } from 'react-dom/client';
|
|
6
6
|
import { RouterProvider } from '@alepha/router';
|
|
@@ -91,6 +91,36 @@ const useRouterEvents = (opts = {}, deps = []) => {
|
|
|
91
91
|
}, deps);
|
|
92
92
|
};
|
|
93
93
|
|
|
94
|
+
class ErrorBoundary extends React.Component {
|
|
95
|
+
constructor(props) {
|
|
96
|
+
super(props);
|
|
97
|
+
this.state = {};
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Update state so the next render shows the fallback UI.
|
|
101
|
+
*/
|
|
102
|
+
static getDerivedStateFromError(error) {
|
|
103
|
+
return {
|
|
104
|
+
error
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Lifecycle method called when an error is caught.
|
|
109
|
+
* You can log the error or perform side effects here.
|
|
110
|
+
*/
|
|
111
|
+
componentDidCatch(error, info) {
|
|
112
|
+
if (this.props.onError) {
|
|
113
|
+
this.props.onError(error, info);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
render() {
|
|
117
|
+
if (this.state.error) {
|
|
118
|
+
return this.props.fallback(this.state.error);
|
|
119
|
+
}
|
|
120
|
+
return this.props.children;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
94
124
|
const NestedView = (props) => {
|
|
95
125
|
const app = useContext(RouterContext);
|
|
96
126
|
const layer = useContext(RouterLayerContext);
|
|
@@ -106,7 +136,11 @@ const NestedView = (props) => {
|
|
|
106
136
|
},
|
|
107
137
|
[app]
|
|
108
138
|
);
|
|
109
|
-
|
|
139
|
+
if (!app) {
|
|
140
|
+
throw new Error("NestedView must be used within a RouterContext.");
|
|
141
|
+
}
|
|
142
|
+
const element = view ?? props.children ?? null;
|
|
143
|
+
return /* @__PURE__ */ jsx(ErrorBoundary, { fallback: app.context.onError, children: element });
|
|
110
144
|
};
|
|
111
145
|
|
|
112
146
|
class RedirectionError extends Error {
|
|
@@ -131,7 +165,7 @@ class PageDescriptorProvider {
|
|
|
131
165
|
}
|
|
132
166
|
throw new Error(`Page ${name} not found`);
|
|
133
167
|
}
|
|
134
|
-
root(state, context
|
|
168
|
+
root(state, context) {
|
|
135
169
|
return createElement(
|
|
136
170
|
RouterContext.Provider,
|
|
137
171
|
{
|
|
@@ -149,6 +183,7 @@ class PageDescriptorProvider {
|
|
|
149
183
|
const layers = [];
|
|
150
184
|
let context = {};
|
|
151
185
|
const stack = [{ route }];
|
|
186
|
+
let onError = this.renderError;
|
|
152
187
|
let parent = route.parent;
|
|
153
188
|
while (parent) {
|
|
154
189
|
stack.unshift({ route: parent });
|
|
@@ -220,7 +255,6 @@ class PageDescriptorProvider {
|
|
|
220
255
|
return {
|
|
221
256
|
layers: [],
|
|
222
257
|
redirect: typeof e.page === "string" ? e.page : this.href(e.page),
|
|
223
|
-
head: request.head,
|
|
224
258
|
pathname,
|
|
225
259
|
search
|
|
226
260
|
};
|
|
@@ -247,13 +281,12 @@ class PageDescriptorProvider {
|
|
|
247
281
|
acc += "/";
|
|
248
282
|
acc += it.route.path ? this.compile(it.route.path, params) : "";
|
|
249
283
|
const path = acc.replace(/\/+/, "/");
|
|
284
|
+
const localErrorHandler = this.getErrorHandler(it.route);
|
|
285
|
+
if (localErrorHandler) {
|
|
286
|
+
onError = localErrorHandler;
|
|
287
|
+
}
|
|
250
288
|
if (it.error) {
|
|
251
|
-
const
|
|
252
|
-
const element = await (errorHandler ? errorHandler({
|
|
253
|
-
...it.config,
|
|
254
|
-
error: it.error,
|
|
255
|
-
url: ""
|
|
256
|
-
}) : this.renderError(it.error));
|
|
289
|
+
const element = await onError(it.error);
|
|
257
290
|
layers.push({
|
|
258
291
|
props,
|
|
259
292
|
error: it.error,
|
|
@@ -280,7 +313,7 @@ class PageDescriptorProvider {
|
|
|
280
313
|
path
|
|
281
314
|
});
|
|
282
315
|
}
|
|
283
|
-
return { layers,
|
|
316
|
+
return { layers, pathname, search };
|
|
284
317
|
}
|
|
285
318
|
getErrorHandler(route) {
|
|
286
319
|
if (route.errorHandler) return route.errorHandler;
|
|
@@ -497,10 +530,17 @@ class BrowserRouterProvider extends RouterProvider {
|
|
|
497
530
|
const state = {
|
|
498
531
|
pathname,
|
|
499
532
|
search,
|
|
500
|
-
layers: []
|
|
501
|
-
|
|
533
|
+
layers: []
|
|
534
|
+
};
|
|
535
|
+
const context = {
|
|
536
|
+
url,
|
|
537
|
+
query: {},
|
|
538
|
+
params: {},
|
|
539
|
+
head: {},
|
|
540
|
+
onError: () => null,
|
|
541
|
+
...options.context ?? {}
|
|
502
542
|
};
|
|
503
|
-
await this.alepha.emit("react:transition:begin", { state });
|
|
543
|
+
await this.alepha.emit("react:transition:begin", { state, context });
|
|
504
544
|
try {
|
|
505
545
|
const previous = options.previous;
|
|
506
546
|
const { route, params } = this.match(pathname);
|
|
@@ -510,29 +550,22 @@ class BrowserRouterProvider extends RouterProvider {
|
|
|
510
550
|
query[key] = String(value);
|
|
511
551
|
}
|
|
512
552
|
}
|
|
553
|
+
context.query = query;
|
|
554
|
+
context.params = params ?? {};
|
|
555
|
+
context.previous = previous;
|
|
513
556
|
if (isPageRoute(route)) {
|
|
514
557
|
const result = await this.pageDescriptorProvider.createLayers(
|
|
515
558
|
route.page,
|
|
516
|
-
|
|
517
|
-
url,
|
|
518
|
-
params: params ?? {},
|
|
519
|
-
query,
|
|
520
|
-
previous,
|
|
521
|
-
...state,
|
|
522
|
-
head: state.head,
|
|
523
|
-
...options.context ?? {}
|
|
524
|
-
}
|
|
559
|
+
context
|
|
525
560
|
);
|
|
526
561
|
if (result.redirect) {
|
|
527
562
|
return {
|
|
528
|
-
element: null,
|
|
529
|
-
layers: [],
|
|
530
563
|
redirect: result.redirect,
|
|
531
|
-
|
|
564
|
+
state,
|
|
565
|
+
context
|
|
532
566
|
};
|
|
533
567
|
}
|
|
534
568
|
state.layers = result.layers;
|
|
535
|
-
state.head = result.head;
|
|
536
569
|
}
|
|
537
570
|
if (state.layers.length === 0) {
|
|
538
571
|
state.layers.push({
|
|
@@ -555,33 +588,25 @@ class BrowserRouterProvider extends RouterProvider {
|
|
|
555
588
|
];
|
|
556
589
|
await this.alepha.emit("react:transition:error", {
|
|
557
590
|
error: e,
|
|
558
|
-
state
|
|
591
|
+
state,
|
|
592
|
+
context
|
|
559
593
|
});
|
|
560
594
|
}
|
|
561
|
-
if (
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
return {
|
|
566
|
-
element: this.root(state, options.context),
|
|
567
|
-
layers: state.layers,
|
|
568
|
-
head: state.head
|
|
569
|
-
};
|
|
595
|
+
if (options.state) {
|
|
596
|
+
options.state.layers = state.layers;
|
|
597
|
+
options.state.pathname = state.pathname;
|
|
598
|
+
options.state.search = state.search;
|
|
570
599
|
}
|
|
571
|
-
options.state.layers = state.layers;
|
|
572
|
-
options.state.pathname = state.pathname;
|
|
573
|
-
options.state.search = state.search;
|
|
574
|
-
options.state.head = state.head;
|
|
575
600
|
await this.alepha.emit("react:transition:end", {
|
|
576
|
-
state: options.state
|
|
601
|
+
state: options.state,
|
|
602
|
+
context
|
|
577
603
|
});
|
|
578
604
|
return {
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
head: state.head
|
|
605
|
+
context,
|
|
606
|
+
state
|
|
582
607
|
};
|
|
583
608
|
}
|
|
584
|
-
root(state, context
|
|
609
|
+
root(state, context) {
|
|
585
610
|
return this.pageDescriptorProvider.root(state, context);
|
|
586
611
|
}
|
|
587
612
|
}
|
|
@@ -601,8 +626,7 @@ class ReactBrowserProvider {
|
|
|
601
626
|
state = {
|
|
602
627
|
layers: [],
|
|
603
628
|
pathname: "",
|
|
604
|
-
search: ""
|
|
605
|
-
head: {}
|
|
629
|
+
search: ""
|
|
606
630
|
};
|
|
607
631
|
get document() {
|
|
608
632
|
return window.document;
|
|
@@ -643,8 +667,8 @@ class ReactBrowserProvider {
|
|
|
643
667
|
const result = await this.render({
|
|
644
668
|
url
|
|
645
669
|
});
|
|
646
|
-
if (result.url !== url) {
|
|
647
|
-
this.history.replaceState({}, "", result.url);
|
|
670
|
+
if (result.context.url.pathname !== url) {
|
|
671
|
+
this.history.replaceState({}, "", result.context.url.pathname);
|
|
648
672
|
return;
|
|
649
673
|
}
|
|
650
674
|
if (options.replace) {
|
|
@@ -668,7 +692,7 @@ class ReactBrowserProvider {
|
|
|
668
692
|
return await this.render({ url: result.redirect });
|
|
669
693
|
}
|
|
670
694
|
this.transitioning = void 0;
|
|
671
|
-
return
|
|
695
|
+
return result;
|
|
672
696
|
}
|
|
673
697
|
/**
|
|
674
698
|
* Get embedded layers from the server.
|
|
@@ -709,14 +733,16 @@ class ReactBrowserProvider {
|
|
|
709
733
|
const hydration = this.getHydrationState();
|
|
710
734
|
const previous = hydration?.layers ?? [];
|
|
711
735
|
if (hydration?.links) {
|
|
712
|
-
|
|
736
|
+
for (const link of hydration.links) {
|
|
737
|
+
this.client.pushLink(link);
|
|
738
|
+
}
|
|
713
739
|
}
|
|
714
|
-
const {
|
|
715
|
-
if (head) {
|
|
716
|
-
this.headProvider.renderHead(this.document, head);
|
|
740
|
+
const { context } = await this.render({ previous });
|
|
741
|
+
if (context.head) {
|
|
742
|
+
this.headProvider.renderHead(this.document, context.head);
|
|
717
743
|
}
|
|
718
|
-
const context = {};
|
|
719
744
|
await this.alepha.emit("react:browser:render", {
|
|
745
|
+
state: this.state,
|
|
720
746
|
context,
|
|
721
747
|
hydration
|
|
722
748
|
});
|
|
@@ -732,17 +758,12 @@ class ReactBrowserProvider {
|
|
|
732
758
|
window.addEventListener("popstate", () => {
|
|
733
759
|
this.render();
|
|
734
760
|
});
|
|
735
|
-
this.alepha.on("react:transition:end", {
|
|
736
|
-
callback: ({ state }) => {
|
|
737
|
-
this.headProvider.renderHead(this.document, state.head);
|
|
738
|
-
}
|
|
739
|
-
});
|
|
740
761
|
}
|
|
741
762
|
});
|
|
742
763
|
onTransitionEnd = $hook({
|
|
743
764
|
name: "react:transition:end",
|
|
744
|
-
handler: async ({
|
|
745
|
-
this.headProvider.renderHead(this.document,
|
|
765
|
+
handler: async ({ context }) => {
|
|
766
|
+
this.headProvider.renderHead(this.document, context.head);
|
|
746
767
|
}
|
|
747
768
|
});
|
|
748
769
|
}
|
|
@@ -808,19 +829,10 @@ class RouterHookApi {
|
|
|
808
829
|
}
|
|
809
830
|
return pathname.startsWith("/") ? pathname : `${layer.path}/${pathname}`.replace(/\/\/+/g, "/");
|
|
810
831
|
}
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
* @param path
|
|
814
|
-
* @param options
|
|
815
|
-
*/
|
|
816
|
-
async go(path, options = {}) {
|
|
817
|
-
return await this.browser?.go(this.createHref(path, this.layer), options);
|
|
832
|
+
async go(path, options) {
|
|
833
|
+
await this.browser?.go(this.createHref(path, this.layer), options);
|
|
818
834
|
}
|
|
819
|
-
|
|
820
|
-
*
|
|
821
|
-
* @param path
|
|
822
|
-
*/
|
|
823
|
-
createAnchorProps(path) {
|
|
835
|
+
anchor(path) {
|
|
824
836
|
const href = this.createHref(path, this.layer);
|
|
825
837
|
return {
|
|
826
838
|
href,
|
|
@@ -838,14 +850,8 @@ class RouterHookApi {
|
|
|
838
850
|
* @param options
|
|
839
851
|
*/
|
|
840
852
|
setQueryParams(record, options = {}) {
|
|
841
|
-
const
|
|
842
|
-
|
|
843
|
-
...this.query,
|
|
844
|
-
...record
|
|
845
|
-
} : {
|
|
846
|
-
...record
|
|
847
|
-
}
|
|
848
|
-
).toString();
|
|
853
|
+
const func = typeof record === "function" ? record : () => record;
|
|
854
|
+
const search = new URLSearchParams(func(this.query)).toString();
|
|
849
855
|
const state = search ? `${this.pathname}?${search}` : this.pathname;
|
|
850
856
|
if (options.push) {
|
|
851
857
|
window.history.pushState({}, "", state);
|
|
@@ -883,7 +889,7 @@ const Link = (props) => {
|
|
|
883
889
|
}
|
|
884
890
|
const name = typeof props.to === "string" ? void 0 : props.to[OPTIONS].name;
|
|
885
891
|
const router = useRouter();
|
|
886
|
-
return /* @__PURE__ */ jsx("a", { ...router.
|
|
892
|
+
return /* @__PURE__ */ jsx("a", { ...router.anchor(to), ...props, children: props.children ?? name });
|
|
887
893
|
};
|
|
888
894
|
|
|
889
895
|
const useInject = (clazz) => {
|
|
@@ -891,12 +897,7 @@ const useInject = (clazz) => {
|
|
|
891
897
|
if (!ctx) {
|
|
892
898
|
throw new Error("useRouter must be used within a <RouterProvider>");
|
|
893
899
|
}
|
|
894
|
-
return useMemo(
|
|
895
|
-
() => ctx.alepha.get(clazz, {
|
|
896
|
-
skipRegistration: true
|
|
897
|
-
}),
|
|
898
|
-
[]
|
|
899
|
-
);
|
|
900
|
+
return useMemo(() => ctx.alepha.get(clazz), []);
|
|
900
901
|
};
|
|
901
902
|
|
|
902
903
|
const useClient = () => {
|
|
@@ -924,12 +925,9 @@ const useQueryParams = (schema, options = {}) => {
|
|
|
924
925
|
queryParams,
|
|
925
926
|
(queryParams2) => {
|
|
926
927
|
setQueryParams(queryParams2);
|
|
927
|
-
router.setQueryParams(
|
|
928
|
-
{ [key]: encode(ctx.alepha, schema, queryParams2) }
|
|
929
|
-
|
|
930
|
-
merge: true
|
|
931
|
-
}
|
|
932
|
-
);
|
|
928
|
+
router.setQueryParams((data) => {
|
|
929
|
+
return { ...data, [key]: encode(ctx.alepha, schema, queryParams2) };
|
|
930
|
+
});
|
|
933
931
|
}
|
|
934
932
|
];
|
|
935
933
|
};
|
|
@@ -995,5 +993,5 @@ const useActive = (path) => {
|
|
|
995
993
|
};
|
|
996
994
|
};
|
|
997
995
|
|
|
998
|
-
export { $page as $, BrowserRouterProvider as B, Link as L, NestedView as N, PageDescriptorProvider as P, RouterContext as R, RouterLayerContext as a, RouterHookApi as b, useClient as c, useApi as d, useQueryParams as e, useRouter as f, useRouterEvents as g, useRouterState as h, useActive as i, RedirectionError as j, isPageRoute as k, ReactBrowserProvider as l, useInject as u };
|
|
999
|
-
//# sourceMappingURL=useActive-
|
|
996
|
+
export { $page as $, BrowserRouterProvider as B, ErrorBoundary as E, Link as L, NestedView as N, PageDescriptorProvider as P, RouterContext as R, RouterLayerContext as a, RouterHookApi as b, useClient as c, useApi as d, useQueryParams as e, useRouter as f, useRouterEvents as g, useRouterState as h, useActive as i, RedirectionError as j, isPageRoute as k, ReactBrowserProvider as l, useInject as u };
|
|
997
|
+
//# sourceMappingURL=useActive-BX41CqY8.js.map
|