native-document 1.0.66 → 1.0.68

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
  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
  };
@@ -207,7 +207,7 @@ var NativeDocument = (function (exports) {
207
207
  try{
208
208
  callback.call(plugin, ...data);
209
209
  } catch (error) {
210
- DebugManager$1.error('Plugin Manager', `Error in plugin ${plugin.$name} for event ${eventName}`, error);
210
+ DebugManager.error('Plugin Manager', `Error in plugin ${plugin.$name} for event ${eventName}`, error);
211
211
  }
212
212
  }
213
213
  }
@@ -459,7 +459,7 @@ var NativeDocument = (function (exports) {
459
459
  ObservableItem.prototype.subscribe = function(callback, target = null) {
460
460
  this.$listeners = this.$listeners ?? [];
461
461
  if (this.$isCleanedUp) {
462
- DebugManager$1.warn('Observable subscription', '⚠️ Attempted to subscribe to a cleaned up observable.');
462
+ DebugManager.warn('Observable subscription', '⚠️ Attempted to subscribe to a cleaned up observable.');
463
463
  return () => {};
464
464
  }
465
465
  if (typeof callback !== 'function') {
@@ -575,30 +575,56 @@ var NativeDocument = (function (exports) {
575
575
  unmounted: new WeakMap(),
576
576
  unmountedSupposedSize: 0,
577
577
  observer: null,
578
+ executeMountedCallback(node) {
579
+ const data = DocumentObserver.mounted.get(node);
580
+ if(!data) {
581
+ return;
582
+ }
583
+ data.inDom = true;
584
+ data.mounted && data.mounted(node);
585
+ },
586
+ executeUnmountedCallback(node) {
587
+ const data = DocumentObserver.unmounted.get(node);
588
+ if(!data) {
589
+ return;
590
+ }
591
+
592
+ data.inDom = false;
593
+ if(data.unmounted && data.unmounted(node) === true) {
594
+ data.disconnect();
595
+ node.nd?.remove();
596
+ }
597
+ },
578
598
  checkMutation: function(mutationsList) {
579
599
  for(const mutation of mutationsList) {
580
600
  if(DocumentObserver.mountedSupposedSize > 0 ) {
581
601
  for(const node of mutation.addedNodes) {
582
- const data = DocumentObserver.mounted.get(node);
583
- if(!data) {
584
- continue;
602
+ DocumentObserver.executeMountedCallback(node);
603
+ if(!node.querySelectorAll) {
604
+ return;
605
+ }
606
+ const children = node.querySelectorAll('[data--nd-mounted]');
607
+ if(!children.length) {
608
+ return;
609
+ }
610
+ for(const node of children) {
611
+ DocumentObserver.executeMountedCallback(node);
585
612
  }
586
- data.inDom = true;
587
- data.mounted && data.mounted(node);
588
613
  }
589
614
  }
590
615
 
591
616
  if(DocumentObserver.unmountedSupposedSize > 0 ) {
592
617
  for(const node of mutation.removedNodes) {
593
- const data = DocumentObserver.unmounted.get(node);
594
- if(!data) {
595
- continue;
618
+ DocumentObserver.executeUnmountedCallback(node);
619
+ if(!node.querySelectorAll) {
620
+ return;
596
621
  }
597
-
598
- data.inDom = false;
599
- if(data.unmounted && data.unmounted(node) === true) {
600
- data.disconnect();
601
- node.nd?.remove();
622
+ const children = node.querySelectorAll('[data--nd-unmounted]');
623
+ if(!children.length) {
624
+ return;
625
+ }
626
+ for(const node of children) {
627
+ DocumentObserver.executeUnmountedCallback(node);
602
628
  }
603
629
  }
604
630
  }
@@ -732,6 +758,7 @@ var NativeDocument = (function (exports) {
732
758
  this.$observer = null;
733
759
  PluginsManager.emit('NDElementCreated', element, this);
734
760
  }
761
+
735
762
  NDElement.prototype.__$isNDElement = true;
736
763
 
737
764
  NDElement.prototype.valueOf = function() {
@@ -775,10 +802,17 @@ var NativeDocument = (function (exports) {
775
802
  NDElement.prototype.lifecycle = function(states) {
776
803
  this.$observer = this.$observer || DocumentObserver.watch(this.$element);
777
804
 
778
- states.mounted && this.$observer.mounted(states.mounted);
779
- states.unmounted && this.$observer.unmounted(states.unmounted);
805
+ if(states.mounted) {
806
+ this.$element.setAttribute('data--nd-mounted', '1');
807
+ this.$observer.mounted(states.mounted);
808
+ }
809
+ if(states.unmounted) {
810
+ this.$element.setAttribute('data--nd-unmounted', '1');
811
+ this.$observer.unmounted(states.unmounted);
812
+ }
780
813
  return this;
781
814
  };
815
+
782
816
  NDElement.prototype.mounted = function(callback) {
783
817
  return this.lifecycle({ mounted: callback });
784
818
  };
@@ -808,9 +842,11 @@ var NativeDocument = (function (exports) {
808
842
 
809
843
  return this;
810
844
  };
845
+
811
846
  NDElement.prototype.openShadow = function(style = null) {
812
847
  return this.shadow('open', style);
813
848
  };
849
+
814
850
  NDElement.prototype.closedShadow = function(style = null) {
815
851
  return this.shadow('closed', style);
816
852
  };
@@ -878,7 +914,6 @@ var NativeDocument = (function (exports) {
878
914
  });
879
915
  };
880
916
 
881
-
882
917
  const preventDefaultWrapper = function(element, eventName, callback) {
883
918
  element.addEventListener(eventName, (event) => {
884
919
  event.preventDefault();
@@ -886,6 +921,7 @@ var NativeDocument = (function (exports) {
886
921
  });
887
922
  return this;
888
923
  };
924
+
889
925
  const stopPropagationWrapper = function(element, eventName, callback) {
890
926
  element.addEventListener(eventName, (event) => {
891
927
  event.stopPropagation();
@@ -893,6 +929,7 @@ var NativeDocument = (function (exports) {
893
929
  });
894
930
  return this;
895
931
  };
932
+
896
933
  const preventDefaultAndStopPropagationWrapper = function(element, eventName, callback) {
897
934
  element.addEventListener(eventName, (event) => {
898
935
  event.stopPropagation();
@@ -901,6 +938,7 @@ var NativeDocument = (function (exports) {
901
938
  });
902
939
  return this;
903
940
  };
941
+
904
942
  const captureEventWrapper = function(element, eventName, directHandler) {
905
943
  if(directHandler) {
906
944
  element.addEventListener(eventName, directHandler);
@@ -916,14 +954,17 @@ var NativeDocument = (function (exports) {
916
954
  this.$element.addEventListener(eventName, callback);
917
955
  return this;
918
956
  };
957
+
919
958
  NDElement.prototype['onPrevent'+event] = function(callback) {
920
959
  preventDefaultWrapper(this.$element, eventName, callback);
921
960
  return this;
922
961
  };
962
+
923
963
  NDElement.prototype['onStop'+event] = function(callback) {
924
964
  stopPropagationWrapper(this.$element, eventName, callback);
925
965
  return this;
926
966
  };
967
+
927
968
  NDElement.prototype['onPreventStop'+event] = function(callback) {
928
969
  preventDefaultAndStopPropagationWrapper(this.$element, eventName, callback);
929
970
  return this;
@@ -959,7 +1000,7 @@ var NativeDocument = (function (exports) {
959
1000
  }
960
1001
  {
961
1002
  if (this[name] && !this.$localExtensions.has(name)) {
962
- DebugManager$1.warn('NDElement.extend', `Method "${name}" already exists and will be overwritten`);
1003
+ DebugManager.warn('NDElement.extend', `Method "${name}" already exists and will be overwritten`);
963
1004
  }
964
1005
  this.$localExtensions.set(name, method);
965
1006
  }
@@ -993,17 +1034,17 @@ var NativeDocument = (function (exports) {
993
1034
  const method = methods[name];
994
1035
 
995
1036
  if (typeof method !== 'function') {
996
- DebugManager$1.warn('NDElement.extend', `"${name}" is not a function, skipping`);
1037
+ DebugManager.warn('NDElement.extend', `"${name}" is not a function, skipping`);
997
1038
  continue;
998
1039
  }
999
1040
 
1000
1041
  if (protectedMethods.has(name)) {
1001
- DebugManager$1.error('NDElement.extend', `Cannot override protected method "${name}"`);
1042
+ DebugManager.error('NDElement.extend', `Cannot override protected method "${name}"`);
1002
1043
  throw new NativeDocumentError(`Cannot override protected method "${name}"`);
1003
1044
  }
1004
1045
 
1005
1046
  if (NDElement.prototype[name]) {
1006
- DebugManager$1.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
1047
+ DebugManager.warn('NDElement.extend', `Overwriting existing prototype method "${name}"`);
1007
1048
  }
1008
1049
 
1009
1050
  NDElement.prototype[name] = method;
@@ -1149,7 +1190,7 @@ var NativeDocument = (function (exports) {
1149
1190
  const foundReserved = Object.keys(attributes).filter(key => reserved.includes(key));
1150
1191
 
1151
1192
  if (foundReserved.length > 0) {
1152
- DebugManager$1.warn('Validator', `Reserved attributes found: ${foundReserved.join(', ')}`);
1193
+ DebugManager.warn('Validator', `Reserved attributes found: ${foundReserved.join(', ')}`);
1153
1194
  }
1154
1195
 
1155
1196
  return attributes;
@@ -1197,7 +1238,7 @@ var NativeDocument = (function (exports) {
1197
1238
  element.appendChild = function(child, before = null) {
1198
1239
  const parent = anchorEnd.parentNode;
1199
1240
  if(!parent) {
1200
- DebugManager$1.error('Anchor', 'Anchor : parent not found', child);
1241
+ DebugManager.error('Anchor', 'Anchor : parent not found', child);
1201
1242
  return;
1202
1243
  }
1203
1244
  before = before ?? anchorEnd;
@@ -2781,7 +2822,7 @@ var NativeDocument = (function (exports) {
2781
2822
  }
2782
2823
  cache.set(keyId, { keyId, isNew: true, child: new WeakRef(child), indexObserver});
2783
2824
  } catch (e) {
2784
- DebugManager$1.error('ForEach', `Error creating element for key ${keyId}` , e);
2825
+ DebugManager.error('ForEach', `Error creating element for key ${keyId}` , e);
2785
2826
  throw e;
2786
2827
  }
2787
2828
  return keyId;
@@ -3153,7 +3194,7 @@ var NativeDocument = (function (exports) {
3153
3194
  */
3154
3195
  const ShowIf = function(condition, child, { comment = null, shouldKeepInCache = true} = {}) {
3155
3196
  if(!(Validator.isObservable(condition)) && !Validator.isObservableWhenResult(condition)) {
3156
- return DebugManager$1.warn('ShowIf', "ShowIf : condition must be an Observable / "+comment, condition);
3197
+ return DebugManager.warn('ShowIf', "ShowIf : condition must be an Observable / "+comment, condition);
3157
3198
  }
3158
3199
  const element = Anchor('Show if : '+(comment || ''));
3159
3200
 
@@ -3940,7 +3981,7 @@ var NativeDocument = (function (exports) {
3940
3981
  window.history.pushState({ name: route.name(), params, path}, route.name() || path , path);
3941
3982
  this.handleRouteChange(route, params, query, path);
3942
3983
  } catch (e) {
3943
- DebugManager$1.error('HistoryRouter', 'Error in pushState', e);
3984
+ DebugManager.error('HistoryRouter', 'Error in pushState', e);
3944
3985
  }
3945
3986
  };
3946
3987
  /**
@@ -3953,7 +3994,7 @@ var NativeDocument = (function (exports) {
3953
3994
  window.history.replaceState({ name: route.name(), params, path}, route.name() || path , path);
3954
3995
  this.handleRouteChange(route, params, {}, path);
3955
3996
  } catch(e) {
3956
- DebugManager$1.error('HistoryRouter', 'Error in replaceState', e);
3997
+ DebugManager.error('HistoryRouter', 'Error in replaceState', e);
3957
3998
  }
3958
3999
  };
3959
4000
  this.forward = function() {
@@ -3980,7 +4021,7 @@ var NativeDocument = (function (exports) {
3980
4021
  }
3981
4022
  this.handleRouteChange(route, params, query, path);
3982
4023
  } catch(e) {
3983
- DebugManager$1.error('HistoryRouter', 'Error in popstate event', e);
4024
+ DebugManager.error('HistoryRouter', 'Error in popstate event', e);
3984
4025
  }
3985
4026
  });
3986
4027
  const { route, params, query, path } = this.resolve(defaultPath || (window.location.pathname+window.location.search));
@@ -4134,7 +4175,7 @@ var NativeDocument = (function (exports) {
4134
4175
  listener(request);
4135
4176
  next && next(request);
4136
4177
  } catch (e) {
4137
- DebugManager$1.warn('Route Listener', 'Error in listener:', e);
4178
+ DebugManager.warn('Route Listener', 'Error in listener:', e);
4138
4179
  }
4139
4180
  }
4140
4181
  };
@@ -4293,7 +4334,7 @@ var NativeDocument = (function (exports) {
4293
4334
  */
4294
4335
  Router.create = function(options, callback) {
4295
4336
  if(!Validator.isFunction(callback)) {
4296
- DebugManager$1.error('Router', 'Callback must be a function', e);
4337
+ DebugManager.error('Router', 'Callback must be a function', e);
4297
4338
  throw new RouterError('Callback must be a function');
4298
4339
  }
4299
4340
  const router = new Router(options);