native-document 1.0.79 → 1.0.80

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.
@@ -256,16 +256,16 @@ var NativeComponents = (function (exports) {
256
256
  return this.$build();
257
257
  };
258
258
 
259
- let DebugManager = {};
259
+ let DebugManager$1 = {};
260
260
  {
261
- DebugManager = {
261
+ DebugManager$1 = {
262
262
  log() {},
263
263
  warn() {},
264
264
  error() {},
265
265
  disable() {}
266
266
  };
267
267
  }
268
- var DebugManager$1 = DebugManager;
268
+ var DebugManager = DebugManager$1;
269
269
 
270
270
  const MemoryManager = (function() {
271
271
 
@@ -314,7 +314,7 @@ var NativeComponents = (function (exports) {
314
314
  }
315
315
  }
316
316
  if (cleanedCount > 0) {
317
- DebugManager$1.log('Memory Auto Clean', `🧹 Cleaned ${cleanedCount} orphaned observables`);
317
+ DebugManager.log('Memory Auto Clean', `🧹 Cleaned ${cleanedCount} orphaned observables`);
318
318
  }
319
319
  }
320
320
  };
@@ -428,7 +428,7 @@ var NativeComponents = (function (exports) {
428
428
  try{
429
429
  callback.call(plugin, ...data);
430
430
  } catch (error) {
431
- DebugManager$1.error('Plugin Manager', `Error in plugin ${plugin.$name} for event ${eventName}`, error);
431
+ DebugManager.error('Plugin Manager', `Error in plugin ${plugin.$name} for event ${eventName}`, error);
432
432
  }
433
433
  }
434
434
  }
@@ -732,7 +732,7 @@ var NativeComponents = (function (exports) {
732
732
  ObservableItem.prototype.subscribe = function(callback, target = null) {
733
733
  this.$listeners = this.$listeners ?? [];
734
734
  if (this.$isCleanedUp) {
735
- DebugManager$1.warn('Observable subscription', '⚠️ Attempted to subscribe to a cleaned up observable.');
735
+ DebugManager.warn('Observable subscription', '⚠️ Attempted to subscribe to a cleaned up observable.');
736
736
  return () => {};
737
737
  }
738
738
  if (typeof callback !== 'function') {
@@ -1108,17 +1108,17 @@ var NativeComponents = (function (exports) {
1108
1108
  const method = methods[name];
1109
1109
 
1110
1110
  if (typeof method !== 'function') {
1111
- DebugManager$1.warn('NDElement.extend', `"${name}" is not a function, skipping`);
1111
+ DebugManager.warn('NDElement.extend', `"${name}" is not a function, skipping`);
1112
1112
  continue;
1113
1113
  }
1114
1114
 
1115
1115
  if (protectedMethods.has(name)) {
1116
- DebugManager$1.error('NDElement.extend', `Cannot override protected method "${name}"`);
1116
+ DebugManager.error('NDElement.extend', `Cannot override protected method "${name}"`);
1117
1117
  throw new NativeDocumentError(`Cannot override protected method "${name}"`);
1118
1118
  }
1119
1119
 
1120
1120
  if (NDElement.prototype[name]) {
1121
- DebugManager$1.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
1121
+ DebugManager.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
1122
1122
  }
1123
1123
 
1124
1124
  NDElement.prototype[name] = method;
@@ -1308,7 +1308,7 @@ var NativeComponents = (function (exports) {
1308
1308
  anchorFragment.appendChild = function(child, before = null) {
1309
1309
  const parent = anchorEnd.parentNode;
1310
1310
  if(!parent) {
1311
- DebugManager$1.error('Anchor', 'Anchor : parent not found', child);
1311
+ DebugManager.error('Anchor', 'Anchor : parent not found', child);
1312
1312
  return;
1313
1313
  }
1314
1314
  before = before ?? anchorEnd;
@@ -1552,8 +1552,18 @@ var NativeComponents = (function (exports) {
1552
1552
  function bindClassAttribute(element, data) {
1553
1553
  for(let className in data) {
1554
1554
  const value = data[className];
1555
- if(value?.bindNdClass) {
1556
- value.bindNdClass(element, className);
1555
+ if(Validator.isObservable(value)) {
1556
+ element.classes.toggle(className, value.val());
1557
+ value.subscribe(toggleElementClass.bind(null, element, className));
1558
+ continue;
1559
+ }
1560
+ if(Validator.isObservableWhenResult(value)) {
1561
+ element.classes.toggle(className, value.isMath());
1562
+ value.subscribe(toggleElementClass.bind(null, element, className));
1563
+ continue;
1564
+ }
1565
+ if(value.$hydrate) {
1566
+ value.$hydrate(element, className);
1557
1567
  continue;
1558
1568
  }
1559
1569
  element.classes.toggle(className, value);
@@ -1623,12 +1633,6 @@ var NativeComponents = (function (exports) {
1623
1633
  }
1624
1634
  }
1625
1635
 
1626
- const NdBindings = {
1627
- class: (element, value) => bindClassAttribute(element, value),
1628
- style: (element, value) => bindStyleAttribute(element, value),
1629
- };
1630
-
1631
-
1632
1636
  /**
1633
1637
  *
1634
1638
  * @param {HTMLElement} element
@@ -1642,7 +1646,7 @@ var NativeComponents = (function (exports) {
1642
1646
 
1643
1647
  for(let key in attributes) {
1644
1648
  const attributeName = key.toLowerCase();
1645
- let value = attributes[key];
1649
+ let value = attributes[attributeName];
1646
1650
  if(value == null) {
1647
1651
  continue;
1648
1652
  }
@@ -1650,10 +1654,13 @@ var NativeComponents = (function (exports) {
1650
1654
  value.handleNdAttribute(element, attributeName, value);
1651
1655
  continue;
1652
1656
  }
1653
- if(typeof value === 'object') {
1654
- const binding = NdBindings[attributeName];
1655
- if(binding) {
1656
- binding(element, value);
1657
+ if(typeof value === 'object') {
1658
+ if(attributeName === 'class') {
1659
+ bindClassAttribute(element, value);
1660
+ continue;
1661
+ }
1662
+ if(attributeName === 'style') {
1663
+ bindStyleAttribute(element, value);
1657
1664
  continue;
1658
1665
  }
1659
1666
  }
@@ -1723,14 +1730,6 @@ var NativeComponents = (function (exports) {
1723
1730
  element.setAttribute(attributeName, this);
1724
1731
  };
1725
1732
 
1726
- Number.prototype.handleNdAttribute = function(element, attributeName) {
1727
- element.setAttribute(attributeName, this);
1728
- };
1729
-
1730
- Boolean.prototype.handleNdAttribute = function(element, attrName) {
1731
- bindBooleanAttribute(element, attrName, this);
1732
- };
1733
-
1734
1733
  ObservableItem.prototype.handleNdAttribute = function(element, attributeName) {
1735
1734
  if(BOOLEAN_ATTRIBUTES.has(attributeName)) {
1736
1735
  bindBooleanAttribute(element, attributeName, this);
@@ -1822,14 +1821,19 @@ var NativeComponents = (function (exports) {
1822
1821
  PluginsManager.emit('AfterProcessChildren', parent);
1823
1822
  },
1824
1823
  getChild(child) {
1825
- while (child?.toNdElement) {
1826
- child = child.toNdElement();
1827
-
1828
- if (Validator.isElement(child)) return child;
1829
- if (!child) return null;
1824
+ if(child == null) {
1825
+ return null;
1826
+ }
1827
+ if(child.toNdElement) {
1828
+ do {
1829
+ child = child.toNdElement();
1830
+ if(Validator.isElement(child)) {
1831
+ return child;
1832
+ }
1833
+ } while (child.toNdElement);
1830
1834
  }
1831
1835
 
1832
- return child ? ElementCreator.createStaticTextNode(null, child) : null;
1836
+ return ElementCreator.createStaticTextNode(null, child);
1833
1837
  },
1834
1838
  /**
1835
1839
  *
@@ -2168,6 +2172,8 @@ var NativeComponents = (function (exports) {
2168
2172
  return createHtmlElement.bind(null, name.toLowerCase(), customWrapper);
2169
2173
  }
2170
2174
 
2175
+ DocumentFragment.prototype.__IS_FRAGMENT = true;
2176
+
2171
2177
  Function.prototype.args = function(...args) {
2172
2178
  return withValidation(this);
2173
2179
  };
@@ -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
  }
@@ -506,7 +506,7 @@ var NativeDocument = (function (exports) {
506
506
  ObservableItem.prototype.subscribe = function(callback, target = null) {
507
507
  this.$listeners = this.$listeners ?? [];
508
508
  if (this.$isCleanedUp) {
509
- 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.');
510
510
  return () => {};
511
511
  }
512
512
  if (typeof callback !== 'function') {
@@ -859,7 +859,7 @@ var NativeDocument = (function (exports) {
859
859
  }
860
860
  {
861
861
  if (this[name] && !this.$localExtensions.has(name)) {
862
- 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`);
863
863
  }
864
864
  this.$localExtensions.set(name, method);
865
865
  }
@@ -893,17 +893,17 @@ var NativeDocument = (function (exports) {
893
893
  const method = methods[name];
894
894
 
895
895
  if (typeof method !== 'function') {
896
- DebugManager.warn('NDElement.extend', `"${name}" is not a function, skipping`);
896
+ DebugManager$1.warn('NDElement.extend', `"${name}" is not a function, skipping`);
897
897
  continue;
898
898
  }
899
899
 
900
900
  if (protectedMethods.has(name)) {
901
- DebugManager.error('NDElement.extend', `Cannot override protected method "${name}"`);
901
+ DebugManager$1.error('NDElement.extend', `Cannot override protected method "${name}"`);
902
902
  throw new NativeDocumentError(`Cannot override protected method "${name}"`);
903
903
  }
904
904
 
905
905
  if (NDElement.prototype[name]) {
906
- DebugManager.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
906
+ DebugManager$1.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
907
907
  }
908
908
 
909
909
  NDElement.prototype[name] = method;
@@ -1062,7 +1062,7 @@ var NativeDocument = (function (exports) {
1062
1062
  const foundReserved = Object.keys(attributes).filter(key => reserved.includes(key));
1063
1063
 
1064
1064
  if (foundReserved.length > 0) {
1065
- DebugManager.warn('Validator', `Reserved attributes found: ${foundReserved.join(', ')}`);
1065
+ DebugManager$1.warn('Validator', `Reserved attributes found: ${foundReserved.join(', ')}`);
1066
1066
  }
1067
1067
 
1068
1068
  return attributes;
@@ -1110,7 +1110,7 @@ var NativeDocument = (function (exports) {
1110
1110
  anchorFragment.appendChild = function(child, before = null) {
1111
1111
  const parent = anchorEnd.parentNode;
1112
1112
  if(!parent) {
1113
- DebugManager.error('Anchor', 'Anchor : parent not found', child);
1113
+ DebugManager$1.error('Anchor', 'Anchor : parent not found', child);
1114
1114
  return;
1115
1115
  }
1116
1116
  before = before ?? anchorEnd;
@@ -1368,8 +1368,18 @@ var NativeDocument = (function (exports) {
1368
1368
  function bindClassAttribute(element, data) {
1369
1369
  for(let className in data) {
1370
1370
  const value = data[className];
1371
- if(value?.bindNdClass) {
1372
- value.bindNdClass(element, className);
1371
+ if(Validator.isObservable(value)) {
1372
+ element.classes.toggle(className, value.val());
1373
+ value.subscribe(toggleElementClass.bind(null, element, className));
1374
+ continue;
1375
+ }
1376
+ if(Validator.isObservableWhenResult(value)) {
1377
+ element.classes.toggle(className, value.isMath());
1378
+ value.subscribe(toggleElementClass.bind(null, element, className));
1379
+ continue;
1380
+ }
1381
+ if(value.$hydrate) {
1382
+ value.$hydrate(element, className);
1373
1383
  continue;
1374
1384
  }
1375
1385
  element.classes.toggle(className, value);
@@ -1439,12 +1449,6 @@ var NativeDocument = (function (exports) {
1439
1449
  }
1440
1450
  }
1441
1451
 
1442
- const NdBindings = {
1443
- class: (element, value) => bindClassAttribute(element, value),
1444
- style: (element, value) => bindStyleAttribute(element, value),
1445
- };
1446
-
1447
-
1448
1452
  /**
1449
1453
  *
1450
1454
  * @param {HTMLElement} element
@@ -1460,7 +1464,7 @@ var NativeDocument = (function (exports) {
1460
1464
 
1461
1465
  for(let key in attributes) {
1462
1466
  const attributeName = key.toLowerCase();
1463
- let value = attributes[key];
1467
+ let value = attributes[attributeName];
1464
1468
  if(value == null) {
1465
1469
  continue;
1466
1470
  }
@@ -1468,10 +1472,13 @@ var NativeDocument = (function (exports) {
1468
1472
  value.handleNdAttribute(element, attributeName, value);
1469
1473
  continue;
1470
1474
  }
1471
- if(typeof value === 'object') {
1472
- const binding = NdBindings[attributeName];
1473
- if(binding) {
1474
- binding(element, value);
1475
+ if(typeof value === 'object') {
1476
+ if(attributeName === 'class') {
1477
+ bindClassAttribute(element, value);
1478
+ continue;
1479
+ }
1480
+ if(attributeName === 'style') {
1481
+ bindStyleAttribute(element, value);
1475
1482
  continue;
1476
1483
  }
1477
1484
  }
@@ -1541,14 +1548,6 @@ var NativeDocument = (function (exports) {
1541
1548
  element.setAttribute(attributeName, this);
1542
1549
  };
1543
1550
 
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
-
1552
1551
  ObservableItem.prototype.handleNdAttribute = function(element, attributeName) {
1553
1552
  if(BOOLEAN_ATTRIBUTES.has(attributeName)) {
1554
1553
  bindBooleanAttribute(element, attributeName, this);
@@ -1640,14 +1639,19 @@ var NativeDocument = (function (exports) {
1640
1639
  PluginsManager.emit('AfterProcessChildren', parent);
1641
1640
  },
1642
1641
  getChild(child) {
1643
- while (child?.toNdElement) {
1644
- child = child.toNdElement();
1645
-
1646
- if (Validator.isElement(child)) return child;
1647
- if (!child) return null;
1642
+ if(child == null) {
1643
+ return null;
1644
+ }
1645
+ if(child.toNdElement) {
1646
+ do {
1647
+ child = child.toNdElement();
1648
+ if(Validator.isElement(child)) {
1649
+ return child;
1650
+ }
1651
+ } while (child.toNdElement);
1648
1652
  }
1649
1653
 
1650
- return child ? ElementCreator.createStaticTextNode(null, child) : null;
1654
+ return ElementCreator.createStaticTextNode(null, child);
1651
1655
  },
1652
1656
  /**
1653
1657
  *
@@ -2357,6 +2361,8 @@ var NativeDocument = (function (exports) {
2357
2361
  };
2358
2362
  }
2359
2363
 
2364
+ DocumentFragment.prototype.__IS_FRAGMENT = true;
2365
+
2360
2366
  Function.prototype.args = function(...args) {
2361
2367
  return exports.withValidation(this, args);
2362
2368
  };
@@ -3434,7 +3440,7 @@ var NativeDocument = (function (exports) {
3434
3440
  }
3435
3441
  cache.set(keyId, { keyId, isNew: true, child: new WeakRef(child), indexObserver});
3436
3442
  } catch (e) {
3437
- DebugManager.error('ForEach', `Error creating element for key ${keyId}` , e);
3443
+ DebugManager$1.error('ForEach', `Error creating element for key ${keyId}` , e);
3438
3444
  throw e;
3439
3445
  }
3440
3446
  return keyId;
@@ -3780,7 +3786,7 @@ var NativeDocument = (function (exports) {
3780
3786
  */
3781
3787
  const ShowIf = function(condition, child, { comment = null, shouldKeepInCache = true} = {}) {
3782
3788
  if(!(Validator.isObservable(condition)) && !Validator.isObservableWhenResult(condition)) {
3783
- return DebugManager.warn('ShowIf', "ShowIf : condition must be an Observable / "+comment, condition);
3789
+ return DebugManager$1.warn('ShowIf', "ShowIf : condition must be an Observable / "+comment, condition);
3784
3790
  }
3785
3791
  const element = Anchor('Show if : '+(comment || ''));
3786
3792
 
@@ -4567,7 +4573,7 @@ var NativeDocument = (function (exports) {
4567
4573
  window.history.pushState({ name: route.name(), params, path}, route.name() || path , path);
4568
4574
  this.handleRouteChange(route, params, query, path);
4569
4575
  } catch (e) {
4570
- DebugManager.error('HistoryRouter', 'Error in pushState', e);
4576
+ DebugManager$1.error('HistoryRouter', 'Error in pushState', e);
4571
4577
  }
4572
4578
  };
4573
4579
  /**
@@ -4580,7 +4586,7 @@ var NativeDocument = (function (exports) {
4580
4586
  window.history.replaceState({ name: route.name(), params, path}, route.name() || path , path);
4581
4587
  this.handleRouteChange(route, params, {}, path);
4582
4588
  } catch(e) {
4583
- DebugManager.error('HistoryRouter', 'Error in replaceState', e);
4589
+ DebugManager$1.error('HistoryRouter', 'Error in replaceState', e);
4584
4590
  }
4585
4591
  };
4586
4592
  this.forward = function() {
@@ -4607,7 +4613,7 @@ var NativeDocument = (function (exports) {
4607
4613
  }
4608
4614
  this.handleRouteChange(route, params, query, path);
4609
4615
  } catch(e) {
4610
- DebugManager.error('HistoryRouter', 'Error in popstate event', e);
4616
+ DebugManager$1.error('HistoryRouter', 'Error in popstate event', e);
4611
4617
  }
4612
4618
  });
4613
4619
  const { route, params, query, path } = this.resolve(defaultPath || (window.location.pathname+window.location.search));
@@ -4770,7 +4776,7 @@ var NativeDocument = (function (exports) {
4770
4776
  listener(request);
4771
4777
  next && next(request);
4772
4778
  } catch (e) {
4773
- DebugManager.warn('Route Listener', 'Error in listener:', e);
4779
+ DebugManager$1.warn('Route Listener', 'Error in listener:', e);
4774
4780
  }
4775
4781
  }
4776
4782
  };
@@ -4929,7 +4935,7 @@ var NativeDocument = (function (exports) {
4929
4935
  */
4930
4936
  Router.create = function(options, callback) {
4931
4937
  if(!Validator.isFunction(callback)) {
4932
- DebugManager.error('Router', 'Callback must be a function', e);
4938
+ DebugManager$1.error('Router', 'Callback must be a function', e);
4933
4939
  throw new RouterError('Callback must be a function');
4934
4940
  }
4935
4941
  const router = new Router(options);