native-document 1.0.17-1.8 → 1.0.17-1.9
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "native-document",
|
|
3
|
-
"version": "1.0.171.
|
|
3
|
+
"version": "1.0.171.9",
|
|
4
4
|
"description": "A reactive JavaScript framework that preserves native DOM simplicity without sacrificing modern features",
|
|
5
5
|
"author": "AfroCodeur <https://github.com/afrocodeur>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -1,38 +1,9 @@
|
|
|
1
1
|
import Validator from '../utils/validator';
|
|
2
|
-
import NativeDocumentError from '../errors/NativeDocumentError';
|
|
3
2
|
import {BOOL_ATTRIBUTES_NAME, BOOLEAN_ATTRIBUTES} from './constants.js';
|
|
4
3
|
import {Observable} from '../data/Observable';
|
|
5
4
|
|
|
6
5
|
|
|
7
6
|
|
|
8
|
-
export const handleClassAttributeItem = (element, className, value) => {
|
|
9
|
-
if (value.__$isObservableChecker) {
|
|
10
|
-
let lastClass = value.val();
|
|
11
|
-
if (typeof lastClass === 'string') {
|
|
12
|
-
element.classes.toggle(lastClass, true);
|
|
13
|
-
value.subscribe((currentValue) => {
|
|
14
|
-
element.classes.remove(lastClass);
|
|
15
|
-
element.classes.toggle(currentValue, true);
|
|
16
|
-
lastClass = currentValue;
|
|
17
|
-
});
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (value.__$Observable) {
|
|
23
|
-
element.classes.toggle(className, value.val());
|
|
24
|
-
value.subscribe((shouldAdd) => element.classes.toggle(className, shouldAdd));
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (value.$hydrate) {
|
|
29
|
-
value.$hydrate(element, className);
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
element.classes.toggle(className, value);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
7
|
/**
|
|
37
8
|
* Applies a reactive class map to an HTMLElement.
|
|
38
9
|
* Each key is a CSS class name; each value is a boolean or ObservableItem<boolean>.
|
|
@@ -44,7 +15,31 @@ export const handleClassAttributeItem = (element, className, value) => {
|
|
|
44
15
|
export const bindClassAttribute = (element, data) => {
|
|
45
16
|
for(const className in data) {
|
|
46
17
|
const value = data[className];
|
|
47
|
-
|
|
18
|
+
if (value.__$isObservableChecker) {
|
|
19
|
+
let lastClass = value.val();
|
|
20
|
+
if (typeof lastClass === 'string') {
|
|
21
|
+
element.classes.toggle(lastClass, true);
|
|
22
|
+
value.subscribe((currentValue) => {
|
|
23
|
+
element.classes.remove(lastClass);
|
|
24
|
+
element.classes.toggle(currentValue, true);
|
|
25
|
+
lastClass = currentValue;
|
|
26
|
+
});
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (value.__$Observable) {
|
|
32
|
+
element.classes.toggle(className, value.val());
|
|
33
|
+
value.subscribe((shouldAdd) => element.classes.toggle(className, shouldAdd));
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (value.$hydrate) {
|
|
38
|
+
value.$hydrate(element, className);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
element.classes.toggle(className, value);
|
|
48
43
|
}
|
|
49
44
|
};
|
|
50
45
|
|
|
@@ -90,15 +90,8 @@ export const ElementCreator = {
|
|
|
90
90
|
}
|
|
91
91
|
if(Array.isArray(children)) {
|
|
92
92
|
for(let i = 0, length = children.length; i < length; i++) {
|
|
93
|
-
|
|
94
|
-
if(child
|
|
95
|
-
continue;
|
|
96
|
-
}
|
|
97
|
-
if(!child.__$isNativeNode) {
|
|
98
|
-
child = ElementCreator.getChild(children[i]);
|
|
99
|
-
if(child) {
|
|
100
|
-
parent.appendChild(child);
|
|
101
|
-
}
|
|
93
|
+
const child = ElementCreator.getChild(children[i]);
|
|
94
|
+
if(child === null) {
|
|
102
95
|
continue;
|
|
103
96
|
}
|
|
104
97
|
parent.appendChild(child);
|
|
@@ -5,7 +5,7 @@ import DebugManager from '../utils/debug-manager.js';
|
|
|
5
5
|
import attributesWrapper, {
|
|
6
6
|
bindAttributeWithObservable,
|
|
7
7
|
bindClassAttribute,
|
|
8
|
-
bindStyleAttribute,
|
|
8
|
+
bindStyleAttribute,
|
|
9
9
|
} from './AttributesWrapper';
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -434,17 +434,6 @@ NDElement.prototype.style = function(style) {
|
|
|
434
434
|
return this;
|
|
435
435
|
};
|
|
436
436
|
|
|
437
|
-
NDElement.prototype.className = function(classes) {
|
|
438
|
-
this.$element.classes.add(classes);
|
|
439
|
-
return this;
|
|
440
|
-
};
|
|
441
|
-
|
|
442
|
-
NDElement.prototype.class = function(className, value) {
|
|
443
|
-
handleClassAttributeItem(this.$element, className, value);
|
|
444
|
-
return this;
|
|
445
|
-
};
|
|
446
|
-
|
|
447
|
-
|
|
448
437
|
/**
|
|
449
438
|
* Extends the NDElement prototype with new methods available to all NDElement instances.
|
|
450
439
|
* Use this to add global methods to all NDElements.
|
|
@@ -29,9 +29,9 @@ EVENTS.forEach(eventSourceName => {
|
|
|
29
29
|
NDElement.prototype['on'+eventSourceName] = function(callback = null, options = null) {
|
|
30
30
|
if(!this.$element[inlineHandler] && !options) {
|
|
31
31
|
this.$element[inlineHandler] = callback;
|
|
32
|
-
|
|
33
|
-
this.$element.addEventListener(eventName, callback, options);
|
|
32
|
+
return this;
|
|
34
33
|
}
|
|
34
|
+
this.$element.addEventListener(eventName, callback, options);
|
|
35
35
|
return this;
|
|
36
36
|
};
|
|
37
37
|
});
|
|
@@ -160,6 +160,7 @@ const _preventStop = function(element, eventName, callback, options) {
|
|
|
160
160
|
const inlineHandler = 'on' + eventName;
|
|
161
161
|
if(!element[inlineHandler] && !options) {
|
|
162
162
|
element[inlineHandler] = handler;
|
|
163
|
+
return;
|
|
163
164
|
}
|
|
164
165
|
element.addEventListener(eventName, handler, options);
|
|
165
166
|
return this;
|