native-document 1.0.113 → 1.0.115
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
CHANGED
|
@@ -128,7 +128,10 @@ if(process.env.NODE_ENV === 'production') {
|
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
export const normalizeComponentArgs = function(props, children = null) {
|
|
131
|
-
if(
|
|
131
|
+
if(props && children) {
|
|
132
|
+
return { props, children };
|
|
133
|
+
}
|
|
134
|
+
if(typeof props !== 'object' || Array.isArray(props) || props === null || props.constructor.name !== 'Object' || props.$hydrate) { // IF it's not a JSON
|
|
132
135
|
return { props: children, children: props }
|
|
133
136
|
}
|
|
134
137
|
return { props, children };
|
|
@@ -36,7 +36,7 @@ export const ElementCreator = {
|
|
|
36
36
|
* @param {{$hydrate: Function}} item
|
|
37
37
|
* @returns {Text}
|
|
38
38
|
*/
|
|
39
|
-
createHydratableNode(parent, item) {
|
|
39
|
+
createHydratableNode: (parent, item) => {
|
|
40
40
|
const text = ElementCreator.createTextNode();
|
|
41
41
|
item.$hydrate(text);
|
|
42
42
|
return text;
|
|
@@ -48,7 +48,7 @@ export const ElementCreator = {
|
|
|
48
48
|
* @param {*} value
|
|
49
49
|
* @returns {Text}
|
|
50
50
|
*/
|
|
51
|
-
createStaticTextNode(parent, value) {
|
|
51
|
+
createStaticTextNode: (parent, value) => {
|
|
52
52
|
let text = ElementCreator.createTextNode();
|
|
53
53
|
text.nodeValue = value;
|
|
54
54
|
parent && parent.appendChild(text);
|
|
@@ -60,15 +60,10 @@ export const ElementCreator = {
|
|
|
60
60
|
* @returns {HTMLElement|DocumentFragment}
|
|
61
61
|
*/
|
|
62
62
|
createElement: (name) => {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
const node = document.createElement(name);
|
|
69
|
-
$nodeCache.set(name, node);
|
|
70
|
-
return node.cloneNode();
|
|
71
|
-
}
|
|
63
|
+
const node = document.createElement(name);
|
|
64
|
+
return node.cloneNode();
|
|
65
|
+
},
|
|
66
|
+
createFragment: (name) => {
|
|
72
67
|
return Anchor('Fragment');
|
|
73
68
|
},
|
|
74
69
|
bindTextNode: (textNode, value) => {
|
|
@@ -84,12 +79,12 @@ export const ElementCreator = {
|
|
|
84
79
|
* @param {*} children
|
|
85
80
|
* @param {HTMLElement|DocumentFragment} parent
|
|
86
81
|
*/
|
|
87
|
-
processChildren(children, parent) {
|
|
82
|
+
processChildren: (children, parent) => {
|
|
88
83
|
if(children === null) return;
|
|
89
84
|
if(process.env.NODE_ENV === 'development') {
|
|
90
85
|
PluginsManager.emit('BeforeProcessChildren', parent);
|
|
91
86
|
}
|
|
92
|
-
let child =
|
|
87
|
+
let child = ElementCreator.getChild(children);
|
|
93
88
|
if(child) {
|
|
94
89
|
parent.appendChild(child);
|
|
95
90
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Validator from "../utils/validator";
|
|
2
|
+
import Anchor from "../elements/anchor";
|
|
2
3
|
import {ElementCreator} from "./ElementCreator";
|
|
3
4
|
import './NdPrototype';
|
|
4
5
|
import {normalizeComponentArgs} from "../utils/args-types";
|
|
@@ -8,21 +9,19 @@ import {normalizeComponentArgs} from "../utils/args-types";
|
|
|
8
9
|
* @param {*} value
|
|
9
10
|
* @returns {Text}
|
|
10
11
|
*/
|
|
11
|
-
export const createTextNode =
|
|
12
|
+
export const createTextNode = (value) => {
|
|
12
13
|
return (Validator.isObservable(value))
|
|
13
14
|
? ElementCreator.createObservableNode(null, value)
|
|
14
15
|
: ElementCreator.createStaticTextNode(null, value);
|
|
15
16
|
};
|
|
16
17
|
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
const createHtmlElement = (element, _attributes, _children = null) => {
|
|
19
20
|
let { props: attributes, children = null } = normalizeComponentArgs(_attributes, _children);
|
|
20
|
-
let element = ElementCreator.createElement($tagName);
|
|
21
|
-
let finalElement = (customWrapper && typeof customWrapper === 'function') ? customWrapper(element) : element;
|
|
22
21
|
|
|
23
|
-
ElementCreator.processAttributes(
|
|
24
|
-
ElementCreator.processChildren(children,
|
|
25
|
-
return
|
|
22
|
+
ElementCreator.processAttributes(element, attributes);
|
|
23
|
+
ElementCreator.processChildren(children, element);
|
|
24
|
+
return element;
|
|
26
25
|
}
|
|
27
26
|
|
|
28
27
|
/**
|
|
@@ -32,6 +31,31 @@ function createHtmlElement($tagName, customWrapper, _attributes, _children = nul
|
|
|
32
31
|
* @returns {Function}
|
|
33
32
|
*/
|
|
34
33
|
export default function HtmlElementWrapper(name, customWrapper = null) {
|
|
35
|
-
|
|
34
|
+
if(name) {
|
|
35
|
+
if(customWrapper) {
|
|
36
|
+
let node = null;
|
|
37
|
+
let createElement = (attr, children) => {
|
|
38
|
+
node = document.createElement(name);
|
|
39
|
+
createElement = (attr, children) => {
|
|
40
|
+
return createHtmlElement(customWrapper(node.cloneNode()), attr, children);
|
|
41
|
+
};
|
|
42
|
+
return createHtmlElement(customWrapper(node.cloneNode()), attr, children);;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
return (attr, children) => createElement(attr, children)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
let node = null;
|
|
49
|
+
let createElement = (attr, children) => {
|
|
50
|
+
node = document.createElement(name);
|
|
51
|
+
createElement = (attr, children) => {
|
|
52
|
+
return createHtmlElement(node.cloneNode(), attr, children);
|
|
53
|
+
};
|
|
54
|
+
return createHtmlElement(node.cloneNode(), attr, children);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
return (attr, children) => createElement(attr, children)
|
|
58
|
+
}
|
|
59
|
+
return () => Anchor('');
|
|
36
60
|
};
|
|
37
61
|
|