@opengeoweb/shared 4.4.0 → 4.6.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.
package/index.umd.js CHANGED
@@ -483,39 +483,58 @@
483
483
  };
484
484
  };
485
485
 
486
- var useMakeSureContainerStaysInsideWindow = function useMakeSureContainerStaysInsideWindow(nodeRef, position, setPosition) {
487
- var onResizeWindow = React__default["default"].useCallback(function (event) {
488
- if (!nodeRef.current) return;
489
- var bbox = nodeRef.current.firstChild.getBoundingClientRect();
490
- var windowTarget = event.currentTarget;
491
- if (!windowTarget) return;
492
- var innerHeight = windowTarget.innerHeight,
493
- innerWidth = windowTarget.innerWidth;
494
- var isHorizontallyLarger = bbox.width > innerWidth;
495
- var isVerticallyLarger = bbox.height > innerHeight; // left screen
496
-
497
- if (bbox.x < 0 || isHorizontallyLarger) {
498
- setPosition(__assign(__assign({}, position), {
499
- x: position.x - bbox.x
500
- }));
501
- } // right screen
502
- else if (bbox.x + bbox.width >= innerWidth) {
503
- var diffX = innerWidth - bbox.x - bbox.width;
486
+ var adjustPosition = function adjustPosition(bbox, containingView, position, setPosition) {
487
+ var isHorizontallyLarger = bbox.width > containingView.width;
488
+ var isVerticallyLarger = bbox.height > containingView.height; // Check corner cases first
489
+ // bottom left
490
+
491
+ if (bbox.x < containingView.x && bbox.bottom >= containingView.bottom) {
492
+ var diffX = containingView.x - bbox.x;
493
+ var diffY = containingView.bottom - bbox.bottom;
494
+ setPosition({
495
+ x: position.x + diffX,
496
+ y: position.y + diffY
497
+ });
498
+ } // bottom right
499
+ else if (bbox.right >= containingView.right && bbox.bottom >= containingView.bottom) {
500
+ var diffX = containingView.right - bbox.right;
501
+ var diffY = containingView.bottom - bbox.bottom;
502
+ setPosition({
503
+ x: position.x + diffX,
504
+ y: position.y + diffY
505
+ });
506
+ } // left screen
507
+ else if (bbox.x < containingView.x || isHorizontallyLarger) {
508
+ var diffX = containingView.x - bbox.x;
504
509
  setPosition(__assign(__assign({}, position), {
505
510
  x: position.x + diffX
506
511
  }));
507
- } // top screen
508
- else if (bbox.y < 0 || isVerticallyLarger) {
512
+ } // right screen
513
+ else if (bbox.right >= containingView.right) {
514
+ var diffX = containingView.right - bbox.right;
509
515
  setPosition(__assign(__assign({}, position), {
510
- y: position.y - bbox.y
516
+ x: position.x + diffX
511
517
  }));
512
- } // bottom screen
513
- else if (bbox.y + bbox.height >= innerHeight) {
514
- var diffY = innerHeight - bbox.y - bbox.height;
518
+ } // top screen
519
+ else if (bbox.y < containingView.y || isVerticallyLarger) {
520
+ var diffY = containingView.y - bbox.y;
515
521
  setPosition(__assign(__assign({}, position), {
516
522
  y: position.y + diffY
517
523
  }));
518
- }
524
+ } // bottom screen
525
+ else if (bbox.bottom >= containingView.bottom) {
526
+ var diffY = containingView.bottom - bbox.bottom;
527
+ setPosition(__assign(__assign({}, position), {
528
+ y: position.y + diffY
529
+ }));
530
+ }
531
+ };
532
+ var useMakeSureContainerStaysInsideWindow = function useMakeSureContainerStaysInsideWindow(nodeRef, position, setPosition) {
533
+ var onResizeWindow = React__default["default"].useCallback(function () {
534
+ if (!nodeRef.current) return;
535
+ var bbox = nodeRef.current.firstChild.getBoundingClientRect();
536
+ var containingView = nodeRef.current.parentElement.getBoundingClientRect();
537
+ adjustPosition(bbox, containingView, position, setPosition);
519
538
  }, [nodeRef, position, setPosition]);
520
539
  React__default["default"].useEffect(function () {
521
540
  var throttledResize = lodash.throttle(onResizeWindow, 100);
@@ -935,29 +954,26 @@
935
954
  * Copyright 2021 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
936
955
  * Copyright 2021 - Finnish Meteorological Institute (FMI)
937
956
  * */
957
+ var isDraggingClassName = 'is-dragging';
938
958
 
939
959
  var ResizeComponent = function ResizeComponent(_a) {
940
- var _b = _a.startPosition,
941
- startPosition = _b === void 0 ? {
942
- left: undefined,
943
- right: undefined,
944
- top: undefined
945
- } : _b,
946
- children = _a.children,
947
- _c = _a.onResizeStart,
948
- onResizeStart = _c === void 0 ? function () {} : _c,
960
+ var children = _a.children,
961
+ _b = _a.onResizeStart,
962
+ onResizeStart = _b === void 0 ? function () {} : _b,
963
+ _c = _a.onResizeStop,
964
+ onResizeStop = _c === void 0 ? function () {} : _c,
949
965
  size = _a.size,
950
966
  setSize = _a.setSize,
951
967
  _d = _a.minHeight,
952
968
  minHeight = _d === void 0 ? 50 : _d,
953
969
  _e = _a.minWidth,
954
970
  minWidth = _e === void 0 ? 50 : _e,
955
- props = __rest(_a, ["startPosition", "children", "onResizeStart", "size", "setSize", "minHeight", "minWidth"]);
971
+ props = __rest(_a, ["children", "onResizeStart", "onResizeStop", "size", "setSize", "minHeight", "minWidth"]);
956
972
 
957
973
  var theme$1 = material.useTheme();
958
- var isRightAligned = startPosition && startPosition.right !== null && startPosition.right !== undefined;
959
974
  var onStartResize = React__default["default"].useCallback(function (event, _direction, node) {
960
975
  event.stopPropagation();
976
+ node.classList.add(isDraggingClassName);
961
977
 
962
978
  var _a = node.getBoundingClientRect(),
963
979
  width = _a.width,
@@ -972,32 +988,42 @@
972
988
  node.style.height = height + "px";
973
989
  onResizeStart();
974
990
  }, [onResizeStart, setSize]);
975
- var onResizeStop = React__default["default"].useCallback(function (_event, _direction, _ref, delta) {
991
+ var onStopResize = React__default["default"].useCallback(function (event, direction, node, delta) {
992
+ node.classList.remove(isDraggingClassName);
976
993
  var width = parseInt(size.width, 10) + delta.width;
977
994
  var height = parseInt(size.height, 10) + delta.height;
978
995
  setSize({
979
996
  width: width,
980
997
  height: height
981
998
  });
982
- }, [setSize, size]);
999
+ onResizeStop(event, direction, node, delta);
1000
+ }, [setSize, onResizeStop, size]);
983
1001
  return /*#__PURE__*/React__default["default"].createElement(reResizable.Resizable // TODO: implement bounds https://gitlab.com/opengeoweb/opengeoweb/-/issues/1035
984
1002
  , __assign({
985
1003
  // TODO: implement bounds https://gitlab.com/opengeoweb/opengeoweb/-/issues/1035
986
1004
  minHeight: minHeight,
987
1005
  minWidth: minWidth,
988
1006
  size: size,
989
- onResizeStop: onResizeStop,
1007
+ onResizeStop: onStopResize,
990
1008
  handleComponent: {
991
1009
  bottomRight: /*#__PURE__*/React__default["default"].createElement(theme.Resize, {
992
1010
  style: {
993
1011
  fill: "" + theme$1.palette.geowebColors.buttons.flat["default"].color
994
- }
1012
+ },
1013
+ sx: {
1014
+ display: 'none'
1015
+ },
1016
+ className: "resizableHandle"
995
1017
  }),
996
1018
  bottomLeft: /*#__PURE__*/React__default["default"].createElement(theme.Resize, {
997
1019
  isRightAligned: true,
998
1020
  style: {
999
1021
  fill: "" + theme$1.palette.geowebColors.buttons.flat["default"].color
1000
- }
1022
+ },
1023
+ sx: {
1024
+ display: 'none'
1025
+ },
1026
+ className: "resizableHandle"
1001
1027
  })
1002
1028
  },
1003
1029
  enable: {
@@ -1006,8 +1032,8 @@
1006
1032
  bottom: false,
1007
1033
  left: false,
1008
1034
  topRight: false,
1009
- bottomRight: !isRightAligned,
1010
- bottomLeft: isRightAligned,
1035
+ bottomRight: true,
1036
+ bottomLeft: true,
1011
1037
  topLeft: false
1012
1038
  },
1013
1039
  onResizeStart: onStartResize
@@ -1258,6 +1284,55 @@
1258
1284
  });
1259
1285
  };
1260
1286
 
1287
+ /* *
1288
+ * Licensed under the Apache License, Version 2.0 (the "License");
1289
+ * you may not use this file except in compliance with the License.
1290
+ * You may obtain a copy of the License at
1291
+ *
1292
+ * http://www.apache.org/licenses/LICENSE-2.0
1293
+ *
1294
+ * Unless required by applicable law or agreed to in writing, software
1295
+ * distributed under the License is distributed on an "AS IS" BASIS,
1296
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1297
+ * See the License for the specific language governing permissions and
1298
+ * limitations under the License.
1299
+ *
1300
+ * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
1301
+ * Copyright 2022 - Finnish Meteorological Institute (FMI)
1302
+ * */
1303
+ var defaultDelay = 1000;
1304
+ var useControlledTooltip = function useControlledTooltip() {
1305
+ var _a = __read(React__namespace.useState(false), 2),
1306
+ tooltipOpen = _a[0],
1307
+ setTooltipOpen = _a[1];
1308
+
1309
+ var _b = __read(React__namespace.useState(false), 2),
1310
+ delayedTooltip = _b[0],
1311
+ setDelayedTooltip = _b[1];
1312
+
1313
+ React__namespace.useEffect(function () {
1314
+ if (tooltipOpen === true) {
1315
+ var timer_1 = setTimeout(function () {
1316
+ return setDelayedTooltip(true);
1317
+ }, defaultDelay);
1318
+ return function () {
1319
+ clearTimeout(timer_1);
1320
+ };
1321
+ }
1322
+
1323
+ setDelayedTooltip(false);
1324
+ return function () {};
1325
+ }, [tooltipOpen]);
1326
+ return [delayedTooltip, setTooltipOpen];
1327
+ };
1328
+ var CustomTooltip = function CustomTooltip(props) {
1329
+ return /*#__PURE__*/React__namespace.createElement(material.Tooltip, __assign({}, props, {
1330
+ enterDelay: defaultDelay,
1331
+ enterNextDelay: defaultDelay,
1332
+ disableInteractive: true
1333
+ }));
1334
+ };
1335
+
1261
1336
  /* *
1262
1337
  * Licensed under the Apache License, Version 2.0 (the "License");
1263
1338
  * you may not use this file except in compliance with the License.
@@ -1299,7 +1374,8 @@
1299
1374
  return {
1300
1375
  fontSize: 20,
1301
1376
  fontWeight: 400,
1302
- padding: '8px'
1377
+ padding: '4px 8px',
1378
+ height: 40
1303
1379
  };
1304
1380
  }
1305
1381
 
@@ -1336,31 +1412,37 @@
1336
1412
  isDraggable = _c === void 0 ? false : _c,
1337
1413
  _d = _a.className,
1338
1414
  className = _d === void 0 ? '' : _d,
1339
- _e = _a.leftComponent,
1340
- leftComponent = _e === void 0 ? null : _e;
1415
+ _e = _a.leftHeaderComponent,
1416
+ leftHeaderComponent = _e === void 0 ? null : _e,
1417
+ _f = _a.rightHeaderComponent,
1418
+ rightHeaderComponent = _f === void 0 ? null : _f;
1341
1419
  var styles = getStyle(size);
1342
- var columnSizeIcon = leftComponent ? 3 : 1;
1343
- var columnSizeTitle = leftComponent ? 6 : 10;
1420
+ var columnSizeIcon = leftHeaderComponent || rightHeaderComponent ? 4 : 1;
1421
+ var columnSizeTitle = leftHeaderComponent || rightHeaderComponent ? 4 : 10;
1344
1422
  return /*#__PURE__*/React__default["default"].createElement(material.Box, {
1345
1423
  component: "header",
1346
1424
  className: className,
1347
1425
  sx: {
1348
1426
  boxShadow: 1,
1349
1427
  backgroundColor: 'geowebColors.background.surface',
1350
- padding: styles.padding,
1351
1428
  zIndex: 2,
1352
1429
  cursor: isDraggable ? 'move' : null
1353
1430
  }
1354
1431
  }, /*#__PURE__*/React__default["default"].createElement(material.Grid, {
1355
1432
  container: true,
1356
- alignItems: "center"
1433
+ alignItems: "center",
1434
+ sx: {
1435
+ padding: styles.padding,
1436
+ height: styles.height
1437
+ }
1357
1438
  }, /*#__PURE__*/React__default["default"].createElement(material.Grid, {
1439
+ className: "header-left",
1358
1440
  item: true,
1359
1441
  xs: columnSizeIcon,
1360
1442
  sx: {
1361
1443
  paddingRight: 1
1362
1444
  }
1363
- }, isDraggable && size !== 'xxs' && !leftComponent && /*#__PURE__*/React__default["default"].createElement(material.Grid, {
1445
+ }, isDraggable && size !== 'xxs' && !leftHeaderComponent && /*#__PURE__*/React__default["default"].createElement(material.Grid, {
1364
1446
  container: true,
1365
1447
  justifyContent: "flex-start"
1366
1448
  }, /*#__PURE__*/React__default["default"].createElement(material.IconButton, {
@@ -1370,7 +1452,8 @@
1370
1452
  sx: __assign(__assign({}, iconStyle), {
1371
1453
  pointerEvents: 'none'
1372
1454
  })
1373
- }, /*#__PURE__*/React__default["default"].createElement(theme.DragHandle, null))), leftComponent && leftComponent), /*#__PURE__*/React__default["default"].createElement(material.Grid, {
1455
+ }, /*#__PURE__*/React__default["default"].createElement(theme.DragHandle, null))), leftHeaderComponent && leftHeaderComponent), /*#__PURE__*/React__default["default"].createElement(material.Grid, {
1456
+ className: "header-title",
1374
1457
  item: true,
1375
1458
  xs: columnSizeTitle
1376
1459
  }, /*#__PURE__*/React__default["default"].createElement(material.Grid, {
@@ -1394,11 +1477,12 @@
1394
1477
  height: 12
1395
1478
  })
1396
1479
  }, /*#__PURE__*/React__default["default"].createElement(theme.DragHandle, null)))), /*#__PURE__*/React__default["default"].createElement(material.Grid, {
1480
+ className: "header-right",
1397
1481
  item: true,
1398
1482
  xs: columnSizeIcon,
1399
1483
  container: true,
1400
1484
  justifyContent: "flex-end"
1401
- }, onClose && /*#__PURE__*/React__default["default"].createElement(material.Tooltip, {
1485
+ }, rightHeaderComponent && rightHeaderComponent, onClose && /*#__PURE__*/React__default["default"].createElement(CustomTooltip, {
1402
1486
  title: "Close",
1403
1487
  placement: "bottom",
1404
1488
  sx: {
@@ -1466,9 +1550,11 @@
1466
1550
  _h = _a.headerClassName,
1467
1551
  // elevation_06
1468
1552
  headerClassName = _h === void 0 ? '' : _h,
1469
- _j = _a.leftComponent,
1470
- leftComponent = _j === void 0 ? null : _j,
1471
- props = __rest(_a, ["title", "size", "children", "onClose", "isResizable", "isDraggable", "maxHeight", "elevation", "headerClassName", "leftComponent"]);
1553
+ _j = _a.leftHeaderComponent,
1554
+ leftHeaderComponent = _j === void 0 ? null : _j,
1555
+ _k = _a.rightHeaderComponent,
1556
+ rightHeaderComponent = _k === void 0 ? null : _k,
1557
+ props = __rest(_a, ["title", "size", "children", "onClose", "isResizable", "isDraggable", "maxHeight", "elevation", "headerClassName", "leftHeaderComponent", "rightHeaderComponent"]);
1472
1558
 
1473
1559
  return /*#__PURE__*/React__default["default"].createElement(material.Paper, __assign({
1474
1560
  elevation: elevation,
@@ -1479,7 +1565,8 @@
1479
1565
  isDraggable: isDraggable,
1480
1566
  onClose: onClose,
1481
1567
  className: headerClassName,
1482
- leftComponent: leftComponent
1568
+ leftHeaderComponent: leftHeaderComponent,
1569
+ rightHeaderComponent: rightHeaderComponent
1483
1570
  })), /*#__PURE__*/React__default["default"].createElement(material.Box, {
1484
1571
  sx: styles$2.content,
1485
1572
  style: {
@@ -1488,6 +1575,136 @@
1488
1575
  }, children), isResizable && /*#__PURE__*/React__default["default"].createElement(ToolFooter, null));
1489
1576
  };
1490
1577
 
1578
+ var getRightPositionAndSize = function getRightPositionAndSize(_a) {
1579
+ var currentX = _a.currentX,
1580
+ currentWidth = _a.currentWidth,
1581
+ newWidth = _a.newWidth,
1582
+ maxWidth = _a.maxWidth,
1583
+ position = _a.position,
1584
+ startSize = _a.startSize;
1585
+
1586
+ var newSize = __assign(__assign({}, startSize), {
1587
+ width: newWidth
1588
+ }); // if new size is bigger than the window
1589
+
1590
+
1591
+ if (newWidth >= maxWidth) {
1592
+ return {
1593
+ size: __assign(__assign({}, newSize), {
1594
+ width: maxWidth
1595
+ }),
1596
+ position: __assign(__assign({}, position), {
1597
+ x: position.x + (maxWidth - (currentX + currentWidth))
1598
+ })
1599
+ };
1600
+ } // if new size overlaps left side of screen
1601
+
1602
+
1603
+ var newStartX = currentX - (newWidth - currentWidth);
1604
+
1605
+ if (newStartX <= 0) {
1606
+ return {
1607
+ size: newSize,
1608
+ position: __assign(__assign({}, position), {
1609
+ x: position.x - newStartX
1610
+ })
1611
+ };
1612
+ } // there is room to grow
1613
+
1614
+
1615
+ return {
1616
+ size: newSize,
1617
+ position: position
1618
+ };
1619
+ };
1620
+ var getLeftPositionAndSize = function getLeftPositionAndSize(_a) {
1621
+ var currentX = _a.currentX,
1622
+ newWidth = _a.newWidth,
1623
+ maxWidth = _a.maxWidth,
1624
+ position = _a.position,
1625
+ startSize = _a.startSize;
1626
+
1627
+ var newSize = __assign(__assign({}, startSize), {
1628
+ width: newWidth
1629
+ }); // if new size is bigger than the window
1630
+
1631
+
1632
+ if (newWidth >= maxWidth) {
1633
+ return {
1634
+ size: __assign(__assign({}, newSize), {
1635
+ width: maxWidth
1636
+ }),
1637
+ position: __assign(__assign({}, position), {
1638
+ x: position.x - currentX
1639
+ })
1640
+ };
1641
+ } // if new size overlaps right side of screen
1642
+
1643
+
1644
+ var newEndX = currentX + newWidth;
1645
+
1646
+ if (newEndX >= maxWidth) {
1647
+ return {
1648
+ size: newSize,
1649
+ position: __assign(__assign({}, position), {
1650
+ x: position.x + (maxWidth - newEndX)
1651
+ })
1652
+ };
1653
+ } // there is room to grow
1654
+
1655
+
1656
+ return {
1657
+ size: newSize,
1658
+ position: position
1659
+ };
1660
+ };
1661
+ var useHandleSizeFromOutsideComponent = function useHandleSizeFromOutsideComponent(_a) {
1662
+ var nodeRef = _a.nodeRef,
1663
+ startSize = _a.startSize,
1664
+ bounds = _a.bounds,
1665
+ isRightAligned = _a.isRightAligned,
1666
+ size = _a.size,
1667
+ setSize = _a.setSize,
1668
+ position = _a.position,
1669
+ setPosition = _a.setPosition;
1670
+ React__default["default"].useEffect(function () {
1671
+ var _a, _b; // update size when startSize has changed outside the component
1672
+
1673
+
1674
+ if (startSize !== size) {
1675
+ var node = (_a = nodeRef.current) === null || _a === void 0 ? void 0 : _a.firstChild;
1676
+ var boundsNode = bounds === 'parent' ? (_b = nodeRef.current) === null || _b === void 0 ? void 0 : _b.parentNode : document.querySelector(bounds);
1677
+ var maxWidth = boundsNode.getBoundingClientRect().width;
1678
+ var newWidth = Number(startSize.width);
1679
+
1680
+ var _c = node.getBoundingClientRect(),
1681
+ currentX = _c.x,
1682
+ currentWidth = _c.width;
1683
+
1684
+ var _d = isRightAligned ? getRightPositionAndSize({
1685
+ currentX: currentX,
1686
+ currentWidth: currentWidth,
1687
+ newWidth: newWidth,
1688
+ maxWidth: maxWidth,
1689
+ position: position,
1690
+ startSize: startSize
1691
+ }) : getLeftPositionAndSize({
1692
+ currentX: currentX,
1693
+ newWidth: newWidth,
1694
+ maxWidth: maxWidth,
1695
+ position: position,
1696
+ startSize: startSize
1697
+ }),
1698
+ newPosition = _d.position,
1699
+ newSize = _d.size;
1700
+
1701
+ setSize(newSize);
1702
+ setPosition(newPosition);
1703
+ } // eslint-disable-next-line react-hooks/exhaustive-deps
1704
+
1705
+ }, [startSize.width, startSize.height]);
1706
+ };
1707
+
1491
1708
  /* *
1492
1709
  * Licensed under the Apache License, Version 2.0 (the "License");
1493
1710
  * you may not use this file except in compliance with the License.
@@ -1547,42 +1764,60 @@
1547
1764
  onChangeSize = _j === void 0 ? function () {} : _j,
1548
1765
  _k = _a.onMouseDown,
1549
1766
  onMouseDown = _k === void 0 ? function () {} : _k,
1550
- _l = _a.order,
1551
- order = _l === void 0 ? 1 : _l,
1552
- _m = _a.source,
1553
- source = _m === void 0 ? 'app' : _m,
1554
- _o = _a.leftComponent,
1555
- leftComponent = _o === void 0 ? null : _o,
1556
- props = __rest(_a, ["title", "bounds", "headerSize", "startSize", "startPosition", "children", "isOpen", "onClose", "initialMaxHeight", "onChangeSize", "onMouseDown", "order", "source", "leftComponent"]);
1767
+ _l = _a.onResizeStop,
1768
+ onResizeStop = _l === void 0 ? function () {} : _l,
1769
+ _m = _a.onDragEnd,
1770
+ onDragEnd = _m === void 0 ? function () {} : _m,
1771
+ _o = _a.order,
1772
+ order = _o === void 0 ? 1 : _o,
1773
+ _p = _a.source,
1774
+ source = _p === void 0 ? 'app' : _p,
1775
+ _q = _a.leftHeaderComponent,
1776
+ leftHeaderComponent = _q === void 0 ? null : _q,
1777
+ _r = _a.rightHeaderComponent,
1778
+ rightHeaderComponent = _r === void 0 ? null : _r,
1779
+ _s = _a.hasElevation,
1780
+ hasElevation = _s === void 0 ? true : _s,
1781
+ className = _a.className,
1782
+ _t = _a.sx,
1783
+ sx = _t === void 0 ? {} : _t,
1784
+ props = __rest(_a, ["title", "bounds", "headerSize", "startSize", "startPosition", "children", "isOpen", "onClose", "initialMaxHeight", "onChangeSize", "onMouseDown", "onResizeStop", "onDragEnd", "order", "source", "leftHeaderComponent", "rightHeaderComponent", "hasElevation", "className", "sx"]);
1557
1785
 
1558
1786
  var zIndex = (source === 'app' ? BASE_Z_INDEX : 1000) + order;
1559
- var elevation = BASE_ELEVATION + order;
1787
+ var elevation = hasElevation ? BASE_ELEVATION + order : 0;
1560
1788
  var nodeRef = React__default["default"].useRef(null);
1561
1789
 
1562
- var _p = __read(React__default["default"].useState({
1790
+ var _u = __read(React__default["default"].useState({
1563
1791
  x: 0,
1564
1792
  y: 0
1565
1793
  }), 2),
1566
- position = _p[0],
1567
- setPosition = _p[1];
1794
+ position = _u[0],
1795
+ setPosition = _u[1];
1568
1796
 
1569
- var _q = __read(React__default["default"].useState(startSize), 2),
1570
- size = _q[0],
1571
- setSize = _q[1];
1797
+ var _v = __read(React__default["default"].useState(startSize), 2),
1798
+ size = _v[0],
1799
+ setSize = _v[1];
1572
1800
 
1801
+ var isRightAligned = startPosition && startPosition.right !== null && startPosition.right !== undefined;
1573
1802
  var onStopDrag = React__default["default"].useCallback(function (_event, position) {
1574
1803
  setPosition(position);
1575
- }, [setPosition]);
1804
+ onDragEnd(position, size);
1805
+ }, [setPosition, onDragEnd, size]);
1576
1806
 
1577
- var _r = __read(React__default["default"].useState(defaultInitialMaxHeight), 2),
1578
- initialMaxHeight = _r[0],
1579
- setInitialMaxHeight = _r[1];
1807
+ var _w = __read(React__default["default"].useState(defaultInitialMaxHeight), 2),
1808
+ initialMaxHeight = _w[0],
1809
+ setInitialMaxHeight = _w[1];
1810
+
1811
+ var _x = __read(React__default["default"].useState(0), 2),
1812
+ initialDragPositionX = _x[0],
1813
+ setInitialDragPositionX = _x[1];
1580
1814
 
1581
1815
  var onStartResize = function onStartResize() {
1582
1816
  setInitialMaxHeight('initial');
1817
+ setInitialDragPositionX(position.x);
1583
1818
  };
1584
1819
 
1585
- var onResize = React__default["default"].useCallback(function (_event, _handle, node) {
1820
+ var onResize = React__default["default"].useCallback(function (_event, _handle, node, delta) {
1586
1821
  var _a = node.getBoundingClientRect(),
1587
1822
  width = _a.width,
1588
1823
  height = _a.height;
@@ -1590,11 +1825,48 @@
1590
1825
  onChangeSize({
1591
1826
  width: width,
1592
1827
  height: height
1593
- });
1594
- }, [onChangeSize]);
1828
+ }); // If dragging the same side as alignment, adjust position
1829
+
1830
+ if (isRightAligned && _handle === 'bottomRight') {
1831
+ var newX = initialDragPositionX + delta.width; // eslint-disable-next-line no-param-reassign
1832
+
1833
+ node.parentNode.style.transform = "translate(" + newX + "px, " + position.y + "px)";
1834
+ } else if (!isRightAligned && _handle === 'bottomLeft') {
1835
+ var newX = initialDragPositionX - delta.width; // eslint-disable-next-line no-param-reassign
1836
+
1837
+ node.parentNode.style.transform = "translate(" + newX + "px, " + position.y + "px)";
1838
+ }
1839
+ }, [onChangeSize, initialDragPositionX, isRightAligned, position]);
1840
+
1841
+ var onStopResize = function onStopResize(_event, direction, node, delta) {
1842
+ if (isRightAligned && direction === 'bottomRight') {
1843
+ setPosition({
1844
+ x: initialDragPositionX + delta.width,
1845
+ y: position.y
1846
+ });
1847
+ } else if (!isRightAligned && direction === 'bottomLeft') {
1848
+ setPosition({
1849
+ x: initialDragPositionX - delta.width,
1850
+ y: position.y
1851
+ });
1852
+ }
1853
+
1854
+ onResizeStop(_event, direction, node, delta);
1855
+ };
1856
+
1595
1857
  useMakeSureContainerStaysInsideWindow(nodeRef, position, setPosition);
1858
+ useHandleSizeFromOutsideComponent({
1859
+ nodeRef: nodeRef,
1860
+ startSize: startSize,
1861
+ bounds: bounds,
1862
+ isRightAligned: isRightAligned,
1863
+ size: size,
1864
+ setSize: setSize,
1865
+ position: position,
1866
+ setPosition: setPosition
1867
+ });
1596
1868
  var toolcontainerId = React__default["default"].useRef(Date.now().toString()).current;
1597
- var headerClassName = "header-" + toolcontainerId;
1869
+ var headerClassName = "header-" + (className || toolcontainerId);
1598
1870
  return isOpen ? /*#__PURE__*/React__default["default"].createElement(DraggableComponent$1, {
1599
1871
  nodeRef: nodeRef,
1600
1872
  bounds: bounds,
@@ -1602,18 +1874,23 @@
1602
1874
  onStop: onStopDrag,
1603
1875
  handle: "." + headerClassName,
1604
1876
  onMouseDown: onMouseDown
1605
- }, /*#__PURE__*/React__default["default"].createElement("div", {
1606
- style: __assign({
1877
+ }, /*#__PURE__*/React__default["default"].createElement(material.Box, {
1878
+ sx: __assign(__assign(__assign({
1607
1879
  position: 'absolute',
1608
1880
  pointerEvents: 'all',
1609
1881
  zIndex: zIndex
1610
- }, startPosition),
1611
- ref: nodeRef
1882
+ }, startPosition), sx), {
1883
+ '&:hover .resizableHandle': {
1884
+ display: 'inline'
1885
+ }
1886
+ }),
1887
+ ref: nodeRef,
1888
+ className: "toolContainerDraggable"
1612
1889
  }, /*#__PURE__*/React__default["default"].createElement(ResizeComponent, __assign({}, props, {
1613
- startPosition: startPosition,
1614
1890
  size: size,
1615
1891
  setSize: setSize,
1616
1892
  onResizeStart: onStartResize,
1893
+ onResizeStop: onStopResize,
1617
1894
  onResize: onResize
1618
1895
  }), /*#__PURE__*/React__default["default"].createElement(ToolContainer, {
1619
1896
  maxHeight: initialMaxHeight,
@@ -1624,7 +1901,9 @@
1624
1901
  isResizable: true,
1625
1902
  elevation: elevation,
1626
1903
  headerClassName: headerClassName,
1627
- leftComponent: leftComponent
1904
+ leftHeaderComponent: leftHeaderComponent,
1905
+ rightHeaderComponent: rightHeaderComponent,
1906
+ className: className
1628
1907
  }, children)))) : null;
1629
1908
  };
1630
1909
 
@@ -2296,7 +2575,7 @@
2296
2575
  setAnchorEl(document.getElementById(buttonTestId));
2297
2576
  }
2298
2577
  }, [isDefaultOpen, buttonTestId]);
2299
- return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, /*#__PURE__*/React__namespace.createElement(material.Tooltip, {
2578
+ return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, /*#__PURE__*/React__namespace.createElement(CustomTooltip, {
2300
2579
  placement: "top",
2301
2580
  title: tooltipTitle
2302
2581
  }, /*#__PURE__*/React__namespace.createElement(ToolButton, {
@@ -2359,7 +2638,8 @@
2359
2638
  height: '24px',
2360
2639
  width: '24px',
2361
2640
  borderRadius: '5px',
2362
- marginTop: '4px',
2641
+ marginTop: 'auto',
2642
+ marginBottom: 'auto',
2363
2643
  color: function color() {
2364
2644
  if (!isEnabled) {
2365
2645
  return 'geowebColors.buttons.flat.disabled.color';
@@ -2407,7 +2687,8 @@
2407
2687
  _f = _a.isAccessible,
2408
2688
  isAccessible = _f === void 0 ? false : _f,
2409
2689
  sx = _a.sx,
2410
- props = __rest(_a, ["tooltipTitle", "onClick", "isActive", "isEnabled", "icon", "testId", "isAccessible", "sx"]);
2690
+ children = _a.children,
2691
+ props = __rest(_a, ["tooltipTitle", "onClick", "isActive", "isEnabled", "icon", "testId", "isAccessible", "sx", "children"]);
2411
2692
 
2412
2693
  var buttonStyles = makeButtonStyles(isActive, isEnabled, isAccessible);
2413
2694
 
@@ -2415,13 +2696,13 @@
2415
2696
  onClick(event);
2416
2697
  };
2417
2698
 
2418
- return /*#__PURE__*/React__namespace.createElement(material.Tooltip, {
2699
+ return /*#__PURE__*/React__namespace.createElement(CustomTooltip, {
2419
2700
  title: tooltipTitle,
2420
2701
  placement: "top",
2421
2702
  sx: {
2422
2703
  pointerEvents: 'none'
2423
2704
  }
2424
- }, /*#__PURE__*/React__namespace.createElement(material.IconButton, __assign({
2705
+ }, children || /*#__PURE__*/React__namespace.createElement(material.IconButton, __assign({
2425
2706
  size: "small",
2426
2707
  onClick: handleClick,
2427
2708
  "data-testid": testId,
@@ -2451,13 +2732,27 @@
2451
2732
  onClickDelete = _a.onClickDelete,
2452
2733
  _b = _a.isEnabled,
2453
2734
  isEnabled = _b === void 0 ? true : _b;
2454
- return /*#__PURE__*/React__namespace.createElement(ManagerButton, {
2735
+ return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, /*#__PURE__*/React__namespace.createElement(ManagerButton, {
2736
+ tooltipTitle: tooltipTitle,
2737
+ onClick: onClickDelete,
2738
+ testId: "deleteButtonMedium",
2739
+ isEnabled: isEnabled,
2740
+ icon: /*#__PURE__*/React__namespace.createElement(theme.Delete, null)
2741
+ }, /*#__PURE__*/React__namespace.createElement(material.Button, {
2742
+ className: "deleteBtnMedium",
2743
+ variant: "tertiary",
2744
+ onClick: onClickDelete,
2745
+ startIcon: /*#__PURE__*/React__namespace.createElement(theme.Delete, null),
2746
+ sx: {
2747
+ display: 'none'
2748
+ }
2749
+ }, "Delete")), /*#__PURE__*/React__namespace.createElement(ManagerButton, {
2455
2750
  tooltipTitle: tooltipTitle,
2456
2751
  onClick: onClickDelete,
2457
2752
  icon: /*#__PURE__*/React__namespace.createElement(theme.Delete, null),
2458
2753
  testId: "deleteButton",
2459
2754
  isEnabled: isEnabled
2460
- });
2755
+ }));
2461
2756
  };
2462
2757
 
2463
2758
  /* *
@@ -2479,9 +2774,13 @@
2479
2774
  var EnableButton = function EnableButton(_a) {
2480
2775
  var isEnabled = _a.isEnabled,
2481
2776
  title = _a.title,
2482
- onChangeEnableLayer = _a.onChangeEnableLayer;
2777
+ onChangeEnableLayer = _a.onChangeEnableLayer,
2778
+ className = _a.className,
2779
+ _b = _a.id,
2780
+ id = _b === void 0 ? 'enableButton' : _b;
2483
2781
 
2484
- var onClick = function onClick() {
2782
+ var onClick = function onClick(event) {
2783
+ event.stopPropagation();
2485
2784
  onChangeEnableLayer(!isEnabled);
2486
2785
  };
2487
2786
 
@@ -2509,8 +2808,9 @@
2509
2808
  disableFocusRipple: true,
2510
2809
  tabIndex: -1
2511
2810
  }),
2512
- testId: "enableButton",
2513
- isEnabled: isEnabled
2811
+ testId: id,
2812
+ isEnabled: isEnabled,
2813
+ className: className
2514
2814
  });
2515
2815
  };
2516
2816
 
@@ -2549,20 +2849,15 @@
2549
2849
  '& .MuiOutlinedInput-notchedOutline': {
2550
2850
  borderColor: 'transparent!important'
2551
2851
  },
2552
- '&:hover .MuiSelect-select': {
2553
- outline: function outline(theme) {
2554
- return theme.palette.geowebColors.buttons.focusDefault.outline;
2555
- }
2852
+ '&:hover': {
2853
+ backgroundColor: 'geowebColors.buttons.tool.mouseOver.fill',
2854
+ borderRadius: 0
2556
2855
  },
2557
2856
  '&.Mui-focused .MuiSelect-select': {
2558
2857
  outline: function outline(theme) {
2559
2858
  return theme.palette.geowebColors.buttons.focusDefault.outline;
2560
- }
2561
- },
2562
- '&:focus&.MuiButton-root': {
2563
- outline: function outline(theme) {
2564
- return theme.palette.geowebColors.buttons.focusDefault.outline;
2565
- }
2859
+ },
2860
+ borderRadius: 0
2566
2861
  },
2567
2862
  '& .MuiSvgIcon-root': {
2568
2863
  transition: 'none',
@@ -2571,28 +2866,31 @@
2571
2866
  }
2572
2867
  },
2573
2868
  '&>div': {
2574
- paddingLeft: 1
2869
+ paddingLeft: '8px!important'
2575
2870
  }
2576
2871
  }, hasBackgroundColor && backgroundColor);
2577
2872
  };
2578
2873
  var backgroundColor = {
2579
2874
  '&:hover .MuiSelect-select': {
2875
+ backgroundColor: 'geowebColors.buttons.tool.mouseOver.fill',
2876
+ borderRadius: 0
2877
+ },
2878
+ '&.Mui-focused .MuiSelect-select': {
2580
2879
  outline: function outline(theme) {
2581
2880
  return theme.palette.geowebColors.buttons.focusDefault.outline;
2582
2881
  },
2583
- backgroundColor: 'geowebColors.buttons.tool.mouseOver.fill'
2584
- },
2585
- '&.Mui-focused .MuiSelect-select': {
2882
+ borderRadius: 0,
2586
2883
  backgroundColor: 'geowebColors.buttons.tool.mouseOver.fill'
2587
2884
  },
2588
2885
  '&:hover&.MuiButton-root': {
2589
2886
  backgroundColor: 'geowebColors.buttons.tool.mouseOver.fill'
2590
2887
  },
2591
2888
  '&:focus&.MuiButton-root': {
2592
- outline: function outline(theme) {
2889
+ border: function border(theme) {
2593
2890
  return theme.palette.geowebColors.buttons.focusDefault.outline;
2594
2891
  },
2595
- backgroundColor: 'geowebColors.buttons.tool.mouseOver.fill'
2892
+ backgroundColor: 'geowebColors.buttons.tool.mouseOver.fill',
2893
+ transition: 'border'
2596
2894
  }
2597
2895
  };
2598
2896
 
@@ -2634,7 +2932,7 @@
2634
2932
  selectOpen = _f[0],
2635
2933
  setSelectOpen = _f[1];
2636
2934
 
2637
- var _g = __read(React__namespace.useState(false), 2),
2935
+ var _g = __read(useControlledTooltip(), 2),
2638
2936
  tooltipOpen = _g[0],
2639
2937
  setTooltipOpen = _g[1];
2640
2938
 
@@ -2649,27 +2947,26 @@
2649
2947
  var onOpen = React__namespace.useCallback(function () {
2650
2948
  setSelectOpen(true);
2651
2949
  setTooltipOpen(false);
2652
- }, []);
2950
+ }, [setTooltipOpen]);
2653
2951
  var onClose = React__namespace.useCallback(function () {
2654
2952
  setSelectOpen(false);
2655
2953
  }, []);
2656
2954
  var onMouseEnter = React__namespace.useCallback(function () {
2657
2955
  if (!selectOpen) setTooltipOpen(true);
2658
- }, [selectOpen]);
2956
+ }, [selectOpen, setTooltipOpen]);
2659
2957
  var onMouseLeave = React__namespace.useCallback(function () {
2660
2958
  setTooltipOpen(false);
2661
- }, []);
2959
+ }, [setTooltipOpen]);
2662
2960
  var onFocus = React__namespace.useCallback(function () {
2663
2961
  setTooltipOpen(true);
2664
- }, []);
2962
+ }, [setTooltipOpen]);
2665
2963
  var onBlur = React__namespace.useCallback(function () {
2666
2964
  setTooltipOpen(false);
2667
- }, []);
2668
- return /*#__PURE__*/React__namespace.createElement(material.Tooltip, {
2965
+ }, [setTooltipOpen]);
2966
+ return /*#__PURE__*/React__namespace.createElement(CustomTooltip, {
2669
2967
  title: tooltip,
2670
2968
  placement: "top",
2671
- open: tooltipOpen,
2672
- sx: noStyling ? undefined : tooltipContainerStyles(!!isEnabled, hasBackgroundColor)
2969
+ open: tooltipOpen
2673
2970
  }, /*#__PURE__*/React__namespace.createElement(material.Select, __assign({
2674
2971
  onOpen: onOpen,
2675
2972
  onClose: onClose,
@@ -2720,7 +3017,8 @@
2720
3017
  }
2721
3018
  }
2722
3019
  }
2723
- }
3020
+ },
3021
+ sx: noStyling ? undefined : tooltipContainerStyles(!!isEnabled, hasBackgroundColor)
2724
3022
  }, otherProps)));
2725
3023
  };
2726
3024
 
@@ -2745,6 +3043,43 @@
2745
3043
  };
2746
3044
  }
2747
3045
 
3046
+ var CustomAccordion = function CustomAccordion(_a) {
3047
+ var title = _a.title,
3048
+ _b = _a.defaultExpanded,
3049
+ defaultExpanded = _b === void 0 ? true : _b,
3050
+ _c = _a.disableGutters,
3051
+ disableGutters = _c === void 0 ? true : _c,
3052
+ _d = _a.expandedElevation,
3053
+ expandedElevation = _d === void 0 ? 3 : _d,
3054
+ _e = _a.collapsedElevation,
3055
+ collapsedElevation = _e === void 0 ? 0 : _e,
3056
+ _f = _a.transitionDuration,
3057
+ transitionDuration = _f === void 0 ? 150 : _f,
3058
+ detailsSx = _a.detailsSx,
3059
+ children = _a.children,
3060
+ props = __rest(_a, ["title", "defaultExpanded", "disableGutters", "expandedElevation", "collapsedElevation", "transitionDuration", "detailsSx", "children"]);
3061
+
3062
+ var _g = __read(React__namespace.useState(defaultExpanded), 2),
3063
+ expanded = _g[0],
3064
+ setExpanded = _g[1];
3065
+
3066
+ return /*#__PURE__*/React__namespace.createElement(material.Accordion, __assign({}, props, {
3067
+ defaultExpanded: defaultExpanded,
3068
+ elevation: expanded ? expandedElevation : collapsedElevation,
3069
+ onChange: function onChange(_event, expanded) {
3070
+ return setExpanded(expanded);
3071
+ },
3072
+ disableGutters: disableGutters,
3073
+ TransitionProps: {
3074
+ timeout: transitionDuration
3075
+ }
3076
+ }), /*#__PURE__*/React__namespace.createElement(material.AccordionSummary, {
3077
+ expandIcon: /*#__PURE__*/React__namespace.createElement(theme.ChevronDown, null)
3078
+ }, title), /*#__PURE__*/React__namespace.createElement(material.AccordionDetails, {
3079
+ sx: detailsSx
3080
+ }, children));
3081
+ };
3082
+
2748
3083
  /* *
2749
3084
  * Licensed under the Apache License, Version 2.0 (the "License");
2750
3085
  * you may not use this file except in compliance with the License.
@@ -2807,6 +3142,26 @@
2807
3142
  return '';
2808
3143
  };
2809
3144
 
3145
+ /* *
3146
+ * Licensed under the Apache License, Version 2.0 (the "License");
3147
+ * you may not use this file except in compliance with the License.
3148
+ * You may obtain a copy of the License at
3149
+ *
3150
+ * http://www.apache.org/licenses/LICENSE-2.0
3151
+ *
3152
+ * Unless required by applicable law or agreed to in writing, software
3153
+ * distributed under the License is distributed on an "AS IS" BASIS,
3154
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3155
+ * See the License for the specific language governing permissions and
3156
+ * limitations under the License.
3157
+ *
3158
+ * Copyright 2022 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
3159
+ * Copyright 2022 - Finnish Meteorological Institute (FMI)
3160
+ * */
3161
+ // TODO: https://gitlab.com/opengeoweb/geoweb-assets/-/issues/2350
3162
+ // temporary check until we get the unit test passing with container queries
3163
+ var IS_JEST = typeof jest !== 'undefined';
3164
+
2810
3165
  exports.AlertBanner = AlertBanner;
2811
3166
  exports.AlertIcon = AlertIcon;
2812
3167
  exports.AppHeader = AppHeader;
@@ -2814,13 +3169,16 @@
2814
3169
  exports.Avatar = Avatar;
2815
3170
  exports.ConfirmationDialog = ConfirmationDialog;
2816
3171
  exports.ConfirmationServiceProvider = ConfirmationServiceProvider;
3172
+ exports.CustomAccordion = CustomAccordion;
2817
3173
  exports.CustomSlider = CustomSlider;
2818
3174
  exports.CustomToggleButton = CustomToggleButton;
3175
+ exports.CustomTooltip = CustomTooltip;
2819
3176
  exports.DEFAULT_ERROR_MESSAGE = DEFAULT_ERROR_MESSAGE;
2820
3177
  exports.Draggable = DraggableComponent$1;
2821
3178
  exports.EnableButton = EnableButton;
2822
3179
  exports.ErrorBoundary = ErrorBoundary;
2823
3180
  exports.HIDDEN_INPUT_HELPER_IS_DRAFT = HIDDEN_INPUT_HELPER_IS_DRAFT;
3181
+ exports.IS_JEST = IS_JEST;
2824
3182
  exports.ManagerButton = ManagerButton;
2825
3183
  exports.ManagerDeleteButton = ManagerDeleteButton;
2826
3184
  exports.Resizable = ResizeComponent;
@@ -2835,7 +3193,9 @@
2835
3193
  exports.UserMenu = UserMenu;
2836
3194
  exports.UserMenuItemCheatSheet = UserMenuItemCheatSheet;
2837
3195
  exports.UserMenuItemTheme = MenuItemTheme;
3196
+ exports.adjustPosition = adjustPosition;
2838
3197
  exports.calculateDialogSizeAndPosition = calculateDialogSizeAndPosition;
3198
+ exports.defaultDelay = defaultDelay;
2839
3199
  exports.getAxiosErrorMessage = getAxiosErrorMessage;
2840
3200
  exports.getAxiosWarningMessage = getAxiosWarningMessage;
2841
3201
  exports.getErrorMessage = getErrorMessage;
@@ -2847,6 +3207,7 @@
2847
3207
  exports.sliderHeaderStyle = sliderHeaderStyle;
2848
3208
  exports.tooltipContainerStyles = tooltipContainerStyles;
2849
3209
  exports.useConfirmationDialog = useConfirmationDialog;
3210
+ exports.useControlledTooltip = useControlledTooltip;
2850
3211
  exports.useDialogActions = useDialogActions;
2851
3212
  exports.useDraftFormHelpers = useDraftFormHelpers;
2852
3213
  exports.useIsMounted = useIsMounted;