@stemy/ngx-utils 12.0.1 → 12.0.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.
@@ -1683,6 +1683,135 @@
1683
1683
  return MathUtils;
1684
1684
  }());
1685
1685
 
1686
+ /**
1687
+ * Use this service to determine which is the current environment
1688
+ */
1689
+ var UniversalService = /** @class */ (function () {
1690
+ function UniversalService(platformId, dds) {
1691
+ this.platformId = platformId;
1692
+ this.dds = dds;
1693
+ var info = this.dds.getDeviceInfo();
1694
+ this.crawler = /(bot|google|baidu|bing|msn|duckduckbot|teoma|slurp|yandex|lighthouse|angular-universal|PTST)/gi.test(info.userAgent);
1695
+ }
1696
+ Object.defineProperty(UniversalService.prototype, "isBrowser", {
1697
+ get: function () {
1698
+ return common.isPlatformBrowser(this.platformId);
1699
+ },
1700
+ enumerable: false,
1701
+ configurable: true
1702
+ });
1703
+ Object.defineProperty(UniversalService.prototype, "isServer", {
1704
+ get: function () {
1705
+ return common.isPlatformServer(this.platformId);
1706
+ },
1707
+ enumerable: false,
1708
+ configurable: true
1709
+ });
1710
+ Object.defineProperty(UniversalService.prototype, "deviceInfo", {
1711
+ get: function () {
1712
+ return this.isServer
1713
+ ? {
1714
+ userAgent: "angular-universal",
1715
+ os: "unknown",
1716
+ browser: "node",
1717
+ device: "node",
1718
+ os_version: "unknown",
1719
+ browser_version: "unknown",
1720
+ deviceType: "unknown",
1721
+ orientation: "landscape"
1722
+ }
1723
+ : this.dds.getDeviceInfo();
1724
+ },
1725
+ enumerable: false,
1726
+ configurable: true
1727
+ });
1728
+ Object.defineProperty(UniversalService.prototype, "browserName", {
1729
+ get: function () {
1730
+ return this.dds.browser;
1731
+ },
1732
+ enumerable: false,
1733
+ configurable: true
1734
+ });
1735
+ Object.defineProperty(UniversalService.prototype, "browserVersion", {
1736
+ get: function () {
1737
+ return this.dds.browser_version;
1738
+ },
1739
+ enumerable: false,
1740
+ configurable: true
1741
+ });
1742
+ Object.defineProperty(UniversalService.prototype, "isExplorer", {
1743
+ get: function () {
1744
+ return this.dds.browser == "ie";
1745
+ },
1746
+ enumerable: false,
1747
+ configurable: true
1748
+ });
1749
+ Object.defineProperty(UniversalService.prototype, "isEdge", {
1750
+ get: function () {
1751
+ return this.dds.browser == "ms-edge";
1752
+ },
1753
+ enumerable: false,
1754
+ configurable: true
1755
+ });
1756
+ Object.defineProperty(UniversalService.prototype, "isChrome", {
1757
+ get: function () {
1758
+ return this.dds.browser == "chrome";
1759
+ },
1760
+ enumerable: false,
1761
+ configurable: true
1762
+ });
1763
+ Object.defineProperty(UniversalService.prototype, "isFirefox", {
1764
+ get: function () {
1765
+ return this.dds.browser == "firefox";
1766
+ },
1767
+ enumerable: false,
1768
+ configurable: true
1769
+ });
1770
+ Object.defineProperty(UniversalService.prototype, "isSafari", {
1771
+ get: function () {
1772
+ return this.dds.browser == "safari";
1773
+ },
1774
+ enumerable: false,
1775
+ configurable: true
1776
+ });
1777
+ Object.defineProperty(UniversalService.prototype, "isTablet", {
1778
+ get: function () {
1779
+ return this.dds.isTablet();
1780
+ },
1781
+ enumerable: false,
1782
+ configurable: true
1783
+ });
1784
+ Object.defineProperty(UniversalService.prototype, "isMobile", {
1785
+ get: function () {
1786
+ return this.dds.isMobile();
1787
+ },
1788
+ enumerable: false,
1789
+ configurable: true
1790
+ });
1791
+ Object.defineProperty(UniversalService.prototype, "isDesktop", {
1792
+ get: function () {
1793
+ return this.dds.isDesktop();
1794
+ },
1795
+ enumerable: false,
1796
+ configurable: true
1797
+ });
1798
+ Object.defineProperty(UniversalService.prototype, "isCrawler", {
1799
+ get: function () {
1800
+ return this.crawler;
1801
+ },
1802
+ enumerable: false,
1803
+ configurable: true
1804
+ });
1805
+ return UniversalService;
1806
+ }());
1807
+ UniversalService.decorators = [
1808
+ { type: core.Injectable }
1809
+ ];
1810
+ UniversalService.ctorParameters = function () { return [
1811
+ { type: String, decorators: [{ type: core.Inject, args: [core.PLATFORM_ID,] }] },
1812
+ { type: ngxDeviceDetector.DeviceDetectorService }
1813
+ ]; };
1814
+
1686
1815
  var emptySnapshot = new router.ActivatedRouteSnapshot();
1687
1816
  var emptyData = { id: "" };
1688
1817
  var emptyParams = {};
@@ -1690,11 +1819,12 @@
1690
1819
  var emptyComponents = [];
1691
1820
  var StateService = /** @class */ (function (_super) {
1692
1821
  __extends(StateService, _super);
1693
- function StateService(injector, zone, router$1) {
1822
+ function StateService(injector, zone, universal, router$1) {
1694
1823
  if (router$1 === void 0) { router$1 = null; }
1695
1824
  var _this = _super.call(this, null) || this;
1696
1825
  _this.injector = injector;
1697
1826
  _this.zone = zone;
1827
+ _this.universal = universal;
1698
1828
  _this.router = router$1;
1699
1829
  _this.handleRouterEvent = function (event) {
1700
1830
  if (!(event instanceof router.NavigationEnd))
@@ -1865,27 +1995,75 @@
1865
1995
  });
1866
1996
  });
1867
1997
  };
1868
- StateService.prototype.navigate = function (commands, extras) {
1869
- if (!this.router)
1870
- return Promise.resolve(false);
1871
- extras = Object.assign({}, this.globalExtras, extras || {});
1872
- var tree = this.router.createUrlTree(commands, extras);
1873
- return this.navigateByUrl(tree, extras);
1998
+ StateService.prototype.navigateByUrl = function (url, navigationExtras) {
1999
+ if (navigationExtras === void 0) { navigationExtras = {}; }
2000
+ return __awaiter(this, void 0, void 0, function () {
2001
+ return __generator(this, function (_a) {
2002
+ return [2 /*return*/, this.navigate(url, navigationExtras)];
2003
+ });
2004
+ });
1874
2005
  };
1875
- StateService.prototype.navigateByUrl = function (url, extras) {
1876
- var _this = this;
1877
- if (!this.router)
1878
- return Promise.resolve(false);
1879
- extras = Object.assign({}, this.globalExtras, extras || {});
1880
- return new Promise(function (resolve) {
1881
- _this.zone.run(function () {
1882
- _this.router.navigateByUrl(url, extras).then(resolve, function () { return resolve(false); });
2006
+ StateService.prototype.navigate = function (url, navigationExtras) {
2007
+ if (navigationExtras === void 0) { navigationExtras = {}; }
2008
+ return __awaiter(this, void 0, void 0, function () {
2009
+ var _a, tree, extras;
2010
+ var _this = this;
2011
+ return __generator(this, function (_b) {
2012
+ if (!this.router)
2013
+ return [2 /*return*/, false];
2014
+ _a = __read(this.createUrlTree(url, navigationExtras), 2), tree = _a[0], extras = _a[1];
2015
+ return [2 /*return*/, this.zone.run(function () {
2016
+ return _this.router.navigateByUrl(tree, extras);
2017
+ })];
2018
+ });
2019
+ });
2020
+ };
2021
+ StateService.prototype.open = function (url, target, navigationExtras) {
2022
+ if (target === void 0) { target = "_blank"; }
2023
+ if (navigationExtras === void 0) { navigationExtras = {}; }
2024
+ return __awaiter(this, void 0, void 0, function () {
2025
+ var _a, tree, extras;
2026
+ var _this = this;
2027
+ return __generator(this, function (_b) {
2028
+ if (!this.router)
2029
+ return [2 /*return*/, false];
2030
+ _a = __read(this.createUrlTree(url, navigationExtras), 2), tree = _a[0], extras = _a[1];
2031
+ return [2 /*return*/, this.zone.run(function () {
2032
+ return _this.openInNewWindow(tree, target) || _this.router.navigateByUrl(tree, extras);
2033
+ })];
1883
2034
  });
1884
2035
  });
1885
2036
  };
1886
2037
  StateService.prototype.subscribeImmediately = function (next, error, complete) {
1887
2038
  return this.pipe(operators.skipWhile(function (v) { return v == null; })).subscribe(next, error, complete);
1888
2039
  };
2040
+ StateService.prototype.openInNewWindow = function (tree, target) {
2041
+ if (!this.universal.isBrowser)
2042
+ return false;
2043
+ var baseUrl = window.location.href.replace(this.router.url, "");
2044
+ try {
2045
+ var serialized = this.router.serializeUrl(tree);
2046
+ var separator = serialized.startsWith("/") ? "" : "/";
2047
+ window.open(baseUrl + separator + serialized, target);
2048
+ return true;
2049
+ }
2050
+ catch (e) {
2051
+ console.log("Can't open new window: " + e);
2052
+ return false;
2053
+ }
2054
+ };
2055
+ StateService.prototype.createUrlTree = function (url, extras) {
2056
+ if (!this.router)
2057
+ return null;
2058
+ extras = Object.assign(extras, this.globalExtras, extras || {});
2059
+ if (ObjectUtils.isArray(url)) {
2060
+ return [this.router.createUrlTree(url, extras), extras];
2061
+ }
2062
+ if (ObjectUtils.isString(url)) {
2063
+ return [this.router.parseUrl(url), extras];
2064
+ }
2065
+ return [url, extras];
2066
+ };
1889
2067
  return StateService;
1890
2068
  }(rxjs.BehaviorSubject));
1891
2069
  StateService.decorators = [
@@ -1894,6 +2072,7 @@
1894
2072
  StateService.ctorParameters = function () { return [
1895
2073
  { type: core.Injector },
1896
2074
  { type: core.NgZone },
2075
+ { type: UniversalService },
1897
2076
  { type: router.Router, decorators: [{ type: core.Optional }] }
1898
2077
  ]; };
1899
2078
 
@@ -2492,135 +2671,6 @@
2492
2671
  return Vector;
2493
2672
  }());
2494
2673
 
2495
- /**
2496
- * Use this service to determine which is the current environment
2497
- */
2498
- var UniversalService = /** @class */ (function () {
2499
- function UniversalService(platformId, dds) {
2500
- this.platformId = platformId;
2501
- this.dds = dds;
2502
- var info = this.dds.getDeviceInfo();
2503
- this.crawler = /(bot|google|baidu|bing|msn|duckduckbot|teoma|slurp|yandex|lighthouse|angular-universal|PTST)/gi.test(info.userAgent);
2504
- }
2505
- Object.defineProperty(UniversalService.prototype, "isBrowser", {
2506
- get: function () {
2507
- return common.isPlatformBrowser(this.platformId);
2508
- },
2509
- enumerable: false,
2510
- configurable: true
2511
- });
2512
- Object.defineProperty(UniversalService.prototype, "isServer", {
2513
- get: function () {
2514
- return common.isPlatformServer(this.platformId);
2515
- },
2516
- enumerable: false,
2517
- configurable: true
2518
- });
2519
- Object.defineProperty(UniversalService.prototype, "deviceInfo", {
2520
- get: function () {
2521
- return this.isServer
2522
- ? {
2523
- userAgent: "angular-universal",
2524
- os: "unknown",
2525
- browser: "node",
2526
- device: "node",
2527
- os_version: "unknown",
2528
- browser_version: "unknown",
2529
- deviceType: "unknown",
2530
- orientation: "landscape"
2531
- }
2532
- : this.dds.getDeviceInfo();
2533
- },
2534
- enumerable: false,
2535
- configurable: true
2536
- });
2537
- Object.defineProperty(UniversalService.prototype, "browserName", {
2538
- get: function () {
2539
- return this.dds.browser;
2540
- },
2541
- enumerable: false,
2542
- configurable: true
2543
- });
2544
- Object.defineProperty(UniversalService.prototype, "browserVersion", {
2545
- get: function () {
2546
- return this.dds.browser_version;
2547
- },
2548
- enumerable: false,
2549
- configurable: true
2550
- });
2551
- Object.defineProperty(UniversalService.prototype, "isExplorer", {
2552
- get: function () {
2553
- return this.dds.browser == "ie";
2554
- },
2555
- enumerable: false,
2556
- configurable: true
2557
- });
2558
- Object.defineProperty(UniversalService.prototype, "isEdge", {
2559
- get: function () {
2560
- return this.dds.browser == "ms-edge";
2561
- },
2562
- enumerable: false,
2563
- configurable: true
2564
- });
2565
- Object.defineProperty(UniversalService.prototype, "isChrome", {
2566
- get: function () {
2567
- return this.dds.browser == "chrome";
2568
- },
2569
- enumerable: false,
2570
- configurable: true
2571
- });
2572
- Object.defineProperty(UniversalService.prototype, "isFirefox", {
2573
- get: function () {
2574
- return this.dds.browser == "firefox";
2575
- },
2576
- enumerable: false,
2577
- configurable: true
2578
- });
2579
- Object.defineProperty(UniversalService.prototype, "isSafari", {
2580
- get: function () {
2581
- return this.dds.browser == "safari";
2582
- },
2583
- enumerable: false,
2584
- configurable: true
2585
- });
2586
- Object.defineProperty(UniversalService.prototype, "isTablet", {
2587
- get: function () {
2588
- return this.dds.isTablet();
2589
- },
2590
- enumerable: false,
2591
- configurable: true
2592
- });
2593
- Object.defineProperty(UniversalService.prototype, "isMobile", {
2594
- get: function () {
2595
- return this.dds.isMobile();
2596
- },
2597
- enumerable: false,
2598
- configurable: true
2599
- });
2600
- Object.defineProperty(UniversalService.prototype, "isDesktop", {
2601
- get: function () {
2602
- return this.dds.isDesktop();
2603
- },
2604
- enumerable: false,
2605
- configurable: true
2606
- });
2607
- Object.defineProperty(UniversalService.prototype, "isCrawler", {
2608
- get: function () {
2609
- return this.crawler;
2610
- },
2611
- enumerable: false,
2612
- configurable: true
2613
- });
2614
- return UniversalService;
2615
- }());
2616
- UniversalService.decorators = [
2617
- { type: core.Injectable }
2618
- ];
2619
- UniversalService.ctorParameters = function () { return [
2620
- { type: String, decorators: [{ type: core.Inject, args: [core.PLATFORM_ID,] }] },
2621
- { type: ngxDeviceDetector.DeviceDetectorService }
2622
- ]; };
2623
-
2624
2674
  var emptyGuards = [];
2625
2675
  var AclService = /** @class */ (function () {
2626
2676
  function AclService(injector, state, auth) {