native-document 1.0.73 → 1.0.76
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 +52 -49
- package/dist/native-document.dev.js +30 -26
- 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/components/table/DataTable.js +4 -7
- package/src/core/elements/control/for-each-array.js +1 -3
- package/src/core/wrappers/AttributesWrapper.js +19 -17
- package/src/core/wrappers/ElementCreator.js +5 -14
- package/src/core/wrappers/prototypes/attributes-extensions.js +17 -0
- package/src/core/wrappers/{prototype-extensions.js → prototypes/nd-element-extensions.js} +9 -7
|
@@ -4,32 +4,36 @@ import {BOOLEAN_ATTRIBUTES} from "./constants.js";
|
|
|
4
4
|
import {Observable} from "../data/Observable";
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
function toggleElementClass(element, className, shouldAdd) {
|
|
7
|
+
export function toggleElementClass(element, className, shouldAdd) {
|
|
8
8
|
element.classes.toggle(className, shouldAdd);
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
export function toggleElementStyle(element, styleName, newValue) {
|
|
11
12
|
element.style[styleName] = newValue;
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
+
|
|
15
|
+
export function updateInputFromObserver(element, attributeName, newValue) {
|
|
14
16
|
if(Validator.isBoolean(newValue)) {
|
|
15
17
|
element[attributeName] = newValue;
|
|
16
18
|
return;
|
|
17
19
|
}
|
|
18
20
|
element[attributeName] = newValue === element.value;
|
|
19
21
|
}
|
|
20
|
-
|
|
22
|
+
|
|
23
|
+
export function updateObserverFromInput(element, attributeName, defaultValue, value) {
|
|
21
24
|
if(Validator.isBoolean(defaultValue)) {
|
|
22
25
|
value.set(element[attributeName]);
|
|
23
26
|
return;
|
|
24
27
|
}
|
|
25
28
|
value.set(element.value);
|
|
26
29
|
}
|
|
30
|
+
|
|
27
31
|
/**
|
|
28
32
|
*
|
|
29
33
|
* @param {HTMLElement} element
|
|
30
34
|
* @param {Object} data
|
|
31
35
|
*/
|
|
32
|
-
function bindClassAttribute(element, data) {
|
|
36
|
+
export function bindClassAttribute(element, data) {
|
|
33
37
|
for(let className in data) {
|
|
34
38
|
const value = data[className];
|
|
35
39
|
if(Validator.isObservable(value)) {
|
|
@@ -56,7 +60,7 @@ function bindClassAttribute(element, data) {
|
|
|
56
60
|
* @param {HTMLElement} element
|
|
57
61
|
* @param {Object} data
|
|
58
62
|
*/
|
|
59
|
-
function bindStyleAttribute(element, data) {
|
|
63
|
+
export function bindStyleAttribute(element, data) {
|
|
60
64
|
for(let styleName in data) {
|
|
61
65
|
const value = data[styleName];
|
|
62
66
|
if(Validator.isObservable(value)) {
|
|
@@ -74,7 +78,7 @@ function bindStyleAttribute(element, data) {
|
|
|
74
78
|
* @param {string} attributeName
|
|
75
79
|
* @param {boolean|number|Observable} value
|
|
76
80
|
*/
|
|
77
|
-
function bindBooleanAttribute(element, attributeName, value) {
|
|
81
|
+
export function bindBooleanAttribute(element, attributeName, value) {
|
|
78
82
|
const defaultValue = Validator.isObservable(value) ? value.val() : value;
|
|
79
83
|
if(Validator.isBoolean(defaultValue)) {
|
|
80
84
|
element[attributeName] = defaultValue;
|
|
@@ -97,7 +101,7 @@ function bindBooleanAttribute(element, attributeName, value) {
|
|
|
97
101
|
* @param {string} attributeName
|
|
98
102
|
* @param {Observable} value
|
|
99
103
|
*/
|
|
100
|
-
function bindAttributeWithObservable(element, attributeName, value) {
|
|
104
|
+
export function bindAttributeWithObservable(element, attributeName, value) {
|
|
101
105
|
const applyValue = (newValue) => {
|
|
102
106
|
if(attributeName === 'value') {
|
|
103
107
|
element.value = newValue;
|
|
@@ -132,16 +136,13 @@ export default function AttributesWrapper(element, attributes) {
|
|
|
132
136
|
if(value === null || value === undefined) {
|
|
133
137
|
continue;
|
|
134
138
|
}
|
|
139
|
+
if(value.handleNdAttribute) {
|
|
140
|
+
value.handleNdAttribute(element, attributeName, value)
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
135
143
|
if(Validator.isString(value)) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
element.setAttribute(attributeName, value);
|
|
139
|
-
continue;
|
|
140
|
-
}
|
|
141
|
-
const observables = value.filter(item => Validator.isObservable(item));
|
|
142
|
-
value = Observable.computed(() => {
|
|
143
|
-
return value.map(item => Validator.isObservable(item) ? item.val() : item).join(' ') || ' ';
|
|
144
|
-
}, observables);
|
|
144
|
+
element.setAttribute(attributeName, value);
|
|
145
|
+
return;
|
|
145
146
|
}
|
|
146
147
|
if(attributeName === 'class' && Validator.isObject(value)) {
|
|
147
148
|
bindClassAttribute(element, value);
|
|
@@ -163,6 +164,7 @@ export default function AttributesWrapper(element, attributes) {
|
|
|
163
164
|
value.$hydrate(element, attributeName);
|
|
164
165
|
continue;
|
|
165
166
|
}
|
|
167
|
+
|
|
166
168
|
element.setAttribute(attributeName, value);
|
|
167
169
|
|
|
168
170
|
}
|
|
@@ -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,17 @@
|
|
|
1
|
+
import { bindAttributeWithObservable } from "../AttributesWrapper";
|
|
2
|
+
import ObservableItem from "../../data/ObservableItem";
|
|
3
|
+
import TemplateBinding from "../TemplateBinding";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
String.prototype.handleNdAttribute = function(element, attributeName) {
|
|
8
|
+
element.setAttribute(attributeName, this);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
ObservableItem.prototype.handleNdAttribute = function(element, attributeName) {
|
|
12
|
+
bindAttributeWithObservable(element, attributeName, this);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
TemplateBinding.prototype.handleNdAttribute = function(element, attributeName) {
|
|
16
|
+
this.$hydrate(element, attributeName);
|
|
17
|
+
};
|
|
@@ -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
|
};
|