@m4l/components 9.2.45 → 9.2.47

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.
@@ -44,7 +44,7 @@ const DragResizeWindowRND = forwardRef((props, ref) => {
44
44
  ...others
45
45
  } = props;
46
46
  const [currentState, setCurrentState] = useState(
47
- () => getInitialSize(containerSize, defaultPosition, containerElement)
47
+ () => getInitialSize(containerSize, defaultPosition, containerElement, allowHeightResizeContainer, allowWidthResizeContainer)
48
48
  );
49
49
  const minConstraints = useMemo(() => [minWidth, minHeight], [minWidth, minHeight]);
50
50
  const stateRef = useRef({
@@ -12,4 +12,4 @@ import { CurrentState, DefaultPosition } from '../types';
12
12
  * @param {DefaultPosition} defaultPosition - Object defining the default vertical and horizontal positions (`top`, `bottom`, `height`, `left`, `right`, `width`).
13
13
  * @returns {CurrentState} - The initial size and position of the element with `top`, `left`, `width`, and `height` properties.
14
14
  */
15
- export declare const getInitialSize: (containerSize: ContainerSize | undefined, defaultPosition: DefaultPosition, containerElement: HTMLElement | undefined) => CurrentState;
15
+ export declare const getInitialSize: (containerSize: ContainerSize | undefined, defaultPosition: DefaultPosition, containerElement: HTMLElement | undefined, allowHeightResizeContainer: boolean, allowWidthResizeContainer: boolean) => CurrentState;
@@ -1,10 +1,11 @@
1
- const getInitialSize = (containerSize, defaultPosition, containerElement) => {
1
+ const getInitialSize = (containerSize, defaultPosition, containerElement, allowHeightResizeContainer, allowWidthResizeContainer) => {
2
2
  let top;
3
3
  let bottom;
4
4
  let height;
5
5
  let left;
6
6
  let right;
7
7
  let width;
8
+ const LIMIT_PX = 20;
8
9
  const containerHeight = containerSize?.containerHeight || 200;
9
10
  const containerWidth = containerSize?.containerWidth || 200;
10
11
  const scrollTop = containerElement?.scrollTop || 0;
@@ -26,13 +27,13 @@ const getInitialSize = (containerSize, defaultPosition, containerElement) => {
26
27
  }
27
28
  if ("width" in defaultPosition.horizontal) {
28
29
  width = defaultPosition.horizontal.width;
29
- if (!("left" in defaultPosition.horizontal)) {
30
+ if (!("left" in defaultPosition.horizontal) && !("right" in defaultPosition.horizontal)) {
30
31
  left = scrollLeft + (containerWidth - width) / 2;
31
32
  }
32
33
  }
33
34
  if ("height" in defaultPosition.vertical) {
34
35
  height = defaultPosition.vertical.height;
35
- if (!("top" in defaultPosition.vertical)) {
36
+ if (!("top" in defaultPosition.vertical) && !("bottom" in defaultPosition.vertical)) {
36
37
  top = scrollTop + (containerHeight - height) / 2;
37
38
  }
38
39
  }
@@ -44,12 +45,31 @@ const getInitialSize = (containerSize, defaultPosition, containerElement) => {
44
45
  width = containerWidth * defaultPosition.horizontal.percent;
45
46
  left = (containerWidth - width) / 2;
46
47
  }
47
- return {
48
- y: Math.round(top ?? (bottom ? containerHeight - bottom - (height || 0) : 0)),
48
+ const initialSize = {
49
+ y: Math.round(top ?? (bottom !== void 0 ? containerHeight + bottom - (height || 0) : 0)),
49
50
  height: Math.round(height ?? containerHeight - (top || 0) - (bottom || 0)),
50
- x: Math.round(left ?? (right ? containerWidth - right - (width || 0) : 0)),
51
+ x: Math.round(left ?? (right !== void 0 ? containerWidth + right - (width || 0) : 0)),
51
52
  width: Math.round(width ?? containerWidth - (left || 0) - (right || 0))
52
53
  };
54
+ if (!allowHeightResizeContainer) {
55
+ const boundTop = 0 + LIMIT_PX;
56
+ const boundBottom = Math.max(containerHeight - LIMIT_PX - (height || 0), LIMIT_PX);
57
+ initialSize.y = Math.max(initialSize.y, boundTop);
58
+ initialSize.height = Math.min(initialSize.height, containerHeight - LIMIT_PX);
59
+ if (initialSize.y > boundBottom) {
60
+ initialSize.y = boundBottom;
61
+ }
62
+ }
63
+ if (!allowWidthResizeContainer) {
64
+ const boundLeft = 0 + LIMIT_PX;
65
+ const boundRight = Math.max(containerWidth - LIMIT_PX - (width || 0), LIMIT_PX);
66
+ initialSize.x = Math.max(initialSize.x, boundLeft);
67
+ initialSize.width = Math.min(initialSize.width, containerWidth - LIMIT_PX);
68
+ if (initialSize.x > boundRight) {
69
+ initialSize.x = boundRight;
70
+ }
71
+ }
72
+ return initialSize;
53
73
  };
54
74
  export {
55
75
  getInitialSize as g
@@ -18,6 +18,7 @@ const useDragOptions = (props) => {
18
18
  if (!containerElement) {
19
19
  return;
20
20
  }
21
+ e.stopPropagation();
21
22
  if (onDragStart) {
22
23
  if (onDragStart(e, draggableData) === false) {
23
24
  return false;
@@ -53,6 +54,7 @@ const useDragOptions = (props) => {
53
54
  );
54
55
  const localOnDrag = useCallback((e, draggableData) => {
55
56
  const { x, y, deltaX, deltaY } = draggableData;
57
+ e.stopPropagation();
56
58
  if (!stateRef.current.dragging) {
57
59
  return;
58
60
  }
@@ -1,7 +1,6 @@
1
1
  import { BooleanOperator, DateTimeOperator, FilterField, NumberOperator, SelectOperator, StringOperator } from './types';
2
2
  export declare const DYNAMIC_FILTER_KEY_COMPONENT = "M4LDynamicFilter";
3
3
  export declare const DYNAMIC_FILTER_SOTORE_ID = "M4LDynamicFilterStore";
4
- export declare const DYNAMIC_FILTER_POPOVER_CONTAINER_ID = "M4LDynamicFilterPopoverContainer";
5
4
  export declare const ALL_FIELD: FilterField;
6
5
  export declare const STRING_OPERATORS: Array<StringOperator>;
7
6
  export declare const NUMBER_OPERATORS: Array<NumberOperator>;
@@ -1,6 +1,5 @@
1
1
  const DYNAMIC_FILTER_KEY_COMPONENT = "M4LDynamicFilter";
2
2
  const DYNAMIC_FILTER_SOTORE_ID = "M4LDynamicFilterStore";
3
- const DYNAMIC_FILTER_POPOVER_CONTAINER_ID = "M4LDynamicFilterPopoverContainer";
4
3
  const ALL_FIELD = {
5
4
  name: "all",
6
5
  dictionaryId: "dynamic_filter.all_fields",
@@ -30,6 +29,5 @@ export {
30
29
  SELECT_OPERATORS as S,
31
30
  DYNAMIC_FILTER_SOTORE_ID as a,
32
31
  DATE_TIME_OPERATORS as b,
33
- STRING_OPERATORS as c,
34
- DYNAMIC_FILTER_POPOVER_CONTAINER_ID as d
32
+ STRING_OPERATORS as c
35
33
  };
@@ -1,28 +1,14 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { M as MenuItem } from "../../../mui_extended/MenuItem/MenuItem.js";
3
3
  import { u as usePopoverMenuFields } from "./usePopoverMenuFields.js";
4
- import { useRef, useEffect } from "react";
5
- import { d as DYNAMIC_FILTER_POPOVER_CONTAINER_ID } from "../../constants.js";
6
4
  import { u as useDynamicFilterBase } from "../DynamicFilterBase/useDynamicFilterBase.js";
5
+ import { u as usePopoverContainer } from "../../../../hooks/usePopoverContainer/usePopoverContainer.js";
7
6
  import { l as PopoverMenuStyled } from "../../slots/dynamicFilterSlots.js";
8
7
  function PopoverMenuFields(props) {
9
8
  const { fields, selectFieldIndex } = props;
10
9
  const { elementRef, handleOpenPopUpClickItem, handleClosePopover, getItemLabel, isOpenPopoverMenuFields } = usePopoverMenuFields();
11
10
  const anchorEl = elementRef?.current;
12
- const popoverContainerRef = useRef(null);
13
- useEffect(() => {
14
- if (!popoverContainerRef.current) {
15
- const container = document.createElement("div");
16
- container.id = DYNAMIC_FILTER_POPOVER_CONTAINER_ID;
17
- document.body.appendChild(container);
18
- popoverContainerRef.current = container;
19
- }
20
- return () => {
21
- if (popoverContainerRef.current) {
22
- document.body.removeChild(popoverContainerRef.current);
23
- }
24
- };
25
- }, []);
11
+ const popoverContainerRef = usePopoverContainer();
26
12
  const { size } = useDynamicFilterBase();
27
13
  return /* @__PURE__ */ jsx(
28
14
  PopoverMenuStyled,
@@ -1,7 +1,6 @@
1
1
  import { SortOperator } from './types';
2
2
  export declare const DYNAMIC_SORT_KEY_COMPONENT = "M4LDynamicSort";
3
3
  export declare const DYNAMIC_SORT_STORE_ID = "M4LDynamicSortStore";
4
- export declare const DYNAMIC_SORT_POPOVER_CONTAINER_ID = "M4LDynamicSortPopoverContainer";
5
4
  export declare const ASSETS_URL = "frontend/components/Dynamic_sort/assets/icons";
6
5
  export declare const ASSETS: {
7
6
  readonly refresh: "restart.svg";
@@ -1,6 +1,5 @@
1
1
  const DYNAMIC_SORT_KEY_COMPONENT = "M4LDynamicSort";
2
2
  const DYNAMIC_SORT_STORE_ID = "M4LDynamicSortStore";
3
- const DYNAMIC_SORT_POPOVER_CONTAINER_ID = "M4LDynamicSortPopoverContainer";
4
3
  const ASSETS_URL = "frontend/components/Dynamic_sort/assets/icons";
5
4
  const ASSETS = {
6
5
  refresh: "restart.svg",
@@ -14,6 +13,5 @@ export {
14
13
  DYNAMIC_SORT_KEY_COMPONENT as D,
15
14
  OPERATORS as O,
16
15
  DYNAMIC_SORT_STORE_ID as a,
17
- ASSETS as b,
18
- DYNAMIC_SORT_POPOVER_CONTAINER_ID as c
16
+ ASSETS as b
19
17
  };
@@ -1,30 +1,16 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { u as useDynamicSortBase } from "../DynamicSortBase/useDynamicSortBase.js";
3
3
  import { u as usePopoverMenuFields } from "./usePopoverMenuFields.js";
4
- import { useRef, useEffect } from "react";
5
- import { c as DYNAMIC_SORT_POPOVER_CONTAINER_ID } from "../../constants.js";
6
4
  import { M as MenuItem } from "../../../mui_extended/MenuItem/MenuItem.js";
7
5
  import { I as Icon } from "../../../Icon/Icon.js";
8
6
  import { P as PopoverMenuStyled } from "../../slots/DynamicSortSlots.js";
7
+ import { u as usePopoverContainer } from "../../../../hooks/usePopoverContainer/usePopoverContainer.js";
9
8
  function PopoverMenuFields(props) {
10
9
  const { fields, selectFieldIndex } = props;
11
10
  const { elementRef, handleOpenPopUpClickItem, handleClosePopover, getItemLabel, isOpenPopoverMenuFields } = usePopoverMenuFields();
12
11
  const { size } = useDynamicSortBase();
13
12
  const anchorEl = elementRef?.current;
14
- const popoverContainerRef = useRef(null);
15
- useEffect(() => {
16
- if (!popoverContainerRef.current) {
17
- const container = document.createElement("div");
18
- container.id = DYNAMIC_SORT_POPOVER_CONTAINER_ID;
19
- document.body.appendChild(container);
20
- popoverContainerRef.current = container;
21
- }
22
- return () => {
23
- if (popoverContainerRef.current) {
24
- document.body.removeChild(popoverContainerRef.current);
25
- }
26
- };
27
- }, []);
13
+ const popoverContainerRef = usePopoverContainer();
28
14
  return /* @__PURE__ */ jsx(
29
15
  PopoverMenuStyled,
30
16
  {
@@ -3,26 +3,28 @@ import { u as useModal } from "../../hooks/useModal/index.js";
3
3
  import { useIsMobile } from "@m4l/graphics";
4
4
  import { u as useStateRef } from "../../hooks/useStateRef/index.js";
5
5
  import { Paper } from "@mui/material";
6
+ import { u as useSizeContainer } from "../../hooks/useSizeContainer/index.js";
6
7
  import { D as DialogRootStyled, P as PaperModalDialogStyled } from "./slots/ModalDialogSlots.js";
7
8
  import { D as DragResizeWindowRND } from "../DragResizeWindowRND/DragResizeWindowRND.js";
8
9
  const DraggablePaperComponent = (ref, dialogProperties) => {
9
10
  return (props) => {
10
- const { initialWidth, initialHeight, maxWidth, maxHeight } = dialogProperties;
11
- if (!ref) {
12
- return props.children;
11
+ const containerSize = useSizeContainer(ref);
12
+ const { initialWidth, initialHeight = 100, maxWidth, maxHeight } = dialogProperties;
13
+ if (!ref || !containerSize) {
14
+ return null;
13
15
  }
14
- const topPosition = Math.max(0, window.innerHeight / 2 - (initialHeight ?? 100) / 2);
15
16
  const leftPosition = Math.max(0, window.innerWidth / 2 - (initialWidth ?? 100) / 2);
16
17
  return /* @__PURE__ */ jsx(
17
18
  DragResizeWindowRND,
18
19
  {
19
20
  containerElement: ref,
21
+ containerSize,
20
22
  minWindowWidth: maxWidth,
21
23
  minWindowHeight: maxHeight,
22
24
  bounds: { left: 0, top: 0, right: 0, bottom: 0 },
23
25
  resizeHandles: ["se", "nw", "sw", "ne", "n", "e", "s", "w"],
24
26
  defaultPosition: {
25
- vertical: { top: topPosition, height: initialHeight ?? 100 },
27
+ vertical: { height: initialHeight },
26
28
  horizontal: { left: leftPosition, width: initialWidth ?? 100 }
27
29
  },
28
30
  children: /* @__PURE__ */ jsx(PaperModalDialogStyled, { ...props, children: props.children })
package/hooks/index.d.ts CHANGED
@@ -10,3 +10,4 @@ export { useFormReadyForUpdate } from './useFormReadyForUpdate';
10
10
  export { useStateRef } from './useStateRef';
11
11
  export * from './useDynamicFilterAndSort';
12
12
  export * from './useDataGridPersistence';
13
+ export * from './usePopoverContainer';
@@ -0,0 +1 @@
1
+ export declare const POPOVER_CONTAINER_ID = "M4LPopoverContainer";
@@ -0,0 +1,4 @@
1
+ const POPOVER_CONTAINER_ID = "M4LPopoverContainer";
2
+ export {
3
+ POPOVER_CONTAINER_ID as P
4
+ };
@@ -0,0 +1,2 @@
1
+ export { usePopoverContainer } from './usePopoverContainer';
2
+ export * from './usePopoverContainer';
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Hook para manejar un contenedor global para popovers. cuando se requiere que siga teniendo foco el anchorElement
3
+ * Este hook garantiza que solo exista un contenedor con el ID especificado,
4
+ * incluso si el hook se usa en múltiples componentes.
5
+ * @param containerId ID único para el contenedor
6
+ * @returns Referencia al contenedor del popover
7
+ */
8
+ export declare function usePopoverContainer(containerId?: string): import('react').MutableRefObject<HTMLDivElement | null>;
@@ -0,0 +1,20 @@
1
+ import { useRef, useEffect } from "react";
2
+ import { P as POPOVER_CONTAINER_ID } from "./constants.js";
3
+ function usePopoverContainer(containerId = POPOVER_CONTAINER_ID) {
4
+ const containerRef = useRef(null);
5
+ useEffect(() => {
6
+ let container = document.getElementById(containerId);
7
+ if (!container) {
8
+ container = document.createElement("div");
9
+ container.id = containerId;
10
+ document.body.appendChild(container);
11
+ }
12
+ containerRef.current = container;
13
+ return () => {
14
+ };
15
+ }, [containerId]);
16
+ return containerRef;
17
+ }
18
+ export {
19
+ usePopoverContainer as u
20
+ };
@@ -2,5 +2,6 @@
2
2
  * Hook that returns the height of the navigator window
3
3
  */
4
4
  export declare const useSizeWindow: () => {
5
- windowHeight: number;
5
+ height: number;
6
+ width: number;
6
7
  };
package/index.js CHANGED
@@ -202,6 +202,7 @@ import { a as a15 } from "./hooks/useSvgColor/constants.js";
202
202
  import { u as u27 } from "./hooks/useSvgColor/useSvgColor.js";
203
203
  import { u as u28 } from "./hooks/useDynamicFilterAndSort/useDynamicFilterAndSort.js";
204
204
  import { u as u29 } from "./hooks/useDataGridPersistence/useDataGridPersistence.js";
205
+ import { u as u30 } from "./hooks/usePopoverContainer/usePopoverContainer.js";
205
206
  import { c as c4 } from "./utils/capitalizeFirstLetter.js";
206
207
  import { i as i2 } from "./utils/isValidDate.js";
207
208
  import { g as g29 } from "./utils/getComponentUtilityClass.js";
@@ -455,6 +456,7 @@ export {
455
456
  u13 as useFormatPeriod,
456
457
  u23 as useInterval,
457
458
  u20 as useModal,
459
+ u30 as usePopoverContainer,
458
460
  u14 as usePopupsStore,
459
461
  u as useSetWindowsTitle,
460
462
  u26 as useStateRef,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m4l/components",
3
- "version": "9.2.45",
3
+ "version": "9.2.47",
4
4
  "license": "UNLICENSED",
5
5
  "lint-staged": {
6
6
  "*.{js,ts,tsx}": "eslint --fix --max-warnings 0 --no-warn-ignored"
@@ -5,4 +5,6 @@ type Story = StoryObj<typeof DragResizeWindowRND>;
5
5
  export declare const Default: Story;
6
6
  export declare const AllowHeightResizeContainer: Story;
7
7
  export declare const Hidden: Story;
8
+ export declare const WithTopLeftNegative: Story;
9
+ export declare const WithBottomRightPositive: Story;
8
10
  export default meta;