mini-jsx-test-pb 0.0.3 → 0.0.5
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.
|
@@ -31,47 +31,60 @@ function effect(fn) {
|
|
|
31
31
|
runner();
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
// src/mount.ts
|
|
35
|
+
function mountChild(parent, child) {
|
|
36
|
+
if (child == null || child === false || child === true) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (Array.isArray(child)) {
|
|
40
|
+
for (const c of child) {
|
|
41
|
+
mountChild(parent, c);
|
|
42
|
+
}
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (typeof child === "function") {
|
|
46
|
+
const text = document.createTextNode("");
|
|
47
|
+
parent.appendChild(text);
|
|
48
|
+
effect(() => {
|
|
49
|
+
const value = child();
|
|
50
|
+
text.nodeValue = value == null ? "" : String(value);
|
|
51
|
+
});
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (typeof child === "object" && child && "val" in child) {
|
|
55
|
+
mountChild(parent, () => child.val);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (child instanceof Node) {
|
|
59
|
+
parent.appendChild(child);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
parent.appendChild(document.createTextNode(String(child)));
|
|
63
|
+
}
|
|
64
|
+
|
|
34
65
|
// src/jsx.ts
|
|
35
|
-
function h(type, props, ...
|
|
66
|
+
function h(type, props, ...restChildren) {
|
|
36
67
|
if (typeof type === "function") {
|
|
37
|
-
return type({ ...props ?? {}
|
|
68
|
+
return type({ ...props ?? {} });
|
|
38
69
|
}
|
|
39
70
|
const el = document.createElement(type);
|
|
40
71
|
if (props) {
|
|
41
72
|
for (const key in props) {
|
|
73
|
+
if (key === "children") continue;
|
|
42
74
|
const value = props[key];
|
|
43
75
|
if (key.startsWith("on")) {
|
|
44
76
|
el.addEventListener(key.slice(2).toLowerCase(), value);
|
|
45
77
|
} else {
|
|
46
|
-
el.setAttribute(key, value);
|
|
78
|
+
el.setAttribute(key, String(value));
|
|
47
79
|
}
|
|
48
80
|
}
|
|
49
81
|
}
|
|
82
|
+
const children = restChildren.length > 0 ? restChildren : props?.children != null ? Array.isArray(props.children) ? props.children : [props.children] : [];
|
|
50
83
|
for (const child of children.flat()) {
|
|
51
84
|
mountChild(el, child);
|
|
52
85
|
}
|
|
53
86
|
return el;
|
|
54
87
|
}
|
|
55
|
-
function mountChild(parent, child) {
|
|
56
|
-
if (child == null || child === false) return;
|
|
57
|
-
if (typeof child === "function") {
|
|
58
|
-
const text = document.createTextNode("");
|
|
59
|
-
parent.appendChild(text);
|
|
60
|
-
effect(() => {
|
|
61
|
-
text.nodeValue = String(child());
|
|
62
|
-
});
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
if (typeof child === "object" && "val" in child) {
|
|
66
|
-
mountChild(parent, () => child.val);
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
if (child instanceof Node) {
|
|
70
|
-
parent.appendChild(child);
|
|
71
|
-
} else {
|
|
72
|
-
parent.appendChild(document.createTextNode(String(child)));
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
88
|
|
|
76
89
|
export {
|
|
77
90
|
State,
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/jsx-dev-runtime.js
CHANGED
package/dist/jsx-runtime.js
CHANGED
package/package.json
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mini-jsx-test-pb",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
|
-
"
|
|
11
|
-
"
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
12
|
},
|
|
13
13
|
"./jsx-runtime": {
|
|
14
|
-
"
|
|
15
|
-
"
|
|
14
|
+
"types": "./dist/jsx-runtime.d.ts",
|
|
15
|
+
"import": "./dist/jsx-runtime.js"
|
|
16
|
+
},
|
|
17
|
+
"./jsx-dev-runtime": {
|
|
18
|
+
"types": "./dist/jsx-dev-runtime.d.ts",
|
|
19
|
+
"import": "./dist/jsx-dev-runtime.js"
|
|
16
20
|
}
|
|
17
21
|
},
|
|
18
22
|
"files": [
|