@m4l/components 9.4.6-BE20260109-beta.1 → 9.4.6-BE20260109-beta.2
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/components/DynamicFilter/subcomponents/PopoverFilter/PopoverFilter.js +3 -2
- package/components/DynamicFilter/subcomponents/PopoverMenuFields/PopoverMenuFields.d.ts +1 -1
- package/components/DynamicFilter/subcomponents/PopoverMenuFields/PopoverMenuFields.js +6 -2
- package/components/DynamicSort/subcomponents/PopoverMenuFields/PopoverMenuFields.d.ts +1 -1
- package/components/DynamicSort/subcomponents/PopoverMenuFields/PopoverMenuFields.js +6 -2
- package/components/DynamicSort/subcomponents/PopoverSort/PopoverSort.js +3 -2
- package/hooks/usePopoverContainer/usePopoverContainer.d.ts +35 -6
- package/hooks/usePopoverContainer/usePopoverContainer.js +14 -6
- package/package.json +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useId } from "react";
|
|
2
3
|
import { useModuleDictionary } from "@m4l/core";
|
|
3
4
|
import { useFormContext } from "react-hook-form";
|
|
4
5
|
import { D as DataTypeComponent } from "../FieldTypes/DataTypeComponent.js";
|
|
5
6
|
import { u as usePopoverFilter } from "./usePopoverFilter.js";
|
|
6
|
-
import { P as POPOVER_CONTAINER_ID } from "../../../../hooks/usePopoverContainer/constants.js";
|
|
7
7
|
import { u as usePopoverContainer } from "../../../../hooks/usePopoverContainer/usePopoverContainer.js";
|
|
8
8
|
import { P as PopoverStyled, h as PopoverContainerFieldsStyled, i as PopoverHeaderActionsStyled } from "../../slots/dynamicFilterSlots.js";
|
|
9
9
|
import { R as RHFormProvider } from "../../../hook-form/RHFormProvider/RHFormProvider.js";
|
|
@@ -43,7 +43,8 @@ function PopoverFilter() {
|
|
|
43
43
|
statusLoad,
|
|
44
44
|
canRender
|
|
45
45
|
} = usePopoverFilter();
|
|
46
|
-
const
|
|
46
|
+
const containerId = useId();
|
|
47
|
+
const popoverContainerRef = usePopoverContainer(containerId, !!canRender);
|
|
47
48
|
if (!canRender) {
|
|
48
49
|
return null;
|
|
49
50
|
}
|
|
@@ -6,5 +6,5 @@ export type PopoverMenuFieldsProps = {
|
|
|
6
6
|
/**
|
|
7
7
|
* PopoverMenuFields: Componente encargado de mostrar el menú de campos para filtrar
|
|
8
8
|
*/
|
|
9
|
-
declare function PopoverMenuFields(props: PopoverMenuFieldsProps): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
declare function PopoverMenuFields(props: PopoverMenuFieldsProps): import("react/jsx-runtime").JSX.Element | null;
|
|
10
10
|
export default PopoverMenuFields;
|
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useId } from "react";
|
|
2
3
|
import { M as MenuItem } from "../../../mui_extended/MenuItem/MenuItem.js";
|
|
3
4
|
import { u as usePopoverMenuFields } from "./usePopoverMenuFields.js";
|
|
4
5
|
import { u as useDynamicFilterBase } from "../DynamicFilterBase/useDynamicFilterBase.js";
|
|
5
6
|
import { useModuleDictionary } from "@m4l/core";
|
|
6
7
|
import { a as DICCTIONARY } from "../../dictionary.js";
|
|
7
8
|
import { u as usePopoverContainer } from "../../../../hooks/usePopoverContainer/usePopoverContainer.js";
|
|
8
|
-
import { P as POPOVER_CONTAINER_ID } from "../../../../hooks/usePopoverContainer/constants.js";
|
|
9
9
|
import { j as PopoverMenuStyled } from "../../slots/dynamicFilterSlots.js";
|
|
10
10
|
function PopoverMenuFields(props) {
|
|
11
11
|
const { fields, selectFieldIndex } = props;
|
|
12
12
|
const { elementRef, handleOpenPopUpClickItem, handleClosePopover, getItemLabel, isOpenPopoverMenuFields } = usePopoverMenuFields();
|
|
13
13
|
const anchorEl = elementRef?.current;
|
|
14
14
|
const { getLabel } = useModuleDictionary();
|
|
15
|
-
const
|
|
15
|
+
const containerId = useId();
|
|
16
|
+
const popoverContainerRef = usePopoverContainer(containerId, !!isOpenPopoverMenuFields);
|
|
16
17
|
const { size } = useDynamicFilterBase();
|
|
18
|
+
if (!isOpenPopoverMenuFields) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
17
21
|
return /* @__PURE__ */ jsxs(
|
|
18
22
|
PopoverMenuStyled,
|
|
19
23
|
{
|
|
@@ -6,5 +6,5 @@ export type PopoverMenuFieldsProps = {
|
|
|
6
6
|
/**
|
|
7
7
|
* PopoverMenuFields es un componente que permite mostrar un menú desplegable con los campos disponibles para ordenar.
|
|
8
8
|
*/
|
|
9
|
-
declare function PopoverMenuFields(props: PopoverMenuFieldsProps): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
declare function PopoverMenuFields(props: PopoverMenuFieldsProps): import("react/jsx-runtime").JSX.Element | null;
|
|
10
10
|
export default PopoverMenuFields;
|
|
@@ -5,8 +5,8 @@ import { M as MenuItem } from "../../../mui_extended/MenuItem/MenuItem.js";
|
|
|
5
5
|
import { I as Icon } from "../../../Icon/Icon.js";
|
|
6
6
|
import { D as DICCTIONARY } from "../../dictionary.js";
|
|
7
7
|
import { useModuleDictionary } from "@m4l/core";
|
|
8
|
+
import { useId } from "react";
|
|
8
9
|
import { u as usePopoverContainer } from "../../../../hooks/usePopoverContainer/usePopoverContainer.js";
|
|
9
|
-
import { P as POPOVER_CONTAINER_ID } from "../../../../hooks/usePopoverContainer/constants.js";
|
|
10
10
|
import { P as PopoverMenuStyled } from "../../slots/DynamicSortSlots.js";
|
|
11
11
|
function PopoverMenuFields(props) {
|
|
12
12
|
const { fields, selectFieldIndex } = props;
|
|
@@ -14,7 +14,11 @@ function PopoverMenuFields(props) {
|
|
|
14
14
|
const { size } = useDynamicSortBase();
|
|
15
15
|
const anchorEl = elementRef?.current;
|
|
16
16
|
const { getLabel } = useModuleDictionary();
|
|
17
|
-
const
|
|
17
|
+
const containerId = useId();
|
|
18
|
+
const popoverContainerRef = usePopoverContainer(containerId, !!isOpenPopoverMenuFields);
|
|
19
|
+
if (!isOpenPopoverMenuFields) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
18
22
|
return /* @__PURE__ */ jsxs(
|
|
19
23
|
PopoverMenuStyled,
|
|
20
24
|
{
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useId } from "react";
|
|
2
3
|
import { useModuleDictionary } from "@m4l/core";
|
|
3
4
|
import { useFormContext } from "react-hook-form";
|
|
4
5
|
import { u as useDynamicSortBase } from "../DynamicSortBase/useDynamicSortBase.js";
|
|
5
6
|
import { D as DataTypeComponent } from "../FieldTypes/DataTypeComponent.js";
|
|
6
7
|
import { u as usePopoverSort } from "./usePopoverSort.js";
|
|
7
8
|
import { u as usePopoverContainer } from "../../../../hooks/usePopoverContainer/usePopoverContainer.js";
|
|
8
|
-
import { P as POPOVER_CONTAINER_ID } from "../../../../hooks/usePopoverContainer/constants.js";
|
|
9
9
|
import { e as PopoverStyled, f as PopoverContainerFieldsStyled, g as PopoverHeaderActionsStyled } from "../../slots/DynamicSortSlots.js";
|
|
10
10
|
import { R as RHFormProvider } from "../../../hook-form/RHFormProvider/RHFormProvider.js";
|
|
11
11
|
import { W as WindowBase } from "../../../WindowBase/WindowBase.js";
|
|
@@ -49,7 +49,8 @@ function PopoverSort() {
|
|
|
49
49
|
canRender
|
|
50
50
|
} = usePopoverSort();
|
|
51
51
|
const { size } = useDynamicSortBase();
|
|
52
|
-
const
|
|
52
|
+
const containerId = useId();
|
|
53
|
+
const popoverContainerRef = usePopoverContainer(containerId, !!canRender);
|
|
53
54
|
if (!canRender) {
|
|
54
55
|
return null;
|
|
55
56
|
}
|
|
@@ -1,8 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Hook para manejar un contenedor global para popovers
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
2
|
+
* Hook para manejar un contenedor global para popovers cuando se requiere que el anchorElement
|
|
3
|
+
* mantenga el foco mientras el popover está abierto.
|
|
4
|
+
*
|
|
5
|
+
* PROPÓSITO:
|
|
6
|
+
* Este hook crea y gestiona un contenedor DOM personalizado para popovers. Es especialmente útil
|
|
7
|
+
* cuando necesitas que el elemento ancla (anchorElement) mantenga el foco mientras el popover
|
|
8
|
+
* está visible, evitando que el foco se mueva automáticamente al popover.
|
|
9
|
+
*
|
|
10
|
+
* FUNCIONAMIENTO:
|
|
11
|
+
* 1. Busca un contenedor existente en el DOM con el ID especificado
|
|
12
|
+
* 2. Si no existe y `createContainer` es `true`, crea un nuevo contenedor y lo añade al body
|
|
13
|
+
* 3. Retorna una referencia al contenedor que debe pasarse a la prop `container` del Popover
|
|
14
|
+
*
|
|
15
|
+
* IMPORTANTE - TIMING Y RE-RENDERS:
|
|
16
|
+
* Este hook utiliza un re-render forzado para garantizar que el Popover se renderice con la
|
|
17
|
+
* referencia correcta del contenedor. Ver la documentación dentro del código para más detalles
|
|
18
|
+
* sobre por qué esto es necesario y qué ocurre si no se realiza.
|
|
19
|
+
* @param containerId ID único para el contenedor. Si no se proporciona, usa POPOVER_CONTAINER_ID por defecto
|
|
20
|
+
* @param createContainer Si es `true`, crea el contenedor si no existe. Si es `false`, solo busca uno existente
|
|
21
|
+
* @returns Referencia (ref) al contenedor del popover que debe pasarse a la prop `container` del Popover
|
|
22
|
+
* @example
|
|
23
|
+
* ```tsx
|
|
24
|
+
* const containerId = useId();
|
|
25
|
+
* const popoverContainerRef = usePopoverContainer(containerId, !!isOpen);
|
|
26
|
+
*
|
|
27
|
+
* return (
|
|
28
|
+
* <Popover
|
|
29
|
+
* open={isOpen}
|
|
30
|
+
* container={popoverContainerRef.current} // Pasa la referencia aquí
|
|
31
|
+
* >
|
|
32
|
+
* {/* contenido del popover *\/}
|
|
33
|
+
* </Popover>
|
|
34
|
+
* );
|
|
35
|
+
* ```
|
|
7
36
|
*/
|
|
8
|
-
export declare function usePopoverContainer(containerId
|
|
37
|
+
export declare function usePopoverContainer(containerId: string | undefined, createContainer: boolean): import('react').MutableRefObject<HTMLDivElement | null>;
|
|
@@ -1,21 +1,29 @@
|
|
|
1
|
-
import { useRef,
|
|
1
|
+
import { useRef, useState, useLayoutEffect } from "react";
|
|
2
2
|
import { P as POPOVER_CONTAINER_ID } from "./constants.js";
|
|
3
|
-
function usePopoverContainer(containerId = POPOVER_CONTAINER_ID, createContainer
|
|
3
|
+
function usePopoverContainer(containerId = POPOVER_CONTAINER_ID, createContainer) {
|
|
4
4
|
const containerRef = useRef(null);
|
|
5
|
-
|
|
5
|
+
const [, forceUpdate] = useState({});
|
|
6
|
+
useLayoutEffect(() => {
|
|
7
|
+
if (typeof document === "undefined") {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
6
10
|
let container = document.getElementById(containerId);
|
|
7
11
|
if (!container && createContainer) {
|
|
8
12
|
container = document.createElement("div");
|
|
9
13
|
container.id = containerId;
|
|
10
14
|
document.body.appendChild(container);
|
|
11
15
|
}
|
|
12
|
-
containerRef.current
|
|
16
|
+
if (containerRef.current !== container) {
|
|
17
|
+
containerRef.current = container;
|
|
18
|
+
forceUpdate({});
|
|
19
|
+
}
|
|
13
20
|
return () => {
|
|
14
|
-
if (
|
|
21
|
+
if (containerRef.current && containerRef.current.parentNode) {
|
|
15
22
|
containerRef.current.remove();
|
|
23
|
+
containerRef.current = null;
|
|
16
24
|
}
|
|
17
25
|
};
|
|
18
|
-
}, [containerId]);
|
|
26
|
+
}, [containerId, createContainer]);
|
|
19
27
|
return containerRef;
|
|
20
28
|
}
|
|
21
29
|
export {
|