@magic-xpa/angular 4.1200.0-dev4120.142 → 4.1200.0-dev4120.144

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.
@@ -1101,6 +1101,8 @@ class MagicOverlayContainer extends BaseMagicOverlayContainer {
1101
1101
  originalMouseX = 0;
1102
1102
  originalMouseY = 0;
1103
1103
  isCenteredToWindow = true;
1104
+ static minAllowedWidth = 30;
1105
+ static minAllowedHeight = 30;
1104
1106
  /**
1105
1107
  *
1106
1108
  */
@@ -1223,6 +1225,13 @@ class MagicOverlayContainer extends BaseMagicOverlayContainer {
1223
1225
  this.originalHeight = element.offsetHeight;
1224
1226
  this.originalMouseX = event.clientX;
1225
1227
  this.originalMouseY = event.clientY;
1228
+ // Removes auto margin and set left and top style
1229
+ if (this.isCenteredToWindow) {
1230
+ element.style.left = element.offsetLeft + 'px';
1231
+ element.style.top = element.offsetTop + 'px';
1232
+ element.style.margin = '';
1233
+ this.isCenteredToWindow = false;
1234
+ }
1226
1235
  event.preventDefault();
1227
1236
  event.stopPropagation();
1228
1237
  }
@@ -1236,18 +1245,32 @@ class MagicOverlayContainer extends BaseMagicOverlayContainer {
1236
1245
  if (!this.resizing)
1237
1246
  return;
1238
1247
  const element = this.foregroundElementRef.nativeElement;
1248
+ const parentElement = element.parentNode;
1249
+ const parentWidth = parentElement.offsetWidth;
1250
+ const parentHeight = parentElement.offsetHeight;
1251
+ const rect = element.getBoundingClientRect();
1252
+ const left = rect.left;
1253
+ const top = rect.top;
1254
+ // When the user extends the overlay window to its edge, it becomes hard to grab the border for resizing.
1255
+ // To improve this, 2px are subtracted from maxAllowedWidth and maxAllowedHeight, making it easier to grab the overlay's border for resizing.
1256
+ const maxAllowedWidth = parentWidth - left - 2;
1257
+ const maxAllowedHeight = parentHeight - top - 2;
1258
+ let dx = (event.clientX - this.originalMouseX);
1259
+ let dy = (event.clientY - this.originalMouseY);
1239
1260
  if (this.resizeDirection === 'right' || this.resizeDirection === 'corner') {
1240
- let dx = (event.clientX - this.originalMouseX);
1241
1261
  let newWidth = this.originalWidth + dx;
1242
- if (this.isCenteredToWindow)
1243
- newWidth = this.originalWidth + (2 * dx);
1262
+ if (newWidth > maxAllowedWidth)
1263
+ newWidth = maxAllowedWidth;
1264
+ else if (newWidth < MagicOverlayContainer.minAllowedWidth)
1265
+ newWidth = MagicOverlayContainer.minAllowedWidth;
1244
1266
  element.style.width = `${newWidth}px`;
1245
1267
  }
1246
1268
  if (this.resizeDirection === 'bottom' || this.resizeDirection === 'corner') {
1247
- let dy = (event.clientY - this.originalMouseY);
1248
1269
  let newHeight = this.originalHeight + dy;
1249
- if (this.isCenteredToWindow)
1250
- newHeight = this.originalHeight + (2 * dy);
1270
+ if (newHeight > maxAllowedHeight)
1271
+ newHeight = maxAllowedHeight;
1272
+ else if (newHeight < MagicOverlayContainer.minAllowedHeight)
1273
+ newHeight = MagicOverlayContainer.minAllowedHeight;
1251
1274
  element.style.height = `${newHeight}px`;
1252
1275
  }
1253
1276
  }