turbogui-angular 20.10.1 → 20.11.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.
@@ -829,6 +829,10 @@ class DialogService extends SingletoneStrictClass {
829
829
  * A reference to the modal busy state container where the component will be added
830
830
  */
831
831
  this._modalBusyStateHost = null;
832
+ /**
833
+ * Used to store the previous document body overflow values when scroll locks are added
834
+ */
835
+ this._scrollLockSavedOverflowStates = [];
832
836
  /**
833
837
  * Tells if the manager is currently showing a snackbar element or not
834
838
  */
@@ -899,6 +903,27 @@ class DialogService extends SingletoneStrictClass {
899
903
  this._windowBeforeUnloadUnListen = null;
900
904
  }
901
905
  }
906
+ /**
907
+ * Disable application scroll by setting document body overflow to hidden.
908
+ * Each call to this method must be matched with a call to removeScrollLock() to restore it back to previous state.
909
+ * If multiple calls to addScrollLock() are done, multiple calls to removeScrollLock() will be required to restore
910
+ * the original scroll state.
911
+ */
912
+ addScrollLock() {
913
+ this._scrollLockSavedOverflowStates.push(document.body.style.overflow);
914
+ document.body.style.overflow = 'hidden';
915
+ }
916
+ /**
917
+ * Restore application scroll by restoring document body overflow to the value it had before
918
+ * the last call to addScrollLock().
919
+ * Each call to this method will restore one level of scroll lock. If multiple calls to addScrollLock()
920
+ * were done, multiple calls to removeScrollLock() will be required to restore the original scroll state.
921
+ */
922
+ removeScrollLock() {
923
+ if (this._scrollLockSavedOverflowStates.length > 0) {
924
+ document.body.style.overflow = this._scrollLockSavedOverflowStates.pop();
925
+ }
926
+ }
902
927
  /**
903
928
  * Change the application visual appearance so the user perceives that the application is
904
929
  * currently busy. While modal busy state is enabled, no user input is possible neither via
@@ -1022,8 +1047,9 @@ class DialogService extends SingletoneStrictClass {
1022
1047
  * css. By default it is defined as 96vw, which will fit 96% of the viewport on small devices
1023
1048
  * - height: Unset by default. Specify the css value for the dialog height.
1024
1049
  * - maxHeight: Defines the maximum height that the dialog will have. We can specify it in % or vh, just like is done in
1025
- * css. By default it is defined as 96vh, which will fit 96% of the viewport
1026
- * - modal: True (default) if selecting an option is mandatory to close the dialog, false if the dialog can be closed
1050
+ * css. By default it is defined as 96vh, which will fit 96% of the viewport
1051
+ * - scrollLock: (False by default) disables the background scroll to prevent the user from scrolling the document body when the dialog is visible
1052
+ * - modal: (False default) if the dialog can be closed without interaction or true if selecting an option is mandatory to close it
1027
1053
  * by the user clicking outside it
1028
1054
  * - closeOnNavigation: Tells if the dialog should be closed when the user navigates with the browser. By default is true for non modal and false for modal dialogs.
1029
1055
  * - texts: A list with strings containing the dialog texts, sorted by importance. When dialog has a title, this should
@@ -1046,7 +1072,7 @@ class DialogService extends SingletoneStrictClass {
1046
1072
  }
1047
1073
  return new Promise((resolve) => {
1048
1074
  // Set the default values for non specified properties
1049
- properties.modal = properties.modal ?? true;
1075
+ properties.modal = properties.modal ?? false;
1050
1076
  properties.closeOnNavigation = properties.closeOnNavigation ?? !properties.modal;
1051
1077
  properties.texts = properties.texts ?? [];
1052
1078
  properties.options = properties.options ?? [];
@@ -1078,6 +1104,9 @@ class DialogService extends SingletoneStrictClass {
1078
1104
  dialogRefConfig['height'] = properties.height;
1079
1105
  }
1080
1106
  const dialogRef = this.matDialog.open(dialogComponentClass, dialogRefConfig);
1107
+ if (properties.scrollLock) {
1108
+ this.addScrollLock();
1109
+ }
1081
1110
  // Push a new state to handle browser navigation to close the dialog
1082
1111
  if (properties.closeOnNavigation && this._activeCloseableDialogs === 0) {
1083
1112
  history.pushState({ dialogOpen: true }, '');
@@ -1092,6 +1121,9 @@ class DialogService extends SingletoneStrictClass {
1092
1121
  this._activeCloseableDialogs += 1;
1093
1122
  }
1094
1123
  dialogRef.beforeClosed().pipe(take(1)).subscribe((selection) => {
1124
+ if (properties.scrollLock) {
1125
+ this.removeScrollLock();
1126
+ }
1095
1127
  this._activeDialogs = ArrayUtils.removeElement(this._activeDialogs, dialogHash);
1096
1128
  this._activeDialogInstances = ArrayUtils.removeElement(this._activeDialogInstances, dialogRef);
1097
1129
  if (properties.closeOnNavigation) {
@@ -1105,7 +1137,7 @@ class DialogService extends SingletoneStrictClass {
1105
1137
  selection = { index: -1 };
1106
1138
  }
1107
1139
  else if (!NumericUtils.isInteger(selection.index)) {
1108
- throw new Error(`closeDialog() expects index to be an integer`);
1140
+ throw new TypeError(`closeDialog() expects index to be an integer`);
1109
1141
  }
1110
1142
  if (selection.index >= 0 && selection.value === null) {
1111
1143
  selection.value = properties.options[selection.index];
@@ -1271,6 +1303,7 @@ class DialogService extends SingletoneStrictClass {
1271
1303
  * - maxWidth: see addDialog() docs
1272
1304
  * - height: see addDialog() docs
1273
1305
  * - maxHeight: see addDialog() docs
1306
+ * - scrollLock: addDialog() docs
1274
1307
  * - modal: see addDialog() docs
1275
1308
  *
1276
1309
  * @returns A Promise that resolves once the user closes the dialog
@@ -1285,6 +1318,7 @@ class DialogService extends SingletoneStrictClass {
1285
1318
  maxWidth: properties.maxWidth ?? "1200px",
1286
1319
  height: properties.height ?? "98vh",
1287
1320
  maxHeight: properties.maxHeight ?? "3000px",
1321
+ scrollLock: properties.scrollLock ?? false,
1288
1322
  modal: properties.modal ?? false
1289
1323
  });
1290
1324
  }
@@ -1303,6 +1337,7 @@ class DialogService extends SingletoneStrictClass {
1303
1337
  * - maxWidth: see addDialog() docs
1304
1338
  * - height: see addDialog() docs
1305
1339
  * - maxHeight: see addDialog() docs
1340
+ * - scrollLock: addDialog() docs
1306
1341
  * - modal: see addDialog() docs
1307
1342
  *
1308
1343
  * @returns A Promise that resolves once the user closes the dialog
@@ -1317,6 +1352,7 @@ class DialogService extends SingletoneStrictClass {
1317
1352
  maxWidth: properties.maxWidth ?? "1200px",
1318
1353
  height: properties.height ?? "98vh",
1319
1354
  maxHeight: properties.maxHeight ?? "3000px",
1355
+ scrollLock: properties.scrollLock ?? false,
1320
1356
  modal: properties.modal ?? false
1321
1357
  });
1322
1358
  }
@@ -1336,6 +1372,7 @@ class DialogService extends SingletoneStrictClass {
1336
1372
  * - maxWidth: see addDialog() docs
1337
1373
  * - height: see addDialog() docs
1338
1374
  * - maxHeight: see addDialog() docs
1375
+ * - scrollLock: addDialog() docs
1339
1376
  * - modal: see addDialog() docs
1340
1377
  *
1341
1378
  * @returns A Promise that resolves once the user closes the dialog
@@ -1350,6 +1387,7 @@ class DialogService extends SingletoneStrictClass {
1350
1387
  maxWidth: properties.maxWidth ?? "1200px",
1351
1388
  height: properties.height ?? "98vh",
1352
1389
  maxHeight: properties.maxHeight ?? "3000px",
1390
+ scrollLock: properties.scrollLock ?? false,
1353
1391
  modal: properties.modal ?? false
1354
1392
  });
1355
1393
  }
@@ -1364,6 +1402,7 @@ class DialogService extends SingletoneStrictClass {
1364
1402
  * - maxWidth: see addDialog() docs
1365
1403
  * - height: see addDialog() docs
1366
1404
  * - maxHeight: see addDialog() docs
1405
+ * - scrollLock: addDialog() docs
1367
1406
  * - modal: see addDialog() docs
1368
1407
  * - title: The title to show at the top of the dialog
1369
1408
  * - viewContainerRef: MANDATORY! or the component won't render. see addDialog() docs
@@ -1380,6 +1419,7 @@ class DialogService extends SingletoneStrictClass {
1380
1419
  maxWidth: properties.maxWidth ?? "96vw",
1381
1420
  height: properties.height ?? "auto",
1382
1421
  maxHeight: properties.maxHeight ?? "92vw",
1422
+ scrollLock: properties.scrollLock ?? false,
1383
1423
  modal: properties.modal ?? false,
1384
1424
  texts: [properties.title ?? ''],
1385
1425
  viewContainerRef: properties.viewContainerRef
@@ -1400,6 +1440,7 @@ class DialogService extends SingletoneStrictClass {
1400
1440
  * - maxWidth: see addDialog() docs
1401
1441
  * - height: see addDialog() docs
1402
1442
  * - maxHeight: see addDialog() docs
1443
+ * - scrollLock: addDialog() docs
1403
1444
  * - modal: see addDialog() docs
1404
1445
  * - dialogClass: A custom component class to use instead of the default DialogErrorComponent.
1405
1446
  * This custom class must extend DialogErrorComponent
@@ -1418,6 +1459,7 @@ class DialogService extends SingletoneStrictClass {
1418
1459
  maxWidth: properties.maxWidth ?? "500px",
1419
1460
  height: properties.height ?? "auto",
1420
1461
  maxHeight: properties.maxHeight ?? "92vw",
1462
+ scrollLock: properties.scrollLock ?? false,
1421
1463
  modal: properties.modal ?? false,
1422
1464
  texts: texts,
1423
1465
  options: [properties.option]
@@ -1439,6 +1481,7 @@ class DialogService extends SingletoneStrictClass {
1439
1481
  * - maxWidth: see addDialog() docs
1440
1482
  * - height: see addDialog() docs
1441
1483
  * - maxHeight: see addDialog() docs
1484
+ * - scrollLock: addDialog() docs
1442
1485
  * - modal: see addDialog() docs
1443
1486
  * - dialogClass: A custom component class to use instead of the default DialogSingleOptionComponent.
1444
1487
  * This custom class must extend DialogSingleOptionComponent