native-document 1.0.66 → 1.0.67
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.
|
@@ -575,30 +575,57 @@ 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) {
|
|
600
|
+
console.log({ mutation });
|
|
580
601
|
if(DocumentObserver.mountedSupposedSize > 0 ) {
|
|
581
602
|
for(const node of mutation.addedNodes) {
|
|
582
|
-
|
|
583
|
-
if(!
|
|
584
|
-
|
|
603
|
+
DocumentObserver.executeMountedCallback(node);
|
|
604
|
+
if(!node.querySelectorAll) {
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
const children = node.querySelectorAll('[data--nd-mounted]');
|
|
608
|
+
if(!children.length) {
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
for(const node of children) {
|
|
612
|
+
DocumentObserver.executeMountedCallback(node);
|
|
585
613
|
}
|
|
586
|
-
data.inDom = true;
|
|
587
|
-
data.mounted && data.mounted(node);
|
|
588
614
|
}
|
|
589
615
|
}
|
|
590
616
|
|
|
591
617
|
if(DocumentObserver.unmountedSupposedSize > 0 ) {
|
|
592
618
|
for(const node of mutation.removedNodes) {
|
|
593
|
-
|
|
594
|
-
if(!
|
|
595
|
-
|
|
619
|
+
DocumentObserver.executeUnmountedCallback(node);
|
|
620
|
+
if(!node.querySelectorAll) {
|
|
621
|
+
return;
|
|
596
622
|
}
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
623
|
+
const children = node.querySelectorAll('[data--nd-unmounted]');
|
|
624
|
+
if(!children.length) {
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
for(const node of children) {
|
|
628
|
+
DocumentObserver.executeUnmountedCallback(node);
|
|
602
629
|
}
|
|
603
630
|
}
|
|
604
631
|
}
|
|
@@ -732,6 +759,7 @@ var NativeDocument = (function (exports) {
|
|
|
732
759
|
this.$observer = null;
|
|
733
760
|
PluginsManager.emit('NDElementCreated', element, this);
|
|
734
761
|
}
|
|
762
|
+
|
|
735
763
|
NDElement.prototype.__$isNDElement = true;
|
|
736
764
|
|
|
737
765
|
NDElement.prototype.valueOf = function() {
|
|
@@ -775,10 +803,17 @@ var NativeDocument = (function (exports) {
|
|
|
775
803
|
NDElement.prototype.lifecycle = function(states) {
|
|
776
804
|
this.$observer = this.$observer || DocumentObserver.watch(this.$element);
|
|
777
805
|
|
|
778
|
-
|
|
779
|
-
|
|
806
|
+
if(states.mounted) {
|
|
807
|
+
this.$element.setAttribute('data--nd-mounted', '1');
|
|
808
|
+
this.$observer.mounted(states.mounted);
|
|
809
|
+
}
|
|
810
|
+
if(states.unmounted) {
|
|
811
|
+
this.$element.setAttribute('data--nd-unmounted', '1');
|
|
812
|
+
this.$observer.unmounted(states.unmounted);
|
|
813
|
+
}
|
|
780
814
|
return this;
|
|
781
815
|
};
|
|
816
|
+
|
|
782
817
|
NDElement.prototype.mounted = function(callback) {
|
|
783
818
|
return this.lifecycle({ mounted: callback });
|
|
784
819
|
};
|
|
@@ -808,9 +843,11 @@ var NativeDocument = (function (exports) {
|
|
|
808
843
|
|
|
809
844
|
return this;
|
|
810
845
|
};
|
|
846
|
+
|
|
811
847
|
NDElement.prototype.openShadow = function(style = null) {
|
|
812
848
|
return this.shadow('open', style);
|
|
813
849
|
};
|
|
850
|
+
|
|
814
851
|
NDElement.prototype.closedShadow = function(style = null) {
|
|
815
852
|
return this.shadow('closed', style);
|
|
816
853
|
};
|
|
@@ -878,7 +915,6 @@ var NativeDocument = (function (exports) {
|
|
|
878
915
|
});
|
|
879
916
|
};
|
|
880
917
|
|
|
881
|
-
|
|
882
918
|
const preventDefaultWrapper = function(element, eventName, callback) {
|
|
883
919
|
element.addEventListener(eventName, (event) => {
|
|
884
920
|
event.preventDefault();
|
|
@@ -886,6 +922,7 @@ var NativeDocument = (function (exports) {
|
|
|
886
922
|
});
|
|
887
923
|
return this;
|
|
888
924
|
};
|
|
925
|
+
|
|
889
926
|
const stopPropagationWrapper = function(element, eventName, callback) {
|
|
890
927
|
element.addEventListener(eventName, (event) => {
|
|
891
928
|
event.stopPropagation();
|
|
@@ -893,6 +930,7 @@ var NativeDocument = (function (exports) {
|
|
|
893
930
|
});
|
|
894
931
|
return this;
|
|
895
932
|
};
|
|
933
|
+
|
|
896
934
|
const preventDefaultAndStopPropagationWrapper = function(element, eventName, callback) {
|
|
897
935
|
element.addEventListener(eventName, (event) => {
|
|
898
936
|
event.stopPropagation();
|
|
@@ -901,6 +939,7 @@ var NativeDocument = (function (exports) {
|
|
|
901
939
|
});
|
|
902
940
|
return this;
|
|
903
941
|
};
|
|
942
|
+
|
|
904
943
|
const captureEventWrapper = function(element, eventName, directHandler) {
|
|
905
944
|
if(directHandler) {
|
|
906
945
|
element.addEventListener(eventName, directHandler);
|
|
@@ -916,14 +955,17 @@ var NativeDocument = (function (exports) {
|
|
|
916
955
|
this.$element.addEventListener(eventName, callback);
|
|
917
956
|
return this;
|
|
918
957
|
};
|
|
958
|
+
|
|
919
959
|
NDElement.prototype['onPrevent'+event] = function(callback) {
|
|
920
960
|
preventDefaultWrapper(this.$element, eventName, callback);
|
|
921
961
|
return this;
|
|
922
962
|
};
|
|
963
|
+
|
|
923
964
|
NDElement.prototype['onStop'+event] = function(callback) {
|
|
924
965
|
stopPropagationWrapper(this.$element, eventName, callback);
|
|
925
966
|
return this;
|
|
926
967
|
};
|
|
968
|
+
|
|
927
969
|
NDElement.prototype['onPreventStop'+event] = function(callback) {
|
|
928
970
|
preventDefaultAndStopPropagationWrapper(this.$element, eventName, callback);
|
|
929
971
|
return this;
|