@lenne.tech/ng-base 0.0.11 → 0.2.2
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 +338 -32
- package/bundles/lenne.tech-ng-base-src-lib-base.umd.js.map +1 -1
- package/bundles/lenne.tech-ng-base.umd.js +338 -32
- package/bundles/lenne.tech-ng-base.umd.js.map +1 -1
- package/esm2015/lib/base/factories/apollo-options.factory.js +43 -4
- package/esm2015/lib/base/interfaces/base-module-config.interface.js +1 -1
- package/esm2015/lib/base/services/graphql-plus.service.js +5 -2
- package/esm2015/lib/base/services/graphql.service.js +37 -6
- package/esm2015/lib/base/services/scroll.service.js +201 -16
- package/esm2015/src/lib/base/factories/apollo-options.factory.js +43 -4
- package/esm2015/src/lib/base/interfaces/base-module-config.interface.js +1 -1
- package/esm2015/src/lib/base/services/graphql-plus.service.js +5 -2
- package/esm2015/src/lib/base/services/graphql.service.js +37 -6
- package/esm2015/src/lib/base/services/scroll.service.js +201 -16
- package/fesm2015/lenne.tech-ng-base-src-lib-base.js +281 -24
- package/fesm2015/lenne.tech-ng-base-src-lib-base.js.map +1 -1
- package/fesm2015/lenne.tech-ng-base.js +281 -24
- package/fesm2015/lenne.tech-ng-base.js.map +1 -1
- package/lib/base/interfaces/base-module-config.interface.d.ts +9 -0
- package/lib/base/services/graphql.service.d.ts +1 -1
- package/lib/base/services/scroll.service.d.ts +66 -3
- package/package.json +1 -1
- package/src/lib/base/interfaces/base-module-config.interface.d.ts +9 -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
|
-
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('@angular/platform-browser'), require('@angular/router'), require('graphql'), require('rxjs/operators')) :
|
|
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', '@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, i1, i1$2, graphql, operators) { 'use strict';
|
|
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
|
+
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["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
|
|
|
@@ -573,7 +571,8 @@
|
|
|
573
571
|
* Factory for apollo-angular options
|
|
574
572
|
*/
|
|
575
573
|
function apolloOptionsFactory(baseModuleConfig, httpLink, authService) {
|
|
576
|
-
var
|
|
574
|
+
var links = [];
|
|
575
|
+
var http = httpLink.create({
|
|
577
576
|
uri: baseModuleConfig.apiUrl,
|
|
578
577
|
});
|
|
579
578
|
var authMiddleware = new core.ApolloLink(function (operation, forward) {
|
|
@@ -587,8 +586,45 @@
|
|
|
587
586
|
}
|
|
588
587
|
return forward(operation);
|
|
589
588
|
});
|
|
589
|
+
if (baseModuleConfig.wsUrl) {
|
|
590
|
+
var wsClient = void 0;
|
|
591
|
+
if (localStorage) {
|
|
592
|
+
var token = authService.token || null;
|
|
593
|
+
wsClient = new ws.WebSocketLink({
|
|
594
|
+
uri: baseModuleConfig.wsUrl,
|
|
595
|
+
options: {
|
|
596
|
+
reconnect: true,
|
|
597
|
+
connectionParams: {
|
|
598
|
+
authToken: token,
|
|
599
|
+
},
|
|
600
|
+
},
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
else {
|
|
604
|
+
wsClient = new ws.WebSocketLink({
|
|
605
|
+
uri: baseModuleConfig.wsUrl,
|
|
606
|
+
options: {
|
|
607
|
+
reconnect: true,
|
|
608
|
+
},
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
// using the ability to split links, you can send data to each link
|
|
612
|
+
// depending on what kind of operation is being sent
|
|
613
|
+
links.push(core.split(
|
|
614
|
+
// split based on operation type
|
|
615
|
+
function (_a) {
|
|
616
|
+
var query = _a.query;
|
|
617
|
+
// @ts-ignore
|
|
618
|
+
var _b = utilities.getMainDefinition(query), kind = _b.kind, operation = _b.operation;
|
|
619
|
+
return kind === 'OperationDefinition' && operation === 'subscription';
|
|
620
|
+
}, wsClient, core.concat(authMiddleware, http)));
|
|
621
|
+
}
|
|
622
|
+
else {
|
|
623
|
+
links.push(http);
|
|
624
|
+
links.push(authMiddleware);
|
|
625
|
+
}
|
|
590
626
|
return {
|
|
591
|
-
link: core.ApolloLink.from(
|
|
627
|
+
link: core.ApolloLink.from(links),
|
|
592
628
|
cache: new cache.InMemoryCache(),
|
|
593
629
|
defaultOptions: {
|
|
594
630
|
query: {
|
|
@@ -2070,13 +2106,29 @@
|
|
|
2070
2106
|
var documentNode = fields
|
|
2071
2107
|
? i1$1.gql(config.type + '{\n' + graphql + args + fields + '\n}')
|
|
2072
2108
|
: i1$1.gql(config.type + '{\n' + graphql + args + '\n}');
|
|
2109
|
+
// Log
|
|
2110
|
+
if (config.log) {
|
|
2111
|
+
console.log({ documentNode: documentNode });
|
|
2112
|
+
}
|
|
2073
2113
|
var request = {};
|
|
2074
2114
|
request[config.type] = documentNode;
|
|
2075
2115
|
// Log
|
|
2076
2116
|
if (config.log) {
|
|
2077
2117
|
console.log({ request: request });
|
|
2078
2118
|
}
|
|
2079
|
-
var func
|
|
2119
|
+
var func;
|
|
2120
|
+
if (config.type === exports.GraphQLRequestType.MUTATION) {
|
|
2121
|
+
func = 'mutate';
|
|
2122
|
+
request[config.type] = documentNode;
|
|
2123
|
+
}
|
|
2124
|
+
else if (config.type === exports.GraphQLRequestType.SUBSCRIPTION) {
|
|
2125
|
+
func = 'subscribe';
|
|
2126
|
+
request.query = documentNode;
|
|
2127
|
+
}
|
|
2128
|
+
else {
|
|
2129
|
+
func = config.type;
|
|
2130
|
+
request[config.type] = documentNode;
|
|
2131
|
+
}
|
|
2080
2132
|
_this.apollo[func](request).subscribe(function (result) {
|
|
2081
2133
|
var _a;
|
|
2082
2134
|
var data = ((_a = result === null || result === void 0 ? void 0 : result.data) === null || _a === void 0 ? void 0 : _a[graphql]) !== undefined ? result.data[graphql] : result;
|
|
@@ -2094,8 +2146,10 @@
|
|
|
2094
2146
|
else {
|
|
2095
2147
|
subscriber.next(config.model.map(data));
|
|
2096
2148
|
}
|
|
2097
|
-
|
|
2098
|
-
|
|
2149
|
+
if (config.type !== exports.GraphQLRequestType.SUBSCRIPTION) {
|
|
2150
|
+
// Done
|
|
2151
|
+
subscriber.complete();
|
|
2152
|
+
}
|
|
2099
2153
|
}, function (error) {
|
|
2100
2154
|
subscriber.error(error);
|
|
2101
2155
|
subscriber.complete();
|
|
@@ -2106,19 +2160,29 @@
|
|
|
2106
2160
|
/**
|
|
2107
2161
|
* Get fields / args from IGraphQLTypeCollection
|
|
2108
2162
|
*/
|
|
2109
|
-
GraphQLService.prototype.graphQLTypeCollectionToStringArray = function (collection, current, result) {
|
|
2163
|
+
GraphQLService.prototype.graphQLTypeCollectionToStringArray = function (collection, current, result, cacheNode) {
|
|
2110
2164
|
var e_1, _b;
|
|
2111
2165
|
if (current === void 0) { current = ''; }
|
|
2112
2166
|
if (result === void 0) { result = []; }
|
|
2167
|
+
if (cacheNode === void 0) { cacheNode = []; }
|
|
2113
2168
|
if (collection) {
|
|
2114
2169
|
if (collection instanceof GraphQLType) {
|
|
2115
2170
|
result.push(current);
|
|
2116
2171
|
}
|
|
2117
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
|
+
}
|
|
2118
2179
|
try {
|
|
2119
2180
|
for (var _c = __values(Object.keys(collection)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
2120
2181
|
var key = _d.value;
|
|
2121
|
-
|
|
2182
|
+
if (current === key || cacheNode.includes(key)) {
|
|
2183
|
+
continue;
|
|
2184
|
+
}
|
|
2185
|
+
this.graphQLTypeCollectionToStringArray(collection[key], current ? current + '.' + key : key, result, cacheNode);
|
|
2122
2186
|
}
|
|
2123
2187
|
}
|
|
2124
2188
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -2191,6 +2255,10 @@
|
|
|
2191
2255
|
}
|
|
2192
2256
|
// Process object
|
|
2193
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
|
+
}
|
|
2194
2262
|
var _loop_1 = function (key, value) {
|
|
2195
2263
|
// Init data for current entry
|
|
2196
2264
|
var currentKey = parent + key;
|
|
@@ -2471,7 +2539,9 @@
|
|
|
2471
2539
|
}
|
|
2472
2540
|
subscriber.next(response);
|
|
2473
2541
|
_this.handleLoader('stop', options);
|
|
2474
|
-
|
|
2542
|
+
if (options.type !== exports.GraphQLRequestType.SUBSCRIPTION) {
|
|
2543
|
+
subscriber.complete();
|
|
2544
|
+
}
|
|
2475
2545
|
}, function (error) {
|
|
2476
2546
|
if (!options.ignoreErrors) {
|
|
2477
2547
|
_this.handleError(error, options.excludedErrors);
|
|
@@ -2536,32 +2606,80 @@
|
|
|
2536
2606
|
this.router = router;
|
|
2537
2607
|
this.moduleConfig = moduleConfig;
|
|
2538
2608
|
/**
|
|
2539
|
-
*
|
|
2609
|
+
* Is a scroll listener set
|
|
2610
|
+
*
|
|
2611
|
+
* @protected
|
|
2540
2612
|
*/
|
|
2541
|
-
this.
|
|
2613
|
+
this.scrollListener = false;
|
|
2542
2614
|
/**
|
|
2543
|
-
*
|
|
2544
|
-
*
|
|
2615
|
+
* Current scroll timer;
|
|
2616
|
+
*
|
|
2617
|
+
* @protected
|
|
2545
2618
|
*/
|
|
2546
|
-
this.
|
|
2547
|
-
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);
|
|
2548
2621
|
this.detectionOffset = config.scrollDetectionOffset;
|
|
2549
2622
|
this.scrollOffset = config.scrollOffset;
|
|
2623
|
+
this.scrollSamplingRate = config.scrollSamplingRate;
|
|
2550
2624
|
}
|
|
2551
2625
|
/**
|
|
2552
2626
|
* Scroll to structureElement with specific ID
|
|
2553
2627
|
*/
|
|
2554
2628
|
ScrollService.prototype.scrollTo = function (id, options) {
|
|
2555
2629
|
if (options === void 0) { options = {}; }
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
this
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
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
|
+
});
|
|
2565
2683
|
};
|
|
2566
2684
|
/**
|
|
2567
2685
|
* Get last active structureElement
|
|
@@ -2592,6 +2710,194 @@
|
|
|
2592
2710
|
var lastActiveElement = this.getLastActiveElement(list);
|
|
2593
2711
|
return id === lastActiveElement || (lastActiveElement === null && isFirst);
|
|
2594
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
|
+
};
|
|
2595
2901
|
return ScrollService;
|
|
2596
2902
|
}());
|
|
2597
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" });
|
|
@@ -2707,5 +3013,5 @@
|
|
|
2707
3013
|
|
|
2708
3014
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2709
3015
|
|
|
2710
|
-
}))
|
|
3016
|
+
}));
|
|
2711
3017
|
//# sourceMappingURL=lenne.tech-ng-base-src-lib-base.umd.js.map
|