@lenne.tech/ng-base 0.3.4 → 0.3.8
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.
- package/bundles/lenne.tech-ng-base-src-lib-base.umd.js +27 -89
- package/bundles/lenne.tech-ng-base-src-lib-base.umd.js.map +1 -1
- package/bundles/lenne.tech-ng-base.umd.js +27 -89
- package/bundles/lenne.tech-ng-base.umd.js.map +1 -1
- package/esm2015/lib/base/directives/match-height.directive.js +5 -17
- package/esm2015/lib/base/services/graphql.service.js +3 -3
- package/esm2015/lib/base/services/image.service.js +14 -32
- package/esm2015/lib/base/services/scroll.service.js +9 -30
- package/esm2015/src/lib/base/directives/match-height.directive.js +5 -17
- package/esm2015/src/lib/base/services/graphql.service.js +3 -3
- package/esm2015/src/lib/base/services/image.service.js +14 -32
- package/esm2015/src/lib/base/services/scroll.service.js +9 -30
- package/fesm2015/lenne.tech-ng-base-src-lib-base.js +27 -78
- package/fesm2015/lenne.tech-ng-base-src-lib-base.js.map +1 -1
- package/fesm2015/lenne.tech-ng-base.js +27 -78
- package/fesm2015/lenne.tech-ng-base.js.map +1 -1
- package/lib/base/directives/match-height.directive.d.ts +5 -6
- package/lib/base/services/image.service.d.ts +0 -1
- package/lib/base/services/scroll.service.d.ts +1 -2
- package/package.json +1 -1
- package/src/lib/base/directives/match-height.directive.d.ts +5 -6
- package/src/lib/base/lenne.tech-ng-base-src-lib-base.metadata.json +1 -1
- package/src/lib/base/services/image.service.d.ts +0 -1
- package/src/lib/base/services/scroll.service.d.ts +1 -2
|
@@ -722,12 +722,9 @@ class ImageService {
|
|
|
722
722
|
*/
|
|
723
723
|
preLoadImages(options) {
|
|
724
724
|
// Init configuration
|
|
725
|
-
const config = Object.assign({ doneFunnction: undefined, elements: document, regExp: undefined
|
|
725
|
+
const config = Object.assign({ doneFunnction: undefined, elements: document, regExp: undefined }, options);
|
|
726
726
|
return new Promise((resolve) => {
|
|
727
727
|
var _a;
|
|
728
|
-
// Init variables
|
|
729
|
-
let resolved = false;
|
|
730
|
-
let timeoutId;
|
|
731
728
|
// Convert element(s) into array
|
|
732
729
|
if (!Array.isArray(config.elements)) {
|
|
733
730
|
// NodeList or HTMLCollection
|
|
@@ -747,48 +744,33 @@ class ImageService {
|
|
|
747
744
|
images = images.concat(Array.from(element.getElementsByTagName('img')));
|
|
748
745
|
});
|
|
749
746
|
// Prepare images
|
|
750
|
-
for (
|
|
747
|
+
for (let image of images) {
|
|
751
748
|
const src = image.getAttribute('src');
|
|
752
749
|
// Check if changes are necessary and possible
|
|
753
750
|
if ((image.complete && image.naturalHeight !== 0) || // already laoded
|
|
754
|
-
image.getAttribute('loading') !== 'lazy' || // loading attribute !== lazy
|
|
755
751
|
!src || // Image has no src
|
|
756
752
|
((_a = config.regExp) === null || _a === void 0 ? void 0 : _a.test(src)) // Test if src matches regular expression
|
|
757
753
|
) {
|
|
758
754
|
continue;
|
|
759
755
|
}
|
|
760
756
|
// Replace lazy loading image with immediately loading image
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
757
|
+
if (image.getAttribute('loading') === 'lazy') {
|
|
758
|
+
const newImage = document.createElement('img');
|
|
759
|
+
Array.from(image.attributes).forEach((attr) => {
|
|
760
|
+
if (attr.name !== 'loading' && attr.name !== 'src') {
|
|
761
|
+
newImage.setAttribute(attr.name, attr.value);
|
|
762
|
+
}
|
|
763
|
+
});
|
|
764
|
+
image.replaceWith(newImage);
|
|
765
|
+
image = newImage;
|
|
766
|
+
}
|
|
768
767
|
// Wait for laoding
|
|
769
|
-
promises.push(this.loadImage(
|
|
770
|
-
}
|
|
771
|
-
if (config.timeout) {
|
|
772
|
-
timeoutId = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
773
|
-
resolved = true;
|
|
774
|
-
if (config.doneFunnction) {
|
|
775
|
-
yield config.doneFunction();
|
|
776
|
-
}
|
|
777
|
-
resolve(undefined);
|
|
778
|
-
}));
|
|
768
|
+
promises.push(this.loadImage(image, src));
|
|
779
769
|
}
|
|
780
770
|
// Wait until all images loaded
|
|
781
771
|
Promise.all(promises)
|
|
782
772
|
.catch((e) => console.error('Error during image loading', e))
|
|
783
773
|
.finally(() => __awaiter(this, void 0, void 0, function* () {
|
|
784
|
-
// Check if already resolved
|
|
785
|
-
if (resolved) {
|
|
786
|
-
return;
|
|
787
|
-
}
|
|
788
|
-
// Stop timeout
|
|
789
|
-
if (timeoutId) {
|
|
790
|
-
clearTimeout(timeoutId);
|
|
791
|
-
}
|
|
792
774
|
// Return result
|
|
793
775
|
let result;
|
|
794
776
|
if (config.doneFunnction) {
|
|
@@ -831,28 +813,16 @@ class MatchHeightDirective {
|
|
|
831
813
|
this.el = el;
|
|
832
814
|
this.imageService = imageService;
|
|
833
815
|
// Replace lazy loading images with immediate loading images
|
|
834
|
-
this.
|
|
816
|
+
this.loadImages = true;
|
|
835
817
|
this.isBrowser = isPlatformBrowser(platformId);
|
|
836
818
|
}
|
|
837
819
|
onResize() {
|
|
838
820
|
this.matchHeight(this.el.nativeElement, this.ltMatchHeight);
|
|
839
821
|
}
|
|
840
|
-
|
|
822
|
+
ngOnInit() {
|
|
841
823
|
this.matchHeight(this.el.nativeElement, this.ltMatchHeight);
|
|
842
824
|
}
|
|
843
825
|
matchHeight(parent, target) {
|
|
844
|
-
if (this.isBrowser) {
|
|
845
|
-
// Timeout is set to force Angular to wait for all actions and only continue once the process has run through.
|
|
846
|
-
// Otherwise, an infinite loop will occur.
|
|
847
|
-
setTimeout(() => {
|
|
848
|
-
this.matchHeightHelper(parent, target);
|
|
849
|
-
}, 1);
|
|
850
|
-
}
|
|
851
|
-
else {
|
|
852
|
-
this.matchHeightHelper(parent, target);
|
|
853
|
-
}
|
|
854
|
-
}
|
|
855
|
-
matchHeightHelper(parent, target) {
|
|
856
826
|
return __awaiter(this, void 0, void 0, function* () {
|
|
857
827
|
if (!parent) {
|
|
858
828
|
return;
|
|
@@ -871,7 +841,7 @@ class MatchHeightDirective {
|
|
|
871
841
|
continue;
|
|
872
842
|
}
|
|
873
843
|
// Load images of children
|
|
874
|
-
if (this.
|
|
844
|
+
if (this.loadImages) {
|
|
875
845
|
yield this.imageService.preLoadImages({ elements: children });
|
|
876
846
|
}
|
|
877
847
|
// reset all children height
|
|
@@ -905,7 +875,7 @@ MatchHeightDirective.ctorParameters = () => [
|
|
|
905
875
|
];
|
|
906
876
|
MatchHeightDirective.propDecorators = {
|
|
907
877
|
ltMatchHeight: [{ type: Input }],
|
|
908
|
-
|
|
878
|
+
loadImages: [{ type: Input }],
|
|
909
879
|
onResize: [{ type: HostListener, args: ['window:resize',] }]
|
|
910
880
|
};
|
|
911
881
|
|
|
@@ -1730,7 +1700,7 @@ class GraphQLService {
|
|
|
1730
1700
|
.filter((field) => !argsData.usedArgs.includes(field));
|
|
1731
1701
|
console.log({ argsData, filtered, unused });
|
|
1732
1702
|
}
|
|
1733
|
-
const args = argsData.argsString || '';
|
|
1703
|
+
const args = (argsData === null || argsData === void 0 ? void 0 : argsData.argsString) || '';
|
|
1734
1704
|
// Log
|
|
1735
1705
|
if (config.log) {
|
|
1736
1706
|
console.log({ graphQL: graphql, args, fields, type: config.type });
|
|
@@ -1876,7 +1846,7 @@ class GraphQLService {
|
|
|
1876
1846
|
continue;
|
|
1877
1847
|
}
|
|
1878
1848
|
// Skip value if not exists
|
|
1879
|
-
if (value === undefined
|
|
1849
|
+
if (value === undefined || value === null) {
|
|
1880
1850
|
continue;
|
|
1881
1851
|
}
|
|
1882
1852
|
// Add current key to metadata
|
|
@@ -2191,7 +2161,7 @@ class ScrollService {
|
|
|
2191
2161
|
scrollTo(id, options = {}) {
|
|
2192
2162
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2193
2163
|
// Prepare config
|
|
2194
|
-
const config = Object.assign({ checkUrl:
|
|
2164
|
+
const config = Object.assign({ checkUrl: false, loadImagesBefore: true, resetStyles: false, setOverflow: true, stopPropagation: true }, options);
|
|
2195
2165
|
// Check current URL
|
|
2196
2166
|
if (config.checkUrl && this.router.url !== '/' && !this.router.url.startsWith('/#')) {
|
|
2197
2167
|
yield this.router.navigate(['/'], { fragment: id });
|
|
@@ -2269,37 +2239,16 @@ class ScrollService {
|
|
|
2269
2239
|
* Scroll done promise
|
|
2270
2240
|
*/
|
|
2271
2241
|
scrollDone(options = {}) {
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
2276
|
-
// Init variables
|
|
2277
|
-
let rejected = false;
|
|
2278
|
-
let timeoutId;
|
|
2279
|
-
// Set timeout handling if necessary
|
|
2280
|
-
if (config.timeout) {
|
|
2281
|
-
timeoutId = window.setTimeout(() => {
|
|
2282
|
-
rejected = true;
|
|
2283
|
-
reject(new Error('Timeout for scrollDone after:' + config.timeout));
|
|
2284
|
-
}, config.timeout);
|
|
2285
|
-
}
|
|
2242
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2243
|
+
// Init configuration
|
|
2244
|
+
const config = Object.assign({ doneFunction: undefined }, options);
|
|
2286
2245
|
// Wait for scroll done
|
|
2287
2246
|
yield this.scrollDoneDetection();
|
|
2288
|
-
//
|
|
2289
|
-
if (
|
|
2290
|
-
|
|
2291
|
-
if (timeoutId) {
|
|
2292
|
-
window.clearTimeout(timeoutId);
|
|
2293
|
-
}
|
|
2294
|
-
// Get result (if doneFunction is set)
|
|
2295
|
-
let result;
|
|
2296
|
-
if (config.doneFunction) {
|
|
2297
|
-
result = yield config.doneFunction();
|
|
2298
|
-
}
|
|
2299
|
-
// Scroll done
|
|
2300
|
-
resolve(result);
|
|
2247
|
+
// Get result
|
|
2248
|
+
if (config.doneFunction) {
|
|
2249
|
+
return config.doneFunction();
|
|
2301
2250
|
}
|
|
2302
|
-
})
|
|
2251
|
+
});
|
|
2303
2252
|
}
|
|
2304
2253
|
/**
|
|
2305
2254
|
* Scroll done detecton
|