native-document 1.0.103 → 1.0.105

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
1
  var NativeDocument = (function (exports) {
2
2
  'use strict';
3
3
 
4
- let DebugManager = {};
4
+ let DebugManager$1 = {};
5
5
 
6
6
  {
7
- DebugManager = {
7
+ DebugManager$1 = {
8
8
  enabled: false,
9
9
 
10
10
  enable() {
@@ -35,7 +35,7 @@ var NativeDocument = (function (exports) {
35
35
  };
36
36
 
37
37
  }
38
- var DebugManager$1 = DebugManager;
38
+ var DebugManager = DebugManager$1;
39
39
 
40
40
  class NativeDocumentError extends Error {
41
41
  constructor(message, context = {}) {
@@ -313,10 +313,10 @@ var NativeDocument = (function (exports) {
313
313
  subtree: true,
314
314
  });
315
315
 
316
- let PluginsManager = null;
316
+ let PluginsManager$1 = null;
317
317
 
318
318
  {
319
- PluginsManager = (function() {
319
+ PluginsManager$1 = (function() {
320
320
 
321
321
  const $plugins = new Map();
322
322
  const $pluginByEvents = new Map();
@@ -382,7 +382,7 @@ var NativeDocument = (function (exports) {
382
382
  try{
383
383
  callback.call(plugin, ...data);
384
384
  } catch (error) {
385
- DebugManager$1.error('Plugin Manager', `Error in plugin ${plugin.$name} for event ${eventName}`, error);
385
+ DebugManager.error('Plugin Manager', `Error in plugin ${plugin.$name} for event ${eventName}`, error);
386
386
  }
387
387
  }
388
388
  }
@@ -391,13 +391,13 @@ var NativeDocument = (function (exports) {
391
391
  }());
392
392
  }
393
393
 
394
- var PluginsManager$1 = PluginsManager;
394
+ var PluginsManager = PluginsManager$1;
395
395
 
396
396
  function NDElement(element) {
397
397
  this.$element = element;
398
398
  this.$observer = null;
399
399
  {
400
- PluginsManager$1.emit('NDElementCreated', element, this);
400
+ PluginsManager.emit('NDElementCreated', element, this);
401
401
  }
402
402
  }
403
403
 
@@ -572,7 +572,7 @@ var NativeDocument = (function (exports) {
572
572
  }
573
573
  {
574
574
  if (this[name] && !this.$localExtensions.has(name)) {
575
- DebugManager$1.warn('NDElement.extend', `Method "${name}" already exists and will be overwritten`);
575
+ DebugManager.warn('NDElement.extend', `Method "${name}" already exists and will be overwritten`);
576
576
  }
577
577
  this.$localExtensions.set(name, method);
578
578
  }
@@ -623,23 +623,23 @@ var NativeDocument = (function (exports) {
623
623
  const method = methods[name];
624
624
 
625
625
  if (typeof method !== 'function') {
626
- DebugManager$1.warn('NDElement.extend', `"${name}" is not a function, skipping`);
626
+ DebugManager.warn('NDElement.extend', `"${name}" is not a function, skipping`);
627
627
  continue;
628
628
  }
629
629
 
630
630
  if (protectedMethods.has(name)) {
631
- DebugManager$1.error('NDElement.extend', `Cannot override protected method "${name}"`);
631
+ DebugManager.error('NDElement.extend', `Cannot override protected method "${name}"`);
632
632
  throw new NativeDocumentError(`Cannot override protected method "${name}"`);
633
633
  }
634
634
 
635
635
  if (NDElement.prototype[name]) {
636
- DebugManager$1.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
636
+ DebugManager.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
637
637
  }
638
638
 
639
639
  NDElement.prototype[name] = method;
640
640
  }
641
641
  {
642
- PluginsManager$1.emit('NDElementExtended', methods);
642
+ PluginsManager.emit('NDElementExtended', methods);
643
643
  }
644
644
 
645
645
  return NDElement;
@@ -652,6 +652,13 @@ var NativeDocument = (function (exports) {
652
652
  DOCUMENT_FRAGMENT: 11
653
653
  };
654
654
 
655
+ const VALID_TYPES = {
656
+ [COMMON_NODE_TYPES.ELEMENT]: true,
657
+ [COMMON_NODE_TYPES.TEXT]: true,
658
+ [COMMON_NODE_TYPES.DOCUMENT_FRAGMENT]: true,
659
+ [COMMON_NODE_TYPES.COMMENT]: true
660
+ };
661
+
655
662
  const Validator = {
656
663
  isObservable(value) {
657
664
  return value?.__$isObservable;
@@ -702,12 +709,10 @@ var NativeDocument = (function (exports) {
702
709
  return !(typeof value !== 'object' || value === null || Array.isArray(value) || value.constructor.name !== 'Object')
703
710
  },
704
711
  isElement(value) {
705
- return value && (
706
- value.nodeType === COMMON_NODE_TYPES.ELEMENT ||
707
- value.nodeType === COMMON_NODE_TYPES.TEXT ||
708
- value.nodeType === COMMON_NODE_TYPES.DOCUMENT_FRAGMENT ||
709
- value.nodeType === COMMON_NODE_TYPES.COMMENT
710
- );
712
+ return value && VALID_TYPES[value.nodeType];
713
+ },
714
+ isDOMNode(value) {
715
+ return VALID_TYPES[value.nodeType];
711
716
  },
712
717
  isFragment(value) {
713
718
  return value?.nodeType === COMMON_NODE_TYPES.DOCUMENT_FRAGMENT;
@@ -786,7 +791,7 @@ var NativeDocument = (function (exports) {
786
791
  const foundReserved = Object.keys(attributes).filter(key => reserved.includes(key));
787
792
 
788
793
  if (foundReserved.length > 0) {
789
- DebugManager$1.warn('Validator', `Reserved attributes found: ${foundReserved.join(', ')}`);
794
+ DebugManager.warn('Validator', `Reserved attributes found: ${foundReserved.join(', ')}`);
790
795
  }
791
796
 
792
797
  return attributes;
@@ -807,7 +812,9 @@ var NativeDocument = (function (exports) {
807
812
  anchorFragment.nativeAppendChild = anchorFragment.appendChild;
808
813
  anchorFragment.nativeAppend = anchorFragment.append;
809
814
 
810
- const isParentUniqueChild = (parent) => (isUniqueChild || (parent.firstChild === anchorStart && parent.lastChild === anchorEnd));
815
+ const isParentUniqueChild = isUniqueChild
816
+ ? () => true
817
+ : (parent) => (parent.firstChild === anchorStart && parent.lastChild === anchorEnd);
811
818
 
812
819
  const insertBefore = function(parent, child, target) {
813
820
  const childElement = Validator.isElement(child) ? child : ElementCreator.getChild(child);
@@ -835,7 +842,7 @@ var NativeDocument = (function (exports) {
835
842
  anchorFragment.appendChild = function(child, before = null) {
836
843
  const parent = anchorEnd.parentNode;
837
844
  if(!parent) {
838
- DebugManager$1.error('Anchor', 'Anchor : parent not found', child);
845
+ DebugManager.error('Anchor', 'Anchor : parent not found', child);
839
846
  return;
840
847
  }
841
848
  before = before ?? anchorEnd;
@@ -846,61 +853,58 @@ var NativeDocument = (function (exports) {
846
853
  return anchorFragment.appendChild(args);
847
854
  };
848
855
 
849
- anchorFragment.removeChildren = async function() {
856
+ anchorFragment.removeChildren = function() {
850
857
  const parent = anchorEnd.parentNode;
851
858
  if(parent === anchorFragment) {
852
859
  return;
853
860
  }
854
- // if(isParentUniqueChild(parent)) {
855
- // parent.replaceChildren(anchorStart, anchorEnd);
856
- // return;
857
- // }
861
+ if(isParentUniqueChild(parent)) {
862
+ parent.replaceChildren(anchorStart, anchorEnd);
863
+ return;
864
+ }
858
865
 
859
866
  let itemToRemove = anchorStart.nextSibling, tempItem;
860
- const removes = [];
861
867
  while(itemToRemove && itemToRemove !== anchorEnd) {
862
868
  tempItem = itemToRemove.nextSibling;
863
- removes.push(itemToRemove.remove());
869
+ itemToRemove.remove();
864
870
  itemToRemove = tempItem;
865
871
  }
866
- await Promise.all(removes);
867
872
  };
868
873
 
869
- anchorFragment.remove = async function() {
874
+ anchorFragment.remove = function() {
870
875
  const parent = anchorEnd.parentNode;
871
876
  if(parent === anchorFragment) {
872
877
  return;
873
878
  }
879
+ if(isParentUniqueChild(parent)) {
880
+ parent.replaceChildren(anchorStart, anchorEnd);
881
+ return;
882
+ }
874
883
  let itemToRemove = anchorStart.nextSibling, tempItem;
875
- const allItemToRemove = [];
876
- const removes = [];
877
884
  while(itemToRemove && itemToRemove !== anchorEnd) {
878
885
  tempItem = itemToRemove.nextSibling;
879
- allItemToRemove.push(itemToRemove);
880
- removes.push(itemToRemove.remove());
886
+ anchorFragment.nativeAppend(itemToRemove);
881
887
  itemToRemove = tempItem;
882
888
  }
883
- await Promise.all(removes);
884
- anchorFragment.nativeAppend(...allItemToRemove);
885
889
  };
886
890
 
887
- anchorFragment.removeWithAnchors = async function() {
888
- await anchorFragment.removeChildren();
891
+ anchorFragment.removeWithAnchors = function() {
892
+ anchorFragment.removeChildren();
889
893
  anchorStart.remove();
890
894
  anchorEnd.remove();
891
895
  };
892
896
 
893
- anchorFragment.replaceContent = async function(child) {
897
+ anchorFragment.replaceContent = function(child) {
894
898
  const childElement = Validator.isElement(child) ? child : ElementCreator.getChild(child);
895
899
  const parent = anchorEnd.parentNode;
896
900
  if(!parent) {
897
901
  return;
898
902
  }
899
- // if(isParentUniqueChild(parent)) {
900
- // parent.replaceChildren(anchorStart, childElement, anchorEnd);
901
- // return;
902
- // }
903
- await anchorFragment.removeChildren();
903
+ if(isParentUniqueChild(parent)) {
904
+ parent.replaceChildren(anchorStart, childElement, anchorEnd);
905
+ return;
906
+ }
907
+ anchorFragment.removeChildren();
904
908
  parent.insertBefore(childElement, anchorEnd);
905
909
  };
906
910
 
@@ -910,7 +914,6 @@ var NativeDocument = (function (exports) {
910
914
  anchorFragment.appendChild(child, anchor);
911
915
  };
912
916
 
913
-
914
917
  anchorFragment.endElement = function() {
915
918
  return anchorEnd;
916
919
  };
@@ -1033,7 +1036,7 @@ var NativeDocument = (function (exports) {
1033
1036
  }
1034
1037
  }
1035
1038
  if (cleanedCount > 0) {
1036
- DebugManager$1.log('Memory Auto Clean', `🧹 Cleaned ${cleanedCount} orphaned observables`);
1039
+ DebugManager.log('Memory Auto Clean', `🧹 Cleaned ${cleanedCount} orphaned observables`);
1037
1040
  }
1038
1041
  }
1039
1042
  };
@@ -1235,7 +1238,7 @@ var NativeDocument = (function (exports) {
1235
1238
  const $getStoreOrThrow = (method, name) => {
1236
1239
  const item = $stores.get(name);
1237
1240
  if (!item) {
1238
- DebugManager$1.error('Store', `Store.${method}('${name}') : store not found. Did you call Store.create('${name}') first?`);
1241
+ DebugManager.error('Store', `Store.${method}('${name}') : store not found. Did you call Store.create('${name}') first?`);
1239
1242
  throw new NativeDocumentError(
1240
1243
  `Store.${method}('${name}') : store not found.`
1241
1244
  );
@@ -1248,7 +1251,7 @@ var NativeDocument = (function (exports) {
1248
1251
  */
1249
1252
  const $applyReadOnly = (observer, name, context) => {
1250
1253
  const readOnlyError = (method) => () => {
1251
- DebugManager$1.error('Store', `Store.${context}('${name}') is read-only. '${method}()' is not allowed.`);
1254
+ DebugManager.error('Store', `Store.${context}('${name}') is read-only. '${method}()' is not allowed.`);
1252
1255
  throw new NativeDocumentError(
1253
1256
  `Store.${context}('${name}') is read-only.`
1254
1257
  );
@@ -1279,7 +1282,7 @@ var NativeDocument = (function (exports) {
1279
1282
  */
1280
1283
  create(name, value) {
1281
1284
  if ($stores.has(name)) {
1282
- DebugManager$1.warn('Store', `Store.create('${name}') : a store with this name already exists. Use Store.get('${name}') to retrieve it.`);
1285
+ DebugManager.warn('Store', `Store.create('${name}') : a store with this name already exists. Use Store.get('${name}') to retrieve it.`);
1283
1286
  throw new NativeDocumentError(
1284
1287
  `Store.create('${name}') : a store with this name already exists.`
1285
1288
  );
@@ -1300,7 +1303,7 @@ var NativeDocument = (function (exports) {
1300
1303
  */
1301
1304
  createResettable(name, value) {
1302
1305
  if ($stores.has(name)) {
1303
- DebugManager$1.warn('Store', `Store.createResettable('${name}') : a store with this name already exists.`);
1306
+ DebugManager.warn('Store', `Store.createResettable('${name}') : a store with this name already exists.`);
1304
1307
  throw new NativeDocumentError(
1305
1308
  `Store.createResettable('${name}') : a store with this name already exists.`
1306
1309
  );
@@ -1336,7 +1339,7 @@ var NativeDocument = (function (exports) {
1336
1339
  */
1337
1340
  createComposed(name, computation, dependencies) {
1338
1341
  if ($stores.has(name)) {
1339
- DebugManager$1.warn('Store', `Store.createComposed('${name}') : a store with this name already exists.`);
1342
+ DebugManager.warn('Store', `Store.createComposed('${name}') : a store with this name already exists.`);
1340
1343
  throw new NativeDocumentError(
1341
1344
  `Store.createComposed('${name}') : a store with this name already exists.`
1342
1345
  );
@@ -1359,7 +1362,7 @@ var NativeDocument = (function (exports) {
1359
1362
  }
1360
1363
  const depItem = $stores.get(depName);
1361
1364
  if (!depItem) {
1362
- DebugManager$1.error('Store', `Store.createComposed('${name}') : dependency '${depName}' not found. Create it first.`);
1365
+ DebugManager.error('Store', `Store.createComposed('${name}') : dependency '${depName}' not found. Create it first.`);
1363
1366
  throw new NativeDocumentError(
1364
1367
  `Store.createComposed('${name}') : dependency store '${depName}' not found.`
1365
1368
  );
@@ -1393,13 +1396,13 @@ var NativeDocument = (function (exports) {
1393
1396
  reset(name) {
1394
1397
  const item = $getStoreOrThrow('reset', name);
1395
1398
  if (item.composed) {
1396
- DebugManager$1.error('Store', `Store.reset('${name}') : composed stores cannot be reset. Their value is derived from dependencies.`);
1399
+ DebugManager.error('Store', `Store.reset('${name}') : composed stores cannot be reset. Their value is derived from dependencies.`);
1397
1400
  throw new NativeDocumentError(
1398
1401
  `Store.reset('${name}') : composed stores cannot be reset.`
1399
1402
  );
1400
1403
  }
1401
1404
  if (!item.resettable) {
1402
- DebugManager$1.error('Store', `Store.reset('${name}') : this store is not resettable. Use Store.createResettable('${name}', value) instead of Store.create().`);
1405
+ DebugManager.error('Store', `Store.reset('${name}') : this store is not resettable. Use Store.createResettable('${name}', value) instead of Store.create().`);
1403
1406
  throw new NativeDocumentError(
1404
1407
  `Store.reset('${name}') : this store is not resettable. Use Store.createResettable('${name}', value) instead of Store.create().`
1405
1408
  );
@@ -1420,7 +1423,7 @@ var NativeDocument = (function (exports) {
1420
1423
  const item = $getStoreOrThrow('use', name);
1421
1424
 
1422
1425
  if (item.composed) {
1423
- DebugManager$1.error('Store', `Store.use('${name}') : composed stores are read-only. Use Store.follow('${name}') instead.`);
1426
+ DebugManager.error('Store', `Store.use('${name}') : composed stores are read-only. Use Store.follow('${name}') instead.`);
1424
1427
  throw new NativeDocumentError(
1425
1428
  `Store.use('${name}') : composed stores are read-only. Use Store.follow('${name}') instead.`
1426
1429
  );
@@ -1487,7 +1490,7 @@ var NativeDocument = (function (exports) {
1487
1490
  get(name) {
1488
1491
  const item = $stores.get(name);
1489
1492
  if (!item) {
1490
- DebugManager$1.warn('Store', `Store.get('${name}') : store not found.`);
1493
+ DebugManager.warn('Store', `Store.get('${name}') : store not found.`);
1491
1494
  return null;
1492
1495
  }
1493
1496
  return item.observer;
@@ -1509,7 +1512,7 @@ var NativeDocument = (function (exports) {
1509
1512
  delete(name) {
1510
1513
  const item = $stores.get(name);
1511
1514
  if (!item) {
1512
- DebugManager$1.warn('Store', `Store.delete('${name}') : store not found, nothing to delete.`);
1515
+ DebugManager.warn('Store', `Store.delete('${name}') : store not found, nothing to delete.`);
1513
1516
  return;
1514
1517
  }
1515
1518
  item.subscribers.forEach(follower => follower.destroy());
@@ -1611,7 +1614,7 @@ var NativeDocument = (function (exports) {
1611
1614
  return undefined;
1612
1615
  },
1613
1616
  set(target, prop, value) {
1614
- DebugManager$1.error('Store', `Forbidden: You cannot overwrite the store key '${String(prop)}'. Use .use('${String(prop)}').set(value) instead.`);
1617
+ DebugManager.error('Store', `Forbidden: You cannot overwrite the store key '${String(prop)}'. Use .use('${String(prop)}').set(value) instead.`);
1615
1618
  throw new NativeDocumentError(`Store structure is immutable. Use .set() on the observable.`);
1616
1619
  },
1617
1620
  deleteProperty(target, prop) {
@@ -1743,7 +1746,7 @@ var NativeDocument = (function (exports) {
1743
1746
  }
1744
1747
  }
1745
1748
  {
1746
- PluginsManager$1.emit('CreateObservable', this);
1749
+ PluginsManager.emit('CreateObservable', this);
1747
1750
  }
1748
1751
  }
1749
1752
 
@@ -1847,12 +1850,12 @@ var NativeDocument = (function (exports) {
1847
1850
  this.$previousValue = this.$currentValue;
1848
1851
  this.$currentValue = newValue;
1849
1852
  {
1850
- PluginsManager$1.emit('ObservableBeforeChange', this);
1853
+ PluginsManager.emit('ObservableBeforeChange', this);
1851
1854
  }
1852
1855
  this.trigger();
1853
1856
  this.$previousValue = null;
1854
1857
  {
1855
- PluginsManager$1.emit('ObservableAfterChange', this);
1858
+ PluginsManager.emit('ObservableAfterChange', this);
1856
1859
  }
1857
1860
  };
1858
1861
 
@@ -1885,17 +1888,8 @@ var NativeDocument = (function (exports) {
1885
1888
  };
1886
1889
 
1887
1890
  ObservableItem.prototype.disconnectAll = function() {
1888
- this.$listeners?.splice(0);
1889
1891
  this.$previousValue = null;
1890
1892
  this.$currentValue = null;
1891
- if(this.$watchers) {
1892
- for (const [_, watchValueList] of this.$watchers) {
1893
- if(Validator.isArray(watchValueList)) {
1894
- watchValueList.splice(0);
1895
- }
1896
- }
1897
- }
1898
- this.$watchers?.clear();
1899
1893
  this.$listeners = null;
1900
1894
  this.$watchers = null;
1901
1895
  this.trigger = noneTrigger;
@@ -1939,7 +1933,7 @@ var NativeDocument = (function (exports) {
1939
1933
  ObservableItem.prototype.subscribe = function(callback) {
1940
1934
  {
1941
1935
  if (this.$isCleanedUp) {
1942
- DebugManager$1.warn('Observable subscription', '⚠️ Attempted to subscribe to a cleaned up observable.');
1936
+ DebugManager.warn('Observable subscription', '⚠️ Attempted to subscribe to a cleaned up observable.');
1943
1937
  return;
1944
1938
  }
1945
1939
  if (typeof callback !== 'function') {
@@ -1951,7 +1945,7 @@ var NativeDocument = (function (exports) {
1951
1945
  this.$listeners.push(callback);
1952
1946
  this.assocTrigger();
1953
1947
  {
1954
- PluginsManager$1.emit('ObservableSubscribe', this);
1948
+ PluginsManager.emit('ObservableSubscribe', this);
1955
1949
  }
1956
1950
  };
1957
1951
 
@@ -2062,7 +2056,7 @@ var NativeDocument = (function (exports) {
2062
2056
  }
2063
2057
  this.assocTrigger();
2064
2058
  {
2065
- PluginsManager$1.emit('ObservableUnsubscribe', this);
2059
+ PluginsManager.emit('ObservableUnsubscribe', this);
2066
2060
  }
2067
2061
  };
2068
2062
 
@@ -2494,11 +2488,7 @@ var NativeDocument = (function (exports) {
2494
2488
  TemplateBinding.prototype.__$isTemplateBinding = true;
2495
2489
 
2496
2490
  String.prototype.toNdElement = function () {
2497
- const formattedChild = this.resolveObservableTemplate ? this.resolveObservableTemplate() : this;
2498
- if(Validator.isString(formattedChild)) {
2499
- return ElementCreator.createStaticTextNode(null, formattedChild);
2500
- }
2501
- return ElementCreator.getChild(null, formattedChild);
2491
+ return ElementCreator.createStaticTextNode(null, this);
2502
2492
  };
2503
2493
 
2504
2494
  Element.prototype.toNdElement = function () {
@@ -2540,7 +2530,7 @@ var NativeDocument = (function (exports) {
2540
2530
  Function.prototype.toNdElement = function () {
2541
2531
  const child = this;
2542
2532
  {
2543
- PluginsManager$1.emit('BeforeProcessComponent', child);
2533
+ PluginsManager.emit('BeforeProcessComponent', child);
2544
2534
  }
2545
2535
  return ElementCreator.getChild(child());
2546
2536
  };
@@ -2728,14 +2718,14 @@ var NativeDocument = (function (exports) {
2728
2718
  processChildren(children, parent) {
2729
2719
  if(children === null) return;
2730
2720
  {
2731
- PluginsManager$1.emit('BeforeProcessChildren', parent);
2721
+ PluginsManager.emit('BeforeProcessChildren', parent);
2732
2722
  }
2733
2723
  let child = this.getChild(children);
2734
2724
  if(child) {
2735
2725
  parent.appendChild(child);
2736
2726
  }
2737
2727
  {
2738
- PluginsManager$1.emit('AfterProcessChildren', parent);
2728
+ PluginsManager.emit('AfterProcessChildren', parent);
2739
2729
  }
2740
2730
  },
2741
2731
  async safeRemove(element) {
@@ -3991,7 +3981,7 @@ var NativeDocument = (function (exports) {
3991
3981
 
3992
3982
  ObservableItem.call(this, target, configs);
3993
3983
  {
3994
- PluginsManager$1.emit('CreateObservableArray', this);
3984
+ PluginsManager.emit('CreateObservableArray', this);
3995
3985
  }
3996
3986
  };
3997
3987
 
@@ -4623,7 +4613,7 @@ var NativeDocument = (function (exports) {
4623
4613
  const observable = new ObservableItem(initialValue);
4624
4614
  const updatedValue = nextTick(() => observable.set(callback()));
4625
4615
  {
4626
- PluginsManager$1.emit('CreateObservableComputed', observable, dependencies);
4616
+ PluginsManager.emit('CreateObservableComputed', observable, dependencies);
4627
4617
  }
4628
4618
 
4629
4619
  if(Validator.isFunction(dependencies)) {
@@ -4722,7 +4712,7 @@ var NativeDocument = (function (exports) {
4722
4712
  }
4723
4713
  cache.set(keyId, { keyId, isNew: true, child: new WeakRef(child), indexObserver});
4724
4714
  } catch (e) {
4725
- DebugManager$1.error('ForEach', `Error creating element for key ${keyId}` , e);
4715
+ DebugManager.error('ForEach', `Error creating element for key ${keyId}` , e);
4726
4716
  throw e;
4727
4717
  }
4728
4718
  return keyId;
@@ -4804,6 +4794,8 @@ var NativeDocument = (function (exports) {
4804
4794
  return element;
4805
4795
  }
4806
4796
 
4797
+ const CREATE_AND_CACHE_ACTIONS = new Set(['clear', 'push', 'unshift', 'replace']);
4798
+
4807
4799
  /**
4808
4800
  * Renders items from an ObservableArray with optimized array-specific updates.
4809
4801
  * Provides index observables and handles array mutations efficiently.
@@ -4864,50 +4856,67 @@ var NativeDocument = (function (exports) {
4864
4856
  if(removeChild) {
4865
4857
  const child = cacheItem.child;
4866
4858
  child?.remove();
4867
- cache.delete(cacheItem.keyId);
4859
+ cache.delete(item);
4868
4860
  }
4869
4861
  cacheItem.indexObserver?.cleanup();
4870
4862
  };
4871
4863
 
4872
- const cleanCache = (items) => {
4873
- if(configs.shouldKeepItemsInCache) {
4874
- return;
4875
- }
4876
- if(!isIndexRequired) {
4877
- cache.clear();
4878
- return;
4864
+ const createAndCache = (item) => {
4865
+ const child = ElementCreator.getChild(callback(item, null));
4866
+ {
4867
+ if(!child) {
4868
+ throw new NativeDocumentError("ForEachArray child can't be null or undefined!");
4869
+ }
4879
4870
  }
4880
- for (const [itemAsKey, _] of cache.entries()) {
4881
- if(items && items.contains(itemAsKey)) {
4882
- continue;
4871
+ cache.set(item, { child, indexObserver: null });
4872
+ return child;
4873
+ };
4874
+
4875
+ const createWithIndexAndCache = (item, indexKey) => {
4876
+ const indexObserver = Observable(indexKey);
4877
+ const child = ElementCreator.getChild(callback(item, indexObserver));
4878
+ {
4879
+ if(!child) {
4880
+ throw new NativeDocumentError("ForEachArray child can't be null or undefined!");
4883
4881
  }
4884
- removeCacheItem(itemAsKey, false);
4885
4882
  }
4886
- cache.clear();
4883
+ cache.set(item, { child, indexObserver });
4884
+ return child;
4887
4885
  };
4888
4886
 
4889
- const buildItem = (item, indexKey) => {
4887
+ const getOrCreate = (item, indexKey) => {
4890
4888
  const cacheItem = cache.get(item);
4891
4889
  if(cacheItem) {
4892
4890
  cacheItem.indexObserver?.set(indexKey);
4893
- const child = cacheItem.child;
4894
- if(child) {
4895
- return child;
4896
- }
4897
- cache.delete(item);
4891
+ return cacheItem.child;
4898
4892
  }
4893
+ return createAndCache(item);
4894
+ };
4899
4895
 
4900
- const indexObserver = isIndexRequired ? Observable(indexKey) : null;
4901
- let child = ElementCreator.getChild(callback(item, indexObserver));
4902
- if(child) {
4903
- cache.set(item, {
4904
- child,
4905
- indexObserver
4906
- });
4907
- return child;
4896
+ let buildItem = createAndCache;
4897
+ const selectBuildStrategy = (action = null) => {
4898
+ if(CREATE_AND_CACHE_ACTIONS.includes(action)) {
4899
+ buildItem = isIndexRequired ? createWithIndexAndCache : createAndCache;
4900
+ return;
4908
4901
  }
4902
+ buildItem = cache.size ? getOrCreate : (isIndexRequired ? createWithIndexAndCache : createAndCache);
4903
+ };
4904
+
4909
4905
 
4910
- throw new NativeDocumentError("ForEachArray child can't be null or undefined!");
4906
+ const cleanCache = (items) => {
4907
+ if(!isIndexRequired) {
4908
+ cache.clear();
4909
+ return;
4910
+ }
4911
+ if(configs.shouldKeepItemsInCache) {
4912
+ return;
4913
+ }
4914
+ for (const [itemAsKey, _] of cache.entries()) {
4915
+ if(items && items.includes(itemAsKey)) {
4916
+ continue;
4917
+ }
4918
+ removeCacheItem(itemAsKey, false);
4919
+ }
4911
4920
  };
4912
4921
 
4913
4922
  const removeByItem = function(item, fragment) {
@@ -4928,7 +4937,7 @@ var NativeDocument = (function (exports) {
4928
4937
  };
4929
4938
 
4930
4939
  const Actions = {
4931
- toFragment(items, startIndexFrom = 0){
4940
+ toFragment(items){
4932
4941
  const fragment = document.createDocumentFragment();
4933
4942
  for(let i = 0, length = items.length; i < length; i++) {
4934
4943
  fragment.appendChild(buildItem(items[i], lastNumberOfItems));
@@ -4936,7 +4945,7 @@ var NativeDocument = (function (exports) {
4936
4945
  }
4937
4946
  return fragment;
4938
4947
  },
4939
- add(items, delay = 2) {
4948
+ add(items) {
4940
4949
  element.appendElement(Actions.toFragment(items));
4941
4950
  },
4942
4951
  replace(items) {
@@ -5051,6 +5060,7 @@ var NativeDocument = (function (exports) {
5051
5060
  clear();
5052
5061
  return;
5053
5062
  }
5063
+ selectBuildStrategy(operations?.action);
5054
5064
 
5055
5065
  if(!operations?.action) {
5056
5066
  if(lastNumberOfItems === 0) {
@@ -5092,7 +5102,7 @@ var NativeDocument = (function (exports) {
5092
5102
  */
5093
5103
  const ShowIf = function(condition, child, { comment = null, shouldKeepInCache = true} = {}) {
5094
5104
  if(!(Validator.isObservable(condition)) && !Validator.isObservableWhenResult(condition)) {
5095
- return DebugManager$1.warn('ShowIf', "ShowIf : condition must be an Observable / "+comment, condition);
5105
+ return DebugManager.warn('ShowIf', "ShowIf : condition must be an Observable / "+comment, condition);
5096
5106
  }
5097
5107
  const element = Anchor('Show if : '+(comment || ''));
5098
5108
 
@@ -6107,15 +6117,9 @@ var NativeDocument = (function (exports) {
6107
6117
  /**
6108
6118
  * Creates an empty `DocumentFragment` wrapper.
6109
6119
  * Useful for grouping elements without adding a DOM node.
6110
- * @param {NdChild} children
6111
6120
  * @type {function(GlobalAttributes=, NdChild|NdChild[]=): DocumentFragment}
6112
- * @returns {Anchor}
6113
6121
  */
6114
- const Fragment = (children) => {
6115
- const fragment = Anchor('Fragment');
6116
- fragment.append(children);
6117
- return fragment;
6118
- };
6122
+ const Fragment = HtmlElementWrapper('');
6119
6123
 
6120
6124
  var elements = /*#__PURE__*/Object.freeze({
6121
6125
  __proto__: null,
@@ -6323,13 +6327,13 @@ var NativeDocument = (function (exports) {
6323
6327
  *
6324
6328
  * @param {string} path
6325
6329
  */
6326
- this.match = function(path) {
6330
+ this.match = function(path) {
6327
6331
  path = '/'+trim(path, '/');
6328
6332
  const match = getPattern().exec(path);
6329
6333
  if(!match) return false;
6330
6334
  const params = {};
6331
6335
 
6332
- match.forEach((value, index) => {
6336
+ getPattern().exec(path).forEach((value, index) => {
6333
6337
  if(index < 1) return;
6334
6338
  const name = $paramsNames[index - 1];
6335
6339
  params[name] = value;
@@ -6517,7 +6521,7 @@ var NativeDocument = (function (exports) {
6517
6521
  window.history.pushState({ name: route.name(), params, path}, route.name() || path , path);
6518
6522
  this.handleRouteChange(route, params, query, path);
6519
6523
  } catch (e) {
6520
- DebugManager$1.error('HistoryRouter', 'Error in pushState', e);
6524
+ DebugManager.error('HistoryRouter', 'Error in pushState', e);
6521
6525
  }
6522
6526
  };
6523
6527
  /**
@@ -6530,7 +6534,7 @@ var NativeDocument = (function (exports) {
6530
6534
  window.history.replaceState({ name: route.name(), params, path}, route.name() || path , path);
6531
6535
  this.handleRouteChange(route, params, {}, path);
6532
6536
  } catch(e) {
6533
- DebugManager$1.error('HistoryRouter', 'Error in replaceState', e);
6537
+ DebugManager.error('HistoryRouter', 'Error in replaceState', e);
6534
6538
  }
6535
6539
  };
6536
6540
  this.forward = function() {
@@ -6557,7 +6561,7 @@ var NativeDocument = (function (exports) {
6557
6561
  }
6558
6562
  this.handleRouteChange(route, params, query, path);
6559
6563
  } catch(e) {
6560
- DebugManager$1.error('HistoryRouter', 'Error in popstate event', e);
6564
+ DebugManager.error('HistoryRouter', 'Error in popstate event', e);
6561
6565
  }
6562
6566
  });
6563
6567
  const { route, params, query, path } = this.resolve(defaultPath || (window.location.pathname+window.location.search));
@@ -6782,7 +6786,7 @@ var NativeDocument = (function (exports) {
6782
6786
  listener(request);
6783
6787
  next && next(request);
6784
6788
  } catch (e) {
6785
- DebugManager$1.warn('Route Listener', 'Error in listener:', e);
6789
+ DebugManager.warn('Route Listener', 'Error in listener:', e);
6786
6790
  }
6787
6791
  }
6788
6792
  };
@@ -6960,7 +6964,7 @@ var NativeDocument = (function (exports) {
6960
6964
  */
6961
6965
  Router.create = function(options, callback) {
6962
6966
  if(!Validator.isFunction(callback)) {
6963
- DebugManager$1.error('Router', 'Callback must be a function');
6967
+ DebugManager.error('Router', 'Callback must be a function');
6964
6968
  throw new RouterError('Callback must be a function');
6965
6969
  }
6966
6970
  const router = new Router(options);
@@ -7151,10 +7155,9 @@ var NativeDocument = (function (exports) {
7151
7155
  exports.$ = $;
7152
7156
  exports.ElementCreator = ElementCreator;
7153
7157
  exports.HtmlElementWrapper = HtmlElementWrapper;
7154
- exports.LocalStorage = LocalStorage;
7155
7158
  exports.NDElement = NDElement;
7156
7159
  exports.Observable = Observable;
7157
- exports.PluginsManager = PluginsManager$1;
7160
+ exports.PluginsManager = PluginsManager;
7158
7161
  exports.SingletonView = SingletonView;
7159
7162
  exports.Store = Store;
7160
7163
  exports.StoreFactory = StoreFactory;