native-document 1.0.76 → 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 (154) hide show
  1. package/components.js +26 -1
  2. package/dist/native-document.components.min.js +6447 -1984
  3. package/dist/native-document.dev.js +309 -196
  4. package/dist/native-document.dev.js.map +1 -1
  5. package/dist/native-document.devtools.min.js +1 -1
  6. package/dist/native-document.min.js +1 -1
  7. package/package.json +1 -1
  8. package/rollup.config.js +0 -14
  9. package/src/components/$traits/HasItems.js +38 -0
  10. package/src/components/BaseComponent.js +70 -0
  11. package/src/components/accordion/Accordion.js +133 -0
  12. package/src/components/accordion/AccordionItem.js +119 -0
  13. package/src/components/accordion/index.js +7 -0
  14. package/src/components/alert/Alert.js +155 -0
  15. package/src/components/alert/index.js +6 -0
  16. package/src/components/avatar/Avatar.js +178 -0
  17. package/src/components/avatar/index.js +5 -0
  18. package/src/components/badge/Badge.js +103 -0
  19. package/src/components/badge/index.js +6 -0
  20. package/src/components/breadcrumb/BreadCrumb.js +70 -0
  21. package/src/components/breadcrumb/index.js +5 -0
  22. package/src/components/button/Button.js +174 -0
  23. package/src/components/button/index.js +5 -0
  24. package/src/components/card/Card.js +110 -0
  25. package/src/components/card/index.js +5 -0
  26. package/src/components/context-menu/ContextMenu.js +60 -0
  27. package/src/components/context-menu/ContextMenuGroup.js +16 -0
  28. package/src/components/context-menu/ContextMenuItem.js +16 -0
  29. package/src/components/context-menu/index.js +10 -0
  30. package/src/components/divider/Divider.js +126 -0
  31. package/src/components/divider/index.js +6 -0
  32. package/src/components/dropdown/Dropdown.js +170 -0
  33. package/src/components/dropdown/DropdownDivider.js +24 -0
  34. package/src/components/dropdown/DropdownGroup.js +44 -0
  35. package/src/components/dropdown/DropdownItem.js +71 -0
  36. package/src/components/dropdown/DropdownTrigger.js +64 -0
  37. package/src/components/dropdown/index.js +13 -0
  38. package/src/components/{fom-control → form}/FormControl.js +28 -20
  39. package/src/components/{fom-control → form}/field/DefaultRender.js +1 -15
  40. package/src/components/{fom-control → form}/field/Field.js +64 -137
  41. package/src/components/{fom-control → form}/field/FieldCollection.js +39 -19
  42. package/src/components/{fom-control → form}/field/types/AutocompleteField.js +11 -0
  43. package/src/components/form/field/types/CheckboxField.js +36 -0
  44. package/src/components/{fom-control → form}/field/types/CheckboxGroupField.js +10 -0
  45. package/src/components/{fom-control → form}/field/types/ColorField.js +10 -0
  46. package/src/components/{fom-control → form}/field/types/DateField.js +10 -0
  47. package/src/components/{fom-control → form}/field/types/EmailField.js +10 -0
  48. package/src/components/{fom-control → form}/field/types/FileField.js +10 -0
  49. package/src/components/form/field/types/HiddenField.js +18 -0
  50. package/src/components/{fom-control → form}/field/types/ImageField.js +10 -0
  51. package/src/components/{fom-control → form}/field/types/NumberField.js +10 -0
  52. package/src/components/{fom-control → form}/field/types/PasswordField.js +10 -0
  53. package/src/components/{fom-control → form}/field/types/RadioField.js +28 -2
  54. package/src/components/{fom-control → form}/field/types/RangeField.js +10 -0
  55. package/src/components/{fom-control → form}/field/types/SearchField.js +10 -0
  56. package/src/components/{fom-control → form}/field/types/SelectField.js +10 -0
  57. package/src/components/{fom-control → form}/field/types/StringField.js +10 -0
  58. package/src/components/{fom-control → form}/field/types/TelField.js +10 -1
  59. package/src/components/{fom-control → form}/field/types/TextAreaField.js +10 -0
  60. package/src/components/{fom-control → form}/field/types/TimeField.js +10 -1
  61. package/src/components/{fom-control → form}/field/types/UrlField.js +9 -1
  62. package/src/components/form/index.js +49 -0
  63. package/src/components/list/List.js +106 -0
  64. package/src/components/list/ListGroup.js +67 -0
  65. package/src/components/list/ListItem.js +103 -0
  66. package/src/components/list/index.js +10 -0
  67. package/src/components/menu/Menu.js +82 -0
  68. package/src/components/menu/MenuDivider.js +22 -0
  69. package/src/components/menu/MenuGroup.js +42 -0
  70. package/src/components/menu/MenuItem.js +71 -0
  71. package/src/components/menu/index.js +13 -0
  72. package/src/components/modal/Modal.js +153 -0
  73. package/src/components/modal/index.js +5 -0
  74. package/src/components/pagination/Pagination.js +229 -0
  75. package/src/components/pagination/index.js +5 -0
  76. package/src/components/popover/Popover.js +185 -0
  77. package/src/components/popover/PopoverFooter.js +37 -0
  78. package/src/components/popover/PopoverHeader.js +43 -0
  79. package/src/components/popover/index.js +10 -0
  80. package/src/components/progress/Progress.js +220 -0
  81. package/src/components/progress/index.js +6 -0
  82. package/src/components/skeleton/Skeleton.js +98 -0
  83. package/src/components/skeleton/SkeletonCard.js +0 -0
  84. package/src/components/skeleton/SkeletonList.js +0 -0
  85. package/src/components/skeleton/SkeletonParagraph.js +0 -0
  86. package/src/components/skeleton/SkeletonTable.js +0 -0
  87. package/src/components/skeleton/index.js +6 -0
  88. package/src/components/slider/Slider.js +183 -0
  89. package/src/components/slider/index.js +5 -0
  90. package/src/components/spinner/Spinner.js +160 -0
  91. package/src/components/spinner/index.js +5 -0
  92. package/src/components/splitter/Splitter.js +94 -0
  93. package/src/components/splitter/SplitterGutter.js +57 -0
  94. package/src/components/splitter/SplitterPanel.js +82 -0
  95. package/src/components/splitter/index.js +8 -0
  96. package/src/components/stepper/Stepper.js +229 -0
  97. package/src/components/stepper/StepperStep.js +103 -0
  98. package/src/components/stepper/index.js +8 -0
  99. package/src/components/switch/Switch.js +99 -0
  100. package/src/components/switch/index.js +0 -0
  101. package/src/components/table/SimpleTable.js +36 -32
  102. package/src/components/tabs/Tabs.js +110 -0
  103. package/src/components/tabs/index.js +6 -0
  104. package/src/components/toast/Toast.js +129 -0
  105. package/src/components/toast/ToastError.js +0 -0
  106. package/src/components/toast/ToastInfo.js +0 -0
  107. package/src/components/toast/ToastSuccess.js +0 -0
  108. package/src/components/toast/ToastWarning.js +0 -0
  109. package/src/components/toast/index.js +5 -0
  110. package/src/components/tooltip/Tooltip.js +98 -0
  111. package/src/components/tooltip/index.js +5 -0
  112. package/src/components/tooltip/prototypes.js +6 -0
  113. package/src/core/data/MemoryManager.js +1 -2
  114. package/src/core/data/Observable.js +1 -1
  115. package/src/core/data/ObservableArray.js +10 -4
  116. package/src/core/data/ObservableItem.js +5 -5
  117. package/src/core/data/observable-helpers/array.js +1 -1
  118. package/src/core/data/observable-helpers/batch.js +1 -1
  119. package/src/core/data/observable-helpers/computed.js +1 -1
  120. package/src/core/elements/control/for-each-array.js +37 -64
  121. package/src/core/elements/control/for-each.js +1 -1
  122. package/src/core/elements/control/show-if.js +1 -1
  123. package/src/core/elements/control/switch.js +1 -1
  124. package/src/core/utils/events.js +68 -0
  125. package/src/core/utils/filters/standard.js +1 -1
  126. package/src/core/utils/filters/utils.js +1 -1
  127. package/src/core/utils/helpers.js +10 -7
  128. package/src/core/utils/validator.js +1 -0
  129. package/src/core/wrappers/AttributesWrapper.js +18 -35
  130. package/src/core/wrappers/DocumentObserver.js +0 -1
  131. package/src/core/wrappers/ElementCreator.js +6 -11
  132. package/src/core/wrappers/NdPrototype.js +24 -31
  133. package/src/core/wrappers/TemplateCloner.js +60 -18
  134. package/src/core/wrappers/constants.js +32 -1
  135. package/src/core/wrappers/prototypes/attributes-extensions.js +16 -3
  136. package/src/core/wrappers/prototypes/bind-class-extensions.js +18 -0
  137. package/src/devtools/app/App.js +1 -1
  138. package/src/devtools/hrm/ComponentRegistry.js +1 -1
  139. package/src/router/Router.js +1 -1
  140. package/src/router/link.js +4 -4
  141. package/src/router/modes/HistoryRouter.js +0 -1
  142. package/types/control-flow.d.ts +0 -1
  143. package/types/filters/standard.d.ts +0 -1
  144. package/src/components/fom-control/default/DefaultLayout.js +0 -8
  145. package/src/components/fom-control/default/collection/DefaultCollectionLayout.js +0 -12
  146. package/src/components/fom-control/default/collection/DefaultCollectionTemplate.js +0 -6
  147. package/src/components/fom-control/field/types/CheckboxField.js +0 -17
  148. package/src/components/fom-control/field/types/HiddenField.js +0 -8
  149. package/src/components/fom-control/index.js +0 -8
  150. /package/src/components/{fom-control → form}/field/FieldFactory.js +0 -0
  151. /package/src/components/{fom-control → form}/merge +0 -0
  152. /package/src/components/{fom-control → form}/utils.js +0 -0
  153. /package/src/components/{fom-control → form}/validation/Validation.js +0 -0
  154. /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
  *
@@ -1287,6 +1322,20 @@ var NativeDocument = (function (exports) {
1287
1322
  setInterval(() => MemoryManager.cleanObservables(threshold), interval);
1288
1323
  };
1289
1324
 
1325
+ ObservableItem.prototype.bindNdClass = function(element, className) {
1326
+ element.classes.toggle(className, this.val());
1327
+ this.subscribe(toggleElementClass.bind(null, element, className));
1328
+ };
1329
+
1330
+ ObservableWhen.prototype.bindNdClass = function(element, className) {
1331
+ element.classes.toggle(className, this.isMath());
1332
+ this.subscribe(toggleElementClass.bind(null, element, className));
1333
+ };
1334
+
1335
+ TemplateBinding.prototype.bindNdClass = function(element, className) {
1336
+ this.$hydrate(element, className);
1337
+ };
1338
+
1290
1339
  function toggleElementClass(element, className, shouldAdd) {
1291
1340
  element.classes.toggle(className, shouldAdd);
1292
1341
  }
@@ -1319,18 +1368,8 @@ var NativeDocument = (function (exports) {
1319
1368
  function bindClassAttribute(element, data) {
1320
1369
  for(let className in data) {
1321
1370
  const value = data[className];
1322
- if(Validator.isObservable(value)) {
1323
- element.classes.toggle(className, value.val());
1324
- value.subscribe(toggleElementClass.bind(null, element, className));
1325
- continue;
1326
- }
1327
- if(Validator.isObservableWhenResult(value)) {
1328
- element.classes.toggle(className, value.isMath());
1329
- value.subscribe(toggleElementClass.bind(null, element, className));
1330
- continue;
1331
- }
1332
- if(value.$hydrate) {
1333
- value.$hydrate(element, className);
1371
+ if(value?.bindNdClass) {
1372
+ value.bindNdClass(element, className);
1334
1373
  continue;
1335
1374
  }
1336
1375
  element.classes.toggle(className, value);
@@ -1400,6 +1439,12 @@ var NativeDocument = (function (exports) {
1400
1439
  }
1401
1440
  }
1402
1441
 
1442
+ const NdBindings = {
1443
+ class: (element, value) => bindClassAttribute(element, value),
1444
+ style: (element, value) => bindStyleAttribute(element, value),
1445
+ };
1446
+
1447
+
1403
1448
  /**
1404
1449
  *
1405
1450
  * @param {HTMLElement} element
@@ -1415,41 +1460,27 @@ var NativeDocument = (function (exports) {
1415
1460
 
1416
1461
  for(let key in attributes) {
1417
1462
  const attributeName = key.toLowerCase();
1418
- let value = attributes[attributeName];
1419
- if(value === null || value === undefined) {
1463
+ let value = attributes[key];
1464
+ if(value == null) {
1420
1465
  continue;
1421
1466
  }
1422
1467
  if(value.handleNdAttribute) {
1423
1468
  value.handleNdAttribute(element, attributeName, value);
1424
1469
  continue;
1425
1470
  }
1426
- if(Validator.isString(value)) {
1427
- element.setAttribute(attributeName, value);
1428
- return;
1429
- }
1430
- if(attributeName === 'class' && Validator.isObject(value)) {
1431
- bindClassAttribute(element, value);
1432
- continue;
1433
- }
1434
- if(attributeName === 'style' && Validator.isObject(value)) {
1435
- bindStyleAttribute(element, value);
1436
- continue;
1471
+ if(typeof value === 'object') {
1472
+ const binding = NdBindings[attributeName];
1473
+ if(binding) {
1474
+ binding(element, value);
1475
+ continue;
1476
+ }
1437
1477
  }
1438
- if(BOOLEAN_ATTRIBUTES.includes(attributeName)) {
1478
+ if(BOOLEAN_ATTRIBUTES.has(attributeName)) {
1439
1479
  bindBooleanAttribute(element, attributeName, value);
1440
1480
  continue;
1441
1481
  }
1442
- if(Validator.isObservable(value)) {
1443
- bindAttributeWithObservable(element, attributeName, value);
1444
- continue;
1445
- }
1446
- if(value.$hydrate) {
1447
- value.$hydrate(element, attributeName);
1448
- continue;
1449
- }
1450
1482
 
1451
1483
  element.setAttribute(attributeName, value);
1452
-
1453
1484
  }
1454
1485
  return element;
1455
1486
  }
@@ -1510,7 +1541,20 @@ var NativeDocument = (function (exports) {
1510
1541
  element.setAttribute(attributeName, this);
1511
1542
  };
1512
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
+
1513
1552
  ObservableItem.prototype.handleNdAttribute = function(element, attributeName) {
1553
+ if(BOOLEAN_ATTRIBUTES.has(attributeName)) {
1554
+ bindBooleanAttribute(element, attributeName, this);
1555
+ return;
1556
+ }
1557
+
1514
1558
  bindAttributeWithObservable(element, attributeName, this);
1515
1559
  };
1516
1560
 
@@ -1596,19 +1640,14 @@ var NativeDocument = (function (exports) {
1596
1640
  PluginsManager.emit('AfterProcessChildren', parent);
1597
1641
  },
1598
1642
  getChild(child) {
1599
- if(child == null) {
1600
- return null;
1601
- }
1602
- if(child.toNdElement) {
1603
- do {
1604
- child = child.toNdElement();
1605
- if(Validator.isElement(child)) {
1606
- return child;
1607
- }
1608
- } while (child.toNdElement);
1643
+ while (child?.toNdElement) {
1644
+ child = child.toNdElement();
1645
+
1646
+ if (Validator.isElement(child)) return child;
1647
+ if (!child) return null;
1609
1648
  }
1610
1649
 
1611
- return ElementCreator.createStaticTextNode(null, child);
1650
+ return child ? ElementCreator.createStaticTextNode(null, child) : null;
1612
1651
  },
1613
1652
  /**
1614
1653
  *
@@ -1715,22 +1754,85 @@ var NativeDocument = (function (exports) {
1715
1754
  "ContextMenu"
1716
1755
  ];
1717
1756
 
1718
- let createNdElementInstance = (target) => {
1719
- attachEventPrototypes && attachEventPrototypes();
1720
- attachEventPrototypes = null;
1721
- createNdElementInstance = (target) => new NDElement(target);
1722
- return new NDElement(target);
1723
- };
1757
+ const EVENTS_WITH_PREVENT = [
1758
+ "Click",
1759
+ "DblClick",
1760
+ "MouseDown",
1761
+ "MouseUp",
1762
+ "Wheel",
1763
+ "KeyDown",
1764
+ "KeyPress",
1765
+ "Invalid",
1766
+ "Reset",
1767
+ "Submit",
1768
+ "DragOver",
1769
+ "Drop",
1770
+ "BeforeUnload",
1771
+ "TouchCancel",
1772
+ "TouchEnd",
1773
+ "TouchMove",
1774
+ "TouchStart",
1775
+ "Copy",
1776
+ "Cut",
1777
+ "Paste",
1778
+ "ContextMenu"
1779
+ ];
1780
+
1781
+ const EVENTS_WITH_STOP = [
1782
+ "Click",
1783
+ "DblClick",
1784
+ "MouseDown",
1785
+ "MouseMove",
1786
+ "MouseOut",
1787
+ "MouseOver",
1788
+ "MouseUp",
1789
+ "Wheel",
1790
+ "KeyDown",
1791
+ "KeyPress",
1792
+ "KeyUp",
1793
+ "Change",
1794
+ "Input",
1795
+ "Invalid",
1796
+ "Reset",
1797
+ "Search",
1798
+ "Select",
1799
+ "Submit",
1800
+ "Drag",
1801
+ "DragEnd",
1802
+ "DragEnter",
1803
+ "DragLeave",
1804
+ "DragOver",
1805
+ "DragStart",
1806
+ "Drop",
1807
+ "BeforeUnload",
1808
+ "HashChange",
1809
+ "TouchCancel",
1810
+ "TouchEnd",
1811
+ "TouchMove",
1812
+ "TouchStart",
1813
+ "AnimationEnd",
1814
+ "AnimationIteration",
1815
+ "AnimationStart",
1816
+ "TransitionEnd",
1817
+ "Copy",
1818
+ "Cut",
1819
+ "Paste",
1820
+ "FocusIn",
1821
+ "FocusOut",
1822
+ "ContextMenu"
1823
+ ];
1824
+
1724
1825
  const property = {
1725
1826
  configurable: true,
1726
1827
  get() {
1727
- return createNdElementInstance(this);
1828
+ return new NDElement(this);
1728
1829
  }
1729
1830
  };
1730
1831
 
1731
1832
  Object.defineProperty(HTMLElement.prototype, 'nd', property);
1732
1833
 
1733
1834
  Object.defineProperty(DocumentFragment.prototype, 'nd', property);
1835
+
1734
1836
  Object.defineProperty(NDElement.prototype, 'nd', {
1735
1837
  configurable: true,
1736
1838
  get: function() {
@@ -1743,31 +1845,29 @@ var NativeDocument = (function (exports) {
1743
1845
  // ----------------------------------------------------------------
1744
1846
  // Events helpers
1745
1847
  // ----------------------------------------------------------------
1848
+ EVENTS.forEach(eventSourceName => {
1849
+ const eventName = eventSourceName.toLowerCase();
1850
+ NDElement.prototype['on'+eventSourceName] = function(callback = null) {
1851
+ this.$element.addEventListener(eventName, callback);
1852
+ return this;
1853
+ };
1854
+ });
1746
1855
 
1747
- let attachEventPrototypes = () => {
1748
- EVENTS.forEach(eventSourceName => {
1749
- const eventName = eventSourceName.toLowerCase();
1750
- NDElement.prototype['on'+eventSourceName] = function(callback) {
1751
- this.$element.addEventListener(eventName, callback);
1752
- return this;
1753
- };
1754
-
1755
- NDElement.prototype['onPrevent'+eventSourceName] = function(callback) {
1756
- _prevent(this.$element, eventName, callback);
1757
- return this;
1758
- };
1759
-
1760
- NDElement.prototype['onStop'+eventSourceName] = function(callback) {
1761
- _stop(this.$element, eventName, callback);
1762
- return this;
1763
- };
1856
+ EVENTS_WITH_STOP.forEach(eventSourceName => {
1857
+ const eventName = eventSourceName.toLowerCase();
1858
+ NDElement.prototype['onStop'+eventSourceName] = function(callback = null) {
1859
+ _stop(this.$element, eventName, callback);
1860
+ return this;
1861
+ };
1862
+ });
1764
1863
 
1765
- NDElement.prototype['onPreventStop'+eventSourceName] = function(callback) {
1766
- _preventStop(this.$element, eventName, callback);
1767
- return this;
1768
- };
1769
- });
1770
- };
1864
+ EVENTS_WITH_PREVENT.forEach(eventSourceName => {
1865
+ const eventName = eventSourceName.toLowerCase();
1866
+ NDElement.prototype['onPrevent'+eventSourceName] = function(callback = null) {
1867
+ _prevent(this.$element, eventName, callback);
1868
+ return this;
1869
+ };
1870
+ });
1771
1871
 
1772
1872
  NDElement.prototype.on = function(name, callback, options) {
1773
1873
  this.$element.addEventListener(name.toLowerCase(), callback, options);
@@ -1792,16 +1892,6 @@ var NativeDocument = (function (exports) {
1792
1892
  return this;
1793
1893
  };
1794
1894
 
1795
- const _preventStop = function(element, eventName, callback) {
1796
- const handler = (event) => {
1797
- event.stopPropagation();
1798
- event.preventDefault();
1799
- callback && callback.call(element, event);
1800
- };
1801
- element.addEventListener(eventName, handler);
1802
- return this;
1803
- };
1804
-
1805
1895
 
1806
1896
 
1807
1897
  // ----------------------------------------------------------------
@@ -2025,7 +2115,7 @@ var NativeDocument = (function (exports) {
2025
2115
  if(bindDingData.attributes) {
2026
2116
  attributes = {};
2027
2117
  for (const attr in bindDingData.attributes) {
2028
- attributes[attr] = bindDingData.attributes[attr](...data);
2118
+ attributes[attr] = bindDingData.attributes[attr].apply(null, data);
2029
2119
  }
2030
2120
  }
2031
2121
 
@@ -2033,7 +2123,7 @@ var NativeDocument = (function (exports) {
2033
2123
  attributes = attributes || {};
2034
2124
  attributes.class = {};
2035
2125
  for (const className in bindDingData.classes) {
2036
- attributes.class[className] = bindDingData.classes[className](...data);
2126
+ attributes.class[className] = bindDingData.classes[className].apply(null, data);
2037
2127
  }
2038
2128
  }
2039
2129
 
@@ -2041,7 +2131,7 @@ var NativeDocument = (function (exports) {
2041
2131
  attributes = attributes || {};
2042
2132
  attributes.style = {};
2043
2133
  for (const property in bindDingData.styles) {
2044
- attributes.style[property] = bindDingData.styles[property](...data);
2134
+ attributes.style[property] = bindDingData.styles[property].apply(null, data);
2045
2135
  }
2046
2136
  }
2047
2137
 
@@ -2053,6 +2143,14 @@ var NativeDocument = (function (exports) {
2053
2143
  return null;
2054
2144
  };
2055
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
+
2056
2154
  const $hydrateFn = function(hydrateFunction, targetType, element, property) {
2057
2155
  if(!cloneBindingsDataCache.has(element)) {
2058
2156
  // { classes, styles, attributes, value, attach }
@@ -2073,7 +2171,7 @@ var NativeDocument = (function (exports) {
2073
2171
  }
2074
2172
  for(const methodName in bindDingData.attach) {
2075
2173
  node.nd[methodName](function(...args) {
2076
- bindDingData.attach[methodName].call(this, ...[...args, ...data]);
2174
+ bindDingData.attach[methodName].apply(this, [...args, ...data]);
2077
2175
  });
2078
2176
  }
2079
2177
  };
@@ -2082,44 +2180,78 @@ var NativeDocument = (function (exports) {
2082
2180
  let $node = null;
2083
2181
  let $hasBindingData = false;
2084
2182
 
2085
- const clone = (node, data) => {
2183
+ const $bindingPaths = [];
2184
+
2185
+ const clone = (node, data, path) => {
2086
2186
  const bindDingData = cloneBindingsDataCache.get(node);
2087
2187
  if(node.nodeType === 3) {
2088
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
+ });
2089
2200
  return bindDingData.value(data);
2090
2201
  }
2091
2202
  return node.cloneNode(true);
2092
2203
  }
2093
2204
  const nodeCloned = node.cloneNode(node.fullCloneNode);
2205
+ if(node.fullCloneNode) {
2206
+ return nodeCloned;
2207
+ }
2094
2208
  if(bindDingData) {
2095
2209
  bindAttributes(nodeCloned, bindDingData, data);
2096
2210
  bindAttachMethods(nodeCloned, bindDingData, data);
2097
- }
2098
- if(node.fullCloneNode) {
2099
- return nodeCloned;
2211
+ $bindingPaths.push({
2212
+ path: [...path],
2213
+ fn: (data, targetNode) => {
2214
+ bindAttributes(targetNode, bindDingData, data);
2215
+ bindAttachMethods(targetNode, bindDingData, data);
2216
+ }
2217
+ });
2100
2218
  }
2101
2219
  const childNodes = node.childNodes;
2102
2220
  for(let i = 0, length = childNodes.length; i < length; i++) {
2103
2221
  const childNode = childNodes[i];
2104
- const childNodeCloned = clone(childNode, data);
2222
+ path.push(i);
2223
+ const childNodeCloned = clone(childNode, data, path);
2224
+ path.pop();
2105
2225
  nodeCloned.appendChild(childNodeCloned);
2106
2226
  }
2107
2227
  return nodeCloned;
2108
2228
  };
2109
2229
 
2110
- this.clone = (data) => {
2111
- if(!$node) {
2112
- $node = $fn(this);
2113
- if(!$hasBindingData) {
2114
- const nodeCloned = $node.cloneNode(true);
2115
- nodeCloned.fullCloneNode = true;
2116
- 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;
2117
2239
  }
2118
2240
  }
2241
+
2242
+ return root;
2243
+ };
2244
+
2245
+ this.clone = (data) => {
2246
+ $node = $fn(this);
2119
2247
  if(!$hasBindingData) {
2248
+ this.clone = () => $node.cloneNode(true);
2120
2249
  return $node.cloneNode(true);
2121
2250
  }
2122
- return clone($node, data);
2251
+
2252
+ const firstClone = clone($node, data, []);
2253
+ this.clone = cloneWithBindingPaths;
2254
+ return firstClone;
2123
2255
  };
2124
2256
 
2125
2257
 
@@ -2178,6 +2310,7 @@ var NativeDocument = (function (exports) {
2178
2310
  return wrapper([_, __, ...args]);
2179
2311
  };
2180
2312
  }
2313
+ w;
2181
2314
 
2182
2315
  function SingletonView($viewCreator) {
2183
2316
  let $cacheNode = null;
@@ -2750,6 +2883,13 @@ var NativeDocument = (function (exports) {
2750
2883
  ObservableArray.prototype.constructor = ObservableArray;
2751
2884
  ObservableArray.prototype.__$isObservableArray = true;
2752
2885
 
2886
+
2887
+ Object.defineProperty(ObservableArray.prototype, 'length', {
2888
+ get() {
2889
+ return this.$currentValue.length;
2890
+ }
2891
+ });
2892
+
2753
2893
  mutationMethods.forEach((method) => {
2754
2894
  ObservableArray.prototype[method] = function(...values) {
2755
2895
  const result = this.$currentValue[method](...values);
@@ -2765,6 +2905,9 @@ var NativeDocument = (function (exports) {
2765
2905
  });
2766
2906
 
2767
2907
  ObservableArray.prototype.clear = function() {
2908
+ if(this.$currentValue.length === 0) {
2909
+ return;
2910
+ }
2768
2911
  this.$currentValue.length = 0;
2769
2912
  this.trigger({ action: 'clear' });
2770
2913
  return true;
@@ -2794,10 +2937,6 @@ var NativeDocument = (function (exports) {
2794
2937
  return count;
2795
2938
  };
2796
2939
 
2797
- ObservableArray.prototype.length = function() {
2798
- return this.$currentValue.length;
2799
- };
2800
-
2801
2940
  ObservableArray.prototype.swap = function(indexA, indexB) {
2802
2941
  const value = this.$currentValue;
2803
2942
  const length = value.length;
@@ -3296,7 +3435,7 @@ var NativeDocument = (function (exports) {
3296
3435
  }
3297
3436
  cache.set(keyId, { keyId, isNew: true, child: new WeakRef(child), indexObserver});
3298
3437
  } catch (e) {
3299
- DebugManager.error('ForEach', `Error creating element for key ${keyId}` , e);
3438
+ DebugManager$1.error('ForEach', `Error creating element for key ${keyId}` , e);
3300
3439
  throw e;
3301
3440
  }
3302
3441
  return keyId;
@@ -3378,7 +3517,7 @@ var NativeDocument = (function (exports) {
3378
3517
  return element;
3379
3518
  }
3380
3519
 
3381
- function ForEachArray(data, callback, key, configs = {}) {
3520
+ function ForEachArray(data, callback, configs = {}) {
3382
3521
  const element = Anchor('ForEach Array');
3383
3522
  const blockEnd = element.endElement();
3384
3523
  const blockStart = element.startElement();
@@ -3387,23 +3526,14 @@ var NativeDocument = (function (exports) {
3387
3526
  let lastNumberOfItems = 0;
3388
3527
  const isIndexRequired = callback.length >= 2;
3389
3528
 
3390
- const keysCache = new WeakMap();
3391
-
3392
- const clear = () => {
3529
+ const clear = (items) => {
3393
3530
  element.removeChildren();
3394
- cleanCache();
3531
+ cleanCache(items);
3395
3532
  lastNumberOfItems = 0;
3396
3533
  };
3397
3534
 
3398
- const getItemKey = (item, indexKey) => {
3399
- if(keysCache.has(item)) {
3400
- return keysCache.get(item);
3401
- }
3402
- return getKey(item, indexKey, key);
3403
- };
3404
-
3405
3535
  const getItemChild = (item) => {
3406
- return getChildByKey(getItemKey(item));
3536
+ return cache.get(item)?.child;
3407
3537
  };
3408
3538
 
3409
3539
  const updateIndexObservers = (items, startFrom = 0) => {
@@ -3412,16 +3542,17 @@ var NativeDocument = (function (exports) {
3412
3542
  }
3413
3543
  let index = startFrom;
3414
3544
  for(let i = startFrom, length = items?.length; i < length; i++) {
3415
- const cacheItem = cache.get(getItemKey(items[i], i));
3545
+ const cacheItem = cache.get(items[i]);
3416
3546
  if(!cacheItem) {
3417
3547
  continue;
3418
3548
  }
3419
- cacheItem.indexObserver?.deref()?.set(index);
3549
+ cacheItem.indexObserver?.set(index);
3420
3550
  index++;
3421
3551
  }
3422
3552
  };
3423
3553
 
3424
- const removeCacheItem = (cacheItem, removeChild = true) => {
3554
+ const removeCacheItem = (item, removeChild = true) => {
3555
+ const cacheItem = cache.get(item);
3425
3556
  if(!cacheItem) {
3426
3557
  return;
3427
3558
  }
@@ -3430,14 +3561,10 @@ var NativeDocument = (function (exports) {
3430
3561
  child?.remove();
3431
3562
  cache.delete(cacheItem.keyId);
3432
3563
  }
3433
- cacheItem.indexObserver?.deref()?.cleanup();
3434
- };
3435
-
3436
- const removeCacheItemByKey = (keyId, removeChild = true) => {
3437
- removeCacheItem(cache.get(keyId), removeChild);
3564
+ cacheItem.indexObserver?.cleanup();
3438
3565
  };
3439
3566
 
3440
- const cleanCache = () => {
3567
+ const cleanCache = (items) => {
3441
3568
  if(configs.shouldKeepItemsInCache) {
3442
3569
  return;
3443
3570
  }
@@ -3445,53 +3572,41 @@ var NativeDocument = (function (exports) {
3445
3572
  cache.clear();
3446
3573
  return;
3447
3574
  }
3448
- for (const [keyId, cacheItem] of cache.entries()) {
3449
- removeCacheItem(cacheItem, false);
3575
+ for (const [itemAsKey, _] of cache.entries()) {
3576
+ if(items && items.contains(itemAsKey)) {
3577
+ continue;
3578
+ }
3579
+ removeCacheItem(itemAsKey, false);
3450
3580
  }
3451
3581
  cache.clear();
3452
3582
  };
3453
3583
 
3454
3584
  const buildItem = (item, indexKey) => {
3455
- const keyId = getItemKey(item, indexKey);
3456
-
3457
- if(cache.has(keyId)) {
3458
- const cacheItem = cache.get(keyId);
3459
- cacheItem.indexObserver?.deref()?.set(indexKey);
3585
+ const cacheItem = cache.get(item);
3586
+ if(cacheItem) {
3587
+ cacheItem.indexObserver?.set(indexKey);
3460
3588
  const child = cacheItem.child;
3461
3589
  if(child) {
3462
3590
  return child;
3463
3591
  }
3464
- cache.delete(keyId);
3592
+ cache.delete(item);
3465
3593
  }
3466
3594
 
3467
3595
  const indexObserver = isIndexRequired ? Observable(indexKey) : null;
3468
3596
  let child = ElementCreator.getChild(callback(item, indexObserver));
3469
- if(!child) {
3470
- throw new NativeDocumentError("ForEachArray child can't be null or undefined!");
3471
- }
3472
- cache.set(keyId, {
3473
- keyId,
3474
- child: child,
3475
- indexObserver: (indexObserver ? new WeakRef(indexObserver) : null)
3476
- });
3477
- keysCache.set(item, keyId);
3478
- return child;
3479
- };
3480
- const getChildByKey = function(keyId) {
3481
- const cacheItem = cache.get(keyId);
3482
- if(!cacheItem) {
3483
- return null;
3484
- }
3485
- const child = cacheItem.child;
3486
- if(!child) {
3487
- removeCacheItem(cacheItem, false);
3488
- return null;
3597
+ if(child) {
3598
+ cache.set(item, {
3599
+ child,
3600
+ indexObserver: (indexObserver ? new WeakRef(indexObserver) : null)
3601
+ });
3602
+ return child;
3489
3603
  }
3490
- return child;
3604
+
3605
+ throw new NativeDocumentError("ForEachArray child can't be null or undefined!");
3491
3606
  };
3492
3607
 
3493
- const removeByKey = function(keyId, fragment) {
3494
- const cacheItem = cache.get(keyId);
3608
+ const removeByItem = function(item, fragment) {
3609
+ const cacheItem = cache.get(item);
3495
3610
  if(!cacheItem) {
3496
3611
  return null;
3497
3612
  }
@@ -3517,11 +3632,10 @@ var NativeDocument = (function (exports) {
3517
3632
  return fragment;
3518
3633
  },
3519
3634
  add(items, delay = 2) {
3520
- const fragment = Actions.toFragment(items);
3521
- element.appendElement(fragment);
3635
+ element.appendElement(Actions.toFragment(items));
3522
3636
  },
3523
3637
  replace(items) {
3524
- clear();
3638
+ clear(items);
3525
3639
  Actions.add(items);
3526
3640
  },
3527
3641
  reOrder(items) {
@@ -3537,7 +3651,7 @@ var NativeDocument = (function (exports) {
3537
3651
  element.appendElement(fragment, blockEnd);
3538
3652
  },
3539
3653
  removeOne(element, index) {
3540
- removeCacheItemByKey(getItemKey(element, index), true);
3654
+ removeCacheItem(element, true);
3541
3655
  },
3542
3656
  clear,
3543
3657
  merge(items) {
@@ -3571,16 +3685,15 @@ var NativeDocument = (function (exports) {
3571
3685
  const garbageFragment = document.createDocumentFragment();
3572
3686
 
3573
3687
  if(deleted.length > 0) {
3574
- let firstKey = getItemKey(deleted[0], start);
3688
+ let firstItem = deleted[0];
3575
3689
  if(deleted.length === 1) {
3576
- removeByKey(firstKey, garbageFragment);
3690
+ removeByItem(firstItem, garbageFragment);
3577
3691
  } else if(deleted.length > 1) {
3578
- const firstChildRemoved = getChildByKey(firstKey);
3692
+ const firstChildRemoved = getItemChild(deleted[0]);
3579
3693
  elementBeforeFirst = firstChildRemoved?.previousSibling;
3580
3694
 
3581
3695
  for(let i = 0; i < deleted.length; i++) {
3582
- const keyId = getItemKey(deleted[i], start + i);
3583
- removeByKey(keyId, garbageFragment);
3696
+ firstItem(deleted[i], garbageFragment);
3584
3697
  }
3585
3698
  }
3586
3699
  } else {
@@ -3668,7 +3781,7 @@ var NativeDocument = (function (exports) {
3668
3781
  */
3669
3782
  const ShowIf = function(condition, child, { comment = null, shouldKeepInCache = true} = {}) {
3670
3783
  if(!(Validator.isObservable(condition)) && !Validator.isObservableWhenResult(condition)) {
3671
- 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);
3672
3785
  }
3673
3786
  const element = Anchor('Show if : '+(comment || ''));
3674
3787
 
@@ -4455,7 +4568,7 @@ var NativeDocument = (function (exports) {
4455
4568
  window.history.pushState({ name: route.name(), params, path}, route.name() || path , path);
4456
4569
  this.handleRouteChange(route, params, query, path);
4457
4570
  } catch (e) {
4458
- DebugManager.error('HistoryRouter', 'Error in pushState', e);
4571
+ DebugManager$1.error('HistoryRouter', 'Error in pushState', e);
4459
4572
  }
4460
4573
  };
4461
4574
  /**
@@ -4468,7 +4581,7 @@ var NativeDocument = (function (exports) {
4468
4581
  window.history.replaceState({ name: route.name(), params, path}, route.name() || path , path);
4469
4582
  this.handleRouteChange(route, params, {}, path);
4470
4583
  } catch(e) {
4471
- DebugManager.error('HistoryRouter', 'Error in replaceState', e);
4584
+ DebugManager$1.error('HistoryRouter', 'Error in replaceState', e);
4472
4585
  }
4473
4586
  };
4474
4587
  this.forward = function() {
@@ -4495,7 +4608,7 @@ var NativeDocument = (function (exports) {
4495
4608
  }
4496
4609
  this.handleRouteChange(route, params, query, path);
4497
4610
  } catch(e) {
4498
- DebugManager.error('HistoryRouter', 'Error in popstate event', e);
4611
+ DebugManager$1.error('HistoryRouter', 'Error in popstate event', e);
4499
4612
  }
4500
4613
  });
4501
4614
  const { route, params, query, path } = this.resolve(defaultPath || (window.location.pathname+window.location.search));
@@ -4658,7 +4771,7 @@ var NativeDocument = (function (exports) {
4658
4771
  listener(request);
4659
4772
  next && next(request);
4660
4773
  } catch (e) {
4661
- DebugManager.warn('Route Listener', 'Error in listener:', e);
4774
+ DebugManager$1.warn('Route Listener', 'Error in listener:', e);
4662
4775
  }
4663
4776
  }
4664
4777
  };
@@ -4817,7 +4930,7 @@ var NativeDocument = (function (exports) {
4817
4930
  */
4818
4931
  Router.create = function(options, callback) {
4819
4932
  if(!Validator.isFunction(callback)) {
4820
- DebugManager.error('Router', 'Callback must be a function', e);
4933
+ DebugManager$1.error('Router', 'Callback must be a function', e);
4821
4934
  throw new RouterError('Callback must be a function');
4822
4935
  }
4823
4936
  const router = new Router(options);