@michalrakus/x-react-web-lib 1.32.8 → 1.32.9

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.
@@ -544,6 +544,9 @@ var XLazyDataTable = function (props) {
544
544
  setFiltersAfterFiltering(filters);
545
545
  setFtsInputValueAfterFiltering(ftsInputValue ? __assign({}, ftsInputValue) : undefined);
546
546
  setOptionalCustomFilterAfterFiltering(optionalCustomFilter);
547
+ // async check for new version - the purpose is to get new version of app to the browser (if available) in short time (10 minutes)
548
+ // (if there is no new version, the check will run async (as the last operation) and nothing will happen)
549
+ XUtils_1.XUtils.reloadIfNewVersion();
547
550
  return [2 /*return*/];
548
551
  }
549
552
  });
@@ -49,6 +49,8 @@ export declare class XUtils {
49
49
  static csvEncodingOptions: CsvEncoding[];
50
50
  static remSize: number | null;
51
51
  static FIELD_LABEL_WIDTH: string;
52
+ static lastVersionCheckTimestamp: number | null;
53
+ static VERSION_CHECK_PERIOD: number;
52
54
  static demo(): boolean;
53
55
  static isMobile(): boolean;
54
56
  static mobileCssSuffix(): string;
@@ -108,4 +110,8 @@ export declare class XUtils {
108
110
  static saveValueIntoStorage(key: string, value: any): void;
109
111
  static getValueFromStorage(key: string, initValue: any): any;
110
112
  static removeValueFromStorage(key: string): void;
113
+ static reloadIfNewVersion(): void;
114
+ static reloadIfNewVersionNow(): Promise<void>;
115
+ static isNewVersion(): Promise<boolean>;
116
+ static reload(): void;
111
117
  }
@@ -749,6 +749,95 @@ var XUtils = /** @class */ (function () {
749
749
  XUtils.removeValueFromStorage = function (key) {
750
750
  sessionStorage.removeItem(key);
751
751
  };
752
+ // hleper method used for items of XLazyDataTable (shortcut ldt)
753
+ // static getValueFromStorageLdt(entity: string, stateKeySuffix: XStateKeySuffix, initValue: any): any {
754
+ // return XUtils.getValueFromStorage(`xldt-state-${entity}-${stateKeySuffix}`, initValue);
755
+ // }
756
+ XUtils.reloadIfNewVersion = function () {
757
+ // to save requests, we check for new version only if 10 minutes (or another time period) are passed from the last check
758
+ // we could use method setInterval (timer) and run check exactly 10 minutes but the disadvantage is that then there will be
759
+ // some processing during idle time and that can exhaust battery on mobile phone (mobile phone will not go to sleeping mode) - is it true?
760
+ var currentTimestamp = Date.now(); // Current time
761
+ if (XUtils.lastVersionCheckTimestamp === null || currentTimestamp - XUtils.lastVersionCheckTimestamp > XUtils.VERSION_CHECK_PERIOD) {
762
+ XUtils.reloadIfNewVersionNow();
763
+ XUtils.lastVersionCheckTimestamp = currentTimestamp;
764
+ }
765
+ };
766
+ XUtils.reloadIfNewVersionNow = function () {
767
+ return __awaiter(this, void 0, void 0, function () {
768
+ return __generator(this, function (_a) {
769
+ switch (_a.label) {
770
+ case 0: return [4 /*yield*/, XUtils.isNewVersion()];
771
+ case 1:
772
+ if (_a.sent()) {
773
+ alert("New version was released. Application will be restarted.");
774
+ XUtils.reload();
775
+ }
776
+ return [2 /*return*/];
777
+ }
778
+ });
779
+ });
780
+ };
781
+ XUtils.isNewVersion = function () {
782
+ return __awaiter(this, void 0, void 0, function () {
783
+ var response, text, r, remoteMainScript, localMainScript, scripts, scripts_1, scripts_1_1, script, rl, err_1;
784
+ var e_7, _a;
785
+ return __generator(this, function (_b) {
786
+ switch (_b.label) {
787
+ case 0:
788
+ _b.trys.push([0, 3, , 4]);
789
+ return [4 /*yield*/, fetch("index.html", { method: 'GET', cache: "no-store" })];
790
+ case 1:
791
+ response = _b.sent();
792
+ return [4 /*yield*/, response.text()];
793
+ case 2:
794
+ text = _b.sent();
795
+ r = /^.*<script.*\/(main.*\.js).*$/gim.exec(text);
796
+ if (!r || r.length < 2) {
797
+ return [2 /*return*/, false];
798
+ }
799
+ remoteMainScript = r.length > 1 ? r[1] : null;
800
+ if (remoteMainScript === null) {
801
+ return [2 /*return*/, false];
802
+ }
803
+ localMainScript = null;
804
+ scripts = document.body.getElementsByTagName('script');
805
+ try {
806
+ for (scripts_1 = __values(scripts), scripts_1_1 = scripts_1.next(); !scripts_1_1.done; scripts_1_1 = scripts_1.next()) {
807
+ script = scripts_1_1.value;
808
+ rl = /^.*\/(main.*\.js).*$/gim.exec(script.src);
809
+ if (!rl || rl.length < 2) {
810
+ continue;
811
+ }
812
+ localMainScript = rl[1];
813
+ break;
814
+ }
815
+ }
816
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
817
+ finally {
818
+ try {
819
+ if (scripts_1_1 && !scripts_1_1.done && (_a = scripts_1.return)) _a.call(scripts_1);
820
+ }
821
+ finally { if (e_7) throw e_7.error; }
822
+ }
823
+ if (localMainScript === null) {
824
+ return [2 /*return*/, false];
825
+ }
826
+ return [2 /*return*/, remoteMainScript !== localMainScript];
827
+ case 3:
828
+ err_1 = _b.sent();
829
+ console.log(err_1);
830
+ return [2 /*return*/, false];
831
+ case 4: return [2 /*return*/];
832
+ }
833
+ });
834
+ });
835
+ };
836
+ XUtils.reload = function () {
837
+ // page reload (like pressing F5 or Enter on url bar)
838
+ // warning - if user has typed some data in form, the data will be lost
839
+ window.location.reload();
840
+ };
752
841
  XUtils.dropdownEmptyOptionValue = " ";
753
842
  XUtils.xBackendUrl = undefined;
754
843
  // nacachovany XToken - na rozlicnych miestach potrebujeme vediet uzivatela
@@ -766,6 +855,8 @@ var XUtils = /** @class */ (function () {
766
855
  XUtils.remSize = null;
767
856
  // konstanty (zatial takto jednoducho)
768
857
  XUtils.FIELD_LABEL_WIDTH = '10.5rem';
858
+ XUtils.lastVersionCheckTimestamp = null;
859
+ XUtils.VERSION_CHECK_PERIOD = 10 * 60 * 1000; // 10 minutes in milliseconds
769
860
  return XUtils;
770
861
  }());
771
862
  exports.XUtils = XUtils;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@michalrakus/x-react-web-lib",
3
- "version": "1.32.8",
3
+ "version": "1.32.9",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "clean": "rimraf lib",