native-document 1.0.118 → 1.0.119
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 +134 -32
- package/dist/native-document.dev.js +177 -73
- package/dist/native-document.dev.js.map +1 -1
- package/dist/native-document.min.js +1 -1
- package/docs/lifecycle-events.md +1 -1
- package/elements.js +2 -2
- package/package.json +1 -1
- package/src/core/elements/anchor/anchor-with-sentinel.js +41 -0
- package/src/core/elements/{anchor.js → anchor/anchor.js} +29 -13
- package/src/core/elements/anchor/one-child-anchor-overwriting.js +44 -0
- package/src/core/elements/control/for-each-array.js +33 -31
- package/src/core/elements/control/for-each.js +1 -1
- package/src/core/elements/control/show-if.js +1 -1
- package/src/core/elements/control/switch.js +1 -1
- package/src/core/wrappers/ElementCreator.js +1 -1
- package/src/core/wrappers/HtmlElementWrapper.js +5 -4
- package/src/core/wrappers/SingletonView.js +1 -1
- package/src/core/wrappers/prototypes/nd-element-extensions.js +4 -0
- package/src/core/wrappers/template-cloner/NodeCloner.js +2 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
var NativeDocument = (function (exports) {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
let DebugManager$
|
|
4
|
+
let DebugManager$2 = {};
|
|
5
5
|
|
|
6
6
|
{
|
|
7
|
-
DebugManager$
|
|
7
|
+
DebugManager$2 = {
|
|
8
8
|
enabled: false,
|
|
9
9
|
|
|
10
10
|
enable() {
|
|
@@ -35,7 +35,7 @@ var NativeDocument = (function (exports) {
|
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
}
|
|
38
|
-
var DebugManager = DebugManager$
|
|
38
|
+
var DebugManager$1 = DebugManager$2;
|
|
39
39
|
|
|
40
40
|
class NativeDocumentError extends Error {
|
|
41
41
|
constructor(message, context = {}) {
|
|
@@ -382,7 +382,7 @@ var NativeDocument = (function (exports) {
|
|
|
382
382
|
try{
|
|
383
383
|
callback.call(plugin, ...data);
|
|
384
384
|
} catch (error) {
|
|
385
|
-
DebugManager.error('Plugin Manager', `Error in plugin ${plugin.$name} for event ${eventName}`, error);
|
|
385
|
+
DebugManager$1.error('Plugin Manager', `Error in plugin ${plugin.$name} for event ${eventName}`, error);
|
|
386
386
|
}
|
|
387
387
|
}
|
|
388
388
|
}
|
|
@@ -561,7 +561,7 @@ var NativeDocument = (function (exports) {
|
|
|
561
561
|
}
|
|
562
562
|
{
|
|
563
563
|
if (this[name] && !this.$localExtensions.has(name)) {
|
|
564
|
-
DebugManager.warn('NDElement.extend', `Method "${name}" already exists and will be overwritten`);
|
|
564
|
+
DebugManager$1.warn('NDElement.extend', `Method "${name}" already exists and will be overwritten`);
|
|
565
565
|
}
|
|
566
566
|
this.$localExtensions.set(name, method);
|
|
567
567
|
}
|
|
@@ -612,17 +612,17 @@ var NativeDocument = (function (exports) {
|
|
|
612
612
|
const method = methods[name];
|
|
613
613
|
|
|
614
614
|
if (typeof method !== 'function') {
|
|
615
|
-
DebugManager.warn('NDElement.extend', `"${name}" is not a function, skipping`);
|
|
615
|
+
DebugManager$1.warn('NDElement.extend', `"${name}" is not a function, skipping`);
|
|
616
616
|
continue;
|
|
617
617
|
}
|
|
618
618
|
|
|
619
619
|
if (protectedMethods.has(name)) {
|
|
620
|
-
DebugManager.error('NDElement.extend', `Cannot override protected method "${name}"`);
|
|
620
|
+
DebugManager$1.error('NDElement.extend', `Cannot override protected method "${name}"`);
|
|
621
621
|
throw new NativeDocumentError(`Cannot override protected method "${name}"`);
|
|
622
622
|
}
|
|
623
623
|
|
|
624
624
|
if (NDElement.prototype[name]) {
|
|
625
|
-
DebugManager.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
|
|
625
|
+
DebugManager$1.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
|
|
626
626
|
}
|
|
627
627
|
|
|
628
628
|
NDElement.prototype[name] = method;
|
|
@@ -779,7 +779,7 @@ var NativeDocument = (function (exports) {
|
|
|
779
779
|
const foundReserved = Object.keys(attributes).filter(key => reserved.includes(key));
|
|
780
780
|
|
|
781
781
|
if (foundReserved.length > 0) {
|
|
782
|
-
DebugManager.warn('Validator', `Reserved attributes found: ${foundReserved.join(', ')}`);
|
|
782
|
+
DebugManager$1.warn('Validator', `Reserved attributes found: ${foundReserved.join(', ')}`);
|
|
783
783
|
}
|
|
784
784
|
|
|
785
785
|
return attributes;
|
|
@@ -866,7 +866,7 @@ var NativeDocument = (function (exports) {
|
|
|
866
866
|
}
|
|
867
867
|
}
|
|
868
868
|
if (cleanedCount > 0) {
|
|
869
|
-
DebugManager.log('Memory Auto Clean', `🧹 Cleaned ${cleanedCount} orphaned observables`);
|
|
869
|
+
DebugManager$1.log('Memory Auto Clean', `🧹 Cleaned ${cleanedCount} orphaned observables`);
|
|
870
870
|
}
|
|
871
871
|
}
|
|
872
872
|
};
|
|
@@ -1363,7 +1363,7 @@ var NativeDocument = (function (exports) {
|
|
|
1363
1363
|
ObservableItem.prototype.subscribe = function(callback) {
|
|
1364
1364
|
{
|
|
1365
1365
|
if (this.$isCleanedUp) {
|
|
1366
|
-
DebugManager.warn('Observable subscription', '⚠️ Attempted to subscribe to a cleaned up observable.');
|
|
1366
|
+
DebugManager$1.warn('Observable subscription', '⚠️ Attempted to subscribe to a cleaned up observable.');
|
|
1367
1367
|
return;
|
|
1368
1368
|
}
|
|
1369
1369
|
if (typeof callback !== 'function') {
|
|
@@ -1922,6 +1922,10 @@ var NativeDocument = (function (exports) {
|
|
|
1922
1922
|
return ElementCreator.createStaticTextNode(null, this);
|
|
1923
1923
|
};
|
|
1924
1924
|
|
|
1925
|
+
Number.prototype.toNdElement = function () {
|
|
1926
|
+
return ElementCreator.createStaticTextNode(null, this.toString());
|
|
1927
|
+
};
|
|
1928
|
+
|
|
1925
1929
|
Element.prototype.toNdElement = function () {
|
|
1926
1930
|
return this;
|
|
1927
1931
|
};
|
|
@@ -2197,8 +2201,103 @@ var NativeDocument = (function (exports) {
|
|
|
2197
2201
|
processStyleAttribute: bindStyleAttribute,
|
|
2198
2202
|
};
|
|
2199
2203
|
|
|
2204
|
+
function AnchorWithSentinel(name) {
|
|
2205
|
+
const instance = Reflect.construct(DocumentFragment, [], AnchorWithSentinel);
|
|
2206
|
+
const sentinel = document.createComment((name || '') + ' Anchor Sentinel');
|
|
2207
|
+
const events = {};
|
|
2208
|
+
|
|
2209
|
+
instance.appendChild(sentinel);
|
|
2210
|
+
|
|
2211
|
+
const observer = new MutationObserver(() => {
|
|
2212
|
+
if (sentinel.parentNode !== instance && !(sentinel.parentNode instanceof DocumentFragment)) {
|
|
2213
|
+
events.connected && events.connected(sentinel.parentNode);
|
|
2214
|
+
}
|
|
2215
|
+
});
|
|
2216
|
+
|
|
2217
|
+
observer.observe(document, { childList: true, subtree: true });
|
|
2218
|
+
|
|
2219
|
+
|
|
2220
|
+
instance.$sentinel = sentinel;
|
|
2221
|
+
instance.$observer = observer;
|
|
2222
|
+
instance.$events = events;
|
|
2223
|
+
|
|
2224
|
+
return instance;
|
|
2225
|
+
}
|
|
2226
|
+
|
|
2227
|
+
AnchorWithSentinel.prototype = Object.create(DocumentFragment.prototype);
|
|
2228
|
+
AnchorWithSentinel.prototype.constructor = AnchorWithSentinel;
|
|
2229
|
+
|
|
2230
|
+
AnchorWithSentinel.prototype.onConnected = function(callback) {
|
|
2231
|
+
this.$events.connected = callback;
|
|
2232
|
+
return this;
|
|
2233
|
+
};
|
|
2234
|
+
|
|
2235
|
+
AnchorWithSentinel.prototype.onConnectedOnce = function(callback) {
|
|
2236
|
+
this.$events.connected = (parent) => {
|
|
2237
|
+
callback(parent);
|
|
2238
|
+
this.$observer.disconnect();
|
|
2239
|
+
this.$events.connectedOnce = null;
|
|
2240
|
+
};
|
|
2241
|
+
};
|
|
2242
|
+
|
|
2243
|
+
function oneChildAnchorOverwriting(anchor, parent) {
|
|
2244
|
+
|
|
2245
|
+
anchor.remove = () => {
|
|
2246
|
+
anchor.append.apply(anchor, parent.childNodes);
|
|
2247
|
+
};
|
|
2248
|
+
|
|
2249
|
+
anchor.appendChild = (child) => {
|
|
2250
|
+
child = Validator.isElement(child) ? child : ElementCreator.getChild(child);
|
|
2251
|
+
parent.appendChild(child);
|
|
2252
|
+
};
|
|
2253
|
+
|
|
2254
|
+
anchor.appendElement = anchor.appendChild;
|
|
2255
|
+
|
|
2256
|
+
anchor.removeChildren = () => {
|
|
2257
|
+
parent.replaceChildren();
|
|
2258
|
+
};
|
|
2259
|
+
|
|
2260
|
+
anchor.replaceContent = function(content) {
|
|
2261
|
+
const child = Validator.isElement(content) ? content : ElementCreator.getChild(content);
|
|
2262
|
+
parent.replaceChildren(child);
|
|
2263
|
+
};
|
|
2264
|
+
anchor.setContent = anchor.replaceContent;
|
|
2265
|
+
|
|
2266
|
+
anchor.insertBefore = (child, anchor) => {
|
|
2267
|
+
child = Validator.isElement(child) ? child : ElementCreator.getChild(child);
|
|
2268
|
+
parent.insertBefore(child, anchor);
|
|
2269
|
+
};
|
|
2270
|
+
anchor.appendChildBefore = anchor.insertBefore;
|
|
2271
|
+
|
|
2272
|
+
anchor.clear = anchor.remove;
|
|
2273
|
+
anchor.detach = anchor.remove;
|
|
2274
|
+
|
|
2275
|
+
anchor.replaceChildren = function() {
|
|
2276
|
+
parent.replaceChildren(...arguments);
|
|
2277
|
+
};
|
|
2278
|
+
|
|
2279
|
+
anchor.getByIndex = (index) => {
|
|
2280
|
+
return parent.childNodes[index];
|
|
2281
|
+
};
|
|
2282
|
+
}
|
|
2283
|
+
|
|
2200
2284
|
function Anchor(name, isUniqueChild = false) {
|
|
2201
|
-
const anchorFragment =
|
|
2285
|
+
const anchorFragment = new AnchorWithSentinel(name);
|
|
2286
|
+
|
|
2287
|
+
/**
|
|
2288
|
+
* State :
|
|
2289
|
+
* 1. Not injected in the DOM
|
|
2290
|
+
* 2. Injected in the DOM and should be the only child of parent
|
|
2291
|
+
* 3. Injected in the DOM and the parent may have other children
|
|
2292
|
+
*/
|
|
2293
|
+
|
|
2294
|
+
anchorFragment.onConnectedOnce((parent) => {
|
|
2295
|
+
if(isUniqueChild) {
|
|
2296
|
+
console.log('Lets overwrite some functions with parent ', parent);
|
|
2297
|
+
oneChildAnchorOverwriting(anchorFragment, parent);
|
|
2298
|
+
}
|
|
2299
|
+
});
|
|
2300
|
+
|
|
2202
2301
|
anchorFragment.__Anchor__ = true;
|
|
2203
2302
|
|
|
2204
2303
|
const anchorStart = document.createComment('Anchor Start : '+name);
|
|
@@ -2212,8 +2311,7 @@ var NativeDocument = (function (exports) {
|
|
|
2212
2311
|
anchorFragment.nativeAppend = anchorFragment.append;
|
|
2213
2312
|
|
|
2214
2313
|
const isParentUniqueChild = isUniqueChild
|
|
2215
|
-
? () => true
|
|
2216
|
-
: (parent) => (parent.firstChild === anchorStart && parent.lastChild === anchorEnd);
|
|
2314
|
+
? () => true: (parent) => (parent.firstChild === anchorStart && parent.lastChild === anchorEnd);
|
|
2217
2315
|
|
|
2218
2316
|
const insertBefore = function(parent, child, target) {
|
|
2219
2317
|
const childElement = Validator.isElement(child) ? child : ElementCreator.getChild(child);
|
|
@@ -2228,14 +2326,13 @@ var NativeDocument = (function (exports) {
|
|
|
2228
2326
|
parent.insertBefore(childElement, target);
|
|
2229
2327
|
};
|
|
2230
2328
|
|
|
2231
|
-
anchorFragment.appendElement = function(child
|
|
2329
|
+
anchorFragment.appendElement = function(child) {
|
|
2232
2330
|
const parentNode = anchorStart.parentNode;
|
|
2233
|
-
const targetBefore = before || anchorEnd;
|
|
2234
2331
|
if(parentNode === anchorFragment) {
|
|
2235
|
-
parentNode.nativeInsertBefore(child,
|
|
2332
|
+
parentNode.nativeInsertBefore(child, anchorEnd);
|
|
2236
2333
|
return;
|
|
2237
2334
|
}
|
|
2238
|
-
parentNode
|
|
2335
|
+
parentNode.insertBefore(child, anchorEnd);
|
|
2239
2336
|
};
|
|
2240
2337
|
|
|
2241
2338
|
anchorFragment.appendChild = function(child, before = null) {
|
|
@@ -2248,8 +2345,8 @@ var NativeDocument = (function (exports) {
|
|
|
2248
2345
|
insertBefore(parent, child, before);
|
|
2249
2346
|
};
|
|
2250
2347
|
|
|
2251
|
-
anchorFragment.append = function(
|
|
2252
|
-
return anchorFragment.appendChild(
|
|
2348
|
+
anchorFragment.append = function() {
|
|
2349
|
+
return anchorFragment.appendChild(Array.from(arguments));
|
|
2253
2350
|
};
|
|
2254
2351
|
|
|
2255
2352
|
anchorFragment.removeChildren = function() {
|
|
@@ -2276,6 +2373,7 @@ var NativeDocument = (function (exports) {
|
|
|
2276
2373
|
return;
|
|
2277
2374
|
}
|
|
2278
2375
|
if(isParentUniqueChild(parent)) {
|
|
2376
|
+
anchorFragment.append.apply(anchorFragment, parent.childNodes);
|
|
2279
2377
|
parent.replaceChildren(anchorStart, anchorEnd);
|
|
2280
2378
|
return;
|
|
2281
2379
|
}
|
|
@@ -2320,9 +2418,11 @@ var NativeDocument = (function (exports) {
|
|
|
2320
2418
|
anchorFragment.startElement = function() {
|
|
2321
2419
|
return anchorStart;
|
|
2322
2420
|
};
|
|
2421
|
+
|
|
2323
2422
|
anchorFragment.restore = function() {
|
|
2324
2423
|
anchorFragment.appendChild(anchorFragment);
|
|
2325
2424
|
};
|
|
2425
|
+
|
|
2326
2426
|
anchorFragment.clear = anchorFragment.remove;
|
|
2327
2427
|
anchorFragment.detach = anchorFragment.remove;
|
|
2328
2428
|
|
|
@@ -2773,9 +2873,10 @@ var NativeDocument = (function (exports) {
|
|
|
2773
2873
|
* @returns {Text}
|
|
2774
2874
|
*/
|
|
2775
2875
|
const createTextNode = (value) => {
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2876
|
+
if(value) {
|
|
2877
|
+
return value.toNdElement();
|
|
2878
|
+
}
|
|
2879
|
+
return ElementCreator.createTextNode();
|
|
2779
2880
|
};
|
|
2780
2881
|
|
|
2781
2882
|
|
|
@@ -2869,8 +2970,9 @@ var NativeDocument = (function (exports) {
|
|
|
2869
2970
|
const methods = Object.keys(this.$ndMethods);
|
|
2870
2971
|
if(methods.length === 1) {
|
|
2871
2972
|
const methodName = methods[0];
|
|
2973
|
+
const callback = this.$ndMethods[methodName];
|
|
2872
2974
|
steps.push((clonedNode, data) => {
|
|
2873
|
-
clonedNode.nd[methodName](
|
|
2975
|
+
clonedNode.nd[methodName](callback.bind(clonedNode, ...data));
|
|
2874
2976
|
});
|
|
2875
2977
|
} else {
|
|
2876
2978
|
steps.push((clonedNode, data) => {
|
|
@@ -4356,7 +4458,7 @@ var NativeDocument = (function (exports) {
|
|
|
4356
4458
|
const $getStoreOrThrow = (method, name) => {
|
|
4357
4459
|
const item = $stores.get(name);
|
|
4358
4460
|
if (!item) {
|
|
4359
|
-
DebugManager.error('Store', `Store.${method}('${name}') : store not found. Did you call Store.create('${name}') first?`);
|
|
4461
|
+
DebugManager$1.error('Store', `Store.${method}('${name}') : store not found. Did you call Store.create('${name}') first?`);
|
|
4360
4462
|
throw new NativeDocumentError(
|
|
4361
4463
|
`Store.${method}('${name}') : store not found.`
|
|
4362
4464
|
);
|
|
@@ -4369,7 +4471,7 @@ var NativeDocument = (function (exports) {
|
|
|
4369
4471
|
*/
|
|
4370
4472
|
const $applyReadOnly = (observer, name, context) => {
|
|
4371
4473
|
const readOnlyError = (method) => () => {
|
|
4372
|
-
DebugManager.error('Store', `Store.${context}('${name}') is read-only. '${method}()' is not allowed.`);
|
|
4474
|
+
DebugManager$1.error('Store', `Store.${context}('${name}') is read-only. '${method}()' is not allowed.`);
|
|
4373
4475
|
throw new NativeDocumentError(
|
|
4374
4476
|
`Store.${context}('${name}') is read-only.`
|
|
4375
4477
|
);
|
|
@@ -4400,7 +4502,7 @@ var NativeDocument = (function (exports) {
|
|
|
4400
4502
|
*/
|
|
4401
4503
|
create(name, value) {
|
|
4402
4504
|
if ($stores.has(name)) {
|
|
4403
|
-
DebugManager.warn('Store', `Store.create('${name}') : a store with this name already exists. Use Store.get('${name}') to retrieve it.`);
|
|
4505
|
+
DebugManager$1.warn('Store', `Store.create('${name}') : a store with this name already exists. Use Store.get('${name}') to retrieve it.`);
|
|
4404
4506
|
throw new NativeDocumentError(
|
|
4405
4507
|
`Store.create('${name}') : a store with this name already exists.`
|
|
4406
4508
|
);
|
|
@@ -4421,7 +4523,7 @@ var NativeDocument = (function (exports) {
|
|
|
4421
4523
|
*/
|
|
4422
4524
|
createResettable(name, value) {
|
|
4423
4525
|
if ($stores.has(name)) {
|
|
4424
|
-
DebugManager.warn('Store', `Store.createResettable('${name}') : a store with this name already exists.`);
|
|
4526
|
+
DebugManager$1.warn('Store', `Store.createResettable('${name}') : a store with this name already exists.`);
|
|
4425
4527
|
throw new NativeDocumentError(
|
|
4426
4528
|
`Store.createResettable('${name}') : a store with this name already exists.`
|
|
4427
4529
|
);
|
|
@@ -4457,7 +4559,7 @@ var NativeDocument = (function (exports) {
|
|
|
4457
4559
|
*/
|
|
4458
4560
|
createComposed(name, computation, dependencies) {
|
|
4459
4561
|
if ($stores.has(name)) {
|
|
4460
|
-
DebugManager.warn('Store', `Store.createComposed('${name}') : a store with this name already exists.`);
|
|
4562
|
+
DebugManager$1.warn('Store', `Store.createComposed('${name}') : a store with this name already exists.`);
|
|
4461
4563
|
throw new NativeDocumentError(
|
|
4462
4564
|
`Store.createComposed('${name}') : a store with this name already exists.`
|
|
4463
4565
|
);
|
|
@@ -4480,7 +4582,7 @@ var NativeDocument = (function (exports) {
|
|
|
4480
4582
|
}
|
|
4481
4583
|
const depItem = $stores.get(depName);
|
|
4482
4584
|
if (!depItem) {
|
|
4483
|
-
DebugManager.error('Store', `Store.createComposed('${name}') : dependency '${depName}' not found. Create it first.`);
|
|
4585
|
+
DebugManager$1.error('Store', `Store.createComposed('${name}') : dependency '${depName}' not found. Create it first.`);
|
|
4484
4586
|
throw new NativeDocumentError(
|
|
4485
4587
|
`Store.createComposed('${name}') : dependency store '${depName}' not found.`
|
|
4486
4588
|
);
|
|
@@ -4514,13 +4616,13 @@ var NativeDocument = (function (exports) {
|
|
|
4514
4616
|
reset(name) {
|
|
4515
4617
|
const item = $getStoreOrThrow('reset', name);
|
|
4516
4618
|
if (item.composed) {
|
|
4517
|
-
DebugManager.error('Store', `Store.reset('${name}') : composed stores cannot be reset. Their value is derived from dependencies.`);
|
|
4619
|
+
DebugManager$1.error('Store', `Store.reset('${name}') : composed stores cannot be reset. Their value is derived from dependencies.`);
|
|
4518
4620
|
throw new NativeDocumentError(
|
|
4519
4621
|
`Store.reset('${name}') : composed stores cannot be reset.`
|
|
4520
4622
|
);
|
|
4521
4623
|
}
|
|
4522
4624
|
if (!item.resettable) {
|
|
4523
|
-
DebugManager.error('Store', `Store.reset('${name}') : this store is not resettable. Use Store.createResettable('${name}', value) instead of Store.create().`);
|
|
4625
|
+
DebugManager$1.error('Store', `Store.reset('${name}') : this store is not resettable. Use Store.createResettable('${name}', value) instead of Store.create().`);
|
|
4524
4626
|
throw new NativeDocumentError(
|
|
4525
4627
|
`Store.reset('${name}') : this store is not resettable. Use Store.createResettable('${name}', value) instead of Store.create().`
|
|
4526
4628
|
);
|
|
@@ -4541,7 +4643,7 @@ var NativeDocument = (function (exports) {
|
|
|
4541
4643
|
const item = $getStoreOrThrow('use', name);
|
|
4542
4644
|
|
|
4543
4645
|
if (item.composed) {
|
|
4544
|
-
DebugManager.error('Store', `Store.use('${name}') : composed stores are read-only. Use Store.follow('${name}') instead.`);
|
|
4646
|
+
DebugManager$1.error('Store', `Store.use('${name}') : composed stores are read-only. Use Store.follow('${name}') instead.`);
|
|
4545
4647
|
throw new NativeDocumentError(
|
|
4546
4648
|
`Store.use('${name}') : composed stores are read-only. Use Store.follow('${name}') instead.`
|
|
4547
4649
|
);
|
|
@@ -4608,7 +4710,7 @@ var NativeDocument = (function (exports) {
|
|
|
4608
4710
|
get(name) {
|
|
4609
4711
|
const item = $stores.get(name);
|
|
4610
4712
|
if (!item) {
|
|
4611
|
-
DebugManager.warn('Store', `Store.get('${name}') : store not found.`);
|
|
4713
|
+
DebugManager$1.warn('Store', `Store.get('${name}') : store not found.`);
|
|
4612
4714
|
return null;
|
|
4613
4715
|
}
|
|
4614
4716
|
return item.observer;
|
|
@@ -4630,7 +4732,7 @@ var NativeDocument = (function (exports) {
|
|
|
4630
4732
|
delete(name) {
|
|
4631
4733
|
const item = $stores.get(name);
|
|
4632
4734
|
if (!item) {
|
|
4633
|
-
DebugManager.warn('Store', `Store.delete('${name}') : store not found, nothing to delete.`);
|
|
4735
|
+
DebugManager$1.warn('Store', `Store.delete('${name}') : store not found, nothing to delete.`);
|
|
4634
4736
|
return;
|
|
4635
4737
|
}
|
|
4636
4738
|
item.subscribers.forEach(follower => follower.destroy());
|
|
@@ -4732,7 +4834,7 @@ var NativeDocument = (function (exports) {
|
|
|
4732
4834
|
return undefined;
|
|
4733
4835
|
},
|
|
4734
4836
|
set(target, prop, value) {
|
|
4735
|
-
DebugManager.error('Store', `Forbidden: You cannot overwrite the store key '${String(prop)}'. Use .use('${String(prop)}').set(value) instead.`);
|
|
4837
|
+
DebugManager$1.error('Store', `Forbidden: You cannot overwrite the store key '${String(prop)}'. Use .use('${String(prop)}').set(value) instead.`);
|
|
4736
4838
|
throw new NativeDocumentError(`Store structure is immutable. Use .set() on the observable.`);
|
|
4737
4839
|
},
|
|
4738
4840
|
deleteProperty(target, prop) {
|
|
@@ -4820,7 +4922,7 @@ var NativeDocument = (function (exports) {
|
|
|
4820
4922
|
}
|
|
4821
4923
|
cache.set(keyId, { keyId, isNew: true, child: new WeakRef(child), indexObserver});
|
|
4822
4924
|
} catch (e) {
|
|
4823
|
-
DebugManager.error('ForEach', `Error creating element for key ${keyId}` , e);
|
|
4925
|
+
DebugManager$1.error('ForEach', `Error creating element for key ${keyId}` , e);
|
|
4824
4926
|
throw e;
|
|
4825
4927
|
}
|
|
4826
4928
|
return keyId;
|
|
@@ -5011,21 +5113,23 @@ var NativeDocument = (function (exports) {
|
|
|
5011
5113
|
};
|
|
5012
5114
|
|
|
5013
5115
|
|
|
5014
|
-
|
|
5015
|
-
|
|
5016
|
-
|
|
5017
|
-
|
|
5018
|
-
|
|
5019
|
-
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
|
|
5023
|
-
|
|
5024
|
-
|
|
5116
|
+
let cleanCache;
|
|
5117
|
+
|
|
5118
|
+
if(!isIndexRequired) {
|
|
5119
|
+
cleanCache = cache.clear.bind(cache);
|
|
5120
|
+
}
|
|
5121
|
+
else if(configs.shouldKeepItemsInCache) {
|
|
5122
|
+
cleanCache = () => {};
|
|
5123
|
+
} else {
|
|
5124
|
+
cleanCache = (items) => {
|
|
5125
|
+
for (const [itemAsKey, _] of cache.entries()) {
|
|
5126
|
+
if(items && items.includes(itemAsKey)) {
|
|
5127
|
+
continue;
|
|
5128
|
+
}
|
|
5129
|
+
removeCacheItem(itemAsKey, false);
|
|
5025
5130
|
}
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
};
|
|
5131
|
+
};
|
|
5132
|
+
}
|
|
5029
5133
|
|
|
5030
5134
|
const removeByItem = (item, fragment) => {
|
|
5031
5135
|
const cacheItem = cache.get(item);
|
|
@@ -5045,7 +5149,7 @@ var NativeDocument = (function (exports) {
|
|
|
5045
5149
|
};
|
|
5046
5150
|
|
|
5047
5151
|
const Actions = {
|
|
5048
|
-
toFragment(items){
|
|
5152
|
+
toFragment: (items) =>{
|
|
5049
5153
|
const fragment = document.createDocumentFragment();
|
|
5050
5154
|
for(let i = 0, length = items.length; i < length; i++) {
|
|
5051
5155
|
fragment.appendChild(buildItem(items[i], lastNumberOfItems));
|
|
@@ -5053,14 +5157,14 @@ var NativeDocument = (function (exports) {
|
|
|
5053
5157
|
}
|
|
5054
5158
|
return fragment;
|
|
5055
5159
|
},
|
|
5056
|
-
add(items) {
|
|
5160
|
+
add: (items) => {
|
|
5057
5161
|
element.appendElement(Actions.toFragment(items));
|
|
5058
5162
|
},
|
|
5059
|
-
replace(items) {
|
|
5163
|
+
replace: (items) => {
|
|
5060
5164
|
clear(items);
|
|
5061
5165
|
Actions.add(items);
|
|
5062
5166
|
},
|
|
5063
|
-
reOrder(items) {
|
|
5167
|
+
reOrder: (items) => {
|
|
5064
5168
|
let child = null;
|
|
5065
5169
|
const fragment = document.createDocumentFragment();
|
|
5066
5170
|
for(const item of items) {
|
|
@@ -5072,14 +5176,14 @@ var NativeDocument = (function (exports) {
|
|
|
5072
5176
|
child = null;
|
|
5073
5177
|
element.appendElement(fragment, blockEnd);
|
|
5074
5178
|
},
|
|
5075
|
-
removeOne(element, index) {
|
|
5179
|
+
removeOne: (element, index) => {
|
|
5076
5180
|
removeCacheItem(element, true);
|
|
5077
5181
|
},
|
|
5078
5182
|
clear,
|
|
5079
|
-
merge(items) {
|
|
5183
|
+
merge: (items) => {
|
|
5080
5184
|
Actions.add(items);
|
|
5081
5185
|
},
|
|
5082
|
-
push(items) {
|
|
5186
|
+
push: (items) => {
|
|
5083
5187
|
let delay = 0;
|
|
5084
5188
|
if(configs.pushDelay) {
|
|
5085
5189
|
delay = configs.pushDelay(items) ?? 0;
|
|
@@ -5087,7 +5191,7 @@ var NativeDocument = (function (exports) {
|
|
|
5087
5191
|
|
|
5088
5192
|
Actions.add(items, delay);
|
|
5089
5193
|
},
|
|
5090
|
-
populate([target, iteration, callback]) {
|
|
5194
|
+
populate: ([target, iteration, callback]) => {
|
|
5091
5195
|
const fragment = document.createDocumentFragment();
|
|
5092
5196
|
for (let i = 0; i < iteration; i++) {
|
|
5093
5197
|
const data = callback(i);
|
|
@@ -5098,10 +5202,10 @@ var NativeDocument = (function (exports) {
|
|
|
5098
5202
|
element.appendChild(fragment);
|
|
5099
5203
|
fragment.replaceChildren();
|
|
5100
5204
|
},
|
|
5101
|
-
unshift(values){
|
|
5205
|
+
unshift: (values) => {
|
|
5102
5206
|
element.insertBefore(Actions.toFragment(values), blockStart.nextSibling);
|
|
5103
5207
|
},
|
|
5104
|
-
splice(args, deleted) {
|
|
5208
|
+
splice: (args, deleted) => {
|
|
5105
5209
|
const [start, deleteCount, ...values] = args;
|
|
5106
5210
|
let elementBeforeFirst = null;
|
|
5107
5211
|
const garbageFragment = document.createDocumentFragment();
|
|
@@ -5128,22 +5232,22 @@ var NativeDocument = (function (exports) {
|
|
|
5128
5232
|
}
|
|
5129
5233
|
|
|
5130
5234
|
},
|
|
5131
|
-
reverse(_, reversed) {
|
|
5235
|
+
reverse: (_, reversed) => {
|
|
5132
5236
|
Actions.reOrder(reversed);
|
|
5133
5237
|
},
|
|
5134
|
-
sort(_, sorted) {
|
|
5238
|
+
sort: (_, sorted) => {
|
|
5135
5239
|
Actions.reOrder(sorted);
|
|
5136
5240
|
},
|
|
5137
|
-
remove(_, deleted) {
|
|
5241
|
+
remove: (_, deleted)=> {
|
|
5138
5242
|
Actions.removeOne(deleted);
|
|
5139
5243
|
},
|
|
5140
|
-
pop(_, deleted) {
|
|
5244
|
+
pop: (_, deleted) => {
|
|
5141
5245
|
Actions.removeOne(deleted);
|
|
5142
5246
|
},
|
|
5143
|
-
shift(_, deleted) {
|
|
5247
|
+
shift: (_, deleted) => {
|
|
5144
5248
|
Actions.removeOne(deleted);
|
|
5145
5249
|
},
|
|
5146
|
-
swap(args, elements) {
|
|
5250
|
+
swap: (args, elements) => {
|
|
5147
5251
|
const parent = blockEnd.parentNode;
|
|
5148
5252
|
|
|
5149
5253
|
let childA = getItemChild(elements[0]);
|
|
@@ -5210,7 +5314,7 @@ var NativeDocument = (function (exports) {
|
|
|
5210
5314
|
*/
|
|
5211
5315
|
const ShowIf = function(condition, child, { comment = null, shouldKeepInCache = true} = {}) {
|
|
5212
5316
|
if(!(Validator.isObservable(condition)) && !Validator.isObservableWhenResult(condition)) {
|
|
5213
|
-
return DebugManager.warn('ShowIf', "ShowIf : condition must be an Observable / "+comment, condition);
|
|
5317
|
+
return DebugManager$1.warn('ShowIf', "ShowIf : condition must be an Observable / "+comment, condition);
|
|
5214
5318
|
}
|
|
5215
5319
|
const element = Anchor('Show if : '+(comment || ''));
|
|
5216
5320
|
|
|
@@ -6629,7 +6733,7 @@ var NativeDocument = (function (exports) {
|
|
|
6629
6733
|
window.history.pushState({ name: route.name(), params, path}, route.name() || path , path);
|
|
6630
6734
|
this.handleRouteChange(route, params, query, path);
|
|
6631
6735
|
} catch (e) {
|
|
6632
|
-
DebugManager.error('HistoryRouter', 'Error in pushState', e);
|
|
6736
|
+
DebugManager$1.error('HistoryRouter', 'Error in pushState', e);
|
|
6633
6737
|
}
|
|
6634
6738
|
};
|
|
6635
6739
|
/**
|
|
@@ -6642,7 +6746,7 @@ var NativeDocument = (function (exports) {
|
|
|
6642
6746
|
window.history.replaceState({ name: route.name(), params, path}, route.name() || path , path);
|
|
6643
6747
|
this.handleRouteChange(route, params, {}, path);
|
|
6644
6748
|
} catch(e) {
|
|
6645
|
-
DebugManager.error('HistoryRouter', 'Error in replaceState', e);
|
|
6749
|
+
DebugManager$1.error('HistoryRouter', 'Error in replaceState', e);
|
|
6646
6750
|
}
|
|
6647
6751
|
};
|
|
6648
6752
|
this.forward = function() {
|
|
@@ -6669,7 +6773,7 @@ var NativeDocument = (function (exports) {
|
|
|
6669
6773
|
}
|
|
6670
6774
|
this.handleRouteChange(route, params, query, path);
|
|
6671
6775
|
} catch(e) {
|
|
6672
|
-
DebugManager.error('HistoryRouter', 'Error in popstate event', e);
|
|
6776
|
+
DebugManager$1.error('HistoryRouter', 'Error in popstate event', e);
|
|
6673
6777
|
}
|
|
6674
6778
|
});
|
|
6675
6779
|
const { route, params, query, path } = this.resolve(defaultPath || (window.location.pathname+window.location.search));
|
|
@@ -6894,7 +6998,7 @@ var NativeDocument = (function (exports) {
|
|
|
6894
6998
|
listener(request);
|
|
6895
6999
|
next && next(request);
|
|
6896
7000
|
} catch (e) {
|
|
6897
|
-
DebugManager.warn('Route Listener', 'Error in listener:', e);
|
|
7001
|
+
DebugManager$1.warn('Route Listener', 'Error in listener:', e);
|
|
6898
7002
|
}
|
|
6899
7003
|
}
|
|
6900
7004
|
};
|
|
@@ -7072,7 +7176,7 @@ var NativeDocument = (function (exports) {
|
|
|
7072
7176
|
*/
|
|
7073
7177
|
Router.create = function(options, callback) {
|
|
7074
7178
|
if(!Validator.isFunction(callback)) {
|
|
7075
|
-
DebugManager.error('Router', 'Callback must be a function');
|
|
7179
|
+
DebugManager$1.error('Router', 'Callback must be a function');
|
|
7076
7180
|
throw new RouterError('Callback must be a function');
|
|
7077
7181
|
}
|
|
7078
7182
|
const router = new Router(options);
|