@server/next 0.28.1 → 0.28.3
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/package.json +1 -1
- package/src/jsx/jsx-runtime.js +44 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@server/next",
|
|
3
|
-
"version": "0.28.
|
|
3
|
+
"version": "0.28.3",
|
|
4
4
|
"description": "A fully-fledged web server with routing, file uploads, sessions, static files, schema validation, websockets, testing, etc.",
|
|
5
5
|
"homepage": "https://server-js.com/",
|
|
6
6
|
"repository": "https://github.com/franciscop/server-next.git",
|
package/src/jsx/jsx-runtime.js
CHANGED
|
@@ -3,6 +3,7 @@ const entities = {
|
|
|
3
3
|
"<": "<",
|
|
4
4
|
">": ">",
|
|
5
5
|
'"': """,
|
|
6
|
+
"'": "'",
|
|
6
7
|
};
|
|
7
8
|
|
|
8
9
|
const encode = (str = "") => {
|
|
@@ -40,34 +41,54 @@ const minifyCss = (str) =>
|
|
|
40
41
|
.replace(/(\{) (\w)/g, "$1$2")
|
|
41
42
|
.trim();
|
|
42
43
|
|
|
44
|
+
const REACT_ELEMENT_TYPE = Symbol.for("react.element");
|
|
45
|
+
|
|
43
46
|
const isReactElement = (val) =>
|
|
44
|
-
val !== null &&
|
|
47
|
+
val !== null &&
|
|
48
|
+
typeof val === "object" &&
|
|
49
|
+
(val.$$typeof === REACT_ELEMENT_TYPE || // real React
|
|
50
|
+
("type" in val && "props" in val)); // your test objects
|
|
51
|
+
|
|
52
|
+
const resolve = (val) => {
|
|
53
|
+
while (typeof val === "function") val = val();
|
|
54
|
+
if (isReactElement(val)) {
|
|
55
|
+
val = jsx(val.type, val.props || {});
|
|
56
|
+
}
|
|
57
|
+
return val ?? "";
|
|
58
|
+
};
|
|
45
59
|
|
|
46
60
|
const renderChild = (child) => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
|
|
61
|
+
while (typeof child === "function") child = child();
|
|
62
|
+
|
|
63
|
+
if (Array.isArray(child)) {
|
|
64
|
+
return child.map(renderChild).join("");
|
|
65
|
+
}
|
|
66
|
+
|
|
52
67
|
if (isReactElement(child)) {
|
|
53
|
-
|
|
54
|
-
return typeof result === "function" ? result() : result ?? "";
|
|
68
|
+
return resolve(jsx(child.type, child.props || {}));
|
|
55
69
|
}
|
|
70
|
+
|
|
71
|
+
if (typeof child === "string") return encode(child);
|
|
72
|
+
if (typeof child === "number") return String(child);
|
|
73
|
+
|
|
74
|
+
if (!isValidChild(child)) return "";
|
|
75
|
+
|
|
76
|
+
console.warn("Unknown child:", child);
|
|
56
77
|
return "";
|
|
57
78
|
};
|
|
58
79
|
|
|
59
80
|
const jsx = (tag, { children, ...props }) => {
|
|
60
81
|
if (typeof tag === "function") {
|
|
61
|
-
|
|
62
|
-
if (isReactElement(result)) return jsx(result.type, result.props || {});
|
|
63
|
-
return result ?? (() => "");
|
|
82
|
+
return () => renderChild(tag({ children, ...props }));
|
|
64
83
|
}
|
|
65
84
|
|
|
66
85
|
// Handle React forwardRef objects: { render: fn }
|
|
67
|
-
if (
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
86
|
+
if (
|
|
87
|
+
typeof tag === "object" &&
|
|
88
|
+
tag !== null &&
|
|
89
|
+
typeof tag.render === "function"
|
|
90
|
+
) {
|
|
91
|
+
return () => renderChild(tag.render({ children, ...props }, null));
|
|
71
92
|
}
|
|
72
93
|
|
|
73
94
|
if (tag === "script" && children) {
|
|
@@ -88,6 +109,7 @@ const jsx = (tag, { children, ...props }) => {
|
|
|
88
109
|
|
|
89
110
|
children = (Array.isArray(children) ? children.flat() : [children])
|
|
90
111
|
.map(renderChild)
|
|
112
|
+
.map((c) => (typeof c === "string" ? c : ""))
|
|
91
113
|
.join("");
|
|
92
114
|
|
|
93
115
|
if (!tag) return () => children;
|
|
@@ -96,11 +118,13 @@ const jsx = (tag, { children, ...props }) => {
|
|
|
96
118
|
.filter(([k]) => k !== "dangerouslySetInnerHTML")
|
|
97
119
|
.filter(([k, v]) => !/on[A-Z]/.test(k) && typeof v !== "function")
|
|
98
120
|
.filter(([, v]) => v !== false)
|
|
99
|
-
.map(([k, v]) =>
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
121
|
+
.map(([k, v]) => {
|
|
122
|
+
const key = altAttrs[k.toLowerCase()] || encode(k);
|
|
123
|
+
if (v === true) return key;
|
|
124
|
+
const value =
|
|
125
|
+
typeof v === "string" || typeof v === "number" ? encode(v) : "";
|
|
126
|
+
return `${key}="${value}"`;
|
|
127
|
+
})
|
|
104
128
|
.join(" ");
|
|
105
129
|
|
|
106
130
|
if (attrStr) attrStr = ` ${attrStr}`;
|