@m4l/components 9.2.46 → 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.
- package/components/DragResizeWindowRND/DragResizeWindowRND.js +1 -1
- package/components/DragResizeWindowRND/helpers/getInitialSize.d.ts +1 -1
- package/components/DragResizeWindowRND/helpers/getInitialSize.js +26 -6
- package/components/DragResizeWindowRND/hooks/useRNDDragOptions.js +2 -0
- package/components/ModalDialog/ModalDialog.js +7 -5
- package/hooks/useSizeWindow/index.d.ts +2 -1
- package/package.json +1 -1
- package/storybook/components/DragResizeWindowRND/stories/DragResizeWindowRND.stories.d.ts +2 -0
|
@@ -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
|
-
|
|
48
|
-
y: Math.round(top ?? (bottom ? containerHeight
|
|
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
|
|
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
|
}
|
|
@@ -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
|
|
11
|
-
|
|
12
|
-
|
|
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: {
|
|
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/package.json
CHANGED
|
@@ -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;
|