native-document 1.0.81 → 1.0.82
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 +6 -100
- package/dist/native-document.dev.js +116 -90
- 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/data/ObservableArray.js +3 -1
- package/src/core/data/ObservableItem.js +15 -6
- package/src/core/data/observable-helpers/computed.js +3 -2
- package/src/core/elements/anchor.js +3 -1
- package/src/core/elements/control/for-each-array.js +1 -1
- package/src/core/utils/plugins-manager.js +66 -62
- package/src/core/wrappers/ElementCreator.js +12 -6
- package/src/core/wrappers/HtmlElementWrapper.js +2 -7
- package/src/core/wrappers/NDElement.js +6 -3
- package/src/core/wrappers/prototypes/nd-element-extensions.js +3 -1
|
@@ -1,77 +1,81 @@
|
|
|
1
1
|
import DebugManager from "./debug-manager";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
let PluginsManager = null;
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
if(process.env.NODE_ENV === 'development') {
|
|
6
|
+
PluginsManager = (function() {
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return $pluginByEvents;
|
|
11
|
-
},
|
|
12
|
-
add(plugin, name){
|
|
13
|
-
if (!plugin || typeof plugin !== 'object') {
|
|
14
|
-
throw new Error(`Plugin ${name} must be an object`);
|
|
15
|
-
}
|
|
16
|
-
name = name || plugin.name;
|
|
17
|
-
if (!name || typeof name !== 'string') {
|
|
18
|
-
throw new Error(`Please, provide a valid plugin name`);
|
|
19
|
-
}
|
|
20
|
-
if($plugins.has(name)) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
8
|
+
const $plugins = new Map();
|
|
9
|
+
const $pluginByEvents = new Map();
|
|
23
10
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
11
|
+
return {
|
|
12
|
+
list() {
|
|
13
|
+
return $pluginByEvents;
|
|
14
|
+
},
|
|
15
|
+
add(plugin, name){
|
|
16
|
+
if (!plugin || typeof plugin !== 'object') {
|
|
17
|
+
throw new Error(`Plugin ${name} must be an object`);
|
|
18
|
+
}
|
|
19
|
+
name = name || plugin.name;
|
|
20
|
+
if (!name || typeof name !== 'string') {
|
|
21
|
+
throw new Error(`Please, provide a valid plugin name`);
|
|
22
|
+
}
|
|
23
|
+
if($plugins.has(name)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
plugin.$name = name;
|
|
28
|
+
$plugins.set(name ,plugin);
|
|
29
|
+
if(typeof plugin?.init === 'function') {
|
|
30
|
+
plugin.init();
|
|
31
|
+
}
|
|
32
|
+
for(const methodName in plugin) {
|
|
33
|
+
if(/^on[A-Z]/.test(methodName)) {
|
|
34
|
+
const eventName = methodName.replace(/^on/, '');
|
|
35
|
+
if(!$pluginByEvents.has(eventName)) {
|
|
36
|
+
$pluginByEvents.set(eventName, new Set());
|
|
37
|
+
}
|
|
38
|
+
$pluginByEvents.get(eventName).add(plugin);
|
|
34
39
|
}
|
|
35
|
-
$pluginByEvents.get(eventName).add(plugin);
|
|
36
40
|
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
const plugin = $plugins.get(pluginName);
|
|
44
|
-
if(typeof plugin.cleanup === 'function') {
|
|
45
|
-
plugin.cleanup();
|
|
46
|
-
}
|
|
47
|
-
for(const [name, sets] of $pluginByEvents.entries() ) {
|
|
48
|
-
if(sets.has(plugin)) {
|
|
49
|
-
sets.delete(plugin);
|
|
41
|
+
},
|
|
42
|
+
remove(pluginName){
|
|
43
|
+
if(!$plugins.has(pluginName)) {
|
|
44
|
+
return;
|
|
50
45
|
}
|
|
51
|
-
|
|
52
|
-
|
|
46
|
+
const plugin = $plugins.get(pluginName);
|
|
47
|
+
if(typeof plugin.cleanup === 'function') {
|
|
48
|
+
plugin.cleanup();
|
|
53
49
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
50
|
+
for(const [name, sets] of $pluginByEvents.entries() ) {
|
|
51
|
+
if(sets.has(plugin)) {
|
|
52
|
+
sets.delete(plugin);
|
|
53
|
+
}
|
|
54
|
+
if(sets.size === 0) {
|
|
55
|
+
$pluginByEvents.delete(name);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
$plugins.delete(pluginName);
|
|
59
|
+
},
|
|
60
|
+
emit(eventName, ...data) {
|
|
61
|
+
if(!$pluginByEvents.has(eventName)) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const plugins = $pluginByEvents.get(eventName);
|
|
62
65
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
for(const plugin of plugins) {
|
|
67
|
+
const callback = plugin['on'+eventName];
|
|
68
|
+
if(typeof callback === 'function') {
|
|
69
|
+
try{
|
|
70
|
+
callback.call(plugin, ...data);
|
|
71
|
+
} catch (error) {
|
|
72
|
+
DebugManager.error('Plugin Manager', `Error in plugin ${plugin.$name} for event ${eventName}`, error);
|
|
73
|
+
}
|
|
70
74
|
}
|
|
71
75
|
}
|
|
72
76
|
}
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
}
|
|
77
|
+
};
|
|
78
|
+
}());
|
|
79
|
+
}
|
|
76
80
|
|
|
77
81
|
export default PluginsManager;
|
|
@@ -59,8 +59,9 @@ export const ElementCreator = {
|
|
|
59
59
|
*/
|
|
60
60
|
createElement(name) {
|
|
61
61
|
if(name) {
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
const cacheNode = $nodeCache.get(name);
|
|
63
|
+
if(cacheNode) {
|
|
64
|
+
return cacheNode.cloneNode();
|
|
64
65
|
}
|
|
65
66
|
const node = document.createElement(name);
|
|
66
67
|
$nodeCache.set(name, node);
|
|
@@ -75,12 +76,16 @@ export const ElementCreator = {
|
|
|
75
76
|
*/
|
|
76
77
|
processChildren(children, parent) {
|
|
77
78
|
if(children === null) return;
|
|
78
|
-
|
|
79
|
+
if(process.env.NODE_ENV === 'development') {
|
|
80
|
+
PluginsManager.emit('BeforeProcessChildren', parent);
|
|
81
|
+
}
|
|
79
82
|
let child = this.getChild(children);
|
|
80
83
|
if(child) {
|
|
81
84
|
parent.appendChild(child);
|
|
82
85
|
}
|
|
83
|
-
|
|
86
|
+
if(process.env.NODE_ENV === 'development') {
|
|
87
|
+
PluginsManager.emit('AfterProcessChildren', parent);
|
|
88
|
+
}
|
|
84
89
|
},
|
|
85
90
|
getChild(child) {
|
|
86
91
|
if(child == null) {
|
|
@@ -103,7 +108,6 @@ export const ElementCreator = {
|
|
|
103
108
|
* @param {Object} attributes
|
|
104
109
|
*/
|
|
105
110
|
processAttributes(element, attributes) {
|
|
106
|
-
if(Validator.isFragment(element)) return;
|
|
107
111
|
if (attributes) {
|
|
108
112
|
AttributesWrapper(element, attributes);
|
|
109
113
|
}
|
|
@@ -116,7 +120,9 @@ export const ElementCreator = {
|
|
|
116
120
|
* @returns {HTMLElement|DocumentFragment}
|
|
117
121
|
*/
|
|
118
122
|
setup(element, attributes, customWrapper) {
|
|
119
|
-
|
|
123
|
+
if(process.env.NODE_ENV === 'development') {
|
|
124
|
+
PluginsManager.emit('Setup', element, attributes, customWrapper);
|
|
125
|
+
}
|
|
120
126
|
return element;
|
|
121
127
|
}
|
|
122
128
|
};
|
|
@@ -20,13 +20,8 @@ function createHtmlElement($tagName, customWrapper, _attributes, _children = nul
|
|
|
20
20
|
let element = ElementCreator.createElement($tagName);
|
|
21
21
|
let finalElement = (customWrapper && typeof customWrapper === 'function') ? customWrapper(element) : element;
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
if(children) {
|
|
27
|
-
ElementCreator.processChildren(children, finalElement);
|
|
28
|
-
}
|
|
29
|
-
|
|
23
|
+
ElementCreator.processAttributes(finalElement, attributes);
|
|
24
|
+
ElementCreator.processChildren(children, finalElement);
|
|
30
25
|
return ElementCreator.setup(finalElement, attributes, customWrapper);
|
|
31
26
|
}
|
|
32
27
|
|
|
@@ -6,7 +6,9 @@ import DebugManager from "../utils/debug-manager.js";
|
|
|
6
6
|
export function NDElement(element) {
|
|
7
7
|
this.$element = element;
|
|
8
8
|
this.$observer = null;
|
|
9
|
-
|
|
9
|
+
if(process.env.NODE_ENV === 'development') {
|
|
10
|
+
PluginsManager.emit('NDElementCreated', element, this);
|
|
11
|
+
}
|
|
10
12
|
}
|
|
11
13
|
|
|
12
14
|
NDElement.prototype.__$isNDElement = true;
|
|
@@ -175,8 +177,9 @@ NDElement.extend = function(methods) {
|
|
|
175
177
|
|
|
176
178
|
NDElement.prototype[name] = method;
|
|
177
179
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
+
if(process.env.NODE_ENV === 'development') {
|
|
181
|
+
PluginsManager.emit('NDElementExtended', methods);
|
|
182
|
+
}
|
|
180
183
|
|
|
181
184
|
return NDElement;
|
|
182
185
|
};
|
|
@@ -49,7 +49,9 @@ Array.prototype.toNdElement = function () {
|
|
|
49
49
|
|
|
50
50
|
Function.prototype.toNdElement = function () {
|
|
51
51
|
const child = this;
|
|
52
|
-
|
|
52
|
+
if(process.env.NODE_ENV === 'development') {
|
|
53
|
+
PluginsManager.emit('BeforeProcessComponent', child);
|
|
54
|
+
}
|
|
53
55
|
return ElementCreator.getChild(child());
|
|
54
56
|
};
|
|
55
57
|
|