@xwadex/fesd-next 0.3.44-beta.19 → 0.3.44-beta.20

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.
@@ -43,17 +43,24 @@ const DragResizeBase = (props) => {
43
43
  onResizeEnd: onResizeEndHandler,
44
44
  });
45
45
  //Context Functions
46
- const setResizeActive = useCallback((active) => setActive(active), [setActive]);
46
+ const setResizeActive = useCallback((active) => setActive(active), []);
47
+ const setResizeClose = useCallback((active) => {
48
+ if (!resizeRef.current)
49
+ return;
50
+ // resizeRef.current.style.width = active0 + "px"
51
+ // resizeRef.current.style.height = minHeight + "px"
52
+ clearResizeStore();
53
+ }, []);
47
54
  const clearResizeStore = useCallback(() => resizeStoreKey
48
55
  ? deleteCookies(resizeStoreKey)
49
- : console.error("resizeStoreKey is not undefined"), [resizeStoreKey]);
56
+ : console.error("resizeStoreKey is not undefined"), []);
50
57
  const defaultResizeSize = useCallback(() => {
51
58
  if (!resizeRef.current)
52
59
  return;
53
60
  resizeRef.current.style.width = minWidth + "px";
54
61
  // resizeRef.current.style.height = minHeight + "px"
55
62
  clearResizeStore();
56
- }, [resizeRef.current, clearResizeStore]);
63
+ }, []);
57
64
  const contextValue = useMemo(() => ({
58
65
  setResizeActive,
59
66
  clearResizeStore,
@@ -7,6 +7,8 @@ export interface DragResizePropsTypes {
7
7
  direction?: "width" | "height";
8
8
  minWidth?: number;
9
9
  maxWidth?: number;
10
+ minHeight?: number;
11
+ maxHeight?: number;
10
12
  onInit?: (size: ResizeTypes) => void;
11
13
  onResizeStart?: (size: ResizeTypes) => void;
12
14
  onResizing?: (size: ResizeTypes) => void;
@@ -15,5 +17,6 @@ export interface DragResizePropsTypes {
15
17
  export type DragResizeTypes = {
16
18
  dragRef: React.RefObject<HTMLDivElement | null>;
17
19
  resizeRef: React.RefObject<HTMLDivElement | null>;
20
+ resize?: ResizeTypes;
18
21
  };
19
- export declare function useDragResize({ active, direction, minWidth, maxWidth, onInit, onResizeStart, onResizing, onResizeEnd }: DragResizePropsTypes): DragResizeTypes;
22
+ export declare function useDragResize({ active, direction, minWidth, maxWidth, minHeight, maxHeight, onInit, onResizeStart, onResizing, onResizeEnd }: DragResizePropsTypes): DragResizeTypes;
@@ -1,9 +1,10 @@
1
1
  "use client";
2
2
  //wade 2024.12.06
3
- import { useEffect, useRef } from "react";
4
- export function useDragResize({ active = true, direction = "width", minWidth = 300, maxWidth = 500, onInit, onResizeStart, onResizing, onResizeEnd }) {
3
+ import { useEffect, useRef, useState } from "react";
4
+ export function useDragResize({ active = true, direction = "width", minWidth, maxWidth, minHeight, maxHeight, onInit, onResizeStart, onResizing, onResizeEnd }) {
5
5
  const dragRef = useRef(null);
6
6
  const resizeRef = useRef(null);
7
+ const [resize, setResize] = useState({ width: 0, height: 0 });
7
8
  const getResizeSizeValue = () => {
8
9
  if (!resizeRef.current)
9
10
  return;
@@ -18,10 +19,13 @@ export function useDragResize({ active = true, direction = "width", minWidth = 3
18
19
  const rect = resizeRef.current.getBoundingClientRect();
19
20
  const resizeWidth = clientX - rect.left;
20
21
  const resizeHeight = clientY - rect.top;
21
- if (resizeWidth <= minWidth || resizeWidth >= maxWidth)
22
- return;
23
- resizeRef.current.style.width = resizeWidth + "px";
24
- return { width: resizeWidth };
22
+ if ((minWidth && resizeWidth > minWidth) || (maxWidth && resizeWidth > maxWidth)) {
23
+ resizeRef.current.style.width = resizeWidth + "px";
24
+ }
25
+ if ((minHeight && resizeWidth > minHeight) || (maxHeight && resizeWidth > maxHeight)) {
26
+ resizeRef.current.style.height = resizeHeight + "px";
27
+ }
28
+ return { width: resizeWidth, height: resizeHeight };
25
29
  };
26
30
  const onInitCallback = () => {
27
31
  const resizeValue = getResizeSizeValue();
@@ -33,7 +37,10 @@ export function useDragResize({ active = true, direction = "width", minWidth = 3
33
37
  };
34
38
  const onMouseMove = (e) => {
35
39
  const resizeValue = setResizeValue(e.clientX, e.clientY);
36
- resizeValue && onResizing?.(resizeValue);
40
+ if (!resizeValue)
41
+ return;
42
+ setResize(() => ({ ...resizeValue }));
43
+ onResizing?.(resizeValue);
37
44
  };
38
45
  const onMouseUp = () => {
39
46
  const resizeValue = getResizeSizeValue();
@@ -59,5 +66,5 @@ export function useDragResize({ active = true, direction = "width", minWidth = 3
59
66
  removeEventListeners();
60
67
  };
61
68
  }, [active]);
62
- return { dragRef, resizeRef };
69
+ return { dragRef, resizeRef, resize };
63
70
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xwadex/fesd-next",
3
- "version": "0.3.44-beta.19",
3
+ "version": "0.3.44-beta.20",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,19 +0,0 @@
1
- import { DragResizePropsTypes, ResizeTypes } from "../../hooks/index.js";
2
- import { AsPropsTypes } from "../../types/index.js";
3
- type PropsTypes<T extends React.ElementType = "div"> = AsPropsTypes<T, {
4
- as?: React.ElementType;
5
- children: React.ReactNode;
6
- defaultWidth?: number;
7
- defaultHeight?: number;
8
- resizeClass?: string;
9
- dragLineWidth?: number;
10
- dragLineColor?: string;
11
- containerClass?: string;
12
- dragClass?: string;
13
- resizeStore?: boolean;
14
- resizeStoreKey?: string;
15
- resizeStoreValue?: ResizeTypes;
16
- } & DragResizePropsTypes>;
17
- declare const DragResizeBase: <T extends React.ElementType = "div">(props: PropsTypes<T>) => import("react/jsx-runtime").JSX.Element;
18
- declare const DragResize: React.MemoExoticComponent<typeof DragResizeBase>;
19
- export default DragResize;
@@ -1,77 +0,0 @@
1
- "use client";
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { memo, useCallback, useMemo, useState } from "react";
4
- import { useDragResize, useCookies } from "../../hooks/index.js";
5
- import { DragResizeContext } from "./dragResizeContext";
6
- import { mergeClassName } from "../../utils/index.js";
7
- import styles from "./dragResize.module.scss";
8
- const DragResizeBase = (props) => {
9
- const { as, children, defaultWidth, defaultHeight, resizeClass, containerClass, dragClass, resizeStore = true, resizeStoreKey, resizeStoreValue, active = true, direction = "width", minWidth = 500, maxWidth = 950, dragLineWidth = 5, dragLineColor = "rgba(0, 0, 0, 1)", onInit, onResizeStart, onResizing, onResizeEnd, ...othersProps } = props;
10
- const RootComponent = as || "div";
11
- const [isActive, setActive] = useState(active);
12
- const { setCookies, deleteCookies } = useCookies();
13
- const resizeCSS = useMemo(() => mergeClassName(styles.root, resizeClass ? resizeClass : ""), [resizeClass]);
14
- const dragCSS = useMemo(() => mergeClassName(styles.drag, dragClass ? dragClass : "", !isActive ? styles.off : ""), [isActive, dragClass]);
15
- const containerCSS = useMemo(() => mergeClassName(styles.container, containerClass ? containerClass : ""), [containerClass]);
16
- const isCookieStore = useMemo(() => resizeStore
17
- && resizeStoreKey
18
- && resizeStoreKey !== ""
19
- ? true : false, [resizeStore, resizeStoreKey]);
20
- const resizeDefauleStyles = useMemo(() => {
21
- if (!isCookieStore || !resizeStoreValue)
22
- return {
23
- width: minWidth + "px",
24
- // height: minHeight + "px"
25
- };
26
- const { width, height } = resizeStoreValue;
27
- return {
28
- width: width ? width + "px" : "inherit",
29
- height: height ? height + "px" : "inherit",
30
- };
31
- }, [isCookieStore, resizeStoreValue]);
32
- const onResizeEndHandler = useCallback((size) => {
33
- onResizeEnd?.(size);
34
- if (!isCookieStore)
35
- return;
36
- setCookies(resizeStoreKey, JSON.stringify(size));
37
- }, [isCookieStore, onResizeEnd, resizeStore]);
38
- //Hooks
39
- const { dragRef, resizeRef } = useDragResize({
40
- active: isActive,
41
- direction,
42
- minWidth,
43
- maxWidth,
44
- onInit,
45
- onResizeStart,
46
- onResizing,
47
- onResizeEnd: onResizeEndHandler,
48
- });
49
- //Context Functions
50
- const setResizeActive = useCallback((active) => setActive(active), [setActive]);
51
- const clearResizeStore = useCallback(() => resizeStoreKey
52
- ? deleteCookies(resizeStoreKey)
53
- : console.error("resizeStoreKey is not undefined"), [resizeStoreKey]);
54
- const defaultResizeSize = useCallback(() => {
55
- if (!resizeRef.current)
56
- return;
57
- resizeRef.current.style.width = minWidth + "px";
58
- // resizeRef.current.style.height = minHeight + "px"
59
- clearResizeStore();
60
- }, [resizeRef.current, clearResizeStore]);
61
- const contextValue = useMemo(() => ({
62
- setResizeActive,
63
- clearResizeStore,
64
- defaultResizeSize
65
- }), [
66
- setResizeActive,
67
- clearResizeStore,
68
- defaultResizeSize
69
- ]);
70
- return (_jsx(DragResizeContext, { value: contextValue, children: _jsxs(RootComponent, { ...othersProps, ref: resizeRef, className: resizeCSS, style: resizeDefauleStyles, children: [_jsx("div", { className: containerCSS, children: children }), _jsx("div", { ref: dragRef, className: dragCSS, style: {
71
- "--drag-line-width": dragLineWidth + "px",
72
- "--drag-line-color": dragLineColor
73
- } })] }) }));
74
- };
75
- const DragResize = memo(DragResizeBase);
76
- DragResize.displayName = "DragResize";
77
- export default DragResize;
@@ -1,42 +0,0 @@
1
- .root {
2
- width: inherit;
3
- height: inherit;
4
- display: flex;
5
- flex-direction: row;
6
- }
7
-
8
- .container {
9
- width: inherit;
10
- height: inherit;
11
- }
12
-
13
- .drag {
14
- --drag-line-width: 2px;
15
- --drag-line-color: rgbs(0, 0, 0, 1);
16
-
17
- width: 0;
18
- height: inherit;
19
- position: relative;
20
- z-index: 2;
21
-
22
- &::before {
23
- content: "";
24
- width: 0;
25
- height: inherit;
26
- border-left: var(--drag-line-width) solid var(--drag-line-color);
27
- position: absolute;
28
- inset: 0 0 0 calc(var(--drag-line-width) / 2 * -1);
29
- z-index: 1;
30
- opacity: 0;
31
- transition: 0.5s ease-in-out;
32
- }
33
-
34
- &:not(.off) {
35
- &:hover {
36
- cursor: ew-resize;
37
- &::before {
38
- opacity: 1;
39
- }
40
- }
41
- }
42
- }