native-document 1.0.84 → 1.0.86

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$1 = {};
259
+ let DebugManager = {};
260
260
  {
261
- DebugManager$1 = {
261
+ DebugManager = {
262
262
  log() {},
263
263
  warn() {},
264
264
  error() {},
265
265
  disable() {}
266
266
  };
267
267
  }
268
- var DebugManager = DebugManager$1;
268
+ var DebugManager$1 = DebugManager;
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.log('Memory Auto Clean', `🧹 Cleaned ${cleanedCount} orphaned observables`);
317
+ DebugManager$1.log('Memory Auto Clean', `🧹 Cleaned ${cleanedCount} orphaned observables`);
318
318
  }
319
319
  }
320
320
  };
@@ -662,7 +662,7 @@ var NativeComponents = (function (exports) {
662
662
  ObservableItem.prototype.subscribe = function(callback, target = null) {
663
663
  this.$listeners = this.$listeners ?? [];
664
664
  if (this.$isCleanedUp) {
665
- DebugManager.warn('Observable subscription', '⚠️ Attempted to subscribe to a cleaned up observable.');
665
+ DebugManager$1.warn('Observable subscription', '⚠️ Attempted to subscribe to a cleaned up observable.');
666
666
  return () => {};
667
667
  }
668
668
  if (typeof callback !== 'function') {
@@ -1035,17 +1035,17 @@ var NativeComponents = (function (exports) {
1035
1035
  const method = methods[name];
1036
1036
 
1037
1037
  if (typeof method !== 'function') {
1038
- DebugManager.warn('NDElement.extend', `"${name}" is not a function, skipping`);
1038
+ DebugManager$1.warn('NDElement.extend', `"${name}" is not a function, skipping`);
1039
1039
  continue;
1040
1040
  }
1041
1041
 
1042
1042
  if (protectedMethods.has(name)) {
1043
- DebugManager.error('NDElement.extend', `Cannot override protected method "${name}"`);
1043
+ DebugManager$1.error('NDElement.extend', `Cannot override protected method "${name}"`);
1044
1044
  throw new NativeDocumentError(`Cannot override protected method "${name}"`);
1045
1045
  }
1046
1046
 
1047
1047
  if (NDElement.prototype[name]) {
1048
- DebugManager.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
1048
+ DebugManager$1.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
1049
1049
  }
1050
1050
 
1051
1051
  NDElement.prototype[name] = method;
@@ -1108,7 +1108,7 @@ var NativeComponents = (function (exports) {
1108
1108
  return typeof value === 'object' && value !== null;
1109
1109
  },
1110
1110
  isJson(value) {
1111
- return typeof value === 'object' && value !== null && !Array.isArray(value) && value.constructor.name === 'Object';
1111
+ return !(typeof value !== 'object' || value === null || Array.isArray(value) || value.constructor.name !== 'Object')
1112
1112
  },
1113
1113
  isElement(value) {
1114
1114
  return value && (
@@ -1227,7 +1227,7 @@ var NativeComponents = (function (exports) {
1227
1227
  anchorFragment.appendChild = function(child, before = null) {
1228
1228
  const parent = anchorEnd.parentNode;
1229
1229
  if(!parent) {
1230
- DebugManager.error('Anchor', 'Anchor : parent not found', child);
1230
+ DebugManager$1.error('Anchor', 'Anchor : parent not found', child);
1231
1231
  return;
1232
1232
  }
1233
1233
  before = before ?? anchorEnd;
@@ -2033,10 +2033,8 @@ var NativeComponents = (function (exports) {
2033
2033
  let withValidation = (fn) => fn;
2034
2034
 
2035
2035
  const normalizeComponentArgs = function(props, children = null) {
2036
- if(!Validator.isJson(props) || props?.$hydrate) {
2037
- const temp = children;
2038
- children = props;
2039
- props = temp;
2036
+ if(Array.isArray(props) || typeof props !== 'object' || props === null || props.constructor.name !== 'Object' || props.$hydrate) { // IF it's not a JSON
2037
+ return { props: children, children: props }
2040
2038
  }
2041
2039
  return { props, children };
2042
2040
  };
@@ -2058,7 +2056,7 @@ var NativeComponents = (function (exports) {
2058
2056
  * @returns {Function}
2059
2057
  */
2060
2058
  function HtmlElementWrapper(name, customWrapper) {
2061
- return createHtmlElement.bind(null, name.toLowerCase(), customWrapper);
2059
+ return createHtmlElement.bind(null, name, customWrapper);
2062
2060
  }
2063
2061
 
2064
2062
  DocumentFragment.prototype.__IS_FRAGMENT = true;
@@ -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
  const MemoryManager = (function() {
41
41
 
@@ -84,7 +84,7 @@ var NativeDocument = (function (exports) {
84
84
  }
85
85
  }
86
86
  if (cleanedCount > 0) {
87
- DebugManager$1.log('Memory Auto Clean', `🧹 Cleaned ${cleanedCount} orphaned observables`);
87
+ DebugManager.log('Memory Auto Clean', `🧹 Cleaned ${cleanedCount} orphaned observables`);
88
88
  }
89
89
  }
90
90
  };
@@ -141,10 +141,10 @@ var NativeDocument = (function (exports) {
141
141
  return this.observable.cleanup();
142
142
  };
143
143
 
144
- let PluginsManager$1 = null;
144
+ let PluginsManager = null;
145
145
 
146
146
  {
147
- PluginsManager$1 = (function() {
147
+ PluginsManager = (function() {
148
148
 
149
149
  const $plugins = new Map();
150
150
  const $pluginByEvents = new Map();
@@ -210,7 +210,7 @@ var NativeDocument = (function (exports) {
210
210
  try{
211
211
  callback.call(plugin, ...data);
212
212
  } catch (error) {
213
- DebugManager$1.error('Plugin Manager', `Error in plugin ${plugin.$name} for event ${eventName}`, error);
213
+ DebugManager.error('Plugin Manager', `Error in plugin ${plugin.$name} for event ${eventName}`, error);
214
214
  }
215
215
  }
216
216
  }
@@ -219,7 +219,7 @@ var NativeDocument = (function (exports) {
219
219
  }());
220
220
  }
221
221
 
222
- var PluginsManager = PluginsManager$1;
222
+ var PluginsManager$1 = PluginsManager;
223
223
 
224
224
  const ObservableWhen = function(observer, value) {
225
225
  this.$target = value;
@@ -341,7 +341,7 @@ var NativeDocument = (function (exports) {
341
341
  }
342
342
  }
343
343
  {
344
- PluginsManager.emit('CreateObservable', this);
344
+ PluginsManager$1.emit('CreateObservable', this);
345
345
  }
346
346
  }
347
347
 
@@ -468,12 +468,12 @@ var NativeDocument = (function (exports) {
468
468
  this.$previousValue = this.$currentValue;
469
469
  this.$currentValue = newValue;
470
470
  {
471
- PluginsManager.emit('ObservableBeforeChange', this);
471
+ PluginsManager$1.emit('ObservableBeforeChange', this);
472
472
  }
473
473
  this.trigger();
474
474
  this.$previousValue = null;
475
475
  {
476
- PluginsManager.emit('ObservableAfterChange', this);
476
+ PluginsManager$1.emit('ObservableAfterChange', this);
477
477
  }
478
478
  };
479
479
 
@@ -525,7 +525,7 @@ var NativeDocument = (function (exports) {
525
525
  ObservableItem.prototype.subscribe = function(callback, target = null) {
526
526
  this.$listeners = this.$listeners ?? [];
527
527
  if (this.$isCleanedUp) {
528
- DebugManager$1.warn('Observable subscription', '⚠️ Attempted to subscribe to a cleaned up observable.');
528
+ DebugManager.warn('Observable subscription', '⚠️ Attempted to subscribe to a cleaned up observable.');
529
529
  return () => {};
530
530
  }
531
531
  if (typeof callback !== 'function') {
@@ -535,13 +535,13 @@ var NativeDocument = (function (exports) {
535
535
  this.$listeners.push(callback);
536
536
  this.assocTrigger();
537
537
  {
538
- PluginsManager.emit('ObservableSubscribe', this, target);
538
+ PluginsManager$1.emit('ObservableSubscribe', this, target);
539
539
  }
540
540
  return () => {
541
541
  this.unsubscribe(callback);
542
542
  this.assocTrigger();
543
543
  {
544
- PluginsManager.emit('ObservableUnsubscribe', this);
544
+ PluginsManager$1.emit('ObservableUnsubscribe', this);
545
545
  }
546
546
  };
547
547
  };
@@ -763,7 +763,7 @@ var NativeDocument = (function (exports) {
763
763
  this.$element = element;
764
764
  this.$observer = null;
765
765
  {
766
- PluginsManager.emit('NDElementCreated', element, this);
766
+ PluginsManager$1.emit('NDElementCreated', element, this);
767
767
  }
768
768
  }
769
769
 
@@ -884,7 +884,7 @@ var NativeDocument = (function (exports) {
884
884
  }
885
885
  {
886
886
  if (this[name] && !this.$localExtensions.has(name)) {
887
- DebugManager$1.warn('NDElement.extend', `Method "${name}" already exists and will be overwritten`);
887
+ DebugManager.warn('NDElement.extend', `Method "${name}" already exists and will be overwritten`);
888
888
  }
889
889
  this.$localExtensions.set(name, method);
890
890
  }
@@ -918,23 +918,23 @@ var NativeDocument = (function (exports) {
918
918
  const method = methods[name];
919
919
 
920
920
  if (typeof method !== 'function') {
921
- DebugManager$1.warn('NDElement.extend', `"${name}" is not a function, skipping`);
921
+ DebugManager.warn('NDElement.extend', `"${name}" is not a function, skipping`);
922
922
  continue;
923
923
  }
924
924
 
925
925
  if (protectedMethods.has(name)) {
926
- DebugManager$1.error('NDElement.extend', `Cannot override protected method "${name}"`);
926
+ DebugManager.error('NDElement.extend', `Cannot override protected method "${name}"`);
927
927
  throw new NativeDocumentError(`Cannot override protected method "${name}"`);
928
928
  }
929
929
 
930
930
  if (NDElement.prototype[name]) {
931
- DebugManager$1.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
931
+ DebugManager.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
932
932
  }
933
933
 
934
934
  NDElement.prototype[name] = method;
935
935
  }
936
936
  {
937
- PluginsManager.emit('NDElementExtended', methods);
937
+ PluginsManager$1.emit('NDElementExtended', methods);
938
938
  }
939
939
 
940
940
  return NDElement;
@@ -1000,7 +1000,7 @@ var NativeDocument = (function (exports) {
1000
1000
  return typeof value === 'object' && value !== null;
1001
1001
  },
1002
1002
  isJson(value) {
1003
- return typeof value === 'object' && value !== null && !Array.isArray(value) && value.constructor.name === 'Object';
1003
+ return !(typeof value !== 'object' || value === null || Array.isArray(value) || value.constructor.name !== 'Object')
1004
1004
  },
1005
1005
  isElement(value) {
1006
1006
  return value && (
@@ -1088,7 +1088,7 @@ var NativeDocument = (function (exports) {
1088
1088
  const foundReserved = Object.keys(attributes).filter(key => reserved.includes(key));
1089
1089
 
1090
1090
  if (foundReserved.length > 0) {
1091
- DebugManager$1.warn('Validator', `Reserved attributes found: ${foundReserved.join(', ')}`);
1091
+ DebugManager.warn('Validator', `Reserved attributes found: ${foundReserved.join(', ')}`);
1092
1092
  }
1093
1093
 
1094
1094
  return attributes;
@@ -1136,7 +1136,7 @@ var NativeDocument = (function (exports) {
1136
1136
  anchorFragment.appendChild = function(child, before = null) {
1137
1137
  const parent = anchorEnd.parentNode;
1138
1138
  if(!parent) {
1139
- DebugManager$1.error('Anchor', 'Anchor : parent not found', child);
1139
+ DebugManager.error('Anchor', 'Anchor : parent not found', child);
1140
1140
  return;
1141
1141
  }
1142
1142
  before = before ?? anchorEnd;
@@ -1565,7 +1565,7 @@ var NativeDocument = (function (exports) {
1565
1565
  Function.prototype.toNdElement = function () {
1566
1566
  const child = this;
1567
1567
  {
1568
- PluginsManager.emit('BeforeProcessComponent', child);
1568
+ PluginsManager$1.emit('BeforeProcessComponent', child);
1569
1569
  }
1570
1570
  return ElementCreator.getChild(child());
1571
1571
  };
@@ -1663,14 +1663,14 @@ var NativeDocument = (function (exports) {
1663
1663
  processChildren(children, parent) {
1664
1664
  if(children === null) return;
1665
1665
  {
1666
- PluginsManager.emit('BeforeProcessChildren', parent);
1666
+ PluginsManager$1.emit('BeforeProcessChildren', parent);
1667
1667
  }
1668
1668
  let child = this.getChild(children);
1669
1669
  if(child) {
1670
1670
  parent.appendChild(child);
1671
1671
  }
1672
1672
  {
1673
- PluginsManager.emit('AfterProcessChildren', parent);
1673
+ PluginsManager$1.emit('AfterProcessChildren', parent);
1674
1674
  }
1675
1675
  },
1676
1676
  getChild(child) {
@@ -2089,10 +2089,8 @@ var NativeDocument = (function (exports) {
2089
2089
  }
2090
2090
 
2091
2091
  const normalizeComponentArgs = function(props, children = null) {
2092
- if(!Validator.isJson(props) || props?.$hydrate) {
2093
- const temp = children;
2094
- children = props;
2095
- props = temp;
2092
+ if(Array.isArray(props) || typeof props !== 'object' || props === null || props.constructor.name !== 'Object' || props.$hydrate) { // IF it's not a JSON
2093
+ return { props: children, children: props }
2096
2094
  }
2097
2095
  return { props, children };
2098
2096
  };
@@ -2126,7 +2124,7 @@ var NativeDocument = (function (exports) {
2126
2124
  * @returns {Function}
2127
2125
  */
2128
2126
  function HtmlElementWrapper(name, customWrapper) {
2129
- return createHtmlElement.bind(null, name.toLowerCase(), customWrapper);
2127
+ return createHtmlElement.bind(null, name, customWrapper);
2130
2128
  }
2131
2129
 
2132
2130
  const cloneBindingsDataCache = new WeakMap();
@@ -2908,7 +2906,7 @@ var NativeDocument = (function (exports) {
2908
2906
 
2909
2907
  ObservableItem.call(this, target, configs);
2910
2908
  {
2911
- PluginsManager.emit('CreateObservableArray', this);
2909
+ PluginsManager$1.emit('CreateObservableArray', this);
2912
2910
  }
2913
2911
  };
2914
2912
 
@@ -3309,7 +3307,7 @@ var NativeDocument = (function (exports) {
3309
3307
  const observable = new ObservableItem(initialValue);
3310
3308
  const updatedValue = nextTick(() => observable.set(callback()));
3311
3309
  {
3312
- PluginsManager.emit('CreateObservableComputed', observable, dependencies);
3310
+ PluginsManager$1.emit('CreateObservableComputed', observable, dependencies);
3313
3311
  }
3314
3312
 
3315
3313
  if(Validator.isFunction(dependencies)) {
@@ -3469,7 +3467,7 @@ var NativeDocument = (function (exports) {
3469
3467
  }
3470
3468
  cache.set(keyId, { keyId, isNew: true, child: new WeakRef(child), indexObserver});
3471
3469
  } catch (e) {
3472
- DebugManager$1.error('ForEach', `Error creating element for key ${keyId}` , e);
3470
+ DebugManager.error('ForEach', `Error creating element for key ${keyId}` , e);
3473
3471
  throw e;
3474
3472
  }
3475
3473
  return keyId;
@@ -3815,7 +3813,7 @@ var NativeDocument = (function (exports) {
3815
3813
  */
3816
3814
  const ShowIf = function(condition, child, { comment = null, shouldKeepInCache = true} = {}) {
3817
3815
  if(!(Validator.isObservable(condition)) && !Validator.isObservableWhenResult(condition)) {
3818
- return DebugManager$1.warn('ShowIf', "ShowIf : condition must be an Observable / "+comment, condition);
3816
+ return DebugManager.warn('ShowIf', "ShowIf : condition must be an Observable / "+comment, condition);
3819
3817
  }
3820
3818
  const element = Anchor('Show if : '+(comment || ''));
3821
3819
 
@@ -4602,7 +4600,7 @@ var NativeDocument = (function (exports) {
4602
4600
  window.history.pushState({ name: route.name(), params, path}, route.name() || path , path);
4603
4601
  this.handleRouteChange(route, params, query, path);
4604
4602
  } catch (e) {
4605
- DebugManager$1.error('HistoryRouter', 'Error in pushState', e);
4603
+ DebugManager.error('HistoryRouter', 'Error in pushState', e);
4606
4604
  }
4607
4605
  };
4608
4606
  /**
@@ -4615,7 +4613,7 @@ var NativeDocument = (function (exports) {
4615
4613
  window.history.replaceState({ name: route.name(), params, path}, route.name() || path , path);
4616
4614
  this.handleRouteChange(route, params, {}, path);
4617
4615
  } catch(e) {
4618
- DebugManager$1.error('HistoryRouter', 'Error in replaceState', e);
4616
+ DebugManager.error('HistoryRouter', 'Error in replaceState', e);
4619
4617
  }
4620
4618
  };
4621
4619
  this.forward = function() {
@@ -4642,7 +4640,7 @@ var NativeDocument = (function (exports) {
4642
4640
  }
4643
4641
  this.handleRouteChange(route, params, query, path);
4644
4642
  } catch(e) {
4645
- DebugManager$1.error('HistoryRouter', 'Error in popstate event', e);
4643
+ DebugManager.error('HistoryRouter', 'Error in popstate event', e);
4646
4644
  }
4647
4645
  });
4648
4646
  const { route, params, query, path } = this.resolve(defaultPath || (window.location.pathname+window.location.search));
@@ -4805,7 +4803,7 @@ var NativeDocument = (function (exports) {
4805
4803
  listener(request);
4806
4804
  next && next(request);
4807
4805
  } catch (e) {
4808
- DebugManager$1.warn('Route Listener', 'Error in listener:', e);
4806
+ DebugManager.warn('Route Listener', 'Error in listener:', e);
4809
4807
  }
4810
4808
  }
4811
4809
  };
@@ -4964,7 +4962,7 @@ var NativeDocument = (function (exports) {
4964
4962
  */
4965
4963
  Router.create = function(options, callback) {
4966
4964
  if(!Validator.isFunction(callback)) {
4967
- DebugManager$1.error('Router', 'Callback must be a function', e);
4965
+ DebugManager.error('Router', 'Callback must be a function', e);
4968
4966
  throw new RouterError('Callback must be a function');
4969
4967
  }
4970
4968
  const router = new Router(options);
@@ -5015,13 +5013,13 @@ var NativeDocument = (function (exports) {
5015
5013
 
5016
5014
  function Link(options, children){
5017
5015
  const { to, href, ...attributes } = options;
5018
- const target = to || href;
5019
- if(Validator.isString(target)) {
5016
+ if(href) {
5020
5017
  const router = Router.get();
5021
- return Link$1({ ...attributes, href: target}, children).nd.onPreventClick(() => {
5022
- router.push(target);
5018
+ return Link$1({ ...attributes, href}, children).nd.onPreventClick(() => {
5019
+ router.push(href);
5023
5020
  });
5024
5021
  }
5022
+ const target = typeof to === 'string' ? { name: to } : to;
5025
5023
  const routerName = target.router || DEFAULT_ROUTER_NAME;
5026
5024
  const router = Router.get(routerName);
5027
5025
  if(!router) {
@@ -5148,7 +5146,7 @@ var NativeDocument = (function (exports) {
5148
5146
  exports.HtmlElementWrapper = HtmlElementWrapper;
5149
5147
  exports.NDElement = NDElement;
5150
5148
  exports.Observable = Observable;
5151
- exports.PluginsManager = PluginsManager;
5149
+ exports.PluginsManager = PluginsManager$1;
5152
5150
  exports.SingletonView = SingletonView;
5153
5151
  exports.Store = Store;
5154
5152
  exports.TemplateCloner = TemplateCloner;