@webtypen/webframez-react 0.0.48 → 0.0.50
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/README.md +61 -0
- package/defaults/webpack.client.cjs +6 -2
- package/dist/client.cjs +1 -1
- package/dist/client.js +1 -1
- package/dist/http.cjs +134 -46
- package/dist/http.d.ts +5 -0
- package/dist/http.js +131 -45
- package/dist/index.cjs +207 -53
- package/dist/index.d.ts +2 -0
- package/dist/index.js +227 -53
- package/dist/navigation.cjs +80 -15
- package/dist/navigation.d.ts +1 -1
- package/dist/navigation.js +92 -15
- package/dist/paths.cjs +102 -0
- package/dist/paths.d.ts +4 -0
- package/dist/paths.js +92 -0
- package/dist/router.cjs +58 -8
- package/dist/router.d.ts +8 -2
- package/dist/router.js +58 -8
- package/dist/types.d.ts +24 -0
- package/dist/webframez-core.cjs +186 -53
- package/dist/webframez-core.d.ts +2 -8
- package/dist/webframez-core.js +206 -53
- package/package.json +18 -4
package/dist/index.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
1
7
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
8
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
9
|
}) : x)(function(x) {
|
|
@@ -5,6 +11,79 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
5
11
|
return require.apply(this, arguments);
|
|
6
12
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
7
13
|
});
|
|
14
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
15
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
16
|
+
};
|
|
17
|
+
var __copyProps = (to, from, except, desc) => {
|
|
18
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
19
|
+
for (let key of __getOwnPropNames(from))
|
|
20
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
21
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
26
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
27
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
28
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
29
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
30
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
31
|
+
mod
|
|
32
|
+
));
|
|
33
|
+
|
|
34
|
+
// node_modules/@webtypen/webframez-core/dist/routing.js
|
|
35
|
+
var require_routing = __commonJS({
|
|
36
|
+
"node_modules/@webtypen/webframez-core/dist/routing.js"(exports) {
|
|
37
|
+
"use strict";
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.appRelativePath = exports.appPath = exports.getBasename = exports.normalizeBasename = void 0;
|
|
40
|
+
function normalizeBasename2(value) {
|
|
41
|
+
if (value == null || value === "" || value === "/")
|
|
42
|
+
return "";
|
|
43
|
+
if (typeof value !== "string")
|
|
44
|
+
throw new Error("Router basename must be a string.");
|
|
45
|
+
const base = value.trim().replace(/\/+$/, "");
|
|
46
|
+
if (!base && value.trim().length <= 1)
|
|
47
|
+
return "";
|
|
48
|
+
if (!/^\/(?:[A-Za-z0-9_~-]+(?:\.[A-Za-z0-9_~-]+)*)(?:\/[A-Za-z0-9_~-]+(?:\.[A-Za-z0-9_~-]+)*)*$/.test(base)) {
|
|
49
|
+
throw new Error("Router basename must be empty or an absolute path such as /my-app.");
|
|
50
|
+
}
|
|
51
|
+
return base;
|
|
52
|
+
}
|
|
53
|
+
exports.normalizeBasename = normalizeBasename2;
|
|
54
|
+
function getBasename2() {
|
|
55
|
+
var _a, _b, _c, _d;
|
|
56
|
+
const runtime = globalThis;
|
|
57
|
+
return (_d = (_c = (_b = (_a = runtime.__WEBFRAMEZ_ROUTING_CONTEXT__) === null || _a === void 0 ? void 0 : _a.getStore()) !== null && _b !== void 0 ? _b : runtime.__RSC_BASENAME) !== null && _c !== void 0 ? _c : runtime.__WEBFRAMEZ_ROUTER_BASENAME__) !== null && _d !== void 0 ? _d : "";
|
|
58
|
+
}
|
|
59
|
+
exports.getBasename = getBasename2;
|
|
60
|
+
function appPath2(value, basename = getBasename2()) {
|
|
61
|
+
const base = normalizeBasename2(basename);
|
|
62
|
+
if (!base || !value.startsWith("/") || value.startsWith("//") || hasBasename(value, base))
|
|
63
|
+
return value;
|
|
64
|
+
return base + value;
|
|
65
|
+
}
|
|
66
|
+
exports.appPath = appPath2;
|
|
67
|
+
function appRelativePath2(value, basename = getBasename2()) {
|
|
68
|
+
const base = normalizeBasename2(basename);
|
|
69
|
+
if (!base || !hasBasename(value, base))
|
|
70
|
+
return value;
|
|
71
|
+
const relative = value.slice(base.length);
|
|
72
|
+
return !relative || relative.startsWith("?") || relative.startsWith("#") ? "/" + relative : relative;
|
|
73
|
+
}
|
|
74
|
+
exports.appRelativePath = appRelativePath2;
|
|
75
|
+
function hasBasename(value, base) {
|
|
76
|
+
return value === base || value.startsWith(base + "/") || value.startsWith(base + "?") || value.startsWith(base + "#");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// node_modules/@webtypen/webframez-core/routing.js
|
|
82
|
+
var require_routing2 = __commonJS({
|
|
83
|
+
"node_modules/@webtypen/webframez-core/routing.js"(exports, module) {
|
|
84
|
+
module.exports = require_routing();
|
|
85
|
+
}
|
|
86
|
+
});
|
|
8
87
|
|
|
9
88
|
// src/server.ts
|
|
10
89
|
import path from "node:path";
|
|
@@ -23,6 +102,8 @@ function createHTMLShell(options = {}) {
|
|
|
23
102
|
buildId = "",
|
|
24
103
|
headTags = "",
|
|
25
104
|
bodyClassName = "",
|
|
105
|
+
bodyStartHtml = "",
|
|
106
|
+
bodyEndHtml = "",
|
|
26
107
|
rootHtml = "",
|
|
27
108
|
initialFlightData = "",
|
|
28
109
|
basename = "",
|
|
@@ -72,7 +153,9 @@ function createHTMLShell(options = {}) {
|
|
|
72
153
|
${headTags}
|
|
73
154
|
</head>
|
|
74
155
|
<body${bodyClassName ? ` class="${bodyClassName.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">")}"` : ""}>
|
|
156
|
+
${bodyStartHtml}
|
|
75
157
|
<div id="root">${rootHtml}</div>
|
|
158
|
+
${bodyEndHtml}
|
|
76
159
|
<script>window.__RSC_ENDPOINT = "${rscEndpoint}";</script>
|
|
77
160
|
<script>window.__RSC_BASENAME = "${basename}";</script>
|
|
78
161
|
<script>window.__RSC_ROUTE_BASE_PATH = "${routeBasePath}";</script>
|
|
@@ -215,6 +298,12 @@ function normalizeHeadConfig(head, inheritedBasename) {
|
|
|
215
298
|
href: resolveHeadAssetUrl(link.href, effectiveBasename)
|
|
216
299
|
}));
|
|
217
300
|
}
|
|
301
|
+
if (normalizedHead.scripts) {
|
|
302
|
+
normalizedHead.scripts = normalizedHead.scripts.map((script) => ({
|
|
303
|
+
...script,
|
|
304
|
+
...script.src ? { src: resolveHeadAssetUrl(script.src, effectiveBasename) } : {}
|
|
305
|
+
}));
|
|
306
|
+
}
|
|
218
307
|
return normalizedHead;
|
|
219
308
|
}
|
|
220
309
|
|
|
@@ -327,8 +416,7 @@ var FORCED_PACKAGE_REQUESTS = [
|
|
|
327
416
|
"react-server-dom-webpack",
|
|
328
417
|
"react-server-dom-webpack/server",
|
|
329
418
|
"react-server-dom-webpack/client",
|
|
330
|
-
"react-server-dom-webpack/client.node"
|
|
331
|
-
"scheduler"
|
|
419
|
+
"react-server-dom-webpack/client.node"
|
|
332
420
|
];
|
|
333
421
|
var forcedPackageResolutionInstalled = false;
|
|
334
422
|
function normalizePathname(pathname) {
|
|
@@ -467,7 +555,9 @@ function matchRoute(entry, pathname) {
|
|
|
467
555
|
function mergeHead(...configs) {
|
|
468
556
|
const merged = {
|
|
469
557
|
meta: [],
|
|
470
|
-
links: []
|
|
558
|
+
links: [],
|
|
559
|
+
scripts: [],
|
|
560
|
+
html: []
|
|
471
561
|
};
|
|
472
562
|
for (const candidate of configs) {
|
|
473
563
|
const config = normalizeHeadConfig(candidate, merged.basename);
|
|
@@ -502,9 +592,28 @@ function mergeHead(...configs) {
|
|
|
502
592
|
if (config.links) {
|
|
503
593
|
merged.links?.push(...config.links);
|
|
504
594
|
}
|
|
595
|
+
if (config.scripts) {
|
|
596
|
+
merged.scripts?.push(...config.scripts);
|
|
597
|
+
}
|
|
598
|
+
if (config.html) {
|
|
599
|
+
merged.html?.push(...Array.isArray(config.html) ? config.html : [config.html]);
|
|
600
|
+
}
|
|
601
|
+
if (config.bodyStartHtml) {
|
|
602
|
+
merged.bodyStartHtml = [merged.bodyStartHtml, config.bodyStartHtml].filter(Boolean).join("\n");
|
|
603
|
+
}
|
|
604
|
+
if (config.bodyEndHtml) {
|
|
605
|
+
merged.bodyEndHtml = [merged.bodyEndHtml, config.bodyEndHtml].filter(Boolean).join("\n");
|
|
606
|
+
}
|
|
505
607
|
}
|
|
506
608
|
return merged;
|
|
507
609
|
}
|
|
610
|
+
function renderGenericAttributes(entry, excluded = []) {
|
|
611
|
+
return Object.entries(entry).filter(
|
|
612
|
+
([key, value]) => !excluded.includes(key) && value !== void 0 && value !== null && value !== false
|
|
613
|
+
).map(
|
|
614
|
+
([key, value]) => value === true ? key : `${key}="${escapeHtml(String(value))}"`
|
|
615
|
+
).join(" ");
|
|
616
|
+
}
|
|
508
617
|
function renderHeadToString(head) {
|
|
509
618
|
const normalizedHead = normalizeHeadConfig(head) ?? head;
|
|
510
619
|
const tags = [];
|
|
@@ -526,6 +635,23 @@ function renderHeadToString(head) {
|
|
|
526
635
|
const attrs = Object.entries(link).filter(([, value]) => Boolean(value)).map(([key, value]) => `${key}="${escapeHtml(String(value))}"`).join(" ");
|
|
527
636
|
tags.push(`<link ${createManagedAttributes()} ${attrs} />`);
|
|
528
637
|
}
|
|
638
|
+
for (const script of normalizedHead.scripts ?? []) {
|
|
639
|
+
if (script.html) {
|
|
640
|
+
tags.push(script.html);
|
|
641
|
+
continue;
|
|
642
|
+
}
|
|
643
|
+
const attrs = renderGenericAttributes(script, [
|
|
644
|
+
"content",
|
|
645
|
+
"html"
|
|
646
|
+
]);
|
|
647
|
+
const content = script.content ? String(script.content) : "";
|
|
648
|
+
tags.push(`<script ${createManagedAttributes()} ${attrs}>${content}</script>`);
|
|
649
|
+
}
|
|
650
|
+
for (const html of normalizedHead.html ?? []) {
|
|
651
|
+
if (typeof html === "string" && html.trim() !== "") {
|
|
652
|
+
tags.push(html);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
529
655
|
return tags.join("\n");
|
|
530
656
|
}
|
|
531
657
|
function clearModuleCache(modulePath, rootDir, visited = /* @__PURE__ */ new Set()) {
|
|
@@ -611,6 +737,7 @@ function isRouteAbort(value) {
|
|
|
611
737
|
function createFileRouter(options) {
|
|
612
738
|
installForcedPackageResolution();
|
|
613
739
|
const pagesDir = options.pagesDir;
|
|
740
|
+
const onData = options.onData;
|
|
614
741
|
const layoutPath = path2.join(pagesDir, "layout.js");
|
|
615
742
|
const errorPath = path2.join(pagesDir, "errors.js");
|
|
616
743
|
const middlewaresPath = path2.join(pagesDir, "middlewares.js");
|
|
@@ -775,10 +902,16 @@ function createFileRouter(options) {
|
|
|
775
902
|
data: mergeRouteData(middlewareContext.data, pageData)
|
|
776
903
|
};
|
|
777
904
|
activeContext = pageContext;
|
|
778
|
-
const
|
|
779
|
-
const
|
|
780
|
-
|
|
781
|
-
|
|
905
|
+
const onDataResult = typeof onData === "function" ? await onData(pageContext) : void 0;
|
|
906
|
+
const eventContext = {
|
|
907
|
+
...pageContext,
|
|
908
|
+
data: mergeRouteData(pageContext.data, onDataResult)
|
|
909
|
+
};
|
|
910
|
+
activeContext = eventContext;
|
|
911
|
+
const pageNode = await pageModule.default(eventContext);
|
|
912
|
+
const layoutHead = layoutModule ? await resolveHead(layoutModule, eventContext) : void 0;
|
|
913
|
+
const pageHead = await resolveHead(pageModule, eventContext);
|
|
914
|
+
const layoutNode = layoutModule ? await layoutModule.default(eventContext) : null;
|
|
782
915
|
const model = layoutNode ? injectRouteChildren(layoutNode, pageNode) : pageNode;
|
|
783
916
|
const contextModel = layoutNode ? injectRouteChildren(layoutNode, /* @__PURE__ */ jsx(RouteChildren, {})) : void 0;
|
|
784
917
|
return {
|
|
@@ -787,7 +920,7 @@ function createFileRouter(options) {
|
|
|
787
920
|
contextModel,
|
|
788
921
|
pageModel: pageNode,
|
|
789
922
|
head: mergeHead(layoutHead, pageHead),
|
|
790
|
-
context:
|
|
923
|
+
context: eventContext
|
|
791
924
|
};
|
|
792
925
|
} catch (error) {
|
|
793
926
|
if (isRouteAbort(error)) {
|
|
@@ -807,6 +940,7 @@ function parseSearchParams(query) {
|
|
|
807
940
|
}
|
|
808
941
|
|
|
809
942
|
// src/http.ts
|
|
943
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
810
944
|
import fs2 from "node:fs";
|
|
811
945
|
import path3 from "node:path";
|
|
812
946
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
@@ -944,6 +1078,7 @@ const rootParent = {
|
|
|
944
1078
|
path: process.cwd(),
|
|
945
1079
|
paths: Module._nodeModulePaths(process.cwd()),
|
|
946
1080
|
};
|
|
1081
|
+
// Transitive dependencies (e.g. scheduler) must resolve from their importer.
|
|
947
1082
|
const forcedPackageRequests = [
|
|
948
1083
|
"@webtypen/webframez-core",
|
|
949
1084
|
"@webtypen/webframez-react",
|
|
@@ -958,7 +1093,6 @@ const forcedPackageRequests = [
|
|
|
958
1093
|
"react-server-dom-webpack/server",
|
|
959
1094
|
"react-server-dom-webpack/client",
|
|
960
1095
|
"react-server-dom-webpack/client.node",
|
|
961
|
-
"scheduler"
|
|
962
1096
|
];
|
|
963
1097
|
|
|
964
1098
|
function shouldForcePackageResolution(request) {
|
|
@@ -1150,13 +1284,17 @@ async function renderHtmlFromFlightData(flightData, moduleMap) {
|
|
|
1150
1284
|
? payload.head.basename
|
|
1151
1285
|
: "";
|
|
1152
1286
|
|
|
1153
|
-
const
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1287
|
+
const routingContext = globalThis.__WEBFRAMEZ_ROUTING_CONTEXT__ ??=
|
|
1288
|
+
new (require("node:async_hooks").AsyncLocalStorage)();
|
|
1289
|
+
return routingContext.run(basename, async () => {
|
|
1290
|
+
const previousBasename = globalThis.__RSC_BASENAME;
|
|
1291
|
+
globalThis.__RSC_BASENAME = basename;
|
|
1292
|
+
try {
|
|
1293
|
+
return await renderHtml(model);
|
|
1294
|
+
} finally {
|
|
1295
|
+
globalThis.__RSC_BASENAME = previousBasename;
|
|
1296
|
+
}
|
|
1297
|
+
});
|
|
1160
1298
|
}
|
|
1161
1299
|
|
|
1162
1300
|
process.on("message", async (message) => {
|
|
@@ -1392,24 +1530,10 @@ ${stderrBuffer.trim()}` : "";
|
|
|
1392
1530
|
}
|
|
1393
1531
|
};
|
|
1394
1532
|
}
|
|
1533
|
+
var routingRuntime = globalThis;
|
|
1534
|
+
var basenameContext = routingRuntime.__WEBFRAMEZ_ROUTING_CONTEXT__ ??= new AsyncLocalStorage();
|
|
1395
1535
|
function withRequestBasename(basename, fn) {
|
|
1396
|
-
|
|
1397
|
-
const previous = target.__RSC_BASENAME;
|
|
1398
|
-
target.__RSC_BASENAME = basename;
|
|
1399
|
-
const finish = () => {
|
|
1400
|
-
target.__RSC_BASENAME = previous;
|
|
1401
|
-
};
|
|
1402
|
-
try {
|
|
1403
|
-
const result = fn();
|
|
1404
|
-
if (result && typeof result.then === "function") {
|
|
1405
|
-
return result.finally(finish);
|
|
1406
|
-
}
|
|
1407
|
-
finish();
|
|
1408
|
-
return result;
|
|
1409
|
-
} catch (error) {
|
|
1410
|
-
finish();
|
|
1411
|
-
throw error;
|
|
1412
|
-
}
|
|
1536
|
+
return basenameContext.run(basename, fn);
|
|
1413
1537
|
}
|
|
1414
1538
|
function parseCookies(rawCookieHeader) {
|
|
1415
1539
|
const raw = Array.isArray(rawCookieHeader) ? rawCookieHeader.join("; ") : rawCookieHeader ?? "";
|
|
@@ -1444,12 +1568,27 @@ function normalizeClientManifest(manifest, options) {
|
|
|
1444
1568
|
}
|
|
1445
1569
|
};
|
|
1446
1570
|
for (const [key, value] of Object.entries(manifest)) {
|
|
1571
|
+
const hashIndex = key.indexOf("#");
|
|
1572
|
+
const moduleKey = hashIndex < 0 ? key : key.slice(0, hashIndex);
|
|
1573
|
+
const exportSuffix = hashIndex < 0 ? "" : key.slice(hashIndex);
|
|
1574
|
+
if (!path3.isAbsolute(moduleKey) && !moduleKey.includes(":") && !moduleKey.startsWith("file://")) {
|
|
1575
|
+
const runtimePath = path3.resolve(options.cwd, moduleKey);
|
|
1576
|
+
const allowedRoots = [options.distRootDir, ...candidateNodeModulesDirs];
|
|
1577
|
+
const insideArtifact = allowedRoots.some((root) => {
|
|
1578
|
+
const relative = path3.relative(path3.resolve(root), runtimePath);
|
|
1579
|
+
return relative !== "" && relative !== ".." && !relative.startsWith(`..${path3.sep}`) && !path3.isAbsolute(relative);
|
|
1580
|
+
});
|
|
1581
|
+
if (insideArtifact) {
|
|
1582
|
+
addAlias(`${runtimePath}${exportSuffix}`, value);
|
|
1583
|
+
addAlias(`${pathToFileURL(runtimePath).href}${exportSuffix}`, value);
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1447
1586
|
if (!key.startsWith("file://")) {
|
|
1448
1587
|
continue;
|
|
1449
1588
|
}
|
|
1450
1589
|
let absolutePath = "";
|
|
1451
1590
|
try {
|
|
1452
|
-
absolutePath = fileURLToPath(
|
|
1591
|
+
absolutePath = fileURLToPath(moduleKey);
|
|
1453
1592
|
} catch {
|
|
1454
1593
|
continue;
|
|
1455
1594
|
}
|
|
@@ -1460,13 +1599,13 @@ function normalizeClientManifest(manifest, options) {
|
|
|
1460
1599
|
}
|
|
1461
1600
|
const relativeModulePath = absolutePath.slice(markerIndex + marker.length);
|
|
1462
1601
|
const relativeModulePathPosix = relativeModulePath.split(path3.sep).join("/");
|
|
1463
|
-
addAlias(`./node_modules/${relativeModulePathPosix}`, value);
|
|
1464
|
-
addAlias(`node_modules/${relativeModulePathPosix}`, value);
|
|
1465
|
-
addAlias(absolutePath
|
|
1602
|
+
addAlias(`./node_modules/${relativeModulePathPosix}${exportSuffix}`, value);
|
|
1603
|
+
addAlias(`node_modules/${relativeModulePathPosix}${exportSuffix}`, value);
|
|
1604
|
+
addAlias(`${absolutePath}${exportSuffix}`, value);
|
|
1466
1605
|
for (const nodeModulesDir of candidateNodeModulesDirs) {
|
|
1467
1606
|
const aliasPath = path3.join(nodeModulesDir, relativeModulePath);
|
|
1468
|
-
addAlias(aliasPath
|
|
1469
|
-
addAlias(pathToFileURL(aliasPath).href
|
|
1607
|
+
addAlias(`${aliasPath}${exportSuffix}`, value);
|
|
1608
|
+
addAlias(`${pathToFileURL(aliasPath).href}${exportSuffix}`, value);
|
|
1470
1609
|
}
|
|
1471
1610
|
}
|
|
1472
1611
|
return normalized;
|
|
@@ -1611,16 +1750,16 @@ function createNodeRequestHandler(options) {
|
|
|
1611
1750
|
const manifestPath = path3.resolve(
|
|
1612
1751
|
options.manifestPath ?? path3.join(distRootDir, "react-client-manifest.json")
|
|
1613
1752
|
);
|
|
1614
|
-
const assetsPrefix = options.assetsPrefix ?? "/assets/";
|
|
1615
|
-
const rscPath = options.rscPath ?? "/rsc";
|
|
1616
|
-
const clientScriptUrl = options.clientScriptUrl ?? "/assets/client.js";
|
|
1617
1753
|
const basePath = normalizeBasePath(options.basePath);
|
|
1754
|
+
const assetsPrefix = options.assetsPrefix ?? `${basePath}/assets/`;
|
|
1755
|
+
const rscPath = options.rscPath ?? `${basePath}/rsc`;
|
|
1756
|
+
const clientScriptUrl = options.clientScriptUrl ?? `${basePath}/assets/client.js`;
|
|
1618
1757
|
const nodeEnv = process.env.NODE_ENV || "";
|
|
1619
1758
|
const runningInWatchMode = Array.isArray(process.execArgv) && process.execArgv.includes("--watch");
|
|
1620
1759
|
const liveReloadEnabled = options.liveReloadPath !== false && (nodeEnv === "development" || runningInWatchMode);
|
|
1621
1760
|
const liveReloadPath = !liveReloadEnabled ? "" : options.liveReloadPath ?? `${basePath || ""}/__webframez_live_reload`;
|
|
1622
1761
|
const liveReloadClients = /* @__PURE__ */ new Set();
|
|
1623
|
-
const router = createFileRouter({ pagesDir });
|
|
1762
|
+
const router = createFileRouter({ pagesDir, onData: options.onData });
|
|
1624
1763
|
const getManifestState = createManifestLoader({
|
|
1625
1764
|
distRootDir,
|
|
1626
1765
|
manifestPath,
|
|
@@ -1633,7 +1772,7 @@ function createNodeRequestHandler(options) {
|
|
|
1633
1772
|
process.once("exit", disposeInitialHtmlWorker);
|
|
1634
1773
|
process.once("SIGINT", disposeInitialHtmlWorker);
|
|
1635
1774
|
process.once("SIGTERM", disposeInitialHtmlWorker);
|
|
1636
|
-
|
|
1775
|
+
const handleRequest = async (req, res) => {
|
|
1637
1776
|
if (!req.url) {
|
|
1638
1777
|
res.statusCode = 400;
|
|
1639
1778
|
res.end("Bad request");
|
|
@@ -1697,6 +1836,7 @@ function createNodeRequestHandler(options) {
|
|
|
1697
1836
|
request: requestContext
|
|
1698
1837
|
})
|
|
1699
1838
|
);
|
|
1839
|
+
resolved2.head = { ...resolved2.head, basename: resolved2.head.basename ?? basePath };
|
|
1700
1840
|
attachResolvedContextToCoreRequest(req, resolved2.context);
|
|
1701
1841
|
const payload = {
|
|
1702
1842
|
model: resolved2.model,
|
|
@@ -1772,6 +1912,7 @@ function createNodeRequestHandler(options) {
|
|
|
1772
1912
|
)
|
|
1773
1913
|
})
|
|
1774
1914
|
);
|
|
1915
|
+
resolved.head = { ...resolved.head, basename: resolved.head.basename ?? basePath };
|
|
1775
1916
|
attachResolvedContextToCoreRequest(req, resolved.context);
|
|
1776
1917
|
const initialPayload = {
|
|
1777
1918
|
model: resolved.model,
|
|
@@ -1844,6 +1985,8 @@ function createNodeRequestHandler(options) {
|
|
|
1844
1985
|
initialFlightData,
|
|
1845
1986
|
basename: shellBasename,
|
|
1846
1987
|
routeBasePath: shellRouteBasePath,
|
|
1988
|
+
bodyStartHtml: resolved.head.bodyStartHtml || "",
|
|
1989
|
+
bodyEndHtml: resolved.head.bodyEndHtml || "",
|
|
1847
1990
|
liveReloadPath: liveReloadPath || void 0,
|
|
1848
1991
|
liveReloadServerId: liveReloadPath ? devServerId : void 0
|
|
1849
1992
|
}),
|
|
@@ -1855,8 +1998,31 @@ function createNodeRequestHandler(options) {
|
|
|
1855
1998
|
}
|
|
1856
1999
|
);
|
|
1857
2000
|
};
|
|
2001
|
+
return (req, res) => withRequestBasename(basePath, () => handleRequest(req, res));
|
|
2002
|
+
}
|
|
2003
|
+
var standaloneHtmlWorker;
|
|
2004
|
+
async function renderReactToHtml(element) {
|
|
2005
|
+
if (!standaloneHtmlWorker) {
|
|
2006
|
+
standaloneHtmlWorker = createInitialHtmlWorker(process.cwd());
|
|
2007
|
+
process.once("exit", disposeReactHtmlRenderer);
|
|
2008
|
+
}
|
|
2009
|
+
const flightData = await renderRSCToString({ model: element }, {
|
|
2010
|
+
moduleMap: {},
|
|
2011
|
+
onError: (error) => {
|
|
2012
|
+
console.error("[webframez-react] HTML render failed", error);
|
|
2013
|
+
}
|
|
2014
|
+
});
|
|
2015
|
+
return standaloneHtmlWorker.renderFromFlightData({ flightData, moduleMap: {} });
|
|
2016
|
+
}
|
|
2017
|
+
function disposeReactHtmlRenderer() {
|
|
2018
|
+
process.removeListener("exit", disposeReactHtmlRenderer);
|
|
2019
|
+
standaloneHtmlWorker?.dispose();
|
|
2020
|
+
standaloneHtmlWorker = void 0;
|
|
1858
2021
|
}
|
|
1859
2022
|
|
|
2023
|
+
// src/paths.ts
|
|
2024
|
+
var import_routing = __toESM(require_routing2(), 1);
|
|
2025
|
+
|
|
1860
2026
|
// src/webframez-core.ts
|
|
1861
2027
|
import path4 from "node:path";
|
|
1862
2028
|
function normalizeMountPath(path5) {
|
|
@@ -1944,6 +2110,17 @@ function buildRenderDefaults(routePathValue) {
|
|
|
1944
2110
|
clientScriptUrl: `${mountPath}/assets/client.js`
|
|
1945
2111
|
};
|
|
1946
2112
|
}
|
|
2113
|
+
function runtimeRoutePaths(routePath, options, basename = (0, import_routing.getBasename)(), groupPrefix = "") {
|
|
2114
|
+
const localMount = normalizeMountPath(options.basePath ?? `${groupPrefix}${normalizeMountPath(routePath)}`);
|
|
2115
|
+
const basePath = normalizeMountPath((0, import_routing.appPath)(localMount, basename)).replace(/\/$/, "");
|
|
2116
|
+
return {
|
|
2117
|
+
basePath,
|
|
2118
|
+
assetsPrefix: options.assetsPrefix !== void 0 ? (0, import_routing.appPath)(options.assetsPrefix, basename) : `${basePath}/assets/`,
|
|
2119
|
+
rscPath: options.rscPath !== void 0 ? (0, import_routing.appPath)(options.rscPath, basename) : `${basePath}/rsc`,
|
|
2120
|
+
clientScriptUrl: options.clientScriptUrl !== void 0 ? (0, import_routing.appPath)(options.clientScriptUrl, basename) : `${basePath}/assets/client.js`,
|
|
2121
|
+
...typeof options.liveReloadPath === "string" ? { liveReloadPath: (0, import_routing.appPath)(options.liveReloadPath, basename) } : {}
|
|
2122
|
+
};
|
|
2123
|
+
}
|
|
1947
2124
|
async function waitForResponseFinish(res) {
|
|
1948
2125
|
if (res.writableEnded || res.destroyed) {
|
|
1949
2126
|
return;
|
|
@@ -2037,10 +2214,7 @@ function registerRouteRenderer(route, methodName) {
|
|
|
2037
2214
|
distRootDir: resolvedTarget.distRootDir,
|
|
2038
2215
|
pagesDir: resolvedTarget.pagesDir,
|
|
2039
2216
|
manifestPath: resolvedTarget.manifestPath,
|
|
2040
|
-
|
|
2041
|
-
assetsPrefix: assetsPrefix ?? defaults.assetsPrefix,
|
|
2042
|
-
rscPath: rscPath ?? defaults.rscPath,
|
|
2043
|
-
clientScriptUrl: clientScriptUrl ?? defaults.clientScriptUrl
|
|
2217
|
+
...runtimeRoutePaths(routePathValue, options, route.basename ?? (0, import_routing.getBasename)(), route.tempGroupPrefix ?? "")
|
|
2044
2218
|
});
|
|
2045
2219
|
const methods = normalizeMethods(method);
|
|
2046
2220
|
for (const currentMethod of methods) {
|
|
@@ -2082,13 +2256,11 @@ function resolveWebframezReactRouteOptions(routePathValue, options = {}) {
|
|
|
2082
2256
|
distRootDir,
|
|
2083
2257
|
pagesDir,
|
|
2084
2258
|
manifestPath,
|
|
2085
|
-
|
|
2086
|
-
rscPath: options.rscPath ?? defaults.rscPath,
|
|
2087
|
-
clientScriptUrl: options.clientScriptUrl ?? defaults.clientScriptUrl,
|
|
2259
|
+
...runtimeRoutePaths(routePathValue, options),
|
|
2088
2260
|
clientEntryPath: options.clientEntryPath ? resolveFromProjectRoot(options.clientEntryPath) : void 0,
|
|
2089
2261
|
styleSrcPath: options.styleSrcPath ? resolveFromProjectRoot(options.styleSrcPath) : defaults.styleSrcPath,
|
|
2090
|
-
|
|
2091
|
-
|
|
2262
|
+
liveReloadPath: typeof options.liveReloadPath === "string" ? (0, import_routing.appPath)(options.liveReloadPath) : options.liveReloadPath,
|
|
2263
|
+
onData: options.onData
|
|
2092
2264
|
};
|
|
2093
2265
|
}
|
|
2094
2266
|
function getRegisteredReactBuildTargets() {
|
|
@@ -2119,10 +2291,12 @@ export {
|
|
|
2119
2291
|
createHTMLShell,
|
|
2120
2292
|
createNodeRequestHandler,
|
|
2121
2293
|
createRSCHandler,
|
|
2294
|
+
disposeReactHtmlRenderer,
|
|
2122
2295
|
getRegisteredReactBuildTargets,
|
|
2123
2296
|
initWebframezReact,
|
|
2124
2297
|
parseSearchParams,
|
|
2125
2298
|
renderHeadToString,
|
|
2299
|
+
renderReactToHtml,
|
|
2126
2300
|
resolveWebframezReactRouteOptions,
|
|
2127
2301
|
sendRSC,
|
|
2128
2302
|
setupWebframezCoreReactRoute
|
package/dist/navigation.cjs
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
6
11
|
var __export = (target, all) => {
|
|
7
12
|
for (var name in all)
|
|
8
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -15,8 +20,70 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
20
|
}
|
|
16
21
|
return to;
|
|
17
22
|
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
18
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
32
|
|
|
33
|
+
// node_modules/@webtypen/webframez-core/dist/routing.js
|
|
34
|
+
var require_routing = __commonJS({
|
|
35
|
+
"node_modules/@webtypen/webframez-core/dist/routing.js"(exports2) {
|
|
36
|
+
"use strict";
|
|
37
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
38
|
+
exports2.appRelativePath = exports2.appPath = exports2.getBasename = exports2.normalizeBasename = void 0;
|
|
39
|
+
function normalizeBasename2(value) {
|
|
40
|
+
if (value == null || value === "" || value === "/")
|
|
41
|
+
return "";
|
|
42
|
+
if (typeof value !== "string")
|
|
43
|
+
throw new Error("Router basename must be a string.");
|
|
44
|
+
const base = value.trim().replace(/\/+$/, "");
|
|
45
|
+
if (!base && value.trim().length <= 1)
|
|
46
|
+
return "";
|
|
47
|
+
if (!/^\/(?:[A-Za-z0-9_~-]+(?:\.[A-Za-z0-9_~-]+)*)(?:\/[A-Za-z0-9_~-]+(?:\.[A-Za-z0-9_~-]+)*)*$/.test(base)) {
|
|
48
|
+
throw new Error("Router basename must be empty or an absolute path such as /my-app.");
|
|
49
|
+
}
|
|
50
|
+
return base;
|
|
51
|
+
}
|
|
52
|
+
exports2.normalizeBasename = normalizeBasename2;
|
|
53
|
+
function getBasename2() {
|
|
54
|
+
var _a, _b, _c, _d;
|
|
55
|
+
const runtime = globalThis;
|
|
56
|
+
return (_d = (_c = (_b = (_a = runtime.__WEBFRAMEZ_ROUTING_CONTEXT__) === null || _a === void 0 ? void 0 : _a.getStore()) !== null && _b !== void 0 ? _b : runtime.__RSC_BASENAME) !== null && _c !== void 0 ? _c : runtime.__WEBFRAMEZ_ROUTER_BASENAME__) !== null && _d !== void 0 ? _d : "";
|
|
57
|
+
}
|
|
58
|
+
exports2.getBasename = getBasename2;
|
|
59
|
+
function appPath2(value, basename = getBasename2()) {
|
|
60
|
+
const base = normalizeBasename2(basename);
|
|
61
|
+
if (!base || !value.startsWith("/") || value.startsWith("//") || hasBasename(value, base))
|
|
62
|
+
return value;
|
|
63
|
+
return base + value;
|
|
64
|
+
}
|
|
65
|
+
exports2.appPath = appPath2;
|
|
66
|
+
function appRelativePath2(value, basename = getBasename2()) {
|
|
67
|
+
const base = normalizeBasename2(basename);
|
|
68
|
+
if (!base || !hasBasename(value, base))
|
|
69
|
+
return value;
|
|
70
|
+
const relative = value.slice(base.length);
|
|
71
|
+
return !relative || relative.startsWith("?") || relative.startsWith("#") ? "/" + relative : relative;
|
|
72
|
+
}
|
|
73
|
+
exports2.appRelativePath = appRelativePath2;
|
|
74
|
+
function hasBasename(value, base) {
|
|
75
|
+
return value === base || value.startsWith(base + "/") || value.startsWith(base + "?") || value.startsWith(base + "#");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// node_modules/@webtypen/webframez-core/routing.js
|
|
81
|
+
var require_routing2 = __commonJS({
|
|
82
|
+
"node_modules/@webtypen/webframez-core/routing.js"(exports2, module2) {
|
|
83
|
+
module2.exports = require_routing();
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
20
87
|
// src/navigation.tsx
|
|
21
88
|
var navigation_exports = {};
|
|
22
89
|
__export(navigation_exports, {
|
|
@@ -24,18 +91,13 @@ __export(navigation_exports, {
|
|
|
24
91
|
Redirect: () => Redirect
|
|
25
92
|
});
|
|
26
93
|
module.exports = __toCommonJS(navigation_exports);
|
|
94
|
+
var import_react = __toESM(require("react"), 1);
|
|
95
|
+
|
|
96
|
+
// src/paths.ts
|
|
97
|
+
var import_routing = __toESM(require_routing2(), 1);
|
|
98
|
+
|
|
99
|
+
// src/navigation.tsx
|
|
27
100
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
28
|
-
function getDefaultBasename() {
|
|
29
|
-
const globalValue = globalThis.__RSC_BASENAME;
|
|
30
|
-
if (globalValue && globalValue !== "/") {
|
|
31
|
-
return globalValue;
|
|
32
|
-
}
|
|
33
|
-
if (typeof window === "undefined") {
|
|
34
|
-
return "";
|
|
35
|
-
}
|
|
36
|
-
const value = window.__RSC_BASENAME;
|
|
37
|
-
return value && value !== "/" ? value : "";
|
|
38
|
-
}
|
|
39
101
|
function getClientRouter() {
|
|
40
102
|
if (typeof window === "undefined") {
|
|
41
103
|
return null;
|
|
@@ -97,13 +159,14 @@ function resolveHref(to, basename) {
|
|
|
97
159
|
const hash = hashPart ? `#${hashPart}` : "";
|
|
98
160
|
return `${resolvedPath}${query}${hash}`;
|
|
99
161
|
}
|
|
100
|
-
|
|
101
|
-
const resolvedHref = resolveHref(to, basename ??
|
|
162
|
+
var Link = import_react.default.forwardRef(function Link2({ to, basename, onClick, ...rest }, ref) {
|
|
163
|
+
const resolvedHref = resolveHref(to, basename ?? (0, import_routing.getBasename)());
|
|
102
164
|
const isServerRender = typeof window === "undefined";
|
|
103
165
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
104
166
|
"a",
|
|
105
167
|
{
|
|
106
168
|
...rest,
|
|
169
|
+
ref,
|
|
107
170
|
href: resolvedHref,
|
|
108
171
|
onClick: isServerRender ? void 0 : (event) => {
|
|
109
172
|
onClick?.(event);
|
|
@@ -113,6 +176,8 @@ function Link({ to, basename, onClick, ...rest }) {
|
|
|
113
176
|
if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) {
|
|
114
177
|
return;
|
|
115
178
|
}
|
|
179
|
+
if (rest.download != null && rest.download !== false)
|
|
180
|
+
return;
|
|
116
181
|
if (rest.target && rest.target !== "_self") {
|
|
117
182
|
return;
|
|
118
183
|
}
|
|
@@ -124,9 +189,9 @@ function Link({ to, basename, onClick, ...rest }) {
|
|
|
124
189
|
}
|
|
125
190
|
}
|
|
126
191
|
);
|
|
127
|
-
}
|
|
192
|
+
});
|
|
128
193
|
function Redirect({ to, basename, replace = true }) {
|
|
129
|
-
const resolvedHref = resolveHref(to, basename ??
|
|
194
|
+
const resolvedHref = resolveHref(to, basename ?? (0, import_routing.getBasename)());
|
|
130
195
|
if (typeof window !== "undefined") {
|
|
131
196
|
const currentHref = `${window.location.pathname}${window.location.search}${window.location.hash}`;
|
|
132
197
|
if (resolvedHref !== currentHref) {
|
package/dist/navigation.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export type LinkProps = Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, "hre
|
|
|
5
5
|
basename?: string;
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
-
export
|
|
8
|
+
export const Link: React.ForwardRefExoticComponent<LinkProps & React.RefAttributes<HTMLAnchorElement>>;
|
|
9
9
|
|
|
10
10
|
export type RedirectProps = {
|
|
11
11
|
to: string;
|