native-document 1.0.73 → 1.0.75
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/dist/native-document.components.min.js +71 -55
- package/dist/native-document.dev.js +53 -39
- package/dist/native-document.dev.js.map +1 -1
- package/dist/native-document.devtools.min.js +1 -1
- package/dist/native-document.min.js +1 -1
- package/package.json +1 -1
- package/src/core/elements/control/for-each-array.js +1 -3
- package/src/core/wrappers/AttributesWrapper.js +16 -30
- package/src/core/wrappers/ElementCreator.js +5 -14
- package/src/core/wrappers/prototypes/attributes-extensions.js +49 -0
- package/src/core/wrappers/{prototype-extensions.js → prototypes/nd-element-extensions.js} +9 -7
|
@@ -2,7 +2,8 @@ import Anchor from "../elements/anchor";
|
|
|
2
2
|
import Validator from "../utils/validator";
|
|
3
3
|
import AttributesWrapper from "./AttributesWrapper";
|
|
4
4
|
import PluginsManager from "../utils/plugins-manager";
|
|
5
|
-
import './
|
|
5
|
+
import './prototypes/nd-element-extensions';
|
|
6
|
+
import './prototypes/attributes-extensions';
|
|
6
7
|
|
|
7
8
|
const $nodeCache = new Map();
|
|
8
9
|
let $textNodeCache = null;
|
|
@@ -75,20 +76,10 @@ export const ElementCreator = {
|
|
|
75
76
|
processChildren(children, parent) {
|
|
76
77
|
if(children === null) return;
|
|
77
78
|
PluginsManager.emit('BeforeProcessChildren', parent);
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
parent.appendChild(child);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
for(let i = 0, length = children.length; i < length; i++) {
|
|
86
|
-
let child = this.getChild(children[i]);
|
|
87
|
-
if (child === null) continue;
|
|
88
|
-
parent.appendChild(child);
|
|
89
|
-
}
|
|
79
|
+
let child = this.getChild(children);
|
|
80
|
+
if(child) {
|
|
81
|
+
parent.appendChild(child);
|
|
90
82
|
}
|
|
91
|
-
|
|
92
83
|
PluginsManager.emit('AfterProcessChildren', parent);
|
|
93
84
|
},
|
|
94
85
|
getChild(child) {
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import Validator from "../../utils/validator";
|
|
2
|
+
import {Observable} from "../../data/Observable";
|
|
3
|
+
import {
|
|
4
|
+
bindAttributeWithObservable,
|
|
5
|
+
bindBooleanAttribute,
|
|
6
|
+
bindClassAttribute,
|
|
7
|
+
bindStyleAttribute
|
|
8
|
+
} from "../AttributesWrapper";
|
|
9
|
+
import ObservableItem from "../../data/ObservableItem";
|
|
10
|
+
import TemplateBinding from "../TemplateBinding";
|
|
11
|
+
import {BOOLEAN_ATTRIBUTES} from "../constants";
|
|
12
|
+
|
|
13
|
+
Object.prototype.handleNdAttribute = function(element, attributeName) {
|
|
14
|
+
if(attributeName === 'class') {
|
|
15
|
+
bindClassAttribute(element, this);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if(attributeName === 'style') {
|
|
19
|
+
bindStyleAttribute(element, this);
|
|
20
|
+
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
String.prototype.handleNdAttribute = function(element, attributeName) {
|
|
25
|
+
let value = this.resolveObservableTemplate ? this.resolveObservableTemplate() : this;
|
|
26
|
+
if(Validator.isString(value)) {
|
|
27
|
+
element.setAttribute(attributeName, value);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const observables = value.filter(item => Validator.isObservable(item));
|
|
31
|
+
value = Observable.computed(() => {
|
|
32
|
+
return value.map(item => Validator.isObservable(item) ? item.val() : item).join(' ') || ' ';
|
|
33
|
+
}, observables);
|
|
34
|
+
|
|
35
|
+
if(BOOLEAN_ATTRIBUTES.includes(attributeName)) {
|
|
36
|
+
bindBooleanAttribute(element, attributeName, value);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
bindAttributeWithObservable(element, attributeName, value);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
ObservableItem.prototype.handleNdAttribute = function(element, attributeName) {
|
|
44
|
+
bindAttributeWithObservable(element, attributeName, this);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
TemplateBinding.prototype.handleNdAttribute = function(element, attributeName) {
|
|
48
|
+
this.$hydrate(element, attributeName);
|
|
49
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import ObservableItem from "
|
|
2
|
-
import {NDElement} from "
|
|
3
|
-
import TemplateBinding from "
|
|
4
|
-
import {ElementCreator} from "
|
|
5
|
-
import PluginsManager from "
|
|
6
|
-
import Validator from "
|
|
1
|
+
import ObservableItem from "../../data/ObservableItem";
|
|
2
|
+
import {NDElement} from "../NDElement";
|
|
3
|
+
import TemplateBinding from "../TemplateBinding";
|
|
4
|
+
import {ElementCreator} from "../ElementCreator";
|
|
5
|
+
import PluginsManager from "../../utils/plugins-manager";
|
|
6
|
+
import Validator from "../../utils/validator";
|
|
7
7
|
|
|
8
8
|
String.prototype.toNdElement = function () {
|
|
9
9
|
const formattedChild = this.resolveObservableTemplate ? this.resolveObservableTemplate() : this;
|
|
@@ -40,7 +40,9 @@ NDElement.prototype.toNdElement = function () {
|
|
|
40
40
|
Array.prototype.toNdElement = function () {
|
|
41
41
|
const fragment = document.createDocumentFragment();
|
|
42
42
|
for(let i = 0, length = this.length; i < length; i++) {
|
|
43
|
-
|
|
43
|
+
const child = ElementCreator.getChild(this[i]);
|
|
44
|
+
if(child === null) continue;
|
|
45
|
+
fragment.appendChild(child);
|
|
44
46
|
}
|
|
45
47
|
return fragment;
|
|
46
48
|
};
|