native-document 1.0.17-1.5 → 1.0.17-1.7
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.7",
|
|
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",
|
|
@@ -124,6 +124,9 @@ ObservableItem.prototype.triggerListeners = function(operations) {
|
|
|
124
124
|
* @param {{ action?: string, args?: any[], result?: any }} [operations] - Mutation metadata
|
|
125
125
|
*/
|
|
126
126
|
ObservableItem.prototype.triggerWatchers = function(operations) {
|
|
127
|
+
if(!this.$watchers) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
127
130
|
const $watchers = this.$watchers;
|
|
128
131
|
const $previousValue = this.$previousValue;
|
|
129
132
|
const $currentValue = this.$currentValue;
|
|
@@ -65,7 +65,7 @@ export function ForEachArray(data, callback, configs = {}) {
|
|
|
65
65
|
throw new NativeDocumentError('ForEachArray child can\'t be null or undefined!');
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
-
cache.set(item,
|
|
68
|
+
cache.set(item, child);
|
|
69
69
|
return child;
|
|
70
70
|
};
|
|
71
71
|
|
|
@@ -77,7 +77,7 @@ export function ForEachArray(data, callback, configs = {}) {
|
|
|
77
77
|
throw new NativeDocumentError('ForEachArray child can\'t be null or undefined!');
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
|
-
cache.set(item,
|
|
80
|
+
cache.set(item, child, indexObserver);
|
|
81
81
|
return child;
|
|
82
82
|
};
|
|
83
83
|
if(!data.__$Observable) {
|
|
@@ -88,7 +88,7 @@ export function ForEachArray(data, callback, configs = {}) {
|
|
|
88
88
|
throw new NativeDocumentError('ForEachArray child can\'t be null or undefined!');
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
|
-
cache.set(item,
|
|
91
|
+
cache.set(item, child);
|
|
92
92
|
return child;
|
|
93
93
|
};
|
|
94
94
|
}
|
|
@@ -151,14 +151,14 @@ export function ForEachArray(data, callback, configs = {}) {
|
|
|
151
151
|
if(Array.isArray(data)) {
|
|
152
152
|
set = () => {
|
|
153
153
|
clear(data);
|
|
154
|
-
|
|
154
|
+
Actions.appendToElement(data);
|
|
155
155
|
};
|
|
156
156
|
}
|
|
157
157
|
else {
|
|
158
158
|
set = () => {
|
|
159
159
|
const items = data.val();
|
|
160
160
|
clear(items);
|
|
161
|
-
|
|
161
|
+
Actions.appendToElement(items);
|
|
162
162
|
};
|
|
163
163
|
}
|
|
164
164
|
|
|
@@ -167,45 +167,36 @@ export function ForEachArray(data, callback, configs = {}) {
|
|
|
167
167
|
const fragment = document.createDocumentFragment();
|
|
168
168
|
for(let i = 0, length = items.length; i < length; i++) {
|
|
169
169
|
fragment.appendChild(buildItem(items[i], lastNumberOfItems));
|
|
170
|
-
lastNumberOfItems++;
|
|
171
170
|
}
|
|
172
171
|
return fragment;
|
|
173
172
|
},
|
|
173
|
+
appendToElement: (items) => {
|
|
174
|
+
for(let i = 0, length = items.length; i < length; i++) {
|
|
175
|
+
element.appendChild(buildItem(items[i], i));
|
|
176
|
+
}
|
|
177
|
+
},
|
|
174
178
|
add: (items) => {
|
|
175
|
-
|
|
179
|
+
Actions.appendToElement(items)
|
|
176
180
|
},
|
|
177
181
|
replace: (items) => {
|
|
178
182
|
clear(items);
|
|
179
|
-
|
|
183
|
+
Actions.appendToElement(items)
|
|
180
184
|
},
|
|
181
185
|
set,
|
|
182
186
|
reOrder: (items) => {
|
|
183
187
|
let child = null;
|
|
184
|
-
const fragment = document.createDocumentFragment();
|
|
185
188
|
for(const item of items) {
|
|
186
189
|
child = getItemChild(item);
|
|
187
190
|
if(child) {
|
|
188
|
-
|
|
191
|
+
element.appendChild(child);
|
|
189
192
|
}
|
|
190
193
|
}
|
|
191
194
|
child = null;
|
|
192
|
-
element.appendChildRaw(fragment);
|
|
193
195
|
},
|
|
194
196
|
removeOne: (element, index) => {
|
|
195
197
|
removeCacheItem(element, true);
|
|
196
198
|
},
|
|
197
199
|
clear,
|
|
198
|
-
populate: ([target, iteration, callback]) => {
|
|
199
|
-
const fragment = document.createDocumentFragment();
|
|
200
|
-
for (let i = 0; i < iteration; i++) {
|
|
201
|
-
const data = callback(i);
|
|
202
|
-
target.push(data);
|
|
203
|
-
fragment.append(buildItem(data, i));
|
|
204
|
-
lastNumberOfItems++;
|
|
205
|
-
}
|
|
206
|
-
element.appendChildRaw(fragment);
|
|
207
|
-
fragment.replaceChildren();
|
|
208
|
-
},
|
|
209
200
|
unshift: (values) => {
|
|
210
201
|
element.insertAtStartRaw(Actions.toFragment(values));
|
|
211
202
|
},
|
|
@@ -204,15 +204,13 @@ NDElement.prototype.destroy = function() {
|
|
|
204
204
|
for(let i = 0, length = nodes.length; i < length; i++) {
|
|
205
205
|
const child = nodes[i];
|
|
206
206
|
child.remove();
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
$lifeCycleObservers.delete(child);
|
|
207
|
+
const childObserver = $lifeCycleObservers.get(child);
|
|
208
|
+
if(childObserver) {
|
|
209
|
+
childObserver.disconnect();
|
|
211
210
|
}
|
|
211
|
+
$lifeCycleObservers.delete(child);
|
|
212
212
|
}
|
|
213
213
|
|
|
214
|
-
this.$element.__$controller?.abort();
|
|
215
|
-
this.$element.__$controller = null;
|
|
216
214
|
$lifeCycleObservers.delete(this.$element);
|
|
217
215
|
this.$element.remove();
|
|
218
216
|
this.$element = null;
|
|
@@ -636,7 +634,7 @@ NDElement.prototype.contentEditable = function($obs, {format = 'html'} = {}) {
|
|
|
636
634
|
|
|
637
635
|
this.$element.addEventListener('input', () => {
|
|
638
636
|
$obs?.set(getValue());
|
|
639
|
-
}
|
|
637
|
+
});
|
|
640
638
|
|
|
641
639
|
return this;
|
|
642
640
|
};
|
|
@@ -27,10 +27,7 @@ Object.defineProperty(NDElement.prototype, 'nd', {
|
|
|
27
27
|
EVENTS.forEach(eventSourceName => {
|
|
28
28
|
const eventName = eventSourceName.toLowerCase();
|
|
29
29
|
NDElement.prototype['on'+eventSourceName] = function(callback = null, options = {}) {
|
|
30
|
-
this.$element.addEventListener(eventName, callback,
|
|
31
|
-
signal: this.$getSignal(),
|
|
32
|
-
...options,
|
|
33
|
-
});
|
|
30
|
+
this.$element.addEventListener(eventName, callback, options);
|
|
34
31
|
return this;
|
|
35
32
|
};
|
|
36
33
|
});
|
|
@@ -38,17 +35,11 @@ EVENTS.forEach(eventSourceName => {
|
|
|
38
35
|
EVENTS_WITH_STOP.forEach(eventSourceName => {
|
|
39
36
|
const eventName = eventSourceName.toLowerCase();
|
|
40
37
|
NDElement.prototype['onStop'+eventSourceName] = function(callback = null, options = {}) {
|
|
41
|
-
_stop(this.$element, eventName, callback,
|
|
42
|
-
signal: this.$getSignal(),
|
|
43
|
-
...options,
|
|
44
|
-
});
|
|
38
|
+
_stop(this.$element, eventName, callback, options);
|
|
45
39
|
return this;
|
|
46
40
|
};
|
|
47
41
|
NDElement.prototype['onPreventStop'+eventSourceName] = function(callback = null, options = {}) {
|
|
48
|
-
_preventStop(this.$element, eventName, callback,
|
|
49
|
-
signal: this.$getSignal(),
|
|
50
|
-
...options,
|
|
51
|
-
});
|
|
42
|
+
_preventStop(this.$element, eventName, callback, options);
|
|
52
43
|
return this;
|
|
53
44
|
};
|
|
54
45
|
});
|
|
@@ -56,29 +47,11 @@ EVENTS_WITH_STOP.forEach(eventSourceName => {
|
|
|
56
47
|
EVENTS_WITH_PREVENT.forEach(eventSourceName => {
|
|
57
48
|
const eventName = eventSourceName.toLowerCase();
|
|
58
49
|
NDElement.prototype['onPrevent'+eventSourceName] = function(callback = null, options = {}) {
|
|
59
|
-
_prevent(this.$element, eventName, callback,
|
|
60
|
-
signal: this.$getSignal(),
|
|
61
|
-
...options,
|
|
62
|
-
});
|
|
50
|
+
_prevent(this.$element, eventName, callback, options);
|
|
63
51
|
return this;
|
|
64
52
|
};
|
|
65
53
|
});
|
|
66
54
|
|
|
67
|
-
/**
|
|
68
|
-
* Retrieves or creates an AbortController signal tied to this element's lifecycle.
|
|
69
|
-
* The signal is automatically aborted when the element is removed via .nd.remove().
|
|
70
|
-
* Used internally by all event listeners (onClick, onInput, etc.) to auto-cleanup on unmount.
|
|
71
|
-
*
|
|
72
|
-
* @internal
|
|
73
|
-
* @returns {AbortSignal} The signal for this element's AbortController
|
|
74
|
-
*/
|
|
75
|
-
NDElement.prototype.$getSignal = function() {
|
|
76
|
-
if(!this.$element.__$controller) {
|
|
77
|
-
// this.$element.__$controller = new AbortController();
|
|
78
|
-
}
|
|
79
|
-
return this.$element.__$controller.signal;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
55
|
|
|
83
56
|
/**
|
|
84
57
|
* Adds a native event listener to the underlying HTMLElement.
|
|
@@ -91,7 +64,6 @@ NDElement.prototype.$getSignal = function() {
|
|
|
91
64
|
*/
|
|
92
65
|
NDElement.prototype.on = function(name, callback, options) {
|
|
93
66
|
this.$element.addEventListener(name.toLowerCase(), callback, {
|
|
94
|
-
signal: this.$getSignal(),
|
|
95
67
|
...options,
|
|
96
68
|
});
|
|
97
69
|
return this;
|
|
@@ -119,7 +91,6 @@ NDElement.prototype.off = function(name, callback) {
|
|
|
119
91
|
*/
|
|
120
92
|
NDElement.prototype.once = function(name, callback) {
|
|
121
93
|
this.$element.addEventListener(name.toLowerCase(), callback, {
|
|
122
|
-
signal: this.$getSignal(),
|
|
123
94
|
once: true,
|
|
124
95
|
});
|
|
125
96
|
return this;
|