native-document 1.0.87 → 1.0.89
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 +89 -95
- package/dist/native-document.dev.js +111 -130
- 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/ObservableChecker.js +4 -4
- package/src/core/data/ObservableItem.js +19 -14
- package/src/core/data/ObservableWhen.js +2 -2
- package/src/core/utils/callback-handler.js +21 -0
- package/src/core/wrappers/AttributesWrapper.js +49 -59
- package/src/core/wrappers/ElementCreator.js +8 -0
- package/src/core/wrappers/TemplateCloner.js +10 -22
- package/src/core/wrappers/prototypes/bind-class-extensions.js +7 -3
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
var NativeDocument = (function (exports) {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
let DebugManager = {};
|
|
4
|
+
let DebugManager$1 = {};
|
|
5
5
|
|
|
6
6
|
{
|
|
7
|
-
DebugManager = {
|
|
7
|
+
DebugManager$1 = {
|
|
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
|
|
38
|
+
var DebugManager = DebugManager$1;
|
|
39
39
|
|
|
40
40
|
const MemoryManager = (function() {
|
|
41
41
|
|
|
@@ -84,7 +84,7 @@ var NativeDocument = (function (exports) {
|
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
if (cleanedCount > 0) {
|
|
87
|
-
DebugManager
|
|
87
|
+
DebugManager.log('Memory Auto Clean', `🧹 Cleaned ${cleanedCount} orphaned observables`);
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
};
|
|
@@ -113,10 +113,10 @@ var NativeDocument = (function (exports) {
|
|
|
113
113
|
|
|
114
114
|
ObservableChecker.prototype.__$isObservableChecker = true;
|
|
115
115
|
|
|
116
|
-
ObservableChecker.prototype.subscribe = function(callback) {
|
|
117
|
-
const unSubscribe = this.observable.subscribe((value) => {
|
|
118
|
-
callback && callback(this.checker(value));
|
|
119
|
-
});
|
|
116
|
+
ObservableChecker.prototype.subscribe = function(callback, context = null) {
|
|
117
|
+
const unSubscribe = this.observable.subscribe((value, _, __) => {
|
|
118
|
+
callback && callback(this.checker(value), _, __, context);
|
|
119
|
+
}, context);
|
|
120
120
|
this.unSubscriptions.push(unSubscribe);
|
|
121
121
|
return unSubscribe;
|
|
122
122
|
};
|
|
@@ -210,7 +210,7 @@ var NativeDocument = (function (exports) {
|
|
|
210
210
|
try{
|
|
211
211
|
callback.call(plugin, ...data);
|
|
212
212
|
} catch (error) {
|
|
213
|
-
DebugManager
|
|
213
|
+
DebugManager.error('Plugin Manager', `Error in plugin ${plugin.$name} for event ${eventName}`, error);
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
}
|
|
@@ -228,8 +228,8 @@ var NativeDocument = (function (exports) {
|
|
|
228
228
|
|
|
229
229
|
ObservableWhen.prototype.__$isObservableWhen = true;
|
|
230
230
|
|
|
231
|
-
ObservableWhen.prototype.subscribe = function(callback) {
|
|
232
|
-
return this.$observer.on(this.$target, callback);
|
|
231
|
+
ObservableWhen.prototype.subscribe = function(callback, context = null) {
|
|
232
|
+
return this.$observer.on(this.$target, callback, context);
|
|
233
233
|
};
|
|
234
234
|
|
|
235
235
|
ObservableWhen.prototype.val = function() {
|
|
@@ -365,7 +365,7 @@ var NativeDocument = (function (exports) {
|
|
|
365
365
|
};
|
|
366
366
|
|
|
367
367
|
ObservableItem.prototype.triggerFirstListener = function(operations) {
|
|
368
|
-
this.$firstListener(this.$currentValue, this.$previousValue, operations || {});
|
|
368
|
+
this.$firstListener.callback(this.$currentValue, this.$previousValue, operations || {}, this.$firstListener.context);
|
|
369
369
|
};
|
|
370
370
|
|
|
371
371
|
ObservableItem.prototype.triggerListeners = function(operations) {
|
|
@@ -375,14 +375,14 @@ var NativeDocument = (function (exports) {
|
|
|
375
375
|
|
|
376
376
|
operations = operations || DEFAULT_OPERATIONS;
|
|
377
377
|
for(let i = 0, length = $listeners.length; i < length; i++) {
|
|
378
|
-
$listeners[i];
|
|
379
|
-
|
|
378
|
+
const listener = $listeners[i];
|
|
379
|
+
listener.callback($currentValue, $previousValue, operations, listener.context);
|
|
380
380
|
}
|
|
381
381
|
};
|
|
382
382
|
|
|
383
383
|
const handleWatcherCallback = function(callbacks, value) {
|
|
384
|
-
if(
|
|
385
|
-
callbacks(value);
|
|
384
|
+
if(callbacks.callback) {
|
|
385
|
+
callbacks.callback(value, null, null, callbacks.context);
|
|
386
386
|
return;
|
|
387
387
|
}
|
|
388
388
|
if (callbacks.set) {
|
|
@@ -390,7 +390,9 @@ var NativeDocument = (function (exports) {
|
|
|
390
390
|
return;
|
|
391
391
|
}
|
|
392
392
|
callbacks.forEach(callback => {
|
|
393
|
-
callback.
|
|
393
|
+
callback.callback
|
|
394
|
+
? callback.callback(value, null, null, callback.context)
|
|
395
|
+
: callback.set(value);
|
|
394
396
|
});
|
|
395
397
|
};
|
|
396
398
|
|
|
@@ -519,26 +521,29 @@ var NativeDocument = (function (exports) {
|
|
|
519
521
|
/**
|
|
520
522
|
*
|
|
521
523
|
* @param {Function} callback
|
|
524
|
+
* @param {?Object} context
|
|
522
525
|
* @param {any} target
|
|
523
526
|
* @returns {(function(): void)}
|
|
524
527
|
*/
|
|
525
|
-
ObservableItem.prototype.subscribe = function(callback, target = null) {
|
|
528
|
+
ObservableItem.prototype.subscribe = function(callback, context = null, target = null) {
|
|
526
529
|
this.$listeners = this.$listeners ?? [];
|
|
527
530
|
if (this.$isCleanedUp) {
|
|
528
|
-
DebugManager
|
|
531
|
+
DebugManager.warn('Observable subscription', '⚠️ Attempted to subscribe to a cleaned up observable.');
|
|
529
532
|
return () => {};
|
|
530
533
|
}
|
|
531
534
|
if (typeof callback !== 'function') {
|
|
532
535
|
throw new NativeDocumentError('Callback must be a function');
|
|
533
536
|
}
|
|
534
537
|
|
|
535
|
-
|
|
538
|
+
|
|
539
|
+
const finalCallback = { callback, context };
|
|
540
|
+
this.$listeners.push(finalCallback);
|
|
536
541
|
this.assocTrigger();
|
|
537
542
|
{
|
|
538
543
|
PluginsManager.emit('ObservableSubscribe', this, target);
|
|
539
544
|
}
|
|
540
545
|
return () => {
|
|
541
|
-
this.unsubscribe(
|
|
546
|
+
this.unsubscribe(finalCallback);
|
|
542
547
|
this.assocTrigger();
|
|
543
548
|
{
|
|
544
549
|
PluginsManager.emit('ObservableUnsubscribe', this);
|
|
@@ -546,24 +551,24 @@ var NativeDocument = (function (exports) {
|
|
|
546
551
|
};
|
|
547
552
|
};
|
|
548
553
|
|
|
549
|
-
ObservableItem.prototype.on = function(value, callback) {
|
|
554
|
+
ObservableItem.prototype.on = function(value, callback, context = null) {
|
|
550
555
|
this.$watchers = this.$watchers ?? new Map();
|
|
551
556
|
|
|
552
557
|
let watchValueList = this.$watchers.get(value);
|
|
558
|
+
const finalCallback = { callback, context };
|
|
553
559
|
|
|
554
560
|
if(!watchValueList) {
|
|
555
|
-
this.$watchers.set(value,
|
|
561
|
+
this.$watchers.set(value, finalCallback);
|
|
556
562
|
} else if(!Validator.isArray(watchValueList)) {
|
|
557
|
-
watchValueList = [watchValueList];
|
|
563
|
+
watchValueList = [watchValueList, finalCallback];
|
|
558
564
|
this.$watchers.set(value, watchValueList);
|
|
559
|
-
return;
|
|
560
565
|
} else {
|
|
561
|
-
watchValueList.push(
|
|
566
|
+
watchValueList.push(finalCallback);
|
|
562
567
|
}
|
|
563
568
|
|
|
564
569
|
this.assocTrigger();
|
|
565
570
|
return () => {
|
|
566
|
-
const index = watchValueList.indexOf(
|
|
571
|
+
const index = watchValueList.indexOf(finalCallback);
|
|
567
572
|
watchValueList?.splice(index, 1);
|
|
568
573
|
if(watchValueList.size === 1) {
|
|
569
574
|
this.$watchers.set(value, watchValueList[0]);
|
|
@@ -884,7 +889,7 @@ var NativeDocument = (function (exports) {
|
|
|
884
889
|
}
|
|
885
890
|
{
|
|
886
891
|
if (this[name] && !this.$localExtensions.has(name)) {
|
|
887
|
-
DebugManager
|
|
892
|
+
DebugManager.warn('NDElement.extend', `Method "${name}" already exists and will be overwritten`);
|
|
888
893
|
}
|
|
889
894
|
this.$localExtensions.set(name, method);
|
|
890
895
|
}
|
|
@@ -918,17 +923,17 @@ var NativeDocument = (function (exports) {
|
|
|
918
923
|
const method = methods[name];
|
|
919
924
|
|
|
920
925
|
if (typeof method !== 'function') {
|
|
921
|
-
DebugManager
|
|
926
|
+
DebugManager.warn('NDElement.extend', `"${name}" is not a function, skipping`);
|
|
922
927
|
continue;
|
|
923
928
|
}
|
|
924
929
|
|
|
925
930
|
if (protectedMethods.has(name)) {
|
|
926
|
-
DebugManager
|
|
931
|
+
DebugManager.error('NDElement.extend', `Cannot override protected method "${name}"`);
|
|
927
932
|
throw new NativeDocumentError(`Cannot override protected method "${name}"`);
|
|
928
933
|
}
|
|
929
934
|
|
|
930
935
|
if (NDElement.prototype[name]) {
|
|
931
|
-
DebugManager
|
|
936
|
+
DebugManager.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
|
|
932
937
|
}
|
|
933
938
|
|
|
934
939
|
NDElement.prototype[name] = method;
|
|
@@ -1087,7 +1092,7 @@ var NativeDocument = (function (exports) {
|
|
|
1087
1092
|
const foundReserved = Object.keys(attributes).filter(key => reserved.includes(key));
|
|
1088
1093
|
|
|
1089
1094
|
if (foundReserved.length > 0) {
|
|
1090
|
-
DebugManager
|
|
1095
|
+
DebugManager.warn('Validator', `Reserved attributes found: ${foundReserved.join(', ')}`);
|
|
1091
1096
|
}
|
|
1092
1097
|
|
|
1093
1098
|
return attributes;
|
|
@@ -1135,7 +1140,7 @@ var NativeDocument = (function (exports) {
|
|
|
1135
1140
|
anchorFragment.appendChild = function(child, before = null) {
|
|
1136
1141
|
const parent = anchorEnd.parentNode;
|
|
1137
1142
|
if(!parent) {
|
|
1138
|
-
DebugManager
|
|
1143
|
+
DebugManager.error('Anchor', 'Anchor : parent not found', child);
|
|
1139
1144
|
return;
|
|
1140
1145
|
}
|
|
1141
1146
|
before = before ?? anchorEnd;
|
|
@@ -1349,60 +1354,29 @@ var NativeDocument = (function (exports) {
|
|
|
1349
1354
|
setInterval(() => MemoryManager.cleanObservables(threshold), interval);
|
|
1350
1355
|
};
|
|
1351
1356
|
|
|
1352
|
-
|
|
1353
|
-
element.classes.toggle(className,
|
|
1354
|
-
this.subscribe(toggleElementClass.bind(null, element, className));
|
|
1357
|
+
const handleElementAttributeClass = function(shouldAdd, _, __, context) {
|
|
1358
|
+
context.element.classes.toggle(context.className, shouldAdd);
|
|
1355
1359
|
};
|
|
1356
|
-
|
|
1357
|
-
ObservableWhen.prototype.bindNdClass = function(element, className) {
|
|
1358
|
-
element.classes.toggle(className, this.isMath());
|
|
1359
|
-
this.subscribe(toggleElementClass.bind(null, element, className));
|
|
1360
|
-
};
|
|
1361
|
-
|
|
1362
|
-
TemplateBinding.prototype.bindNdClass = function(element, className) {
|
|
1363
|
-
this.$hydrate(element, className);
|
|
1364
|
-
};
|
|
1365
|
-
|
|
1366
|
-
function toggleElementClass(element, className, shouldAdd) {
|
|
1367
|
-
element.classes.toggle(className, shouldAdd);
|
|
1368
|
-
}
|
|
1369
|
-
|
|
1370
|
-
function toggleElementStyle(element, styleName, newValue) {
|
|
1371
|
-
element.style[styleName] = newValue;
|
|
1372
|
-
}
|
|
1373
|
-
|
|
1374
|
-
function updateInputFromObserver(element, attributeName, newValue) {
|
|
1375
|
-
if(Validator.isBoolean(newValue)) {
|
|
1376
|
-
element[attributeName] = newValue;
|
|
1377
|
-
return;
|
|
1378
|
-
}
|
|
1379
|
-
element[attributeName] = newValue === element.value;
|
|
1380
|
-
}
|
|
1381
|
-
|
|
1382
|
-
function updateObserverFromInput(element, attributeName, defaultValue, value) {
|
|
1383
|
-
if(Validator.isBoolean(defaultValue)) {
|
|
1384
|
-
value.set(element[attributeName]);
|
|
1385
|
-
return;
|
|
1386
|
-
}
|
|
1387
|
-
value.set(element.value);
|
|
1388
|
-
}
|
|
1389
|
-
|
|
1390
1360
|
/**
|
|
1391
1361
|
*
|
|
1392
1362
|
* @param {HTMLElement} element
|
|
1393
1363
|
* @param {Object} data
|
|
1394
1364
|
*/
|
|
1395
1365
|
function bindClassAttribute(element, data) {
|
|
1396
|
-
|
|
1366
|
+
const classNames = Object.keys(data);
|
|
1367
|
+
|
|
1368
|
+
for(let i = 0, length = classNames.length; i < length; i++) {
|
|
1369
|
+
const className = classNames[i];
|
|
1397
1370
|
const value = data[className];
|
|
1398
|
-
if(
|
|
1371
|
+
if(value.__$isObservable) {
|
|
1399
1372
|
element.classes.toggle(className, value.val());
|
|
1400
|
-
value.subscribe(
|
|
1373
|
+
value.subscribe(handleElementAttributeClass, { element, className });
|
|
1374
|
+
// value.subscribe((shouldAdd) => element.classes.toggle(className, shouldAdd));
|
|
1401
1375
|
continue;
|
|
1402
1376
|
}
|
|
1403
|
-
if(
|
|
1377
|
+
if(value.__$isObservableWhen) {
|
|
1404
1378
|
element.classes.toggle(className, value.isMath());
|
|
1405
|
-
value.subscribe(
|
|
1379
|
+
value.subscribe(handleElementAttributeClass, { element, className });
|
|
1406
1380
|
continue;
|
|
1407
1381
|
}
|
|
1408
1382
|
if(value.$hydrate) {
|
|
@@ -1411,7 +1385,6 @@ var NativeDocument = (function (exports) {
|
|
|
1411
1385
|
}
|
|
1412
1386
|
element.classes.toggle(className, value);
|
|
1413
1387
|
}
|
|
1414
|
-
data = null;
|
|
1415
1388
|
}
|
|
1416
1389
|
|
|
1417
1390
|
/**
|
|
@@ -1420,11 +1393,13 @@ var NativeDocument = (function (exports) {
|
|
|
1420
1393
|
* @param {Object} data
|
|
1421
1394
|
*/
|
|
1422
1395
|
function bindStyleAttribute(element, data) {
|
|
1423
|
-
|
|
1396
|
+
const keys = Object.keys(data);
|
|
1397
|
+
for(let i = 0, length = keys.length; i < length; i++) {
|
|
1398
|
+
const styleName = keys[i];
|
|
1424
1399
|
const value = data[styleName];
|
|
1425
|
-
if(
|
|
1400
|
+
if(value.__$isObservable) {
|
|
1426
1401
|
element.style[styleName] = value.val();
|
|
1427
|
-
value.subscribe(
|
|
1402
|
+
value.subscribe((newValue) => element.style[styleName] = newValue);
|
|
1428
1403
|
continue;
|
|
1429
1404
|
}
|
|
1430
1405
|
element.style[styleName] = value;
|
|
@@ -1438,18 +1413,27 @@ var NativeDocument = (function (exports) {
|
|
|
1438
1413
|
* @param {boolean|number|Observable} value
|
|
1439
1414
|
*/
|
|
1440
1415
|
function bindBooleanAttribute(element, attributeName, value) {
|
|
1441
|
-
const
|
|
1442
|
-
|
|
1416
|
+
const isObservable = value.__$isObservable;
|
|
1417
|
+
const defaultValue = isObservable? value.val() : value;
|
|
1418
|
+
const isBoolValue = typeof defaultValue === "boolean";
|
|
1419
|
+
if(isBoolValue) {
|
|
1443
1420
|
element[attributeName] = defaultValue;
|
|
1444
1421
|
}
|
|
1445
1422
|
else {
|
|
1446
1423
|
element[attributeName] = defaultValue === element.value;
|
|
1447
1424
|
}
|
|
1448
|
-
if(
|
|
1449
|
-
if(
|
|
1450
|
-
|
|
1425
|
+
if(isObservable) {
|
|
1426
|
+
if(attributeName === 'checked') {
|
|
1427
|
+
if(isBoolValue) {
|
|
1428
|
+
element.addEventListener('input', () => value.set(element[attributeName]));
|
|
1429
|
+
value.subscribe((newValue) => element[attributeName] = newValue);
|
|
1430
|
+
return;
|
|
1431
|
+
}
|
|
1432
|
+
element.addEventListener('input', () => value.set(element.value));
|
|
1433
|
+
value.subscribe((newValue) => element[attributeName] = (newValue === element.value));
|
|
1434
|
+
return;
|
|
1451
1435
|
}
|
|
1452
|
-
value.subscribe(
|
|
1436
|
+
value.subscribe((newValue) => element[attributeName] = (newValue === element.value));
|
|
1453
1437
|
}
|
|
1454
1438
|
}
|
|
1455
1439
|
|
|
@@ -1461,19 +1445,15 @@ var NativeDocument = (function (exports) {
|
|
|
1461
1445
|
* @param {Observable} value
|
|
1462
1446
|
*/
|
|
1463
1447
|
function bindAttributeWithObservable(element, attributeName, value) {
|
|
1464
|
-
const applyValue = (newValue) => {
|
|
1465
|
-
if(attributeName === 'value') {
|
|
1466
|
-
element.value = newValue;
|
|
1467
|
-
return;
|
|
1468
|
-
}
|
|
1469
|
-
element.setAttribute(attributeName, newValue);
|
|
1470
|
-
};
|
|
1471
|
-
applyValue(value.val());
|
|
1472
|
-
value.subscribe(applyValue);
|
|
1473
|
-
|
|
1474
1448
|
if(attributeName === 'value') {
|
|
1449
|
+
value.subscribe((newValue) => element.value = newValue);
|
|
1450
|
+
element.value = value.val();
|
|
1475
1451
|
element.addEventListener('input', () => value.set(element.value));
|
|
1452
|
+
return;
|
|
1476
1453
|
}
|
|
1454
|
+
|
|
1455
|
+
value.subscribe((newValue) => element.setAttribute(attributeName, newValue));
|
|
1456
|
+
element.setAttribute(attributeName, value.val());
|
|
1477
1457
|
}
|
|
1478
1458
|
|
|
1479
1459
|
/**
|
|
@@ -1483,15 +1463,15 @@ var NativeDocument = (function (exports) {
|
|
|
1483
1463
|
*/
|
|
1484
1464
|
function AttributesWrapper(element, attributes) {
|
|
1485
1465
|
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
if(!Validator.isObject(attributes)) {
|
|
1489
|
-
throw new NativeDocumentError('Attributes must be an object');
|
|
1466
|
+
{
|
|
1467
|
+
Validator.validateAttributes(attributes);
|
|
1490
1468
|
}
|
|
1469
|
+
const attributeNames = Object.keys(attributes);
|
|
1491
1470
|
|
|
1492
|
-
for(let
|
|
1493
|
-
const
|
|
1494
|
-
|
|
1471
|
+
for(let i = 0, length = attributeNames.length; i < length; i++) {
|
|
1472
|
+
const originalAttributeName = attributeNames[i];
|
|
1473
|
+
const attributeName = originalAttributeName.toLowerCase();
|
|
1474
|
+
let value = attributes[originalAttributeName];
|
|
1495
1475
|
if(value == null) {
|
|
1496
1476
|
continue;
|
|
1497
1477
|
}
|
|
@@ -1514,6 +1494,10 @@ var NativeDocument = (function (exports) {
|
|
|
1514
1494
|
continue;
|
|
1515
1495
|
}
|
|
1516
1496
|
|
|
1497
|
+
if(attributeName === 'value') {
|
|
1498
|
+
element.value = value;
|
|
1499
|
+
continue;
|
|
1500
|
+
}
|
|
1517
1501
|
element.setAttribute(attributeName, value);
|
|
1518
1502
|
}
|
|
1519
1503
|
return element;
|
|
@@ -1654,6 +1638,14 @@ var NativeDocument = (function (exports) {
|
|
|
1654
1638
|
}
|
|
1655
1639
|
return Anchor('Fragment');
|
|
1656
1640
|
},
|
|
1641
|
+
bindTextNode(textNode, value) {
|
|
1642
|
+
if(value?.__$isObservable) {
|
|
1643
|
+
value.subscribe(newValue => textNode.nodeValue = newValue);
|
|
1644
|
+
textNode.nodeValue = value.val();
|
|
1645
|
+
return;
|
|
1646
|
+
}
|
|
1647
|
+
textNode.nodeValue = value;
|
|
1648
|
+
},
|
|
1657
1649
|
/**
|
|
1658
1650
|
*
|
|
1659
1651
|
* @param {*} children
|
|
@@ -2189,9 +2181,8 @@ var NativeDocument = (function (exports) {
|
|
|
2189
2181
|
|
|
2190
2182
|
|
|
2191
2183
|
const applyBindingTreePath = (root, target, data, path) => {
|
|
2192
|
-
let newTarget = null;
|
|
2193
2184
|
if(path.fn) {
|
|
2194
|
-
|
|
2185
|
+
path.fn(data, target, root);
|
|
2195
2186
|
}
|
|
2196
2187
|
if(path.children) {
|
|
2197
2188
|
for(let i = 0, length = path.children.length; i < length; i++) {
|
|
@@ -2200,7 +2191,6 @@ var NativeDocument = (function (exports) {
|
|
|
2200
2191
|
applyBindingTreePath(root, pathTargetNode, data, currentPath);
|
|
2201
2192
|
}
|
|
2202
2193
|
}
|
|
2203
|
-
return newTarget;
|
|
2204
2194
|
};
|
|
2205
2195
|
|
|
2206
2196
|
function TemplateCloner($fn) {
|
|
@@ -2216,15 +2206,10 @@ var NativeDocument = (function (exports) {
|
|
|
2216
2206
|
const bindDingData = cloneBindingsDataCache.get(node);
|
|
2217
2207
|
if(node.nodeType === 3) {
|
|
2218
2208
|
if(bindDingData && bindDingData.value) {
|
|
2219
|
-
currentPath.fn =
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
}
|
|
2224
|
-
targetNode.replaceWith(newNode);
|
|
2225
|
-
return null;
|
|
2226
|
-
};
|
|
2227
|
-
return bindDingData.value(data);
|
|
2209
|
+
currentPath.fn = bindDingData.value;
|
|
2210
|
+
const textNode = node.cloneNode();
|
|
2211
|
+
bindDingData.value(data, textNode);
|
|
2212
|
+
return textNode;
|
|
2228
2213
|
}
|
|
2229
2214
|
return node.cloneNode(true);
|
|
2230
2215
|
}
|
|
@@ -2261,11 +2246,7 @@ var NativeDocument = (function (exports) {
|
|
|
2261
2246
|
const cloneWithBindingPaths = (data) => {
|
|
2262
2247
|
let root = $node.cloneNode(true);
|
|
2263
2248
|
|
|
2264
|
-
|
|
2265
|
-
if(newRoot) {
|
|
2266
|
-
root = newRoot;
|
|
2267
|
-
}
|
|
2268
|
-
|
|
2249
|
+
applyBindingTreePath(root, root, data, $bindingTreePath);
|
|
2269
2250
|
return root;
|
|
2270
2251
|
};
|
|
2271
2252
|
|
|
@@ -2300,13 +2281,13 @@ var NativeDocument = (function (exports) {
|
|
|
2300
2281
|
};
|
|
2301
2282
|
this.value = (callbackOrProperty) => {
|
|
2302
2283
|
if(typeof callbackOrProperty !== 'function') {
|
|
2303
|
-
return createBinding(function(data) {
|
|
2284
|
+
return createBinding(function(data, textNode) {
|
|
2304
2285
|
const firstArgument = data[0];
|
|
2305
|
-
|
|
2286
|
+
ElementCreator.bindTextNode(textNode, firstArgument[callbackOrProperty]);
|
|
2306
2287
|
}, 'value');
|
|
2307
2288
|
}
|
|
2308
|
-
return createBinding(function(data) {
|
|
2309
|
-
|
|
2289
|
+
return createBinding(function(data, textNode) {
|
|
2290
|
+
ElementCreator.bindTextNode(textNode, callbackOrProperty(...data));
|
|
2310
2291
|
}, 'value');
|
|
2311
2292
|
};
|
|
2312
2293
|
this.attr = (fn) => {
|
|
@@ -3466,7 +3447,7 @@ var NativeDocument = (function (exports) {
|
|
|
3466
3447
|
}
|
|
3467
3448
|
cache.set(keyId, { keyId, isNew: true, child: new WeakRef(child), indexObserver});
|
|
3468
3449
|
} catch (e) {
|
|
3469
|
-
DebugManager
|
|
3450
|
+
DebugManager.error('ForEach', `Error creating element for key ${keyId}` , e);
|
|
3470
3451
|
throw e;
|
|
3471
3452
|
}
|
|
3472
3453
|
return keyId;
|
|
@@ -3812,7 +3793,7 @@ var NativeDocument = (function (exports) {
|
|
|
3812
3793
|
*/
|
|
3813
3794
|
const ShowIf = function(condition, child, { comment = null, shouldKeepInCache = true} = {}) {
|
|
3814
3795
|
if(!(Validator.isObservable(condition)) && !Validator.isObservableWhenResult(condition)) {
|
|
3815
|
-
return DebugManager
|
|
3796
|
+
return DebugManager.warn('ShowIf', "ShowIf : condition must be an Observable / "+comment, condition);
|
|
3816
3797
|
}
|
|
3817
3798
|
const element = Anchor('Show if : '+(comment || ''));
|
|
3818
3799
|
|
|
@@ -4599,7 +4580,7 @@ var NativeDocument = (function (exports) {
|
|
|
4599
4580
|
window.history.pushState({ name: route.name(), params, path}, route.name() || path , path);
|
|
4600
4581
|
this.handleRouteChange(route, params, query, path);
|
|
4601
4582
|
} catch (e) {
|
|
4602
|
-
DebugManager
|
|
4583
|
+
DebugManager.error('HistoryRouter', 'Error in pushState', e);
|
|
4603
4584
|
}
|
|
4604
4585
|
};
|
|
4605
4586
|
/**
|
|
@@ -4612,7 +4593,7 @@ var NativeDocument = (function (exports) {
|
|
|
4612
4593
|
window.history.replaceState({ name: route.name(), params, path}, route.name() || path , path);
|
|
4613
4594
|
this.handleRouteChange(route, params, {}, path);
|
|
4614
4595
|
} catch(e) {
|
|
4615
|
-
DebugManager
|
|
4596
|
+
DebugManager.error('HistoryRouter', 'Error in replaceState', e);
|
|
4616
4597
|
}
|
|
4617
4598
|
};
|
|
4618
4599
|
this.forward = function() {
|
|
@@ -4639,7 +4620,7 @@ var NativeDocument = (function (exports) {
|
|
|
4639
4620
|
}
|
|
4640
4621
|
this.handleRouteChange(route, params, query, path);
|
|
4641
4622
|
} catch(e) {
|
|
4642
|
-
DebugManager
|
|
4623
|
+
DebugManager.error('HistoryRouter', 'Error in popstate event', e);
|
|
4643
4624
|
}
|
|
4644
4625
|
});
|
|
4645
4626
|
const { route, params, query, path } = this.resolve(defaultPath || (window.location.pathname+window.location.search));
|
|
@@ -4864,7 +4845,7 @@ var NativeDocument = (function (exports) {
|
|
|
4864
4845
|
listener(request);
|
|
4865
4846
|
next && next(request);
|
|
4866
4847
|
} catch (e) {
|
|
4867
|
-
DebugManager
|
|
4848
|
+
DebugManager.warn('Route Listener', 'Error in listener:', e);
|
|
4868
4849
|
}
|
|
4869
4850
|
}
|
|
4870
4851
|
};
|
|
@@ -5023,7 +5004,7 @@ var NativeDocument = (function (exports) {
|
|
|
5023
5004
|
*/
|
|
5024
5005
|
Router.create = function(options, callback) {
|
|
5025
5006
|
if(!Validator.isFunction(callback)) {
|
|
5026
|
-
DebugManager
|
|
5007
|
+
DebugManager.error('Router', 'Callback must be a function', e);
|
|
5027
5008
|
throw new RouterError('Callback must be a function');
|
|
5028
5009
|
}
|
|
5029
5010
|
const router = new Router(options);
|