native-document 1.0.79 → 1.0.81

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
  }
@@ -548,6 +548,7 @@ var NativeComponents = (function (exports) {
548
548
  this.$currentValue = value;
549
549
  this.$isCleanedUp = false;
550
550
 
551
+ this.$firstListener = null;
551
552
  this.$listeners = null;
552
553
  this.$watchers = null;
553
554
 
@@ -583,7 +584,7 @@ var NativeComponents = (function (exports) {
583
584
  };
584
585
 
585
586
  ObservableItem.prototype.triggerFirstListener = function(operations) {
586
- this.$listeners[0](this.$currentValue, this.$previousValue, operations || {});
587
+ this.$firstListener(this.$currentValue, this.$previousValue, operations || {});
587
588
  };
588
589
 
589
590
  ObservableItem.prototype.triggerListeners = function(operations) {
@@ -632,22 +633,29 @@ var NativeComponents = (function (exports) {
632
633
  };
633
634
 
634
635
  ObservableItem.prototype.triggerAll = function(operations) {
635
- this.triggerListeners(operations);
636
636
  this.triggerWatchers();
637
+ this.triggerListeners(operations);
637
638
  };
638
639
 
639
640
  ObservableItem.prototype.triggerWatchersAndFirstListener = function(operations) {
640
- this.triggerListeners(operations);
641
641
  this.triggerWatchers();
642
+ this.triggerListeners(operations);
642
643
  };
643
644
 
644
645
  ObservableItem.prototype.assocTrigger = function() {
646
+ this.$firstListener = null;
645
647
  if(this.$watchers?.size && this.$listeners?.length) {
646
648
  this.trigger = (this.$listeners.length === 1) ? this.triggerWatchersAndFirstListener : this.triggerAll;
647
649
  return;
648
650
  }
649
651
  if(this.$listeners?.length) {
650
- this.trigger = (this.$listeners.length === 1) ? this.triggerFirstListener : this.triggerListeners;
652
+ if(this.$listeners.length === 1) {
653
+ this.$firstListener = this.$listeners[0];
654
+ this.trigger = this.triggerFirstListener;
655
+ }
656
+ else {
657
+ this.trigger = this.triggerListeners;
658
+ }
651
659
  return;
652
660
  }
653
661
  if(this.$watchers?.size) {
@@ -732,7 +740,7 @@ var NativeComponents = (function (exports) {
732
740
  ObservableItem.prototype.subscribe = function(callback, target = null) {
733
741
  this.$listeners = this.$listeners ?? [];
734
742
  if (this.$isCleanedUp) {
735
- DebugManager$1.warn('Observable subscription', '⚠️ Attempted to subscribe to a cleaned up observable.');
743
+ DebugManager.warn('Observable subscription', '⚠️ Attempted to subscribe to a cleaned up observable.');
736
744
  return () => {};
737
745
  }
738
746
  if (typeof callback !== 'function') {
@@ -1108,17 +1116,17 @@ var NativeComponents = (function (exports) {
1108
1116
  const method = methods[name];
1109
1117
 
1110
1118
  if (typeof method !== 'function') {
1111
- DebugManager$1.warn('NDElement.extend', `"${name}" is not a function, skipping`);
1119
+ DebugManager.warn('NDElement.extend', `"${name}" is not a function, skipping`);
1112
1120
  continue;
1113
1121
  }
1114
1122
 
1115
1123
  if (protectedMethods.has(name)) {
1116
- DebugManager$1.error('NDElement.extend', `Cannot override protected method "${name}"`);
1124
+ DebugManager.error('NDElement.extend', `Cannot override protected method "${name}"`);
1117
1125
  throw new NativeDocumentError(`Cannot override protected method "${name}"`);
1118
1126
  }
1119
1127
 
1120
1128
  if (NDElement.prototype[name]) {
1121
- DebugManager$1.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
1129
+ DebugManager.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
1122
1130
  }
1123
1131
 
1124
1132
  NDElement.prototype[name] = method;
@@ -1308,7 +1316,7 @@ var NativeComponents = (function (exports) {
1308
1316
  anchorFragment.appendChild = function(child, before = null) {
1309
1317
  const parent = anchorEnd.parentNode;
1310
1318
  if(!parent) {
1311
- DebugManager$1.error('Anchor', 'Anchor : parent not found', child);
1319
+ DebugManager.error('Anchor', 'Anchor : parent not found', child);
1312
1320
  return;
1313
1321
  }
1314
1322
  before = before ?? anchorEnd;
@@ -1552,8 +1560,18 @@ var NativeComponents = (function (exports) {
1552
1560
  function bindClassAttribute(element, data) {
1553
1561
  for(let className in data) {
1554
1562
  const value = data[className];
1555
- if(value?.bindNdClass) {
1556
- value.bindNdClass(element, className);
1563
+ if(Validator.isObservable(value)) {
1564
+ element.classes.toggle(className, value.val());
1565
+ value.subscribe(toggleElementClass.bind(null, element, className));
1566
+ continue;
1567
+ }
1568
+ if(Validator.isObservableWhenResult(value)) {
1569
+ element.classes.toggle(className, value.isMath());
1570
+ value.subscribe(toggleElementClass.bind(null, element, className));
1571
+ continue;
1572
+ }
1573
+ if(value.$hydrate) {
1574
+ value.$hydrate(element, className);
1557
1575
  continue;
1558
1576
  }
1559
1577
  element.classes.toggle(className, value);
@@ -1623,12 +1641,6 @@ var NativeComponents = (function (exports) {
1623
1641
  }
1624
1642
  }
1625
1643
 
1626
- const NdBindings = {
1627
- class: (element, value) => bindClassAttribute(element, value),
1628
- style: (element, value) => bindStyleAttribute(element, value),
1629
- };
1630
-
1631
-
1632
1644
  /**
1633
1645
  *
1634
1646
  * @param {HTMLElement} element
@@ -1642,7 +1654,7 @@ var NativeComponents = (function (exports) {
1642
1654
 
1643
1655
  for(let key in attributes) {
1644
1656
  const attributeName = key.toLowerCase();
1645
- let value = attributes[key];
1657
+ let value = attributes[attributeName];
1646
1658
  if(value == null) {
1647
1659
  continue;
1648
1660
  }
@@ -1650,10 +1662,13 @@ var NativeComponents = (function (exports) {
1650
1662
  value.handleNdAttribute(element, attributeName, value);
1651
1663
  continue;
1652
1664
  }
1653
- if(typeof value === 'object') {
1654
- const binding = NdBindings[attributeName];
1655
- if(binding) {
1656
- binding(element, value);
1665
+ if(typeof value === 'object') {
1666
+ if(attributeName === 'class') {
1667
+ bindClassAttribute(element, value);
1668
+ continue;
1669
+ }
1670
+ if(attributeName === 'style') {
1671
+ bindStyleAttribute(element, value);
1657
1672
  continue;
1658
1673
  }
1659
1674
  }
@@ -1723,14 +1738,6 @@ var NativeComponents = (function (exports) {
1723
1738
  element.setAttribute(attributeName, this);
1724
1739
  };
1725
1740
 
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
1741
  ObservableItem.prototype.handleNdAttribute = function(element, attributeName) {
1735
1742
  if(BOOLEAN_ATTRIBUTES.has(attributeName)) {
1736
1743
  bindBooleanAttribute(element, attributeName, this);
@@ -1822,14 +1829,19 @@ var NativeComponents = (function (exports) {
1822
1829
  PluginsManager.emit('AfterProcessChildren', parent);
1823
1830
  },
1824
1831
  getChild(child) {
1825
- while (child?.toNdElement) {
1826
- child = child.toNdElement();
1827
-
1828
- if (Validator.isElement(child)) return child;
1829
- if (!child) return null;
1832
+ if(child == null) {
1833
+ return null;
1834
+ }
1835
+ if(child.toNdElement) {
1836
+ do {
1837
+ child = child.toNdElement();
1838
+ if(Validator.isElement(child)) {
1839
+ return child;
1840
+ }
1841
+ } while (child.toNdElement);
1830
1842
  }
1831
1843
 
1832
- return child ? ElementCreator.createStaticTextNode(null, child) : null;
1844
+ return ElementCreator.createStaticTextNode(null, child);
1833
1845
  },
1834
1846
  /**
1835
1847
  *
@@ -2168,6 +2180,8 @@ var NativeComponents = (function (exports) {
2168
2180
  return createHtmlElement.bind(null, name.toLowerCase(), customWrapper);
2169
2181
  }
2170
2182
 
2183
+ DocumentFragment.prototype.__IS_FRAGMENT = true;
2184
+
2171
2185
  Function.prototype.args = function(...args) {
2172
2186
  return withValidation(this);
2173
2187
  };
@@ -2294,7 +2308,7 @@ var NativeComponents = (function (exports) {
2294
2308
 
2295
2309
  mutationMethods.forEach((method) => {
2296
2310
  ObservableArray.prototype[method] = function(...values) {
2297
- const result = this.$currentValue[method](...values);
2311
+ const result = this.$currentValue[method].apply(this.$currentValue, values);
2298
2312
  this.trigger({ action: method, args: values, result });
2299
2313
  return result;
2300
2314
  };
@@ -2302,7 +2316,7 @@ var NativeComponents = (function (exports) {
2302
2316
 
2303
2317
  noMutationMethods.forEach((method) => {
2304
2318
  ObservableArray.prototype[method] = function(...values) {
2305
- return this.$currentValue[method](...values);
2319
+ return this.$currentValue[method].apply(this.$currentValue, values);
2306
2320
  };
2307
2321
  });
2308
2322
 
@@ -2320,7 +2334,7 @@ var NativeComponents = (function (exports) {
2320
2334
  };
2321
2335
 
2322
2336
  ObservableArray.prototype.merge = function(values) {
2323
- this.$currentValue.push(...values);
2337
+ this.$currentValue.push.apply(this.$currentValue, values);
2324
2338
  this.trigger({ action: 'merge', args: values });
2325
2339
  };
2326
2340
 
@@ -2396,7 +2410,7 @@ var NativeComponents = (function (exports) {
2396
2410
  const deps = Array.isArray(predicate.dependencies)
2397
2411
  ? predicate.dependencies
2398
2412
  : [predicate.dependencies];
2399
- observableDependencies.push(...deps);
2413
+ observableDependencies.push.apply(observableDependencies, deps);
2400
2414
  }
2401
2415
  } else if(typeof predicate === 'function') {
2402
2416
  filterCallbacks[key] = predicate;