native-document 1.0.104 → 1.0.105
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 +55 -65
- package/dist/native-document.dev.js +135 -126
- package/dist/native-document.dev.js.map +1 -1
- package/dist/native-document.min.js +1 -1
- package/index.d.ts +3 -2
- package/index.js +0 -1
- package/package.json +2 -2
- package/src/core/data/ObservableItem.js +0 -9
- package/src/core/elements/anchor.js +23 -25
- package/src/core/elements/control/for-each-array.js +53 -32
- package/src/core/utils/validator.js +11 -6
- package/src/core/wrappers/prototypes/nd-element-extensions.js +1 -5
- package/src/router/Route.js +2 -2
- package/src/router/RouterComponent.js +1 -1
- package/types/service.d.ts +1 -1
|
@@ -363,16 +363,16 @@ var NativeComponents = (function (exports) {
|
|
|
363
363
|
// });
|
|
364
364
|
};
|
|
365
365
|
|
|
366
|
-
let DebugManager = {};
|
|
366
|
+
let DebugManager$1 = {};
|
|
367
367
|
{
|
|
368
|
-
DebugManager = {
|
|
368
|
+
DebugManager$1 = {
|
|
369
369
|
log() {},
|
|
370
370
|
warn() {},
|
|
371
371
|
error() {},
|
|
372
372
|
disable() {}
|
|
373
373
|
};
|
|
374
374
|
}
|
|
375
|
-
var DebugManager
|
|
375
|
+
var DebugManager = DebugManager$1;
|
|
376
376
|
|
|
377
377
|
/**
|
|
378
378
|
*
|
|
@@ -857,17 +857,17 @@ var NativeComponents = (function (exports) {
|
|
|
857
857
|
const method = methods[name];
|
|
858
858
|
|
|
859
859
|
if (typeof method !== 'function') {
|
|
860
|
-
DebugManager
|
|
860
|
+
DebugManager.warn('NDElement.extend', `"${name}" is not a function, skipping`);
|
|
861
861
|
continue;
|
|
862
862
|
}
|
|
863
863
|
|
|
864
864
|
if (protectedMethods.has(name)) {
|
|
865
|
-
DebugManager
|
|
865
|
+
DebugManager.error('NDElement.extend', `Cannot override protected method "${name}"`);
|
|
866
866
|
throw new NativeDocumentError(`Cannot override protected method "${name}"`);
|
|
867
867
|
}
|
|
868
868
|
|
|
869
869
|
if (NDElement.prototype[name]) {
|
|
870
|
-
DebugManager
|
|
870
|
+
DebugManager.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
|
|
871
871
|
}
|
|
872
872
|
|
|
873
873
|
NDElement.prototype[name] = method;
|
|
@@ -883,6 +883,13 @@ var NativeComponents = (function (exports) {
|
|
|
883
883
|
DOCUMENT_FRAGMENT: 11
|
|
884
884
|
};
|
|
885
885
|
|
|
886
|
+
const VALID_TYPES = {
|
|
887
|
+
[COMMON_NODE_TYPES.ELEMENT]: true,
|
|
888
|
+
[COMMON_NODE_TYPES.TEXT]: true,
|
|
889
|
+
[COMMON_NODE_TYPES.DOCUMENT_FRAGMENT]: true,
|
|
890
|
+
[COMMON_NODE_TYPES.COMMENT]: true
|
|
891
|
+
};
|
|
892
|
+
|
|
886
893
|
const Validator = {
|
|
887
894
|
isObservable(value) {
|
|
888
895
|
return value?.__$isObservable;
|
|
@@ -933,12 +940,10 @@ var NativeComponents = (function (exports) {
|
|
|
933
940
|
return !(typeof value !== 'object' || value === null || Array.isArray(value) || value.constructor.name !== 'Object')
|
|
934
941
|
},
|
|
935
942
|
isElement(value) {
|
|
936
|
-
return value &&
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
value.nodeType === COMMON_NODE_TYPES.COMMENT
|
|
941
|
-
);
|
|
943
|
+
return value && VALID_TYPES[value.nodeType];
|
|
944
|
+
},
|
|
945
|
+
isDOMNode(value) {
|
|
946
|
+
return VALID_TYPES[value.nodeType];
|
|
942
947
|
},
|
|
943
948
|
isFragment(value) {
|
|
944
949
|
return value?.nodeType === COMMON_NODE_TYPES.DOCUMENT_FRAGMENT;
|
|
@@ -1022,7 +1027,9 @@ var NativeComponents = (function (exports) {
|
|
|
1022
1027
|
anchorFragment.nativeAppendChild = anchorFragment.appendChild;
|
|
1023
1028
|
anchorFragment.nativeAppend = anchorFragment.append;
|
|
1024
1029
|
|
|
1025
|
-
const isParentUniqueChild =
|
|
1030
|
+
const isParentUniqueChild = isUniqueChild
|
|
1031
|
+
? () => true
|
|
1032
|
+
: (parent) => (parent.firstChild === anchorStart && parent.lastChild === anchorEnd);
|
|
1026
1033
|
|
|
1027
1034
|
const insertBefore = function(parent, child, target) {
|
|
1028
1035
|
const childElement = Validator.isElement(child) ? child : ElementCreator.getChild(child);
|
|
@@ -1050,7 +1057,7 @@ var NativeComponents = (function (exports) {
|
|
|
1050
1057
|
anchorFragment.appendChild = function(child, before = null) {
|
|
1051
1058
|
const parent = anchorEnd.parentNode;
|
|
1052
1059
|
if(!parent) {
|
|
1053
|
-
DebugManager
|
|
1060
|
+
DebugManager.error('Anchor', 'Anchor : parent not found', child);
|
|
1054
1061
|
return;
|
|
1055
1062
|
}
|
|
1056
1063
|
before = before ?? anchorEnd;
|
|
@@ -1061,61 +1068,58 @@ var NativeComponents = (function (exports) {
|
|
|
1061
1068
|
return anchorFragment.appendChild(args);
|
|
1062
1069
|
};
|
|
1063
1070
|
|
|
1064
|
-
anchorFragment.removeChildren =
|
|
1071
|
+
anchorFragment.removeChildren = function() {
|
|
1065
1072
|
const parent = anchorEnd.parentNode;
|
|
1066
1073
|
if(parent === anchorFragment) {
|
|
1067
1074
|
return;
|
|
1068
1075
|
}
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1076
|
+
if(isParentUniqueChild(parent)) {
|
|
1077
|
+
parent.replaceChildren(anchorStart, anchorEnd);
|
|
1078
|
+
return;
|
|
1079
|
+
}
|
|
1073
1080
|
|
|
1074
1081
|
let itemToRemove = anchorStart.nextSibling, tempItem;
|
|
1075
|
-
const removes = [];
|
|
1076
1082
|
while(itemToRemove && itemToRemove !== anchorEnd) {
|
|
1077
1083
|
tempItem = itemToRemove.nextSibling;
|
|
1078
|
-
|
|
1084
|
+
itemToRemove.remove();
|
|
1079
1085
|
itemToRemove = tempItem;
|
|
1080
1086
|
}
|
|
1081
|
-
await Promise.all(removes);
|
|
1082
1087
|
};
|
|
1083
1088
|
|
|
1084
|
-
anchorFragment.remove =
|
|
1089
|
+
anchorFragment.remove = function() {
|
|
1085
1090
|
const parent = anchorEnd.parentNode;
|
|
1086
1091
|
if(parent === anchorFragment) {
|
|
1087
1092
|
return;
|
|
1088
1093
|
}
|
|
1094
|
+
if(isParentUniqueChild(parent)) {
|
|
1095
|
+
parent.replaceChildren(anchorStart, anchorEnd);
|
|
1096
|
+
return;
|
|
1097
|
+
}
|
|
1089
1098
|
let itemToRemove = anchorStart.nextSibling, tempItem;
|
|
1090
|
-
const allItemToRemove = [];
|
|
1091
|
-
const removes = [];
|
|
1092
1099
|
while(itemToRemove && itemToRemove !== anchorEnd) {
|
|
1093
1100
|
tempItem = itemToRemove.nextSibling;
|
|
1094
|
-
|
|
1095
|
-
removes.push(itemToRemove.remove());
|
|
1101
|
+
anchorFragment.nativeAppend(itemToRemove);
|
|
1096
1102
|
itemToRemove = tempItem;
|
|
1097
1103
|
}
|
|
1098
|
-
await Promise.all(removes);
|
|
1099
|
-
anchorFragment.nativeAppend(...allItemToRemove);
|
|
1100
1104
|
};
|
|
1101
1105
|
|
|
1102
|
-
anchorFragment.removeWithAnchors =
|
|
1103
|
-
|
|
1106
|
+
anchorFragment.removeWithAnchors = function() {
|
|
1107
|
+
anchorFragment.removeChildren();
|
|
1104
1108
|
anchorStart.remove();
|
|
1105
1109
|
anchorEnd.remove();
|
|
1106
1110
|
};
|
|
1107
1111
|
|
|
1108
|
-
anchorFragment.replaceContent =
|
|
1112
|
+
anchorFragment.replaceContent = function(child) {
|
|
1109
1113
|
const childElement = Validator.isElement(child) ? child : ElementCreator.getChild(child);
|
|
1110
1114
|
const parent = anchorEnd.parentNode;
|
|
1111
1115
|
if(!parent) {
|
|
1112
1116
|
return;
|
|
1113
1117
|
}
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1118
|
+
if(isParentUniqueChild(parent)) {
|
|
1119
|
+
parent.replaceChildren(anchorStart, childElement, anchorEnd);
|
|
1120
|
+
return;
|
|
1121
|
+
}
|
|
1122
|
+
anchorFragment.removeChildren();
|
|
1119
1123
|
parent.insertBefore(childElement, anchorEnd);
|
|
1120
1124
|
};
|
|
1121
1125
|
|
|
@@ -1125,7 +1129,6 @@ var NativeComponents = (function (exports) {
|
|
|
1125
1129
|
anchorFragment.appendChild(child, anchor);
|
|
1126
1130
|
};
|
|
1127
1131
|
|
|
1128
|
-
|
|
1129
1132
|
anchorFragment.endElement = function() {
|
|
1130
1133
|
return anchorEnd;
|
|
1131
1134
|
};
|
|
@@ -1234,7 +1237,7 @@ var NativeComponents = (function (exports) {
|
|
|
1234
1237
|
}
|
|
1235
1238
|
}
|
|
1236
1239
|
if (cleanedCount > 0) {
|
|
1237
|
-
DebugManager
|
|
1240
|
+
DebugManager.log('Memory Auto Clean', `🧹 Cleaned ${cleanedCount} orphaned observables`);
|
|
1238
1241
|
}
|
|
1239
1242
|
}
|
|
1240
1243
|
};
|
|
@@ -1441,7 +1444,7 @@ var NativeComponents = (function (exports) {
|
|
|
1441
1444
|
const $getStoreOrThrow = (method, name) => {
|
|
1442
1445
|
const item = $stores.get(name);
|
|
1443
1446
|
if (!item) {
|
|
1444
|
-
DebugManager
|
|
1447
|
+
DebugManager.error('Store', `Store.${method}('${name}') : store not found. Did you call Store.create('${name}') first?`);
|
|
1445
1448
|
throw new NativeDocumentError(
|
|
1446
1449
|
`Store.${method}('${name}') : store not found.`
|
|
1447
1450
|
);
|
|
@@ -1454,7 +1457,7 @@ var NativeComponents = (function (exports) {
|
|
|
1454
1457
|
*/
|
|
1455
1458
|
const $applyReadOnly = (observer, name, context) => {
|
|
1456
1459
|
const readOnlyError = (method) => () => {
|
|
1457
|
-
DebugManager
|
|
1460
|
+
DebugManager.error('Store', `Store.${context}('${name}') is read-only. '${method}()' is not allowed.`);
|
|
1458
1461
|
throw new NativeDocumentError(
|
|
1459
1462
|
`Store.${context}('${name}') is read-only.`
|
|
1460
1463
|
);
|
|
@@ -1485,7 +1488,7 @@ var NativeComponents = (function (exports) {
|
|
|
1485
1488
|
*/
|
|
1486
1489
|
create(name, value) {
|
|
1487
1490
|
if ($stores.has(name)) {
|
|
1488
|
-
DebugManager
|
|
1491
|
+
DebugManager.warn('Store', `Store.create('${name}') : a store with this name already exists. Use Store.get('${name}') to retrieve it.`);
|
|
1489
1492
|
throw new NativeDocumentError(
|
|
1490
1493
|
`Store.create('${name}') : a store with this name already exists.`
|
|
1491
1494
|
);
|
|
@@ -1506,7 +1509,7 @@ var NativeComponents = (function (exports) {
|
|
|
1506
1509
|
*/
|
|
1507
1510
|
createResettable(name, value) {
|
|
1508
1511
|
if ($stores.has(name)) {
|
|
1509
|
-
DebugManager
|
|
1512
|
+
DebugManager.warn('Store', `Store.createResettable('${name}') : a store with this name already exists.`);
|
|
1510
1513
|
throw new NativeDocumentError(
|
|
1511
1514
|
`Store.createResettable('${name}') : a store with this name already exists.`
|
|
1512
1515
|
);
|
|
@@ -1542,7 +1545,7 @@ var NativeComponents = (function (exports) {
|
|
|
1542
1545
|
*/
|
|
1543
1546
|
createComposed(name, computation, dependencies) {
|
|
1544
1547
|
if ($stores.has(name)) {
|
|
1545
|
-
DebugManager
|
|
1548
|
+
DebugManager.warn('Store', `Store.createComposed('${name}') : a store with this name already exists.`);
|
|
1546
1549
|
throw new NativeDocumentError(
|
|
1547
1550
|
`Store.createComposed('${name}') : a store with this name already exists.`
|
|
1548
1551
|
);
|
|
@@ -1565,7 +1568,7 @@ var NativeComponents = (function (exports) {
|
|
|
1565
1568
|
}
|
|
1566
1569
|
const depItem = $stores.get(depName);
|
|
1567
1570
|
if (!depItem) {
|
|
1568
|
-
DebugManager
|
|
1571
|
+
DebugManager.error('Store', `Store.createComposed('${name}') : dependency '${depName}' not found. Create it first.`);
|
|
1569
1572
|
throw new NativeDocumentError(
|
|
1570
1573
|
`Store.createComposed('${name}') : dependency store '${depName}' not found.`
|
|
1571
1574
|
);
|
|
@@ -1599,13 +1602,13 @@ var NativeComponents = (function (exports) {
|
|
|
1599
1602
|
reset(name) {
|
|
1600
1603
|
const item = $getStoreOrThrow('reset', name);
|
|
1601
1604
|
if (item.composed) {
|
|
1602
|
-
DebugManager
|
|
1605
|
+
DebugManager.error('Store', `Store.reset('${name}') : composed stores cannot be reset. Their value is derived from dependencies.`);
|
|
1603
1606
|
throw new NativeDocumentError(
|
|
1604
1607
|
`Store.reset('${name}') : composed stores cannot be reset.`
|
|
1605
1608
|
);
|
|
1606
1609
|
}
|
|
1607
1610
|
if (!item.resettable) {
|
|
1608
|
-
DebugManager
|
|
1611
|
+
DebugManager.error('Store', `Store.reset('${name}') : this store is not resettable. Use Store.createResettable('${name}', value) instead of Store.create().`);
|
|
1609
1612
|
throw new NativeDocumentError(
|
|
1610
1613
|
`Store.reset('${name}') : this store is not resettable. Use Store.createResettable('${name}', value) instead of Store.create().`
|
|
1611
1614
|
);
|
|
@@ -1626,7 +1629,7 @@ var NativeComponents = (function (exports) {
|
|
|
1626
1629
|
const item = $getStoreOrThrow('use', name);
|
|
1627
1630
|
|
|
1628
1631
|
if (item.composed) {
|
|
1629
|
-
DebugManager
|
|
1632
|
+
DebugManager.error('Store', `Store.use('${name}') : composed stores are read-only. Use Store.follow('${name}') instead.`);
|
|
1630
1633
|
throw new NativeDocumentError(
|
|
1631
1634
|
`Store.use('${name}') : composed stores are read-only. Use Store.follow('${name}') instead.`
|
|
1632
1635
|
);
|
|
@@ -1693,7 +1696,7 @@ var NativeComponents = (function (exports) {
|
|
|
1693
1696
|
get(name) {
|
|
1694
1697
|
const item = $stores.get(name);
|
|
1695
1698
|
if (!item) {
|
|
1696
|
-
DebugManager
|
|
1699
|
+
DebugManager.warn('Store', `Store.get('${name}') : store not found.`);
|
|
1697
1700
|
return null;
|
|
1698
1701
|
}
|
|
1699
1702
|
return item.observer;
|
|
@@ -1715,7 +1718,7 @@ var NativeComponents = (function (exports) {
|
|
|
1715
1718
|
delete(name) {
|
|
1716
1719
|
const item = $stores.get(name);
|
|
1717
1720
|
if (!item) {
|
|
1718
|
-
DebugManager
|
|
1721
|
+
DebugManager.warn('Store', `Store.delete('${name}') : store not found, nothing to delete.`);
|
|
1719
1722
|
return;
|
|
1720
1723
|
}
|
|
1721
1724
|
item.subscribers.forEach(follower => follower.destroy());
|
|
@@ -1817,7 +1820,7 @@ var NativeComponents = (function (exports) {
|
|
|
1817
1820
|
return undefined;
|
|
1818
1821
|
},
|
|
1819
1822
|
set(target, prop, value) {
|
|
1820
|
-
DebugManager
|
|
1823
|
+
DebugManager.error('Store', `Forbidden: You cannot overwrite the store key '${String(prop)}'. Use .use('${String(prop)}').set(value) instead.`);
|
|
1821
1824
|
throw new NativeDocumentError(`Store structure is immutable. Use .set() on the observable.`);
|
|
1822
1825
|
},
|
|
1823
1826
|
deleteProperty(target, prop) {
|
|
@@ -2079,17 +2082,8 @@ var NativeComponents = (function (exports) {
|
|
|
2079
2082
|
};
|
|
2080
2083
|
|
|
2081
2084
|
ObservableItem.prototype.disconnectAll = function() {
|
|
2082
|
-
this.$listeners?.splice(0);
|
|
2083
2085
|
this.$previousValue = null;
|
|
2084
2086
|
this.$currentValue = null;
|
|
2085
|
-
if(this.$watchers) {
|
|
2086
|
-
for (const [_, watchValueList] of this.$watchers) {
|
|
2087
|
-
if(Validator.isArray(watchValueList)) {
|
|
2088
|
-
watchValueList.splice(0);
|
|
2089
|
-
}
|
|
2090
|
-
}
|
|
2091
|
-
}
|
|
2092
|
-
this.$watchers?.clear();
|
|
2093
2087
|
this.$listeners = null;
|
|
2094
2088
|
this.$watchers = null;
|
|
2095
2089
|
this.trigger = noneTrigger;
|
|
@@ -2653,11 +2647,7 @@ var NativeComponents = (function (exports) {
|
|
|
2653
2647
|
}
|
|
2654
2648
|
|
|
2655
2649
|
String.prototype.toNdElement = function () {
|
|
2656
|
-
|
|
2657
|
-
if(Validator.isString(formattedChild)) {
|
|
2658
|
-
return ElementCreator.createStaticTextNode(null, formattedChild);
|
|
2659
|
-
}
|
|
2660
|
-
return ElementCreator.getChild(null, formattedChild);
|
|
2650
|
+
return ElementCreator.createStaticTextNode(null, this);
|
|
2661
2651
|
};
|
|
2662
2652
|
|
|
2663
2653
|
Element.prototype.toNdElement = function () {
|