native-document 1.0.77 → 1.0.78
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 +158 -130
- package/dist/native-document.dev.js +191 -144
- 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/rollup.config.js +0 -16
- package/src/components/$traits/HasItems.js +1 -1
- package/src/components/accordion/Accordion.js +2 -2
- package/src/components/accordion/AccordionItem.js +2 -2
- package/src/components/alert/Alert.js +2 -2
- package/src/components/avatar/Avatar.js +2 -2
- package/src/components/badge/Badge.js +2 -2
- package/src/components/breadcrumb/BreadCrumb.js +2 -2
- package/src/components/button/Button.js +2 -2
- package/src/components/card/Card.js +1 -1
- package/src/components/context-menu/ContextMenu.js +2 -2
- package/src/components/context-menu/ContextMenuGroup.js +1 -1
- package/src/components/context-menu/ContextMenuItem.js +1 -1
- package/src/components/divider/Divider.js +1 -1
- package/src/components/dropdown/Dropdown.js +2 -2
- package/src/components/dropdown/DropdownDivider.js +1 -1
- package/src/components/dropdown/DropdownGroup.js +1 -1
- package/src/components/dropdown/DropdownItem.js +1 -1
- package/src/components/dropdown/DropdownTrigger.js +1 -1
- package/src/components/form/FormControl.js +5 -5
- package/src/components/form/field/DefaultRender.js +2 -2
- package/src/components/form/field/Field.js +4 -4
- package/src/components/form/field/FieldCollection.js +5 -5
- package/src/components/form/field/types/CheckboxField.js +1 -1
- package/src/components/form/field/types/ColorField.js +1 -1
- package/src/components/form/field/types/DateField.js +1 -1
- package/src/components/form/field/types/EmailField.js +1 -1
- package/src/components/form/field/types/FileField.js +1 -1
- package/src/components/form/field/types/ImageField.js +1 -1
- package/src/components/form/field/types/NumberField.js +1 -1
- package/src/components/form/field/types/PasswordField.js +1 -1
- package/src/components/form/field/types/RadioField.js +1 -1
- package/src/components/form/field/types/StringField.js +1 -1
- package/src/components/form/field/types/TelField.js +1 -1
- package/src/components/form/field/types/TimeField.js +1 -1
- package/src/components/form/field/types/UrlField.js +1 -1
- package/src/components/form/validation/Validation.js +1 -1
- package/src/components/list/List.js +4 -4
- package/src/components/list/ListGroup.js +2 -2
- package/src/components/list/ListItem.js +2 -2
- package/src/components/menu/Menu.js +3 -3
- package/src/components/menu/MenuDivider.js +1 -1
- package/src/components/menu/MenuGroup.js +2 -2
- package/src/components/menu/MenuItem.js +2 -2
- package/src/components/modal/Modal.js +2 -2
- package/src/components/pagination/Pagination.js +2 -2
- package/src/components/popover/Popover.js +2 -2
- package/src/components/popover/PopoverFooter.js +1 -1
- package/src/components/popover/PopoverHeader.js +1 -1
- package/src/components/progress/Progress.js +3 -3
- package/src/components/slider/Slider.js +2 -2
- package/src/components/splitter/Splitter.js +3 -4
- package/src/components/splitter/SplitterPanel.js +1 -1
- package/src/components/stepper/Stepper.js +3 -3
- package/src/components/stepper/StepperStep.js +2 -2
- package/src/components/switch/Switch.js +2 -2
- package/src/components/table/ColumnGroup.js +1 -1
- package/src/components/table/DataTable.js +1 -1
- package/src/components/table/SimpleTable.js +1 -1
- package/src/components/tabs/Tabs.js +2 -2
- package/src/components/toast/Toast.js +2 -2
- package/src/components/tooltip/prototypes.js +1 -1
- package/src/core/data/MemoryManager.js +1 -2
- package/src/core/data/Observable.js +1 -1
- package/src/core/data/ObservableArray.js +4 -4
- package/src/core/data/ObservableItem.js +5 -5
- package/src/core/data/observable-helpers/array.js +2 -2
- package/src/core/data/observable-helpers/batch.js +2 -2
- package/src/core/data/observable-helpers/computed.js +6 -6
- package/src/core/data/observable-helpers/object.js +2 -2
- package/src/core/elements/anchor.js +3 -3
- package/src/core/elements/content-formatter.js +1 -1
- package/src/core/elements/control/for-each-array.js +5 -6
- package/src/core/elements/control/for-each.js +7 -7
- package/src/core/elements/control/show-if.js +5 -5
- package/src/core/elements/control/show-when.js +2 -2
- package/src/core/elements/control/switch.js +4 -4
- package/src/core/elements/description-list.js +1 -1
- package/src/core/elements/form.js +1 -1
- package/src/core/elements/html5-semantics.js +1 -1
- package/src/core/elements/img.js +3 -3
- package/src/core/elements/index.js +1 -1
- package/src/core/elements/interactive.js +1 -1
- package/src/core/elements/list.js +1 -1
- package/src/core/elements/medias.js +1 -1
- package/src/core/elements/meta-data.js +1 -1
- package/src/core/elements/table.js +1 -1
- package/src/core/utils/EventEmitter.js +1 -1
- package/src/core/utils/args-types.js +2 -2
- package/src/core/utils/filters/standard.js +1 -1
- package/src/core/utils/filters/utils.js +1 -1
- package/src/core/utils/prototypes.js +2 -2
- package/src/core/utils/validator.js +5 -5
- package/src/core/wrappers/AttributesWrapper.js +3 -3
- package/src/core/wrappers/DocumentObserver.js +0 -1
- package/src/core/wrappers/ElementCreator.js +3 -3
- package/src/core/wrappers/HtmlElementWrapper.js +2 -2
- package/src/core/wrappers/NDElement.js +3 -3
- package/src/core/wrappers/NdPrototype.js +1 -1
- package/src/core/wrappers/SingletonView.js +1 -1
- package/src/core/wrappers/prototypes/attributes-extensions.js +4 -4
- package/src/core/wrappers/prototypes/bind-class-extensions.js +4 -4
- package/src/core/wrappers/prototypes/nd-element-extensions.js +6 -6
- package/src/devtools/app/App.js +2 -2
- package/src/devtools/hrm/ComponentRegistry.js +2 -2
- package/src/devtools/plugin.js +1 -1
- package/src/devtools/widget/DevToolsWidget.js +2 -2
- package/src/router/Route.js +1 -1
- package/src/router/RouteGroupHelper.js +1 -1
- package/src/router/Router.js +4 -4
- package/src/router/RouterComponent.js +1 -1
- package/src/router/link.js +4 -4
- package/src/router/modes/HistoryRouter.js +1 -1
- package/types/control-flow.d.ts +0 -1
- package/types/filters/dates.d.ts +1 -1
- package/types/filters/types.d.ts +1 -1
- package/utils.js +3 -3
- package/jsconfig.json +0 -15
- /package/src/{core → router}/errors/RouterError.js +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
var NativeDocument = (function (exports) {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
let DebugManager
|
|
4
|
+
let DebugManager = {};
|
|
5
5
|
|
|
6
6
|
{
|
|
7
|
-
DebugManager
|
|
7
|
+
DebugManager = {
|
|
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;
|
|
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.log('Memory Auto Clean', `🧹 Cleaned ${cleanedCount} orphaned observables`);
|
|
87
|
+
DebugManager$1.log('Memory Auto Clean', `🧹 Cleaned ${cleanedCount} orphaned observables`);
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
};
|
|
@@ -207,7 +207,7 @@ var NativeDocument = (function (exports) {
|
|
|
207
207
|
try{
|
|
208
208
|
callback.call(plugin, ...data);
|
|
209
209
|
} catch (error) {
|
|
210
|
-
DebugManager.error('Plugin Manager', `Error in plugin ${plugin.$name} for event ${eventName}`, error);
|
|
210
|
+
DebugManager$1.error('Plugin Manager', `Error in plugin ${plugin.$name} for event ${eventName}`, error);
|
|
211
211
|
}
|
|
212
212
|
}
|
|
213
213
|
}
|
|
@@ -259,15 +259,18 @@ var NativeDocument = (function (exports) {
|
|
|
259
259
|
* @returns {*}
|
|
260
260
|
*/
|
|
261
261
|
const getKey = (item, defaultKey, key) => {
|
|
262
|
-
if(Validator.
|
|
263
|
-
|
|
264
|
-
const
|
|
265
|
-
return (
|
|
262
|
+
if (Validator.isString(key)) {
|
|
263
|
+
const val = Validator.isObservable(item) ? item.val() : item;
|
|
264
|
+
const result = val?.[key];
|
|
265
|
+
return Validator.isObservable(result) ? result.val() : (result ?? defaultKey);
|
|
266
266
|
}
|
|
267
|
-
|
|
268
|
-
|
|
267
|
+
|
|
268
|
+
if (Validator.isFunction(key)) {
|
|
269
|
+
return key(item, defaultKey);
|
|
269
270
|
}
|
|
270
|
-
|
|
271
|
+
|
|
272
|
+
const val = Validator.isObservable(item) ? item.val() : item;
|
|
273
|
+
return val ?? defaultKey;
|
|
271
274
|
};
|
|
272
275
|
|
|
273
276
|
const trim = function(str, char) {
|
|
@@ -503,7 +506,7 @@ var NativeDocument = (function (exports) {
|
|
|
503
506
|
ObservableItem.prototype.subscribe = function(callback, target = null) {
|
|
504
507
|
this.$listeners = this.$listeners ?? [];
|
|
505
508
|
if (this.$isCleanedUp) {
|
|
506
|
-
DebugManager.warn('Observable subscription', '⚠️ Attempted to subscribe to a cleaned up observable.');
|
|
509
|
+
DebugManager$1.warn('Observable subscription', '⚠️ Attempted to subscribe to a cleaned up observable.');
|
|
507
510
|
return () => {};
|
|
508
511
|
}
|
|
509
512
|
if (typeof callback !== 'function') {
|
|
@@ -856,7 +859,7 @@ var NativeDocument = (function (exports) {
|
|
|
856
859
|
}
|
|
857
860
|
{
|
|
858
861
|
if (this[name] && !this.$localExtensions.has(name)) {
|
|
859
|
-
DebugManager.warn('NDElement.extend', `Method "${name}" already exists and will be overwritten`);
|
|
862
|
+
DebugManager$1.warn('NDElement.extend', `Method "${name}" already exists and will be overwritten`);
|
|
860
863
|
}
|
|
861
864
|
this.$localExtensions.set(name, method);
|
|
862
865
|
}
|
|
@@ -890,17 +893,17 @@ var NativeDocument = (function (exports) {
|
|
|
890
893
|
const method = methods[name];
|
|
891
894
|
|
|
892
895
|
if (typeof method !== 'function') {
|
|
893
|
-
DebugManager.warn('NDElement.extend', `"${name}" is not a function, skipping`);
|
|
896
|
+
DebugManager$1.warn('NDElement.extend', `"${name}" is not a function, skipping`);
|
|
894
897
|
continue;
|
|
895
898
|
}
|
|
896
899
|
|
|
897
900
|
if (protectedMethods.has(name)) {
|
|
898
|
-
DebugManager.error('NDElement.extend', `Cannot override protected method "${name}"`);
|
|
901
|
+
DebugManager$1.error('NDElement.extend', `Cannot override protected method "${name}"`);
|
|
899
902
|
throw new NativeDocumentError(`Cannot override protected method "${name}"`);
|
|
900
903
|
}
|
|
901
904
|
|
|
902
905
|
if (NDElement.prototype[name]) {
|
|
903
|
-
DebugManager.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
|
|
906
|
+
DebugManager$1.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
|
|
904
907
|
}
|
|
905
908
|
|
|
906
909
|
NDElement.prototype[name] = method;
|
|
@@ -1050,6 +1053,7 @@ var NativeDocument = (function (exports) {
|
|
|
1050
1053
|
};
|
|
1051
1054
|
{
|
|
1052
1055
|
Validator.validateAttributes = function(attributes) {
|
|
1056
|
+
console.log('AttributesWrapper', attributes);
|
|
1053
1057
|
if (!attributes || typeof attributes !== 'object') {
|
|
1054
1058
|
return attributes;
|
|
1055
1059
|
}
|
|
@@ -1058,7 +1062,7 @@ var NativeDocument = (function (exports) {
|
|
|
1058
1062
|
const foundReserved = Object.keys(attributes).filter(key => reserved.includes(key));
|
|
1059
1063
|
|
|
1060
1064
|
if (foundReserved.length > 0) {
|
|
1061
|
-
DebugManager.warn('Validator', `Reserved attributes found: ${foundReserved.join(', ')}`);
|
|
1065
|
+
DebugManager$1.warn('Validator', `Reserved attributes found: ${foundReserved.join(', ')}`);
|
|
1062
1066
|
}
|
|
1063
1067
|
|
|
1064
1068
|
return attributes;
|
|
@@ -1106,7 +1110,7 @@ var NativeDocument = (function (exports) {
|
|
|
1106
1110
|
anchorFragment.appendChild = function(child, before = null) {
|
|
1107
1111
|
const parent = anchorEnd.parentNode;
|
|
1108
1112
|
if(!parent) {
|
|
1109
|
-
DebugManager.error('Anchor', 'Anchor : parent not found', child);
|
|
1113
|
+
DebugManager$1.error('Anchor', 'Anchor : parent not found', child);
|
|
1110
1114
|
return;
|
|
1111
1115
|
}
|
|
1112
1116
|
before = before ?? anchorEnd;
|
|
@@ -1215,7 +1219,38 @@ var NativeDocument = (function (exports) {
|
|
|
1215
1219
|
return anchor;
|
|
1216
1220
|
}
|
|
1217
1221
|
|
|
1218
|
-
const BOOLEAN_ATTRIBUTES = [
|
|
1222
|
+
const BOOLEAN_ATTRIBUTES = new Set([
|
|
1223
|
+
'checked',
|
|
1224
|
+
'selected',
|
|
1225
|
+
'disabled',
|
|
1226
|
+
'readonly',
|
|
1227
|
+
'required',
|
|
1228
|
+
'autofocus',
|
|
1229
|
+
'multiple',
|
|
1230
|
+
'autocomplete',
|
|
1231
|
+
'hidden',
|
|
1232
|
+
'contenteditable',
|
|
1233
|
+
'spellcheck',
|
|
1234
|
+
'translate',
|
|
1235
|
+
'draggable',
|
|
1236
|
+
'async',
|
|
1237
|
+
'defer',
|
|
1238
|
+
'autoplay',
|
|
1239
|
+
'controls',
|
|
1240
|
+
'loop',
|
|
1241
|
+
'muted',
|
|
1242
|
+
'download',
|
|
1243
|
+
'reversed',
|
|
1244
|
+
'open',
|
|
1245
|
+
'default',
|
|
1246
|
+
'formnovalidate',
|
|
1247
|
+
'novalidate',
|
|
1248
|
+
'scoped',
|
|
1249
|
+
'itemscope',
|
|
1250
|
+
'allowfullscreen',
|
|
1251
|
+
'allowpaymentrequest',
|
|
1252
|
+
'playsinline'
|
|
1253
|
+
]);
|
|
1219
1254
|
|
|
1220
1255
|
/**
|
|
1221
1256
|
*
|
|
@@ -1404,6 +1439,12 @@ var NativeDocument = (function (exports) {
|
|
|
1404
1439
|
}
|
|
1405
1440
|
}
|
|
1406
1441
|
|
|
1442
|
+
const NdBindings = {
|
|
1443
|
+
class: (element, value) => bindClassAttribute(element, value),
|
|
1444
|
+
style: (element, value) => bindStyleAttribute(element, value),
|
|
1445
|
+
};
|
|
1446
|
+
|
|
1447
|
+
|
|
1407
1448
|
/**
|
|
1408
1449
|
*
|
|
1409
1450
|
* @param {HTMLElement} element
|
|
@@ -1419,41 +1460,27 @@ var NativeDocument = (function (exports) {
|
|
|
1419
1460
|
|
|
1420
1461
|
for(let key in attributes) {
|
|
1421
1462
|
const attributeName = key.toLowerCase();
|
|
1422
|
-
let value = attributes[
|
|
1423
|
-
if(value
|
|
1463
|
+
let value = attributes[key];
|
|
1464
|
+
if(value == null) {
|
|
1424
1465
|
continue;
|
|
1425
1466
|
}
|
|
1426
1467
|
if(value.handleNdAttribute) {
|
|
1427
1468
|
value.handleNdAttribute(element, attributeName, value);
|
|
1428
1469
|
continue;
|
|
1429
1470
|
}
|
|
1430
|
-
if(
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
continue;
|
|
1437
|
-
}
|
|
1438
|
-
if(attributeName === 'style' && Validator.isObject(value)) {
|
|
1439
|
-
bindStyleAttribute(element, value);
|
|
1440
|
-
continue;
|
|
1471
|
+
if(typeof value === 'object') {
|
|
1472
|
+
const binding = NdBindings[attributeName];
|
|
1473
|
+
if(binding) {
|
|
1474
|
+
binding(element, value);
|
|
1475
|
+
continue;
|
|
1476
|
+
}
|
|
1441
1477
|
}
|
|
1442
|
-
if(BOOLEAN_ATTRIBUTES.
|
|
1478
|
+
if(BOOLEAN_ATTRIBUTES.has(attributeName)) {
|
|
1443
1479
|
bindBooleanAttribute(element, attributeName, value);
|
|
1444
1480
|
continue;
|
|
1445
1481
|
}
|
|
1446
|
-
if(Validator.isObservable(value)) {
|
|
1447
|
-
bindAttributeWithObservable(element, attributeName, value);
|
|
1448
|
-
continue;
|
|
1449
|
-
}
|
|
1450
|
-
if(value.$hydrate) {
|
|
1451
|
-
value.$hydrate(element, attributeName);
|
|
1452
|
-
continue;
|
|
1453
|
-
}
|
|
1454
1482
|
|
|
1455
1483
|
element.setAttribute(attributeName, value);
|
|
1456
|
-
|
|
1457
1484
|
}
|
|
1458
1485
|
return element;
|
|
1459
1486
|
}
|
|
@@ -1514,8 +1541,16 @@ var NativeDocument = (function (exports) {
|
|
|
1514
1541
|
element.setAttribute(attributeName, this);
|
|
1515
1542
|
};
|
|
1516
1543
|
|
|
1544
|
+
Number.prototype.handleNdAttribute = function(element, attributeName) {
|
|
1545
|
+
element.setAttribute(attributeName, this);
|
|
1546
|
+
};
|
|
1547
|
+
|
|
1548
|
+
Boolean.prototype.handleNdAttribute = function(element, attrName) {
|
|
1549
|
+
bindBooleanAttribute(element, attrName, this);
|
|
1550
|
+
};
|
|
1551
|
+
|
|
1517
1552
|
ObservableItem.prototype.handleNdAttribute = function(element, attributeName) {
|
|
1518
|
-
if(BOOLEAN_ATTRIBUTES.
|
|
1553
|
+
if(BOOLEAN_ATTRIBUTES.has(attributeName)) {
|
|
1519
1554
|
bindBooleanAttribute(element, attributeName, this);
|
|
1520
1555
|
return;
|
|
1521
1556
|
}
|
|
@@ -1605,22 +1640,14 @@ var NativeDocument = (function (exports) {
|
|
|
1605
1640
|
PluginsManager.emit('AfterProcessChildren', parent);
|
|
1606
1641
|
},
|
|
1607
1642
|
getChild(child) {
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
child = child.toNdElement();
|
|
1614
|
-
if(Validator.isElement(child)) {
|
|
1615
|
-
return child;
|
|
1616
|
-
}
|
|
1617
|
-
if(child == null) {
|
|
1618
|
-
return null;
|
|
1619
|
-
}
|
|
1620
|
-
} while (child.toNdElement);
|
|
1643
|
+
while (child?.toNdElement) {
|
|
1644
|
+
child = child.toNdElement();
|
|
1645
|
+
|
|
1646
|
+
if (Validator.isElement(child)) return child;
|
|
1647
|
+
if (!child) return null;
|
|
1621
1648
|
}
|
|
1622
1649
|
|
|
1623
|
-
return ElementCreator.createStaticTextNode(null, child);
|
|
1650
|
+
return child ? ElementCreator.createStaticTextNode(null, child) : null;
|
|
1624
1651
|
},
|
|
1625
1652
|
/**
|
|
1626
1653
|
*
|
|
@@ -2088,7 +2115,7 @@ var NativeDocument = (function (exports) {
|
|
|
2088
2115
|
if(bindDingData.attributes) {
|
|
2089
2116
|
attributes = {};
|
|
2090
2117
|
for (const attr in bindDingData.attributes) {
|
|
2091
|
-
attributes[attr] = bindDingData.attributes[attr](
|
|
2118
|
+
attributes[attr] = bindDingData.attributes[attr].apply(null, data);
|
|
2092
2119
|
}
|
|
2093
2120
|
}
|
|
2094
2121
|
|
|
@@ -2096,7 +2123,7 @@ var NativeDocument = (function (exports) {
|
|
|
2096
2123
|
attributes = attributes || {};
|
|
2097
2124
|
attributes.class = {};
|
|
2098
2125
|
for (const className in bindDingData.classes) {
|
|
2099
|
-
attributes.class[className] = bindDingData.classes[className](
|
|
2126
|
+
attributes.class[className] = bindDingData.classes[className].apply(null, data);
|
|
2100
2127
|
}
|
|
2101
2128
|
}
|
|
2102
2129
|
|
|
@@ -2104,7 +2131,7 @@ var NativeDocument = (function (exports) {
|
|
|
2104
2131
|
attributes = attributes || {};
|
|
2105
2132
|
attributes.style = {};
|
|
2106
2133
|
for (const property in bindDingData.styles) {
|
|
2107
|
-
attributes.style[property] = bindDingData.styles[property](
|
|
2134
|
+
attributes.style[property] = bindDingData.styles[property].apply(null, data);
|
|
2108
2135
|
}
|
|
2109
2136
|
}
|
|
2110
2137
|
|
|
@@ -2116,6 +2143,14 @@ var NativeDocument = (function (exports) {
|
|
|
2116
2143
|
return null;
|
|
2117
2144
|
};
|
|
2118
2145
|
|
|
2146
|
+
const findByPath = (root, path) => {
|
|
2147
|
+
let target = root;
|
|
2148
|
+
for (let i = 0, len = path.length; i < len; i++) {
|
|
2149
|
+
target = target.childNodes[path[i]];
|
|
2150
|
+
}
|
|
2151
|
+
return target;
|
|
2152
|
+
};
|
|
2153
|
+
|
|
2119
2154
|
const $hydrateFn = function(hydrateFunction, targetType, element, property) {
|
|
2120
2155
|
if(!cloneBindingsDataCache.has(element)) {
|
|
2121
2156
|
// { classes, styles, attributes, value, attach }
|
|
@@ -2136,7 +2171,7 @@ var NativeDocument = (function (exports) {
|
|
|
2136
2171
|
}
|
|
2137
2172
|
for(const methodName in bindDingData.attach) {
|
|
2138
2173
|
node.nd[methodName](function(...args) {
|
|
2139
|
-
bindDingData.attach[methodName].
|
|
2174
|
+
bindDingData.attach[methodName].apply(this, [...args, ...data]);
|
|
2140
2175
|
});
|
|
2141
2176
|
}
|
|
2142
2177
|
};
|
|
@@ -2145,44 +2180,78 @@ var NativeDocument = (function (exports) {
|
|
|
2145
2180
|
let $node = null;
|
|
2146
2181
|
let $hasBindingData = false;
|
|
2147
2182
|
|
|
2148
|
-
const
|
|
2183
|
+
const $bindingPaths = [];
|
|
2184
|
+
|
|
2185
|
+
const clone = (node, data, path) => {
|
|
2149
2186
|
const bindDingData = cloneBindingsDataCache.get(node);
|
|
2150
2187
|
if(node.nodeType === 3) {
|
|
2151
2188
|
if(bindDingData && bindDingData.value) {
|
|
2189
|
+
$bindingPaths.push({
|
|
2190
|
+
path: [...path],
|
|
2191
|
+
fn: (data, targetNode, currentRoot) => {
|
|
2192
|
+
const newNode = bindDingData.value(data);
|
|
2193
|
+
targetNode.replaceWith(newNode);
|
|
2194
|
+
if (targetNode === currentRoot) {
|
|
2195
|
+
return newNode;
|
|
2196
|
+
}
|
|
2197
|
+
return null;
|
|
2198
|
+
}
|
|
2199
|
+
});
|
|
2152
2200
|
return bindDingData.value(data);
|
|
2153
2201
|
}
|
|
2154
2202
|
return node.cloneNode(true);
|
|
2155
2203
|
}
|
|
2156
2204
|
const nodeCloned = node.cloneNode(node.fullCloneNode);
|
|
2205
|
+
if(node.fullCloneNode) {
|
|
2206
|
+
return nodeCloned;
|
|
2207
|
+
}
|
|
2157
2208
|
if(bindDingData) {
|
|
2158
2209
|
bindAttributes(nodeCloned, bindDingData, data);
|
|
2159
2210
|
bindAttachMethods(nodeCloned, bindDingData, data);
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2211
|
+
$bindingPaths.push({
|
|
2212
|
+
path: [...path],
|
|
2213
|
+
fn: (data, targetNode) => {
|
|
2214
|
+
bindAttributes(targetNode, bindDingData, data);
|
|
2215
|
+
bindAttachMethods(targetNode, bindDingData, data);
|
|
2216
|
+
}
|
|
2217
|
+
});
|
|
2163
2218
|
}
|
|
2164
2219
|
const childNodes = node.childNodes;
|
|
2165
2220
|
for(let i = 0, length = childNodes.length; i < length; i++) {
|
|
2166
2221
|
const childNode = childNodes[i];
|
|
2167
|
-
|
|
2222
|
+
path.push(i);
|
|
2223
|
+
const childNodeCloned = clone(childNode, data, path);
|
|
2224
|
+
path.pop();
|
|
2168
2225
|
nodeCloned.appendChild(childNodeCloned);
|
|
2169
2226
|
}
|
|
2170
2227
|
return nodeCloned;
|
|
2171
2228
|
};
|
|
2172
2229
|
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2230
|
+
const cloneWithBindingPaths = (data) => {
|
|
2231
|
+
let root = $node.cloneNode(true);
|
|
2232
|
+
|
|
2233
|
+
for (let i = 0, len = $bindingPaths.length; i < len; i++) {
|
|
2234
|
+
const binding = $bindingPaths[i];
|
|
2235
|
+
const target = findByPath(root, binding.path);
|
|
2236
|
+
const newRoot = binding.fn(data, target, root);
|
|
2237
|
+
if(newRoot) {
|
|
2238
|
+
root = newRoot;
|
|
2180
2239
|
}
|
|
2181
2240
|
}
|
|
2241
|
+
|
|
2242
|
+
return root;
|
|
2243
|
+
};
|
|
2244
|
+
|
|
2245
|
+
this.clone = (data) => {
|
|
2246
|
+
$node = $fn(this);
|
|
2182
2247
|
if(!$hasBindingData) {
|
|
2248
|
+
this.clone = () => $node.cloneNode(true);
|
|
2183
2249
|
return $node.cloneNode(true);
|
|
2184
2250
|
}
|
|
2185
|
-
|
|
2251
|
+
|
|
2252
|
+
const firstClone = clone($node, data, []);
|
|
2253
|
+
this.clone = cloneWithBindingPaths;
|
|
2254
|
+
return firstClone;
|
|
2186
2255
|
};
|
|
2187
2256
|
|
|
2188
2257
|
|
|
@@ -2241,6 +2310,7 @@ var NativeDocument = (function (exports) {
|
|
|
2241
2310
|
return wrapper([_, __, ...args]);
|
|
2242
2311
|
};
|
|
2243
2312
|
}
|
|
2313
|
+
w;
|
|
2244
2314
|
|
|
2245
2315
|
function SingletonView($viewCreator) {
|
|
2246
2316
|
let $cacheNode = null;
|
|
@@ -2835,6 +2905,9 @@ var NativeDocument = (function (exports) {
|
|
|
2835
2905
|
});
|
|
2836
2906
|
|
|
2837
2907
|
ObservableArray.prototype.clear = function() {
|
|
2908
|
+
if(this.$currentValue.length === 0) {
|
|
2909
|
+
return;
|
|
2910
|
+
}
|
|
2838
2911
|
this.$currentValue.length = 0;
|
|
2839
2912
|
this.trigger({ action: 'clear' });
|
|
2840
2913
|
return true;
|
|
@@ -3362,7 +3435,7 @@ var NativeDocument = (function (exports) {
|
|
|
3362
3435
|
}
|
|
3363
3436
|
cache.set(keyId, { keyId, isNew: true, child: new WeakRef(child), indexObserver});
|
|
3364
3437
|
} catch (e) {
|
|
3365
|
-
DebugManager.error('ForEach', `Error creating element for key ${keyId}` , e);
|
|
3438
|
+
DebugManager$1.error('ForEach', `Error creating element for key ${keyId}` , e);
|
|
3366
3439
|
throw e;
|
|
3367
3440
|
}
|
|
3368
3441
|
return keyId;
|
|
@@ -3444,7 +3517,7 @@ var NativeDocument = (function (exports) {
|
|
|
3444
3517
|
return element;
|
|
3445
3518
|
}
|
|
3446
3519
|
|
|
3447
|
-
function ForEachArray(data, callback,
|
|
3520
|
+
function ForEachArray(data, callback, configs = {}) {
|
|
3448
3521
|
const element = Anchor('ForEach Array');
|
|
3449
3522
|
const blockEnd = element.endElement();
|
|
3450
3523
|
const blockStart = element.startElement();
|
|
@@ -3453,23 +3526,14 @@ var NativeDocument = (function (exports) {
|
|
|
3453
3526
|
let lastNumberOfItems = 0;
|
|
3454
3527
|
const isIndexRequired = callback.length >= 2;
|
|
3455
3528
|
|
|
3456
|
-
const
|
|
3457
|
-
|
|
3458
|
-
const clear = () => {
|
|
3529
|
+
const clear = (items) => {
|
|
3459
3530
|
element.removeChildren();
|
|
3460
|
-
cleanCache();
|
|
3531
|
+
cleanCache(items);
|
|
3461
3532
|
lastNumberOfItems = 0;
|
|
3462
3533
|
};
|
|
3463
3534
|
|
|
3464
|
-
const getItemKey = (item, indexKey) => {
|
|
3465
|
-
if(keysCache.has(item)) {
|
|
3466
|
-
return keysCache.get(item);
|
|
3467
|
-
}
|
|
3468
|
-
return getKey(item, indexKey, key);
|
|
3469
|
-
};
|
|
3470
|
-
|
|
3471
3535
|
const getItemChild = (item) => {
|
|
3472
|
-
return
|
|
3536
|
+
return cache.get(item)?.child;
|
|
3473
3537
|
};
|
|
3474
3538
|
|
|
3475
3539
|
const updateIndexObservers = (items, startFrom = 0) => {
|
|
@@ -3478,16 +3542,17 @@ var NativeDocument = (function (exports) {
|
|
|
3478
3542
|
}
|
|
3479
3543
|
let index = startFrom;
|
|
3480
3544
|
for(let i = startFrom, length = items?.length; i < length; i++) {
|
|
3481
|
-
const cacheItem = cache.get(
|
|
3545
|
+
const cacheItem = cache.get(items[i]);
|
|
3482
3546
|
if(!cacheItem) {
|
|
3483
3547
|
continue;
|
|
3484
3548
|
}
|
|
3485
|
-
cacheItem.indexObserver?.
|
|
3549
|
+
cacheItem.indexObserver?.set(index);
|
|
3486
3550
|
index++;
|
|
3487
3551
|
}
|
|
3488
3552
|
};
|
|
3489
3553
|
|
|
3490
|
-
const removeCacheItem = (
|
|
3554
|
+
const removeCacheItem = (item, removeChild = true) => {
|
|
3555
|
+
const cacheItem = cache.get(item);
|
|
3491
3556
|
if(!cacheItem) {
|
|
3492
3557
|
return;
|
|
3493
3558
|
}
|
|
@@ -3496,14 +3561,10 @@ var NativeDocument = (function (exports) {
|
|
|
3496
3561
|
child?.remove();
|
|
3497
3562
|
cache.delete(cacheItem.keyId);
|
|
3498
3563
|
}
|
|
3499
|
-
cacheItem.indexObserver?.
|
|
3564
|
+
cacheItem.indexObserver?.cleanup();
|
|
3500
3565
|
};
|
|
3501
3566
|
|
|
3502
|
-
const
|
|
3503
|
-
removeCacheItem(cache.get(keyId), removeChild);
|
|
3504
|
-
};
|
|
3505
|
-
|
|
3506
|
-
const cleanCache = () => {
|
|
3567
|
+
const cleanCache = (items) => {
|
|
3507
3568
|
if(configs.shouldKeepItemsInCache) {
|
|
3508
3569
|
return;
|
|
3509
3570
|
}
|
|
@@ -3511,53 +3572,41 @@ var NativeDocument = (function (exports) {
|
|
|
3511
3572
|
cache.clear();
|
|
3512
3573
|
return;
|
|
3513
3574
|
}
|
|
3514
|
-
for (const [
|
|
3515
|
-
|
|
3575
|
+
for (const [itemAsKey, _] of cache.entries()) {
|
|
3576
|
+
if(items && items.contains(itemAsKey)) {
|
|
3577
|
+
continue;
|
|
3578
|
+
}
|
|
3579
|
+
removeCacheItem(itemAsKey, false);
|
|
3516
3580
|
}
|
|
3517
3581
|
cache.clear();
|
|
3518
3582
|
};
|
|
3519
3583
|
|
|
3520
3584
|
const buildItem = (item, indexKey) => {
|
|
3521
|
-
const
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
const cacheItem = cache.get(keyId);
|
|
3525
|
-
cacheItem.indexObserver?.deref()?.set(indexKey);
|
|
3585
|
+
const cacheItem = cache.get(item);
|
|
3586
|
+
if(cacheItem) {
|
|
3587
|
+
cacheItem.indexObserver?.set(indexKey);
|
|
3526
3588
|
const child = cacheItem.child;
|
|
3527
3589
|
if(child) {
|
|
3528
3590
|
return child;
|
|
3529
3591
|
}
|
|
3530
|
-
cache.delete(
|
|
3592
|
+
cache.delete(item);
|
|
3531
3593
|
}
|
|
3532
3594
|
|
|
3533
3595
|
const indexObserver = isIndexRequired ? Observable(indexKey) : null;
|
|
3534
3596
|
let child = ElementCreator.getChild(callback(item, indexObserver));
|
|
3535
|
-
if(
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
indexObserver: (indexObserver ? new WeakRef(indexObserver) : null)
|
|
3542
|
-
});
|
|
3543
|
-
keysCache.set(item, keyId);
|
|
3544
|
-
return child;
|
|
3545
|
-
};
|
|
3546
|
-
const getChildByKey = function(keyId) {
|
|
3547
|
-
const cacheItem = cache.get(keyId);
|
|
3548
|
-
if(!cacheItem) {
|
|
3549
|
-
return null;
|
|
3550
|
-
}
|
|
3551
|
-
const child = cacheItem.child;
|
|
3552
|
-
if(!child) {
|
|
3553
|
-
removeCacheItem(cacheItem, false);
|
|
3554
|
-
return null;
|
|
3597
|
+
if(child) {
|
|
3598
|
+
cache.set(item, {
|
|
3599
|
+
child,
|
|
3600
|
+
indexObserver: (indexObserver ? new WeakRef(indexObserver) : null)
|
|
3601
|
+
});
|
|
3602
|
+
return child;
|
|
3555
3603
|
}
|
|
3556
|
-
|
|
3604
|
+
|
|
3605
|
+
throw new NativeDocumentError("ForEachArray child can't be null or undefined!");
|
|
3557
3606
|
};
|
|
3558
3607
|
|
|
3559
|
-
const
|
|
3560
|
-
const cacheItem = cache.get(
|
|
3608
|
+
const removeByItem = function(item, fragment) {
|
|
3609
|
+
const cacheItem = cache.get(item);
|
|
3561
3610
|
if(!cacheItem) {
|
|
3562
3611
|
return null;
|
|
3563
3612
|
}
|
|
@@ -3583,11 +3632,10 @@ var NativeDocument = (function (exports) {
|
|
|
3583
3632
|
return fragment;
|
|
3584
3633
|
},
|
|
3585
3634
|
add(items, delay = 2) {
|
|
3586
|
-
|
|
3587
|
-
element.appendElement(fragment);
|
|
3635
|
+
element.appendElement(Actions.toFragment(items));
|
|
3588
3636
|
},
|
|
3589
3637
|
replace(items) {
|
|
3590
|
-
clear();
|
|
3638
|
+
clear(items);
|
|
3591
3639
|
Actions.add(items);
|
|
3592
3640
|
},
|
|
3593
3641
|
reOrder(items) {
|
|
@@ -3603,7 +3651,7 @@ var NativeDocument = (function (exports) {
|
|
|
3603
3651
|
element.appendElement(fragment, blockEnd);
|
|
3604
3652
|
},
|
|
3605
3653
|
removeOne(element, index) {
|
|
3606
|
-
|
|
3654
|
+
removeCacheItem(element, true);
|
|
3607
3655
|
},
|
|
3608
3656
|
clear,
|
|
3609
3657
|
merge(items) {
|
|
@@ -3637,16 +3685,15 @@ var NativeDocument = (function (exports) {
|
|
|
3637
3685
|
const garbageFragment = document.createDocumentFragment();
|
|
3638
3686
|
|
|
3639
3687
|
if(deleted.length > 0) {
|
|
3640
|
-
let
|
|
3688
|
+
let firstItem = deleted[0];
|
|
3641
3689
|
if(deleted.length === 1) {
|
|
3642
|
-
|
|
3690
|
+
removeByItem(firstItem, garbageFragment);
|
|
3643
3691
|
} else if(deleted.length > 1) {
|
|
3644
|
-
const firstChildRemoved =
|
|
3692
|
+
const firstChildRemoved = getItemChild(deleted[0]);
|
|
3645
3693
|
elementBeforeFirst = firstChildRemoved?.previousSibling;
|
|
3646
3694
|
|
|
3647
3695
|
for(let i = 0; i < deleted.length; i++) {
|
|
3648
|
-
|
|
3649
|
-
removeByKey(keyId, garbageFragment);
|
|
3696
|
+
firstItem(deleted[i], garbageFragment);
|
|
3650
3697
|
}
|
|
3651
3698
|
}
|
|
3652
3699
|
} else {
|
|
@@ -3734,7 +3781,7 @@ var NativeDocument = (function (exports) {
|
|
|
3734
3781
|
*/
|
|
3735
3782
|
const ShowIf = function(condition, child, { comment = null, shouldKeepInCache = true} = {}) {
|
|
3736
3783
|
if(!(Validator.isObservable(condition)) && !Validator.isObservableWhenResult(condition)) {
|
|
3737
|
-
return DebugManager.warn('ShowIf', "ShowIf : condition must be an Observable / "+comment, condition);
|
|
3784
|
+
return DebugManager$1.warn('ShowIf', "ShowIf : condition must be an Observable / "+comment, condition);
|
|
3738
3785
|
}
|
|
3739
3786
|
const element = Anchor('Show if : '+(comment || ''));
|
|
3740
3787
|
|
|
@@ -4521,7 +4568,7 @@ var NativeDocument = (function (exports) {
|
|
|
4521
4568
|
window.history.pushState({ name: route.name(), params, path}, route.name() || path , path);
|
|
4522
4569
|
this.handleRouteChange(route, params, query, path);
|
|
4523
4570
|
} catch (e) {
|
|
4524
|
-
DebugManager.error('HistoryRouter', 'Error in pushState', e);
|
|
4571
|
+
DebugManager$1.error('HistoryRouter', 'Error in pushState', e);
|
|
4525
4572
|
}
|
|
4526
4573
|
};
|
|
4527
4574
|
/**
|
|
@@ -4534,7 +4581,7 @@ var NativeDocument = (function (exports) {
|
|
|
4534
4581
|
window.history.replaceState({ name: route.name(), params, path}, route.name() || path , path);
|
|
4535
4582
|
this.handleRouteChange(route, params, {}, path);
|
|
4536
4583
|
} catch(e) {
|
|
4537
|
-
DebugManager.error('HistoryRouter', 'Error in replaceState', e);
|
|
4584
|
+
DebugManager$1.error('HistoryRouter', 'Error in replaceState', e);
|
|
4538
4585
|
}
|
|
4539
4586
|
};
|
|
4540
4587
|
this.forward = function() {
|
|
@@ -4561,7 +4608,7 @@ var NativeDocument = (function (exports) {
|
|
|
4561
4608
|
}
|
|
4562
4609
|
this.handleRouteChange(route, params, query, path);
|
|
4563
4610
|
} catch(e) {
|
|
4564
|
-
DebugManager.error('HistoryRouter', 'Error in popstate event', e);
|
|
4611
|
+
DebugManager$1.error('HistoryRouter', 'Error in popstate event', e);
|
|
4565
4612
|
}
|
|
4566
4613
|
});
|
|
4567
4614
|
const { route, params, query, path } = this.resolve(defaultPath || (window.location.pathname+window.location.search));
|
|
@@ -4724,7 +4771,7 @@ var NativeDocument = (function (exports) {
|
|
|
4724
4771
|
listener(request);
|
|
4725
4772
|
next && next(request);
|
|
4726
4773
|
} catch (e) {
|
|
4727
|
-
DebugManager.warn('Route Listener', 'Error in listener:', e);
|
|
4774
|
+
DebugManager$1.warn('Route Listener', 'Error in listener:', e);
|
|
4728
4775
|
}
|
|
4729
4776
|
}
|
|
4730
4777
|
};
|
|
@@ -4883,7 +4930,7 @@ var NativeDocument = (function (exports) {
|
|
|
4883
4930
|
*/
|
|
4884
4931
|
Router.create = function(options, callback) {
|
|
4885
4932
|
if(!Validator.isFunction(callback)) {
|
|
4886
|
-
DebugManager.error('Router', 'Callback must be a function', e);
|
|
4933
|
+
DebugManager$1.error('Router', 'Callback must be a function', e);
|
|
4887
4934
|
throw new RouterError('Callback must be a function');
|
|
4888
4935
|
}
|
|
4889
4936
|
const router = new Router(options);
|