native-document 1.0.80 → 1.0.82

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.
@@ -362,80 +362,6 @@ var NativeComponents = (function (exports) {
362
362
  return this.observable.cleanup();
363
363
  };
364
364
 
365
- const PluginsManager = (function() {
366
-
367
- const $plugins = new Map();
368
- const $pluginByEvents = new Map();
369
-
370
- return {
371
- list() {
372
- return $pluginByEvents;
373
- },
374
- add(plugin, name){
375
- if (!plugin || typeof plugin !== 'object') {
376
- throw new Error(`Plugin ${name} must be an object`);
377
- }
378
- name = name || plugin.name;
379
- if (!name || typeof name !== 'string') {
380
- throw new Error(`Please, provide a valid plugin name`);
381
- }
382
- if($plugins.has(name)) {
383
- return;
384
- }
385
-
386
- plugin.$name = name;
387
- $plugins.set(name ,plugin);
388
- if(typeof plugin?.init === 'function') {
389
- plugin.init();
390
- }
391
- for(const methodName in plugin) {
392
- if(/^on[A-Z]/.test(methodName)) {
393
- const eventName = methodName.replace(/^on/, '');
394
- if(!$pluginByEvents.has(eventName)) {
395
- $pluginByEvents.set(eventName, new Set());
396
- }
397
- $pluginByEvents.get(eventName).add(plugin);
398
- }
399
- }
400
- },
401
- remove(pluginName){
402
- if(!$plugins.has(pluginName)) {
403
- return;
404
- }
405
- const plugin = $plugins.get(pluginName);
406
- if(typeof plugin.cleanup === 'function') {
407
- plugin.cleanup();
408
- }
409
- for(const [name, sets] of $pluginByEvents.entries() ) {
410
- if(sets.has(plugin)) {
411
- sets.delete(plugin);
412
- }
413
- if(sets.size === 0) {
414
- $pluginByEvents.delete(name);
415
- }
416
- }
417
- $plugins.delete(pluginName);
418
- },
419
- emit(eventName, ...data) {
420
- if(!$pluginByEvents.has(eventName)) {
421
- return;
422
- }
423
- const plugins = $pluginByEvents.get(eventName);
424
-
425
- for(const plugin of plugins) {
426
- const callback = plugin['on'+eventName];
427
- if(typeof callback === 'function') {
428
- try{
429
- callback.call(plugin, ...data);
430
- } catch (error) {
431
- DebugManager.error('Plugin Manager', `Error in plugin ${plugin.$name} for event ${eventName}`, error);
432
- }
433
- }
434
- }
435
- }
436
- };
437
- }());
438
-
439
365
  const ObservableWhen = function(observer, value) {
440
366
  this.$target = value;
441
367
  this.$observer = observer;
@@ -548,6 +474,7 @@ var NativeComponents = (function (exports) {
548
474
  this.$currentValue = value;
549
475
  this.$isCleanedUp = false;
550
476
 
477
+ this.$firstListener = null;
551
478
  this.$listeners = null;
552
479
  this.$watchers = null;
553
480
 
@@ -559,8 +486,6 @@ var NativeComponents = (function (exports) {
559
486
  this.$initialValue = Validator.isObject(value) ? deepClone(value) : value;
560
487
  }
561
488
  }
562
-
563
- PluginsManager.emit('CreateObservable', this);
564
489
  }
565
490
 
566
491
  Object.defineProperty(ObservableItem.prototype, '$value', {
@@ -583,7 +508,7 @@ var NativeComponents = (function (exports) {
583
508
  };
584
509
 
585
510
  ObservableItem.prototype.triggerFirstListener = function(operations) {
586
- this.$listeners[0](this.$currentValue, this.$previousValue, operations || {});
511
+ this.$firstListener(this.$currentValue, this.$previousValue, operations || {});
587
512
  };
588
513
 
589
514
  ObservableItem.prototype.triggerListeners = function(operations) {
@@ -632,22 +557,29 @@ var NativeComponents = (function (exports) {
632
557
  };
633
558
 
634
559
  ObservableItem.prototype.triggerAll = function(operations) {
635
- this.triggerListeners(operations);
636
560
  this.triggerWatchers();
561
+ this.triggerListeners(operations);
637
562
  };
638
563
 
639
564
  ObservableItem.prototype.triggerWatchersAndFirstListener = function(operations) {
640
- this.triggerListeners(operations);
641
565
  this.triggerWatchers();
566
+ this.triggerListeners(operations);
642
567
  };
643
568
 
644
569
  ObservableItem.prototype.assocTrigger = function() {
570
+ this.$firstListener = null;
645
571
  if(this.$watchers?.size && this.$listeners?.length) {
646
572
  this.trigger = (this.$listeners.length === 1) ? this.triggerWatchersAndFirstListener : this.triggerAll;
647
573
  return;
648
574
  }
649
575
  if(this.$listeners?.length) {
650
- this.trigger = (this.$listeners.length === 1) ? this.triggerFirstListener : this.triggerListeners;
576
+ if(this.$listeners.length === 1) {
577
+ this.$firstListener = this.$listeners[0];
578
+ this.trigger = this.triggerFirstListener;
579
+ }
580
+ else {
581
+ this.trigger = this.triggerListeners;
582
+ }
651
583
  return;
652
584
  }
653
585
  if(this.$watchers?.size) {
@@ -678,10 +610,8 @@ var NativeComponents = (function (exports) {
678
610
  }
679
611
  this.$previousValue = this.$currentValue;
680
612
  this.$currentValue = newValue;
681
- PluginsManager.emit('ObservableBeforeChange', this);
682
613
  this.trigger();
683
614
  this.$previousValue = null;
684
- PluginsManager.emit('ObservableAfterChange', this);
685
615
  };
686
616
 
687
617
  ObservableItem.prototype.val = function() {
@@ -741,11 +671,9 @@ var NativeComponents = (function (exports) {
741
671
 
742
672
  this.$listeners.push(callback);
743
673
  this.assocTrigger();
744
- PluginsManager.emit('ObservableSubscribe', this, target);
745
674
  return () => {
746
675
  this.unsubscribe(callback);
747
676
  this.assocTrigger();
748
- PluginsManager.emit('ObservableUnsubscribe', this);
749
677
  };
750
678
  };
751
679
 
@@ -965,7 +893,6 @@ var NativeComponents = (function (exports) {
965
893
  function NDElement(element) {
966
894
  this.$element = element;
967
895
  this.$observer = null;
968
- PluginsManager.emit('NDElementCreated', element, this);
969
896
  }
970
897
 
971
898
  NDElement.prototype.__$isNDElement = true;
@@ -1124,8 +1051,6 @@ var NativeComponents = (function (exports) {
1124
1051
  NDElement.prototype[name] = method;
1125
1052
  }
1126
1053
 
1127
- PluginsManager.emit('NDElementExtended', methods);
1128
-
1129
1054
  return NDElement;
1130
1055
  };
1131
1056
 
@@ -1403,6 +1328,7 @@ var NativeComponents = (function (exports) {
1403
1328
 
1404
1329
  return anchorFragment;
1405
1330
  }
1331
+ DocumentFragment.prototype.setAttribute = () => {};
1406
1332
 
1407
1333
  const BOOLEAN_ATTRIBUTES = new Set([
1408
1334
  'checked',
@@ -1718,7 +1644,6 @@ var NativeComponents = (function (exports) {
1718
1644
 
1719
1645
  Function.prototype.toNdElement = function () {
1720
1646
  const child = this;
1721
- PluginsManager.emit('BeforeProcessComponent', child);
1722
1647
  return ElementCreator.getChild(child());
1723
1648
  };
1724
1649
 
@@ -1797,8 +1722,9 @@ var NativeComponents = (function (exports) {
1797
1722
  */
1798
1723
  createElement(name) {
1799
1724
  if(name) {
1800
- if($nodeCache.has(name)) {
1801
- return $nodeCache.get(name).cloneNode();
1725
+ const cacheNode = $nodeCache.get(name);
1726
+ if(cacheNode) {
1727
+ return cacheNode.cloneNode();
1802
1728
  }
1803
1729
  const node = document.createElement(name);
1804
1730
  $nodeCache.set(name, node);
@@ -1813,12 +1739,10 @@ var NativeComponents = (function (exports) {
1813
1739
  */
1814
1740
  processChildren(children, parent) {
1815
1741
  if(children === null) return;
1816
- PluginsManager.emit('BeforeProcessChildren', parent);
1817
1742
  let child = this.getChild(children);
1818
1743
  if(child) {
1819
1744
  parent.appendChild(child);
1820
1745
  }
1821
- PluginsManager.emit('AfterProcessChildren', parent);
1822
1746
  },
1823
1747
  getChild(child) {
1824
1748
  if(child == null) {
@@ -1841,7 +1765,6 @@ var NativeComponents = (function (exports) {
1841
1765
  * @param {Object} attributes
1842
1766
  */
1843
1767
  processAttributes(element, attributes) {
1844
- if(Validator.isFragment(element)) return;
1845
1768
  if (attributes) {
1846
1769
  AttributesWrapper(element, attributes);
1847
1770
  }
@@ -1854,7 +1777,6 @@ var NativeComponents = (function (exports) {
1854
1777
  * @returns {HTMLElement|DocumentFragment}
1855
1778
  */
1856
1779
  setup(element, attributes, customWrapper) {
1857
- PluginsManager.emit('Setup', element, attributes, customWrapper);
1858
1780
  return element;
1859
1781
  }
1860
1782
  };
@@ -2152,13 +2074,8 @@ var NativeComponents = (function (exports) {
2152
2074
  let element = ElementCreator.createElement($tagName);
2153
2075
  let finalElement = (customWrapper && typeof customWrapper === 'function') ? customWrapper(element) : element;
2154
2076
 
2155
- if(attributes) {
2156
- ElementCreator.processAttributes(finalElement, attributes);
2157
- }
2158
- if(children) {
2159
- ElementCreator.processChildren(children, finalElement);
2160
- }
2161
-
2077
+ ElementCreator.processAttributes(finalElement, attributes);
2078
+ ElementCreator.processChildren(children, finalElement);
2162
2079
  return ElementCreator.setup(finalElement, attributes, customWrapper);
2163
2080
  }
2164
2081
 
@@ -2284,7 +2201,6 @@ var NativeComponents = (function (exports) {
2284
2201
  }
2285
2202
 
2286
2203
  ObservableItem.call(this, target, configs);
2287
- PluginsManager.emit('CreateObservableArray', this);
2288
2204
  };
2289
2205
 
2290
2206
  ObservableArray.prototype = Object.create(ObservableItem.prototype);
@@ -2300,7 +2216,7 @@ var NativeComponents = (function (exports) {
2300
2216
 
2301
2217
  mutationMethods.forEach((method) => {
2302
2218
  ObservableArray.prototype[method] = function(...values) {
2303
- const result = this.$currentValue[method](...values);
2219
+ const result = this.$currentValue[method].apply(this.$currentValue, values);
2304
2220
  this.trigger({ action: method, args: values, result });
2305
2221
  return result;
2306
2222
  };
@@ -2308,7 +2224,7 @@ var NativeComponents = (function (exports) {
2308
2224
 
2309
2225
  noMutationMethods.forEach((method) => {
2310
2226
  ObservableArray.prototype[method] = function(...values) {
2311
- return this.$currentValue[method](...values);
2227
+ return this.$currentValue[method].apply(this.$currentValue, values);
2312
2228
  };
2313
2229
  });
2314
2230
 
@@ -2326,7 +2242,7 @@ var NativeComponents = (function (exports) {
2326
2242
  };
2327
2243
 
2328
2244
  ObservableArray.prototype.merge = function(values) {
2329
- this.$currentValue.push(...values);
2245
+ this.$currentValue.push.apply(this.$currentValue, values);
2330
2246
  this.trigger({ action: 'merge', args: values });
2331
2247
  };
2332
2248
 
@@ -2402,7 +2318,7 @@ var NativeComponents = (function (exports) {
2402
2318
  const deps = Array.isArray(predicate.dependencies)
2403
2319
  ? predicate.dependencies
2404
2320
  : [predicate.dependencies];
2405
- observableDependencies.push(...deps);
2321
+ observableDependencies.push.apply(observableDependencies, deps);
2406
2322
  }
2407
2323
  } else if(typeof predicate === 'function') {
2408
2324
  filterCallbacks[key] = predicate;
@@ -2684,8 +2600,6 @@ var NativeComponents = (function (exports) {
2684
2600
  const observable = new ObservableItem(initialValue);
2685
2601
  const updatedValue = nextTick(() => observable.set(callback()));
2686
2602
 
2687
- PluginsManager.emit('CreateObservableComputed', observable, dependencies);
2688
-
2689
2603
  if(Validator.isFunction(dependencies)) {
2690
2604
  if(!Validator.isObservable(dependencies.$observer)) {
2691
2605
  throw new NativeDocumentError('Observable.computed : dependencies must be valid batch function');