vaderjs 1.5.4 → 1.5.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.
- package/document/index.ts +35 -31
- package/index.ts +4 -3
- package/package.json +1 -1
package/document/index.ts
CHANGED
|
@@ -1,39 +1,43 @@
|
|
|
1
|
-
export const document = (element: any) => {
|
|
1
|
+
export const document = (element: any) => {
|
|
2
2
|
let type = element.type;
|
|
3
|
-
let el = `<${type}
|
|
3
|
+
let el = type === null ? `` : `<${type}`
|
|
4
|
+
console.log(el)
|
|
4
5
|
let attributes = element.props;
|
|
5
6
|
let children = element.children;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (key === "className") {
|
|
12
|
-
el += ` class="${attributes[key]}"`;
|
|
13
|
-
continue;
|
|
14
|
-
}
|
|
15
|
-
if (key === "style") {
|
|
16
|
-
// convert style object to string
|
|
17
|
-
let styles = attributes[key];
|
|
18
|
-
let styleString = "";
|
|
19
|
-
// convert camelCase to kebab-case
|
|
20
|
-
for (let style in styles) {
|
|
21
|
-
let kebabStyle = style.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2').toLowerCase();
|
|
22
|
-
styleString += `${kebabStyle}:${styles[style]};`;
|
|
7
|
+
if(type != null){
|
|
8
|
+
for (let key in attributes) {
|
|
9
|
+
if(key === "key"){
|
|
10
|
+
el += ` key="${attributes[key]}"`;
|
|
11
|
+
continue;
|
|
23
12
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
13
|
+
if (key === "className") {
|
|
14
|
+
el += ` class="${attributes[key]}"`;
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
if (key === "style") {
|
|
18
|
+
// convert style object to string
|
|
19
|
+
let styles = attributes[key];
|
|
20
|
+
let styleString = "";
|
|
21
|
+
// convert camelCase to kebab-case
|
|
22
|
+
for (let style in styles) {
|
|
23
|
+
let kebabStyle = style.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2').toLowerCase();
|
|
24
|
+
styleString += `${kebabStyle}:${styles[style]};`;
|
|
25
|
+
}
|
|
26
|
+
el += ` style="${styleString}"`;
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
//@ts-ignore
|
|
30
|
+
if (key.startsWith("on")){
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
el += ` ${key}="${attributes[key]}"`;
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
el += type === null ? `` : `>`
|
|
35
38
|
for (let i = 0;i < children.length; i++) {
|
|
36
39
|
let child = children[i];
|
|
40
|
+
console.log(child)
|
|
37
41
|
if (Array.isArray(child)) {
|
|
38
42
|
child.forEach((c) => {
|
|
39
43
|
el += document(c);
|
|
@@ -48,6 +52,6 @@ export const document = (element: any) => {
|
|
|
48
52
|
el += child;
|
|
49
53
|
}
|
|
50
54
|
}
|
|
51
|
-
el += `</${type}
|
|
55
|
+
el += type === null ? `` : `</${type}>`
|
|
52
56
|
return el;
|
|
53
57
|
}
|
package/index.ts
CHANGED
|
@@ -76,8 +76,8 @@ export const useEffect = (callback:any, dependencies: any[]) => {
|
|
|
76
76
|
|
|
77
77
|
export const Fragment = (props: any, children: any) => {
|
|
78
78
|
return {
|
|
79
|
-
type: "div",
|
|
80
|
-
props:
|
|
79
|
+
type: isServer ? null : "div",
|
|
80
|
+
props:{},
|
|
81
81
|
children: children || [],
|
|
82
82
|
}
|
|
83
83
|
}
|
|
@@ -105,7 +105,8 @@ export const e = (element, props, ...children) => {
|
|
|
105
105
|
let firstEl = instance.render({key: instance.key, children: children, ...props});
|
|
106
106
|
instance.children = children;
|
|
107
107
|
if (!firstEl) firstEl = {type: "div", props: {key: instance.key, children: [], ...props}, children: []};
|
|
108
|
-
firstEl.props = {key: instance.key,
|
|
108
|
+
firstEl.props = {key: instance.key, ...props};
|
|
109
|
+
firstEl.children = children;
|
|
109
110
|
return firstEl;
|
|
110
111
|
default:
|
|
111
112
|
return { type: element, props: props || {}, children: children || [] };
|