@lenne.tech/ng-base 0.1.0 → 0.3.0
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 +272 -24
- package/bundles/lenne.tech-ng-base-src-lib-base.umd.js.map +1 -1
- package/bundles/lenne.tech-ng-base.umd.js +272 -24
- package/bundles/lenne.tech-ng-base.umd.js.map +1 -1
- package/esm2015/lib/base/interfaces/base-module-config.interface.js +1 -1
- package/esm2015/lib/base/services/graphql.service.js +16 -3
- package/esm2015/lib/base/services/scroll.service.js +201 -16
- package/esm2015/src/lib/base/interfaces/base-module-config.interface.js +1 -1
- package/esm2015/src/lib/base/services/graphql.service.js +16 -3
- package/esm2015/src/lib/base/services/scroll.service.js +201 -16
- package/fesm2015/lenne.tech-ng-base-src-lib-base.js +215 -17
- package/fesm2015/lenne.tech-ng-base-src-lib-base.js.map +1 -1
- package/fesm2015/lenne.tech-ng-base.js +215 -17
- package/fesm2015/lenne.tech-ng-base.js.map +1 -1
- package/lib/base/interfaces/base-module-config.interface.d.ts +5 -0
- package/lib/base/services/graphql.service.d.ts +1 -1
- package/lib/base/services/scroll.service.d.ts +66 -3
- package/package.json +12 -11
- package/src/lib/base/interfaces/base-module-config.interface.d.ts +5 -0
- package/src/lib/base/lenne.tech-ng-base-src-lib-base.metadata.json +1 -1
- package/src/lib/base/services/graphql.service.d.ts +1 -1
- package/src/lib/base/services/scroll.service.d.ts +66 -3
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('apollo-angular'), require('apollo-angular/http'), require('@angular/core'), require('rxjs'), require('@apollo/client/core'), require('@apollo/client/cache'), require('@apollo/client/link/ws'), require('@apollo/client/utilities'), require('@angular/platform-browser'), require('@angular/router'), require('graphql'), require('rxjs/operators')) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define('@lenne.tech/ng-base/src/lib/base', ['exports', 'apollo-angular', 'apollo-angular/http', '@angular/core', 'rxjs', '@apollo/client/core', '@apollo/client/cache', '@apollo/client/link/ws', '@apollo/client/utilities', '@angular/platform-browser', '@angular/router', 'graphql', 'rxjs/operators'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.lenne = global.lenne || {}, global.lenne.tech = global.lenne.tech || {}, global.lenne.tech[
|
|
5
|
-
}(this, (function (exports, i1$1, http, i0, rxjs, core, cache, ws, utilities, i1, i1$2, graphql, operators) { 'use strict';
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.lenne = global.lenne || {}, global.lenne.tech = global.lenne.tech || {}, global.lenne.tech["ng-base"] = global.lenne.tech["ng-base"] || {}, global.lenne.tech["ng-base"].src = global.lenne.tech["ng-base"].src || {}, global.lenne.tech["ng-base"].src.lib = global.lenne.tech["ng-base"].src.lib || {}, global.lenne.tech["ng-base"].src.lib.base = {}), global.i1$1, global.http, global.ng.core, global.rxjs, global.core, global.cache, global.ws, global.utilities, global.ng.platformBrowser, global.ng.router, global.graphql, global.rxjs.operators));
|
|
5
|
+
})(this, (function (exports, i1$1, http, i0, rxjs, core, cache, ws, utilities, i1, i1$2, graphql, operators) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopNamespace(e) {
|
|
8
8
|
if (e && e.__esModule) return e;
|
|
@@ -13,14 +13,12 @@
|
|
|
13
13
|
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
14
|
Object.defineProperty(n, k, d.get ? d : {
|
|
15
15
|
enumerable: true,
|
|
16
|
-
get: function () {
|
|
17
|
-
return e[k];
|
|
18
|
-
}
|
|
16
|
+
get: function () { return e[k]; }
|
|
19
17
|
});
|
|
20
18
|
}
|
|
21
19
|
});
|
|
22
20
|
}
|
|
23
|
-
n[
|
|
21
|
+
n["default"] = e;
|
|
24
22
|
return Object.freeze(n);
|
|
25
23
|
}
|
|
26
24
|
|
|
@@ -2162,19 +2160,29 @@
|
|
|
2162
2160
|
/**
|
|
2163
2161
|
* Get fields / args from IGraphQLTypeCollection
|
|
2164
2162
|
*/
|
|
2165
|
-
GraphQLService.prototype.graphQLTypeCollectionToStringArray = function (collection, current, result) {
|
|
2163
|
+
GraphQLService.prototype.graphQLTypeCollectionToStringArray = function (collection, current, result, cacheNode) {
|
|
2166
2164
|
var e_1, _b;
|
|
2167
2165
|
if (current === void 0) { current = ''; }
|
|
2168
2166
|
if (result === void 0) { result = []; }
|
|
2167
|
+
if (cacheNode === void 0) { cacheNode = []; }
|
|
2169
2168
|
if (collection) {
|
|
2170
2169
|
if (collection instanceof GraphQLType) {
|
|
2171
2170
|
result.push(current);
|
|
2172
2171
|
}
|
|
2173
2172
|
else {
|
|
2173
|
+
if (current === null || current === void 0 ? void 0 : current.includes('.')) {
|
|
2174
|
+
cacheNode.push(current.split('.')[1]);
|
|
2175
|
+
}
|
|
2176
|
+
else if (current) {
|
|
2177
|
+
cacheNode.push(current);
|
|
2178
|
+
}
|
|
2174
2179
|
try {
|
|
2175
2180
|
for (var _c = __values(Object.keys(collection)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
2176
2181
|
var key = _d.value;
|
|
2177
|
-
|
|
2182
|
+
if (current === key || cacheNode.includes(key)) {
|
|
2183
|
+
continue;
|
|
2184
|
+
}
|
|
2185
|
+
this.graphQLTypeCollectionToStringArray(collection[key], current ? current + '.' + key : key, result, cacheNode);
|
|
2178
2186
|
}
|
|
2179
2187
|
}
|
|
2180
2188
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -2247,6 +2255,10 @@
|
|
|
2247
2255
|
}
|
|
2248
2256
|
// Process object
|
|
2249
2257
|
else if (typeof args === 'object') {
|
|
2258
|
+
// Check object is empty
|
|
2259
|
+
if (args && Object.keys(args).length === 0 && Object.getPrototypeOf(args) === Object.prototype) {
|
|
2260
|
+
return { argsString: '{}', schemaArgs: schemaArgs, usedArgs: usedArgs };
|
|
2261
|
+
}
|
|
2250
2262
|
var _loop_1 = function (key, value) {
|
|
2251
2263
|
// Init data for current entry
|
|
2252
2264
|
var currentKey = parent + key;
|
|
@@ -2594,32 +2606,80 @@
|
|
|
2594
2606
|
this.router = router;
|
|
2595
2607
|
this.moduleConfig = moduleConfig;
|
|
2596
2608
|
/**
|
|
2597
|
-
*
|
|
2609
|
+
* Is a scroll listener set
|
|
2610
|
+
*
|
|
2611
|
+
* @protected
|
|
2598
2612
|
*/
|
|
2599
|
-
this.
|
|
2613
|
+
this.scrollListener = false;
|
|
2600
2614
|
/**
|
|
2601
|
-
*
|
|
2602
|
-
*
|
|
2615
|
+
* Current scroll timer;
|
|
2616
|
+
*
|
|
2617
|
+
* @protected
|
|
2603
2618
|
*/
|
|
2604
|
-
this.
|
|
2605
|
-
var config = Object.assign({ scrollDetectionOffset: 200, scrollOffset: 100 }, moduleConfig);
|
|
2619
|
+
this.scrollTimer = -1;
|
|
2620
|
+
var config = Object.assign({ scrollDetectionOffset: 200, scrollOffset: 100, scrollSamplingRate: 100 }, moduleConfig);
|
|
2606
2621
|
this.detectionOffset = config.scrollDetectionOffset;
|
|
2607
2622
|
this.scrollOffset = config.scrollOffset;
|
|
2623
|
+
this.scrollSamplingRate = config.scrollSamplingRate;
|
|
2608
2624
|
}
|
|
2609
2625
|
/**
|
|
2610
2626
|
* Scroll to structureElement with specific ID
|
|
2611
2627
|
*/
|
|
2612
2628
|
ScrollService.prototype.scrollTo = function (id, options) {
|
|
2613
2629
|
if (options === void 0) { options = {}; }
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
this
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2630
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2631
|
+
var config, el, body, undoOverflowChanges, scrollBodyStyles, cords;
|
|
2632
|
+
return __generator(this, function (_a) {
|
|
2633
|
+
switch (_a.label) {
|
|
2634
|
+
case 0:
|
|
2635
|
+
config = Object.assign({ checkUrl: true, loadImagesBefore: true, resetStyles: false, setOverflow: true, stopPropagation: true }, options);
|
|
2636
|
+
if (!(config.checkUrl && this.router.url !== '/' && !this.router.url.startsWith('/#'))) return [3 /*break*/, 2];
|
|
2637
|
+
return [4 /*yield*/, this.router.navigate(['/'], { fragment: id })];
|
|
2638
|
+
case 1:
|
|
2639
|
+
_a.sent();
|
|
2640
|
+
return [2 /*return*/, !config.stopPropagation];
|
|
2641
|
+
case 2:
|
|
2642
|
+
el = document.getElementById(id);
|
|
2643
|
+
if (!el) {
|
|
2644
|
+
console.error('Missing scroll element with ID:', id);
|
|
2645
|
+
return [2 /*return*/, !config.stopPropagation];
|
|
2646
|
+
}
|
|
2647
|
+
body = document.querySelector('body');
|
|
2648
|
+
undoOverflowChanges = false;
|
|
2649
|
+
scrollBodyStyles = JSON.parse(JSON.stringify(window.getComputedStyle(body)));
|
|
2650
|
+
if (config.setOverflow && (scrollBodyStyles.overflowX !== 'visible' || scrollBodyStyles.overflowY !== 'visible')) {
|
|
2651
|
+
// Set body overflow to visible
|
|
2652
|
+
console.warn('Style of body element for overflowX and overflowY will be set to "visible" for scrolling!');
|
|
2653
|
+
body.style.overflowX = 'visible';
|
|
2654
|
+
body.style.overflowY = 'visible';
|
|
2655
|
+
undoOverflowChanges = true;
|
|
2656
|
+
}
|
|
2657
|
+
if (!config.loadImagesBefore) return [3 /*break*/, 4];
|
|
2658
|
+
return [4 /*yield*/, this.preLoadImages()];
|
|
2659
|
+
case 3:
|
|
2660
|
+
_a.sent();
|
|
2661
|
+
_a.label = 4;
|
|
2662
|
+
case 4:
|
|
2663
|
+
cords = el.getBoundingClientRect();
|
|
2664
|
+
// Scroll to element
|
|
2665
|
+
window.scrollBy({ top: cords.top - this.scrollOffset, behavior: 'smooth' });
|
|
2666
|
+
return [4 /*yield*/, this.scrollDone({
|
|
2667
|
+
doneFunction: function () {
|
|
2668
|
+
// Undo changes
|
|
2669
|
+
if (undoOverflowChanges && config.resetStyles) {
|
|
2670
|
+
body.style.overflowX = scrollBodyStyles.overflowX;
|
|
2671
|
+
body.style.overflowY = scrollBodyStyles.overflowY;
|
|
2672
|
+
console.warn('Original style of body element for overflowX and overflowY is set.');
|
|
2673
|
+
}
|
|
2674
|
+
},
|
|
2675
|
+
})];
|
|
2676
|
+
case 5:
|
|
2677
|
+
_a.sent();
|
|
2678
|
+
// Return stop propagation configuration
|
|
2679
|
+
return [2 /*return*/, !config.stopPropagation];
|
|
2680
|
+
}
|
|
2681
|
+
});
|
|
2682
|
+
});
|
|
2623
2683
|
};
|
|
2624
2684
|
/**
|
|
2625
2685
|
* Get last active structureElement
|
|
@@ -2650,6 +2710,194 @@
|
|
|
2650
2710
|
var lastActiveElement = this.getLastActiveElement(list);
|
|
2651
2711
|
return id === lastActiveElement || (lastActiveElement === null && isFirst);
|
|
2652
2712
|
};
|
|
2713
|
+
/**
|
|
2714
|
+
* Scroll done promise
|
|
2715
|
+
*/
|
|
2716
|
+
ScrollService.prototype.scrollDone = function (options) {
|
|
2717
|
+
var _this = this;
|
|
2718
|
+
if (options === void 0) { options = {}; }
|
|
2719
|
+
// Init configuration
|
|
2720
|
+
var config = Object.assign({ doneFunction: undefined, timeout: undefined }, options);
|
|
2721
|
+
// Return promise for scroll done
|
|
2722
|
+
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
2723
|
+
var rejected, timeoutId, result;
|
|
2724
|
+
return __generator(this, function (_a) {
|
|
2725
|
+
switch (_a.label) {
|
|
2726
|
+
case 0:
|
|
2727
|
+
rejected = false;
|
|
2728
|
+
// Set timeout handling if necessary
|
|
2729
|
+
if (config.timeout) {
|
|
2730
|
+
timeoutId = window.setTimeout(function () {
|
|
2731
|
+
rejected = true;
|
|
2732
|
+
reject(new Error('Timeout for scrollDone after:' + config.timeout));
|
|
2733
|
+
}, config.timeout);
|
|
2734
|
+
}
|
|
2735
|
+
// Wait for scroll done
|
|
2736
|
+
return [4 /*yield*/, this.scrollDoneDetection()];
|
|
2737
|
+
case 1:
|
|
2738
|
+
// Wait for scroll done
|
|
2739
|
+
_a.sent();
|
|
2740
|
+
if (!!rejected) return [3 /*break*/, 4];
|
|
2741
|
+
// Stop timeout if set
|
|
2742
|
+
if (timeoutId) {
|
|
2743
|
+
window.clearTimeout(timeoutId);
|
|
2744
|
+
}
|
|
2745
|
+
result = void 0;
|
|
2746
|
+
if (!config.doneFunction) return [3 /*break*/, 3];
|
|
2747
|
+
return [4 /*yield*/, config.doneFunction()];
|
|
2748
|
+
case 2:
|
|
2749
|
+
result = _a.sent();
|
|
2750
|
+
_a.label = 3;
|
|
2751
|
+
case 3:
|
|
2752
|
+
// Scroll done
|
|
2753
|
+
resolve(result);
|
|
2754
|
+
_a.label = 4;
|
|
2755
|
+
case 4: return [2 /*return*/];
|
|
2756
|
+
}
|
|
2757
|
+
});
|
|
2758
|
+
}); });
|
|
2759
|
+
};
|
|
2760
|
+
/**
|
|
2761
|
+
* Scroll done detecton
|
|
2762
|
+
*
|
|
2763
|
+
* @protected
|
|
2764
|
+
*/
|
|
2765
|
+
ScrollService.prototype.scrollDoneDetection = function () {
|
|
2766
|
+
var _this = this;
|
|
2767
|
+
// Return current scroll promise (Singelton)
|
|
2768
|
+
if (this.scrollPromise) {
|
|
2769
|
+
return this.scrollPromise;
|
|
2770
|
+
}
|
|
2771
|
+
// Create current scroll promise
|
|
2772
|
+
this.scrollPromise = new Promise(function (resolve) {
|
|
2773
|
+
_this.scrollPromiseResolve = resolve;
|
|
2774
|
+
if (_this.scrollTimer !== -1) {
|
|
2775
|
+
window.clearTimeout(_this.scrollTimer);
|
|
2776
|
+
}
|
|
2777
|
+
_this.scrollTimer = window.setTimeout(function () {
|
|
2778
|
+
window.removeEventListener('scroll', _this.scrollDoneDetection.bind(_this));
|
|
2779
|
+
_this.scrollPromise = undefined;
|
|
2780
|
+
resolve();
|
|
2781
|
+
}, _this.scrollSamplingRate);
|
|
2782
|
+
});
|
|
2783
|
+
// Lisitening to scroll event;
|
|
2784
|
+
window.addEventListener('scroll', this.scrollDoneDetection.bind(this));
|
|
2785
|
+
// Return promise
|
|
2786
|
+
return this.scrollPromise;
|
|
2787
|
+
};
|
|
2788
|
+
/**
|
|
2789
|
+
* Preaload images (for lazy handling)
|
|
2790
|
+
*
|
|
2791
|
+
* @param options
|
|
2792
|
+
* @protected
|
|
2793
|
+
*/
|
|
2794
|
+
ScrollService.prototype.preLoadImages = function (options) {
|
|
2795
|
+
var _this = this;
|
|
2796
|
+
// Init configuration
|
|
2797
|
+
var config = Object.assign({ doneFunnction: undefined, timeout: undefined }, options);
|
|
2798
|
+
return new Promise(function (resolve) {
|
|
2799
|
+
var e_1, _a;
|
|
2800
|
+
// Init variables
|
|
2801
|
+
var resolved = false;
|
|
2802
|
+
var timeoutId;
|
|
2803
|
+
// Init loading
|
|
2804
|
+
var images = Array.from(document.getElementsByTagName('img'));
|
|
2805
|
+
var promises = [];
|
|
2806
|
+
var _loop_1 = function (image) {
|
|
2807
|
+
var src = image.getAttribute('src');
|
|
2808
|
+
// Check if changes are necessary and possible
|
|
2809
|
+
if ((image.complete && image.naturalHeight !== 0) || image.getAttribute('loading') !== 'lazy' || !src) {
|
|
2810
|
+
return "continue";
|
|
2811
|
+
}
|
|
2812
|
+
var newImage = document.createElement('img');
|
|
2813
|
+
Array.from(image.attributes).forEach(function (attr) {
|
|
2814
|
+
if (attr.name !== 'loading' && attr.name !== 'src') {
|
|
2815
|
+
newImage.setAttribute(attr.name, attr.value);
|
|
2816
|
+
}
|
|
2817
|
+
});
|
|
2818
|
+
image.replaceWith(newImage);
|
|
2819
|
+
promises.push(_this.loadImage(newImage, src));
|
|
2820
|
+
};
|
|
2821
|
+
try {
|
|
2822
|
+
// Prepare images
|
|
2823
|
+
for (var images_1 = __values(images), images_1_1 = images_1.next(); !images_1_1.done; images_1_1 = images_1.next()) {
|
|
2824
|
+
var image = images_1_1.value;
|
|
2825
|
+
_loop_1(image);
|
|
2826
|
+
}
|
|
2827
|
+
}
|
|
2828
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2829
|
+
finally {
|
|
2830
|
+
try {
|
|
2831
|
+
if (images_1_1 && !images_1_1.done && (_a = images_1.return)) _a.call(images_1);
|
|
2832
|
+
}
|
|
2833
|
+
finally { if (e_1) throw e_1.error; }
|
|
2834
|
+
}
|
|
2835
|
+
if (config.timeout) {
|
|
2836
|
+
timeoutId = setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
2837
|
+
return __generator(this, function (_a) {
|
|
2838
|
+
switch (_a.label) {
|
|
2839
|
+
case 0:
|
|
2840
|
+
resolved = true;
|
|
2841
|
+
if (!config.doneFunnction) return [3 /*break*/, 2];
|
|
2842
|
+
return [4 /*yield*/, config.doneFunction()];
|
|
2843
|
+
case 1:
|
|
2844
|
+
_a.sent();
|
|
2845
|
+
_a.label = 2;
|
|
2846
|
+
case 2:
|
|
2847
|
+
resolve(undefined);
|
|
2848
|
+
return [2 /*return*/];
|
|
2849
|
+
}
|
|
2850
|
+
});
|
|
2851
|
+
}); });
|
|
2852
|
+
}
|
|
2853
|
+
// Wait until all images loaded
|
|
2854
|
+
Promise.all(promises)
|
|
2855
|
+
.catch(function (e) { return console.error('Error during image loading', e); })
|
|
2856
|
+
.finally(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
2857
|
+
var result;
|
|
2858
|
+
return __generator(this, function (_a) {
|
|
2859
|
+
switch (_a.label) {
|
|
2860
|
+
case 0:
|
|
2861
|
+
// Check if already resolved
|
|
2862
|
+
if (resolved) {
|
|
2863
|
+
return [2 /*return*/];
|
|
2864
|
+
}
|
|
2865
|
+
// Stop timeout
|
|
2866
|
+
if (timeoutId) {
|
|
2867
|
+
clearTimeout(timeoutId);
|
|
2868
|
+
}
|
|
2869
|
+
if (!config.doneFunnction) return [3 /*break*/, 2];
|
|
2870
|
+
return [4 /*yield*/, config.doneFunction()];
|
|
2871
|
+
case 1:
|
|
2872
|
+
result = _a.sent();
|
|
2873
|
+
_a.label = 2;
|
|
2874
|
+
case 2:
|
|
2875
|
+
resolve(result);
|
|
2876
|
+
return [2 /*return*/];
|
|
2877
|
+
}
|
|
2878
|
+
});
|
|
2879
|
+
}); });
|
|
2880
|
+
});
|
|
2881
|
+
};
|
|
2882
|
+
/**
|
|
2883
|
+
* Load image for image element
|
|
2884
|
+
*
|
|
2885
|
+
* @param imageElement
|
|
2886
|
+
* @param src
|
|
2887
|
+
* @protected
|
|
2888
|
+
*/
|
|
2889
|
+
ScrollService.prototype.loadImage = function (imageElement, src) {
|
|
2890
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2891
|
+
return __generator(this, function (_a) {
|
|
2892
|
+
src = src || imageElement.src;
|
|
2893
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
2894
|
+
imageElement.onload = function () { return resolve(imageElement); };
|
|
2895
|
+
imageElement.onerror = reject;
|
|
2896
|
+
imageElement.src = src;
|
|
2897
|
+
})];
|
|
2898
|
+
});
|
|
2899
|
+
});
|
|
2900
|
+
};
|
|
2653
2901
|
return ScrollService;
|
|
2654
2902
|
}());
|
|
2655
2903
|
ScrollService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function ScrollService_Factory() { return new ScrollService(i0__namespace.ɵɵinject(i1__namespace$1.Router), i0__namespace.ɵɵinject(BASE_MODULE_CONFIG)); }, token: ScrollService, providedIn: "root" });
|
|
@@ -2765,5 +3013,5 @@
|
|
|
2765
3013
|
|
|
2766
3014
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2767
3015
|
|
|
2768
|
-
}))
|
|
3016
|
+
}));
|
|
2769
3017
|
//# sourceMappingURL=lenne.tech-ng-base-src-lib-base.umd.js.map
|