@webtypen/webframez-react 0.0.47 → 0.0.49

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.
@@ -38,6 +38,8 @@ function createHTMLShell(options = {}) {
38
38
  buildId = "",
39
39
  headTags = "",
40
40
  bodyClassName = "",
41
+ bodyStartHtml = "",
42
+ bodyEndHtml = "",
41
43
  rootHtml = "",
42
44
  initialFlightData = "",
43
45
  basename = "",
@@ -87,7 +89,9 @@ function createHTMLShell(options = {}) {
87
89
  ${headTags}
88
90
  </head>
89
91
  <body${bodyClassName ? ` class="${bodyClassName.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;")}"` : ""}>
92
+ ${bodyStartHtml}
90
93
  <div id="root">${rootHtml}</div>
94
+ ${bodyEndHtml}
91
95
  <script>window.__RSC_ENDPOINT = "${rscEndpoint}";</script>
92
96
  <script>window.__RSC_BASENAME = "${basename}";</script>
93
97
  <script>window.__RSC_ROUTE_BASE_PATH = "${routeBasePath}";</script>
@@ -202,6 +206,12 @@ function normalizeHeadConfig(head, inheritedBasename) {
202
206
  href: resolveHeadAssetUrl(link.href, effectiveBasename)
203
207
  }));
204
208
  }
209
+ if (normalizedHead.scripts) {
210
+ normalizedHead.scripts = normalizedHead.scripts.map((script) => ({
211
+ ...script,
212
+ ...script.src ? { src: resolveHeadAssetUrl(script.src, effectiveBasename) } : {}
213
+ }));
214
+ }
205
215
  return normalizedHead;
206
216
  }
207
217
 
@@ -454,7 +464,9 @@ function matchRoute(entry, pathname) {
454
464
  function mergeHead(...configs) {
455
465
  const merged = {
456
466
  meta: [],
457
- links: []
467
+ links: [],
468
+ scripts: [],
469
+ html: []
458
470
  };
459
471
  for (const candidate of configs) {
460
472
  const config = normalizeHeadConfig(candidate, merged.basename);
@@ -489,9 +501,28 @@ function mergeHead(...configs) {
489
501
  if (config.links) {
490
502
  merged.links?.push(...config.links);
491
503
  }
504
+ if (config.scripts) {
505
+ merged.scripts?.push(...config.scripts);
506
+ }
507
+ if (config.html) {
508
+ merged.html?.push(...Array.isArray(config.html) ? config.html : [config.html]);
509
+ }
510
+ if (config.bodyStartHtml) {
511
+ merged.bodyStartHtml = [merged.bodyStartHtml, config.bodyStartHtml].filter(Boolean).join("\n");
512
+ }
513
+ if (config.bodyEndHtml) {
514
+ merged.bodyEndHtml = [merged.bodyEndHtml, config.bodyEndHtml].filter(Boolean).join("\n");
515
+ }
492
516
  }
493
517
  return merged;
494
518
  }
519
+ function renderGenericAttributes(entry, excluded = []) {
520
+ return Object.entries(entry).filter(
521
+ ([key, value]) => !excluded.includes(key) && value !== void 0 && value !== null && value !== false
522
+ ).map(
523
+ ([key, value]) => value === true ? key : `${key}="${escapeHtml(String(value))}"`
524
+ ).join(" ");
525
+ }
495
526
  function renderHeadToString(head) {
496
527
  const normalizedHead = normalizeHeadConfig(head) ?? head;
497
528
  const tags = [];
@@ -513,6 +544,23 @@ function renderHeadToString(head) {
513
544
  const attrs = Object.entries(link).filter(([, value]) => Boolean(value)).map(([key, value]) => `${key}="${escapeHtml(String(value))}"`).join(" ");
514
545
  tags.push(`<link ${createManagedAttributes()} ${attrs} />`);
515
546
  }
547
+ for (const script of normalizedHead.scripts ?? []) {
548
+ if (script.html) {
549
+ tags.push(script.html);
550
+ continue;
551
+ }
552
+ const attrs = renderGenericAttributes(script, [
553
+ "content",
554
+ "html"
555
+ ]);
556
+ const content = script.content ? String(script.content) : "";
557
+ tags.push(`<script ${createManagedAttributes()} ${attrs}>${content}</script>`);
558
+ }
559
+ for (const html of normalizedHead.html ?? []) {
560
+ if (typeof html === "string" && html.trim() !== "") {
561
+ tags.push(html);
562
+ }
563
+ }
516
564
  return tags.join("\n");
517
565
  }
518
566
  function clearModuleCache(modulePath, rootDir, visited = /* @__PURE__ */ new Set()) {
@@ -598,6 +646,7 @@ function isRouteAbort(value) {
598
646
  function createFileRouter(options) {
599
647
  installForcedPackageResolution();
600
648
  const pagesDir = options.pagesDir;
649
+ const onData = options.onData;
601
650
  const layoutPath = path2.join(pagesDir, "layout.js");
602
651
  const errorPath = path2.join(pagesDir, "errors.js");
603
652
  const middlewaresPath = path2.join(pagesDir, "middlewares.js");
@@ -762,10 +811,16 @@ function createFileRouter(options) {
762
811
  data: mergeRouteData(middlewareContext.data, pageData)
763
812
  };
764
813
  activeContext = pageContext;
765
- const pageNode = await pageModule.default(pageContext);
766
- const layoutHead = layoutModule ? await resolveHead(layoutModule, pageContext) : void 0;
767
- const pageHead = await resolveHead(pageModule, pageContext);
768
- const layoutNode = layoutModule ? await layoutModule.default(pageContext) : null;
814
+ const onDataResult = typeof onData === "function" ? await onData(pageContext) : void 0;
815
+ const eventContext = {
816
+ ...pageContext,
817
+ data: mergeRouteData(pageContext.data, onDataResult)
818
+ };
819
+ activeContext = eventContext;
820
+ const pageNode = await pageModule.default(eventContext);
821
+ const layoutHead = layoutModule ? await resolveHead(layoutModule, eventContext) : void 0;
822
+ const pageHead = await resolveHead(pageModule, eventContext);
823
+ const layoutNode = layoutModule ? await layoutModule.default(eventContext) : null;
769
824
  const model = layoutNode ? injectRouteChildren(layoutNode, pageNode) : pageNode;
770
825
  const contextModel = layoutNode ? injectRouteChildren(layoutNode, /* @__PURE__ */ jsx(RouteChildren, {})) : void 0;
771
826
  return {
@@ -774,7 +829,7 @@ function createFileRouter(options) {
774
829
  contextModel,
775
830
  pageModel: pageNode,
776
831
  head: mergeHead(layoutHead, pageHead),
777
- context: pageContext
832
+ context: eventContext
778
833
  };
779
834
  } catch (error) {
780
835
  if (isRouteAbort(error)) {
@@ -1597,7 +1652,7 @@ function createNodeRequestHandler(options) {
1597
1652
  const liveReloadEnabled = options.liveReloadPath !== false && (nodeEnv === "development" || runningInWatchMode);
1598
1653
  const liveReloadPath = !liveReloadEnabled ? "" : options.liveReloadPath ?? `${basePath || ""}/__webframez_live_reload`;
1599
1654
  const liveReloadClients = /* @__PURE__ */ new Set();
1600
- const router = createFileRouter({ pagesDir });
1655
+ const router = createFileRouter({ pagesDir, onData: options.onData });
1601
1656
  const getManifestState = createManifestLoader({
1602
1657
  distRootDir,
1603
1658
  manifestPath,
@@ -1821,6 +1876,8 @@ function createNodeRequestHandler(options) {
1821
1876
  initialFlightData,
1822
1877
  basename: shellBasename,
1823
1878
  routeBasePath: shellRouteBasePath,
1879
+ bodyStartHtml: resolved.head.bodyStartHtml || "",
1880
+ bodyEndHtml: resolved.head.bodyEndHtml || "",
1824
1881
  liveReloadPath: liveReloadPath || void 0,
1825
1882
  liveReloadServerId: liveReloadPath ? devServerId : void 0
1826
1883
  }),
@@ -2064,7 +2121,8 @@ function resolveWebframezReactRouteOptions(routePathValue, options = {}) {
2064
2121
  clientEntryPath: options.clientEntryPath ? resolveFromProjectRoot(options.clientEntryPath) : void 0,
2065
2122
  styleSrcPath: options.styleSrcPath ? resolveFromProjectRoot(options.styleSrcPath) : defaults.styleSrcPath,
2066
2123
  basePath: options.basePath ?? defaults.basePath,
2067
- liveReloadPath: options.liveReloadPath
2124
+ liveReloadPath: options.liveReloadPath,
2125
+ onData: options.onData
2068
2126
  };
2069
2127
  }
2070
2128
  function getRegisteredReactBuildTargets() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webtypen/webframez-react",
3
- "version": "0.0.47",
3
+ "version": "0.0.49",
4
4
  "description": "TypeScript React RSC addition for @webtypen/webframez-core",
5
5
  "homepage": "https://webtypen.de/",
6
6
  "author": {