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.
Files changed (125) hide show
  1. package/dist/native-document.components.min.js +158 -130
  2. package/dist/native-document.dev.js +191 -144
  3. package/dist/native-document.dev.js.map +1 -1
  4. package/dist/native-document.devtools.min.js +1 -1
  5. package/dist/native-document.min.js +1 -1
  6. package/package.json +1 -1
  7. package/rollup.config.js +0 -16
  8. package/src/components/$traits/HasItems.js +1 -1
  9. package/src/components/accordion/Accordion.js +2 -2
  10. package/src/components/accordion/AccordionItem.js +2 -2
  11. package/src/components/alert/Alert.js +2 -2
  12. package/src/components/avatar/Avatar.js +2 -2
  13. package/src/components/badge/Badge.js +2 -2
  14. package/src/components/breadcrumb/BreadCrumb.js +2 -2
  15. package/src/components/button/Button.js +2 -2
  16. package/src/components/card/Card.js +1 -1
  17. package/src/components/context-menu/ContextMenu.js +2 -2
  18. package/src/components/context-menu/ContextMenuGroup.js +1 -1
  19. package/src/components/context-menu/ContextMenuItem.js +1 -1
  20. package/src/components/divider/Divider.js +1 -1
  21. package/src/components/dropdown/Dropdown.js +2 -2
  22. package/src/components/dropdown/DropdownDivider.js +1 -1
  23. package/src/components/dropdown/DropdownGroup.js +1 -1
  24. package/src/components/dropdown/DropdownItem.js +1 -1
  25. package/src/components/dropdown/DropdownTrigger.js +1 -1
  26. package/src/components/form/FormControl.js +5 -5
  27. package/src/components/form/field/DefaultRender.js +2 -2
  28. package/src/components/form/field/Field.js +4 -4
  29. package/src/components/form/field/FieldCollection.js +5 -5
  30. package/src/components/form/field/types/CheckboxField.js +1 -1
  31. package/src/components/form/field/types/ColorField.js +1 -1
  32. package/src/components/form/field/types/DateField.js +1 -1
  33. package/src/components/form/field/types/EmailField.js +1 -1
  34. package/src/components/form/field/types/FileField.js +1 -1
  35. package/src/components/form/field/types/ImageField.js +1 -1
  36. package/src/components/form/field/types/NumberField.js +1 -1
  37. package/src/components/form/field/types/PasswordField.js +1 -1
  38. package/src/components/form/field/types/RadioField.js +1 -1
  39. package/src/components/form/field/types/StringField.js +1 -1
  40. package/src/components/form/field/types/TelField.js +1 -1
  41. package/src/components/form/field/types/TimeField.js +1 -1
  42. package/src/components/form/field/types/UrlField.js +1 -1
  43. package/src/components/form/validation/Validation.js +1 -1
  44. package/src/components/list/List.js +4 -4
  45. package/src/components/list/ListGroup.js +2 -2
  46. package/src/components/list/ListItem.js +2 -2
  47. package/src/components/menu/Menu.js +3 -3
  48. package/src/components/menu/MenuDivider.js +1 -1
  49. package/src/components/menu/MenuGroup.js +2 -2
  50. package/src/components/menu/MenuItem.js +2 -2
  51. package/src/components/modal/Modal.js +2 -2
  52. package/src/components/pagination/Pagination.js +2 -2
  53. package/src/components/popover/Popover.js +2 -2
  54. package/src/components/popover/PopoverFooter.js +1 -1
  55. package/src/components/popover/PopoverHeader.js +1 -1
  56. package/src/components/progress/Progress.js +3 -3
  57. package/src/components/slider/Slider.js +2 -2
  58. package/src/components/splitter/Splitter.js +3 -4
  59. package/src/components/splitter/SplitterPanel.js +1 -1
  60. package/src/components/stepper/Stepper.js +3 -3
  61. package/src/components/stepper/StepperStep.js +2 -2
  62. package/src/components/switch/Switch.js +2 -2
  63. package/src/components/table/ColumnGroup.js +1 -1
  64. package/src/components/table/DataTable.js +1 -1
  65. package/src/components/table/SimpleTable.js +1 -1
  66. package/src/components/tabs/Tabs.js +2 -2
  67. package/src/components/toast/Toast.js +2 -2
  68. package/src/components/tooltip/prototypes.js +1 -1
  69. package/src/core/data/MemoryManager.js +1 -2
  70. package/src/core/data/Observable.js +1 -1
  71. package/src/core/data/ObservableArray.js +4 -4
  72. package/src/core/data/ObservableItem.js +5 -5
  73. package/src/core/data/observable-helpers/array.js +2 -2
  74. package/src/core/data/observable-helpers/batch.js +2 -2
  75. package/src/core/data/observable-helpers/computed.js +6 -6
  76. package/src/core/data/observable-helpers/object.js +2 -2
  77. package/src/core/elements/anchor.js +3 -3
  78. package/src/core/elements/content-formatter.js +1 -1
  79. package/src/core/elements/control/for-each-array.js +5 -6
  80. package/src/core/elements/control/for-each.js +7 -7
  81. package/src/core/elements/control/show-if.js +5 -5
  82. package/src/core/elements/control/show-when.js +2 -2
  83. package/src/core/elements/control/switch.js +4 -4
  84. package/src/core/elements/description-list.js +1 -1
  85. package/src/core/elements/form.js +1 -1
  86. package/src/core/elements/html5-semantics.js +1 -1
  87. package/src/core/elements/img.js +3 -3
  88. package/src/core/elements/index.js +1 -1
  89. package/src/core/elements/interactive.js +1 -1
  90. package/src/core/elements/list.js +1 -1
  91. package/src/core/elements/medias.js +1 -1
  92. package/src/core/elements/meta-data.js +1 -1
  93. package/src/core/elements/table.js +1 -1
  94. package/src/core/utils/EventEmitter.js +1 -1
  95. package/src/core/utils/args-types.js +2 -2
  96. package/src/core/utils/filters/standard.js +1 -1
  97. package/src/core/utils/filters/utils.js +1 -1
  98. package/src/core/utils/prototypes.js +2 -2
  99. package/src/core/utils/validator.js +5 -5
  100. package/src/core/wrappers/AttributesWrapper.js +3 -3
  101. package/src/core/wrappers/DocumentObserver.js +0 -1
  102. package/src/core/wrappers/ElementCreator.js +3 -3
  103. package/src/core/wrappers/HtmlElementWrapper.js +2 -2
  104. package/src/core/wrappers/NDElement.js +3 -3
  105. package/src/core/wrappers/NdPrototype.js +1 -1
  106. package/src/core/wrappers/SingletonView.js +1 -1
  107. package/src/core/wrappers/prototypes/attributes-extensions.js +4 -4
  108. package/src/core/wrappers/prototypes/bind-class-extensions.js +4 -4
  109. package/src/core/wrappers/prototypes/nd-element-extensions.js +6 -6
  110. package/src/devtools/app/App.js +2 -2
  111. package/src/devtools/hrm/ComponentRegistry.js +2 -2
  112. package/src/devtools/plugin.js +1 -1
  113. package/src/devtools/widget/DevToolsWidget.js +2 -2
  114. package/src/router/Route.js +1 -1
  115. package/src/router/RouteGroupHelper.js +1 -1
  116. package/src/router/Router.js +4 -4
  117. package/src/router/RouterComponent.js +1 -1
  118. package/src/router/link.js +4 -4
  119. package/src/router/modes/HistoryRouter.js +1 -1
  120. package/types/control-flow.d.ts +0 -1
  121. package/types/filters/dates.d.ts +1 -1
  122. package/types/filters/types.d.ts +1 -1
  123. package/utils.js +3 -3
  124. package/jsconfig.json +0 -15
  125. /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$1 = {};
4
+ let DebugManager = {};
5
5
 
6
6
  {
7
- DebugManager$1 = {
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$1;
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.isFunction(key)) return key(item, defaultKey);
263
- if(Validator.isObservable(item)) {
264
- const val = item.val();
265
- return (val && key) ? val[key] : defaultKey;
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
- if(!Validator.isObject(item)) {
268
- return item;
267
+
268
+ if (Validator.isFunction(key)) {
269
+ return key(item, defaultKey);
269
270
  }
270
- return item[key]?.val?.() ?? item[key] ?? defaultKey;
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 = ['checked', 'selected', 'disabled', 'readonly', 'required', 'autofocus', 'multiple', 'autocomplete', 'hidden', 'contenteditable', 'spellcheck', 'translate', 'draggable', 'async', 'defer', 'autoplay', 'controls', 'loop', 'muted', 'download', 'reversed', 'open', 'default', 'formnovalidate', 'novalidate', 'scoped', 'itemscope', 'allowfullscreen', 'allowpaymentrequest', 'playsinline'];
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[attributeName];
1423
- if(value === null || value === undefined) {
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(Validator.isString(value)) {
1431
- element.setAttribute(attributeName, value);
1432
- return;
1433
- }
1434
- if(attributeName === 'class' && Validator.isObject(value)) {
1435
- bindClassAttribute(element, value);
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.includes(attributeName)) {
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.includes(attributeName)) {
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
- if(child == null) {
1609
- return null;
1610
- }
1611
- if(child.toNdElement) {
1612
- do {
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](...data);
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](...data);
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](...data);
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].call(this, ...[...args, ...data]);
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 clone = (node, data) => {
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
- if(node.fullCloneNode) {
2162
- return nodeCloned;
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
- const childNodeCloned = clone(childNode, data);
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
- this.clone = (data) => {
2174
- if(!$node) {
2175
- $node = $fn(this);
2176
- if(!$hasBindingData) {
2177
- const nodeCloned = $node.cloneNode(true);
2178
- nodeCloned.fullCloneNode = true;
2179
- return nodeCloned;
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
- return clone($node, data);
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, key, configs = {}) {
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 keysCache = new WeakMap();
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 getChildByKey(getItemKey(item));
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(getItemKey(items[i], i));
3545
+ const cacheItem = cache.get(items[i]);
3482
3546
  if(!cacheItem) {
3483
3547
  continue;
3484
3548
  }
3485
- cacheItem.indexObserver?.deref()?.set(index);
3549
+ cacheItem.indexObserver?.set(index);
3486
3550
  index++;
3487
3551
  }
3488
3552
  };
3489
3553
 
3490
- const removeCacheItem = (cacheItem, removeChild = true) => {
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?.deref()?.cleanup();
3564
+ cacheItem.indexObserver?.cleanup();
3500
3565
  };
3501
3566
 
3502
- const removeCacheItemByKey = (keyId, removeChild = true) => {
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 [keyId, cacheItem] of cache.entries()) {
3515
- removeCacheItem(cacheItem, false);
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 keyId = getItemKey(item, indexKey);
3522
-
3523
- if(cache.has(keyId)) {
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(keyId);
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(!child) {
3536
- throw new NativeDocumentError("ForEachArray child can't be null or undefined!");
3537
- }
3538
- cache.set(keyId, {
3539
- keyId,
3540
- child: child,
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
- return child;
3604
+
3605
+ throw new NativeDocumentError("ForEachArray child can't be null or undefined!");
3557
3606
  };
3558
3607
 
3559
- const removeByKey = function(keyId, fragment) {
3560
- const cacheItem = cache.get(keyId);
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
- const fragment = Actions.toFragment(items);
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
- removeCacheItemByKey(getItemKey(element, index), true);
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 firstKey = getItemKey(deleted[0], start);
3688
+ let firstItem = deleted[0];
3641
3689
  if(deleted.length === 1) {
3642
- removeByKey(firstKey, garbageFragment);
3690
+ removeByItem(firstItem, garbageFragment);
3643
3691
  } else if(deleted.length > 1) {
3644
- const firstChildRemoved = getChildByKey(firstKey);
3692
+ const firstChildRemoved = getItemChild(deleted[0]);
3645
3693
  elementBeforeFirst = firstChildRemoved?.previousSibling;
3646
3694
 
3647
3695
  for(let i = 0; i < deleted.length; i++) {
3648
- const keyId = getItemKey(deleted[i], start + i);
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);