@xwadex/fesd-next 0.3.7 → 0.3.9

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.
Files changed (55) hide show
  1. package/package.json +1 -1
  2. package/dist/components/accordions/accordions.d.ts +0 -16
  3. package/dist/components/accordions/accordions.js +0 -46
  4. package/dist/components/accordions/accordionsButton.d.ts +0 -9
  5. package/dist/components/accordions/accordionsButton.js +0 -13
  6. package/dist/components/accordions/accordionsContent.d.ts +0 -8
  7. package/dist/components/accordions/accordionsContent.js +0 -44
  8. package/dist/components/accordions/accordionsContext.d.ts +0 -17
  9. package/dist/components/accordions/accordionsContext.js +0 -9
  10. package/dist/components/accordions/accordionsHeader.d.ts +0 -8
  11. package/dist/components/accordions/accordionsHeader.js +0 -13
  12. package/dist/components/accordions/index.d.ts +0 -4
  13. package/dist/components/accordions/index.js +0 -5
  14. package/dist/components/dragResize/dragResize.d.ts +0 -17
  15. package/dist/components/dragResize/dragResize.js +0 -74
  16. package/dist/components/dragResize/dragResizeContext.d.ts +0 -10
  17. package/dist/components/dragResize/dragResizeContext.js +0 -9
  18. package/dist/components/dragResize/index.d.ts +0 -2
  19. package/dist/components/dragResize/index.js +0 -2
  20. package/dist/components/dragSortable/dragSortable.d.ts +0 -19
  21. package/dist/components/dragSortable/dragSortable.js +0 -11
  22. package/dist/components/dragSortable/index.d.ts +0 -1
  23. package/dist/components/dragSortable/index.js +0 -1
  24. package/dist/components/index.d.ts +0 -4
  25. package/dist/components/index.js +0 -4
  26. package/dist/components/myComponents/MyComponent.d.ts +0 -2
  27. package/dist/components/myComponents/MyComponent.js +0 -4
  28. package/dist/components/myComponents/index.d.ts +0 -1
  29. package/dist/components/myComponents/index.js +0 -1
  30. package/dist/hooks/index.d.ts +0 -5
  31. package/dist/hooks/index.js +0 -5
  32. package/dist/hooks/useAsyncFetcher.d.ts +0 -11
  33. package/dist/hooks/useAsyncFetcher.js +0 -40
  34. package/dist/hooks/useCookies.d.ts +0 -6
  35. package/dist/hooks/useCookies.js +0 -24
  36. package/dist/hooks/useDebounce.d.ts +0 -7
  37. package/dist/hooks/useDebounce.js +0 -16
  38. package/dist/hooks/useDebounceValue.d.ts +0 -1
  39. package/dist/hooks/useDebounceValue.js +0 -17
  40. package/dist/hooks/useDragResize.d.ts +0 -19
  41. package/dist/hooks/useDragResize.js +0 -63
  42. package/dist/index.d.ts +0 -4
  43. package/dist/index.js +0 -4
  44. package/dist/types/cms.type.d.ts +0 -27
  45. package/dist/types/cms.type.js +0 -1
  46. package/dist/types/commons.type.d.ts +0 -16
  47. package/dist/types/commons.type.js +0 -1
  48. package/dist/types/components.type.d.ts +0 -9
  49. package/dist/types/components.type.js +0 -1
  50. package/dist/types/index.d.ts +0 -4
  51. package/dist/types/index.js +0 -4
  52. package/dist/types/utils.type.d.ts +0 -1
  53. package/dist/types/utils.type.js +0 -1
  54. package/dist/utils/index.d.ts +0 -13
  55. package/dist/utils/index.js +0 -55
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xwadex/fesd-next",
3
- "version": "0.3.7",
3
+ "version": "0.3.9",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,16 +0,0 @@
1
- import type { AsPropsTypes } from "../../types";
2
- type PropsTypes<T extends React.ElementType = "div"> = AsPropsTypes<T, {
3
- as?: React.ElementType;
4
- children?: React.ReactNode;
5
- defaultActive?: boolean;
6
- active?: boolean;
7
- time?: number;
8
- timingFunction?: string;
9
- isClickExtend?: boolean;
10
- onChanged?: (state: boolean) => void;
11
- onExpanded?: (state: boolean) => void;
12
- onClosed?: (state: boolean) => void;
13
- }>;
14
- declare const AccordionsBase: <T extends React.ElementType = "div">(props: PropsTypes<T>) => import("react/jsx-runtime").JSX.Element;
15
- declare const Accordions: React.MemoExoticComponent<typeof AccordionsBase>;
16
- export default Accordions;
@@ -1,46 +0,0 @@
1
- "use client";
2
- import { jsx as _jsx } from "react/jsx-runtime";
3
- import { useCallback, useState, useMemo, memo } from "react";
4
- import { AccordionsContext } from "./accordionsContext";
5
- const AccordionsBase = (props) => {
6
- const { as, children, defaultActive = false, active, time = 300, timingFunction = "var(--global-animation-timing)", isClickExtend = true, onChanged, onExpanded, onClosed, ...othersProps } = props;
7
- const RootComponent = as || "div";
8
- const [expand, setExpand] = useState(defaultActive);
9
- const [isWorking, setWorking] = useState(false);
10
- const setExtandHandler = useCallback((state) => {
11
- if (isWorking || !isClickExtend)
12
- return;
13
- if (typeof state !== "boolean")
14
- setExpand(prev => !prev);
15
- else
16
- setExpand(state);
17
- }, [isWorking, isClickExtend]);
18
- const contextValue = useMemo(() => ({
19
- time,
20
- timingFunction,
21
- active,
22
- isClickExtend,
23
- expand,
24
- setExtandHandler,
25
- isWorking,
26
- setWorking,
27
- onChanged,
28
- onExpanded,
29
- onClosed
30
- }), [
31
- time,
32
- timingFunction,
33
- active,
34
- isClickExtend,
35
- expand,
36
- isWorking,
37
- setExtandHandler,
38
- onChanged,
39
- onExpanded,
40
- onClosed
41
- ]);
42
- return (_jsx(AccordionsContext, { value: contextValue, children: _jsx(RootComponent, { ...othersProps, children: children }) }));
43
- };
44
- const Accordions = memo(AccordionsBase);
45
- Accordions.displayName = "Accordions";
46
- export default Accordions;
@@ -1,9 +0,0 @@
1
- import type { AsPropsTypes } from "../../types";
2
- type PropsTypes<T extends React.ElementType = "div"> = AsPropsTypes<T, {
3
- as?: React.ElementType;
4
- active?: boolean;
5
- children?: React.ReactNode;
6
- }>;
7
- declare const AccordionsButtonBase: <T extends React.ElementType = "div">(props: PropsTypes<T>) => import("react/jsx-runtime").JSX.Element;
8
- declare const AccordionsButton: React.MemoExoticComponent<typeof AccordionsButtonBase>;
9
- export default AccordionsButton;
@@ -1,13 +0,0 @@
1
- "use client";
2
- import { jsx as _jsx } from "react/jsx-runtime";
3
- import { memo } from "react";
4
- import { useAccordionsContext } from "./accordionsContext";
5
- const AccordionsButtonBase = (props) => {
6
- const { as, active, children, ...othersProps } = props;
7
- const RootComponent = as || "div";
8
- const { setExtandHandler } = useAccordionsContext();
9
- return (_jsx(RootComponent, { ...othersProps, onClick: () => setExtandHandler(active), children: children }));
10
- };
11
- const AccordionsButton = memo(AccordionsButtonBase);
12
- AccordionsButton.displayName = "AccordionsButton";
13
- export default AccordionsButton;
@@ -1,8 +0,0 @@
1
- import type { AsPropsTypes } from "../../types";
2
- type PropsTypes<T extends React.ElementType = "div"> = AsPropsTypes<T, {
3
- as?: React.ElementType;
4
- children?: React.ReactNode;
5
- }>;
6
- declare const AccordionsContentBase: <T extends React.ElementType = "div">(props: PropsTypes<T>) => import("react/jsx-runtime").JSX.Element;
7
- declare const AccordionsContent: React.MemoExoticComponent<typeof AccordionsContentBase>;
8
- export default AccordionsContent;
@@ -1,44 +0,0 @@
1
- "use client";
2
- import { jsx as _jsx } from "react/jsx-runtime";
3
- import { memo, useCallback, useEffect, useRef, useState } from "react";
4
- import { useAccordionsContext } from "./accordionsContext";
5
- import { getDomTransTime, sleep } from "../../utils";
6
- import styles from "./accordions.module.scss";
7
- const AccordionsContentBase = (props) => {
8
- const { as, children, ...othersProps } = props;
9
- const RootComponent = as || "div";
10
- const { time, timingFunction, expand, active, isWorking, setWorking, onChanged, onExpanded, onClosed, } = useAccordionsContext();
11
- const menuRef = useRef(null);
12
- const [open, setOpen] = useState(false);
13
- const callbackHandler = useCallback((state) => state
14
- ? onExpanded?.(state)
15
- : onClosed?.(state), [onExpanded, onClosed]);
16
- const setOpenHandler = useCallback(async (state) => {
17
- if (expand == open || isWorking || !menuRef?.current)
18
- return;
19
- setWorking(true);
20
- const target = menuRef.current;
21
- target.style.height = target.scrollHeight + "px";
22
- await sleep(!state ? 0 : getDomTransTime(target));
23
- target.style.height = "";
24
- setOpen(state);
25
- setWorking(false);
26
- onChanged?.(state);
27
- callbackHandler(state);
28
- }, [expand, isWorking, onChanged]);
29
- useEffect(() => {
30
- setOpenHandler(expand);
31
- }, [expand]);
32
- useEffect(() => {
33
- if (typeof active !== "boolean")
34
- return;
35
- setOpenHandler(active);
36
- }, [active]);
37
- return (_jsx(RootComponent, { ...othersProps, ref: menuRef, className: styles.contents, style: {
38
- transition: time ? time / 1000 + "s" : undefined,
39
- transitionTimingFunction: timingFunction
40
- }, "data-active": open, children: children }));
41
- };
42
- const AccordionsContent = memo(AccordionsContentBase);
43
- AccordionsContent.displayName = "AccordionsContent";
44
- export default AccordionsContent;
@@ -1,17 +0,0 @@
1
- export interface AccordionsContextType {
2
- time?: number;
3
- timingFunction?: string;
4
- active?: boolean;
5
- isClickExtend?: boolean;
6
- expand: boolean;
7
- setExtandHandler: (state?: boolean) => void;
8
- isWorking: boolean;
9
- setWorking: React.Dispatch<React.SetStateAction<boolean>>;
10
- onChanged?: (state: boolean) => void;
11
- onExpanded?: (state: boolean) => void;
12
- onClosed?: (state: boolean) => void;
13
- }
14
- export declare const AccordionsContext: import("react").Context<AccordionsContextType | undefined> & {
15
- displayName: string;
16
- };
17
- export declare const useAccordionsContext: () => AccordionsContextType;
@@ -1,9 +0,0 @@
1
- "use client";
2
- import { use, createContext } from "react";
3
- export const AccordionsContext = Object.assign(createContext(undefined), { displayName: "AccordionsContext" });
4
- export const useAccordionsContext = () => {
5
- const context = use(AccordionsContext);
6
- if (context)
7
- return context;
8
- throw new Error("AccordionsContext is not defined!!");
9
- };
@@ -1,8 +0,0 @@
1
- import type { AsPropsTypes } from "../../types";
2
- type PropsTypes<T extends React.ElementType = "div"> = AsPropsTypes<T, {
3
- as?: React.ElementType;
4
- children?: React.ReactNode;
5
- }>;
6
- declare const AccordionsHeaderBase: <T extends React.ElementType = "div">(props: PropsTypes<T>) => import("react/jsx-runtime").JSX.Element;
7
- declare const AccordionsHeader: React.MemoExoticComponent<typeof AccordionsHeaderBase>;
8
- export default AccordionsHeader;
@@ -1,13 +0,0 @@
1
- "use client";
2
- import { jsx as _jsx } from "react/jsx-runtime";
3
- import { memo } from "react";
4
- import { useAccordionsContext } from "./accordionsContext";
5
- const AccordionsHeaderBase = (props) => {
6
- const { as, children, ...othersProps } = props;
7
- const RootComponent = as || "div";
8
- const { setExtandHandler } = useAccordionsContext();
9
- return (_jsx(RootComponent, { ...othersProps, onClick: setExtandHandler, children: children }));
10
- };
11
- const AccordionsHeader = memo(AccordionsHeaderBase);
12
- AccordionsHeader.displayName = "AccordionsHeader";
13
- export default AccordionsHeader;
@@ -1,4 +0,0 @@
1
- export { default as Accordions } from "./accordions";
2
- export { default as AccordionsContent } from "./accordionsContent";
3
- export { default as AccordionsHeader } from "./accordionsHeader";
4
- export { default as AccordionsButton } from "./accordionsButton";
@@ -1,5 +0,0 @@
1
- export { default as Accordions } from "./accordions";
2
- export { default as AccordionsContent } from "./accordionsContent";
3
- export { default as AccordionsHeader } from "./accordionsHeader";
4
- export { default as AccordionsButton } from "./accordionsButton";
5
- // export { default as Accordions } from "./accordions";
@@ -1,17 +0,0 @@
1
- import { DragResizePropsTypes, ResizeTypes } from "../../hooks";
2
- import { AsPropsTypes } from "../../types";
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
- containerClass?: string;
10
- dragClass?: string;
11
- resizeStore?: boolean;
12
- resizeStoreKey?: string;
13
- resizeStoreValue?: ResizeTypes;
14
- } & DragResizePropsTypes>;
15
- declare const DragResizeBase: <T extends React.ElementType = "div">(props: PropsTypes<T>) => import("react/jsx-runtime").JSX.Element;
16
- declare const DragResize: React.MemoExoticComponent<typeof DragResizeBase>;
17
- export default DragResize;
@@ -1,74 +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";
5
- import { DragResizeContext } from "./dragResizeContext";
6
- import { mergeClassName } from "../../utils";
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, 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 })] }) }));
71
- };
72
- const DragResize = memo(DragResizeBase);
73
- DragResize.displayName = "DragResize";
74
- export default DragResize;
@@ -1,10 +0,0 @@
1
- import React from "react";
2
- export interface DragResizeContextType {
3
- setResizeActive: (active: boolean) => void;
4
- clearResizeStore: () => void;
5
- defaultResizeSize: () => void;
6
- }
7
- export declare const DragResizeContext: React.Context<DragResizeContextType | undefined> & {
8
- displayName: string;
9
- };
10
- export declare const useDragResizeContext: () => DragResizeContextType;
@@ -1,9 +0,0 @@
1
- "use client";
2
- import { use, createContext, } from "react";
3
- export const DragResizeContext = Object.assign(createContext(undefined), { displayName: "DragResizeContext" });
4
- export const useDragResizeContext = () => {
5
- const context = use(DragResizeContext);
6
- if (context)
7
- return context;
8
- throw new Error("DragResizeContext is not defined!!");
9
- };
@@ -1,2 +0,0 @@
1
- export { default as DragResize } from "./dragResize";
2
- export * from "./dragResizeContext";
@@ -1,2 +0,0 @@
1
- export { default as DragResize } from "./dragResize";
2
- export * from "./dragResizeContext";
@@ -1,19 +0,0 @@
1
- import type { Sortable, Store } from "react-sortablejs";
2
- import type { AsPropsTypes } from "../../types";
3
- type PropsTypes<T extends React.ElementType = "div"> = AsPropsTypes<T, {
4
- as?: string;
5
- children: React.ReactNode;
6
- datasets: any[];
7
- rootClass?: string;
8
- sorterClass?: string;
9
- handlerClass?: string;
10
- style?: React.CSSProperties;
11
- disabled?: boolean;
12
- animation?: number;
13
- onChange?: (newState: any[], sortable: Sortable | null, store: Store) => void;
14
- onStart?: ((evt: Sortable.SortableEvent, sortable: Sortable | null, store: Store) => void) | undefined;
15
- onEnd?: ((evt: Sortable.SortableEvent, sortable: Sortable | null, store: Store) => void) | undefined;
16
- }>;
17
- declare const DragSortableBase: <T extends React.ElementType = "div">(props: PropsTypes<T>) => import("react/jsx-runtime").JSX.Element;
18
- declare const DragSortable: React.MemoExoticComponent<typeof DragSortableBase>;
19
- export default DragSortable;
@@ -1,11 +0,0 @@
1
- "use client";
2
- import { jsx as _jsx } from "react/jsx-runtime";
3
- import { memo } from "react";
4
- import { ReactSortable } from "react-sortablejs";
5
- const DragSortableBase = (props) => {
6
- const { as, children, datasets = [], rootClass, sorterClass, handlerClass, style, animation = 150, disabled = false, onChange, onStart, onEnd, ...othersProps } = props;
7
- return (_jsx(ReactSortable, { ...othersProps, tag: as, disabled: disabled, className: rootClass, ghostClass: sorterClass, handle: "." + handlerClass, fallbackClass: "sortable-fallback", list: datasets, setList: onChange, animation: animation, style: style, onStart: onStart, onEnd: onEnd, children: children }));
8
- };
9
- const DragSortable = memo(DragSortableBase);
10
- DragSortable.displayName = "DragSortable";
11
- export default DragSortable;
@@ -1 +0,0 @@
1
- export { default as DragSortable } from "./dragSortable";
@@ -1 +0,0 @@
1
- export { default as DragSortable } from "./dragSortable";
@@ -1,4 +0,0 @@
1
- export * from "./myComponents";
2
- export * from "./accordions";
3
- export * from "./dragResize";
4
- export * from "./dragSortable";
@@ -1,4 +0,0 @@
1
- export * from "./myComponents";
2
- export * from "./accordions";
3
- export * from "./dragResize";
4
- export * from "./dragSortable";
@@ -1,2 +0,0 @@
1
- declare const MyComponent: () => import("react/jsx-runtime").JSX.Element;
2
- export default MyComponent;
@@ -1,4 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import styles from './MyComponent.module.scss';
3
- const MyComponent = () => (_jsx("div", { className: styles.container, children: "Hello World" }));
4
- export default MyComponent;
@@ -1 +0,0 @@
1
- export { default as MyComponent } from './MyComponent';
@@ -1 +0,0 @@
1
- export { default as MyComponent } from './MyComponent';
@@ -1,5 +0,0 @@
1
- export * from "./useDebounce";
2
- export * from "./useDebounceValue";
3
- export * from "./useCookies";
4
- export * from "./useDragResize";
5
- export * from "./useAsyncFetcher";
@@ -1,5 +0,0 @@
1
- export * from "./useDebounce";
2
- export * from "./useDebounceValue";
3
- export * from "./useCookies";
4
- export * from "./useDragResize";
5
- export * from "./useAsyncFetcher";
@@ -1,11 +0,0 @@
1
- type ReturnDatasTypes = {
2
- fetcher: (payload: PayloadTypes) => Promise<any>;
3
- cancel: () => void;
4
- pending: boolean;
5
- };
6
- interface PayloadTypes {
7
- url: string | URL | globalThis.Request;
8
- options?: RequestInit;
9
- }
10
- export declare function useAsyncFetcher(): ReturnDatasTypes;
11
- export {};
@@ -1,40 +0,0 @@
1
- "use client";
2
- import { useRef, useState, useEffect, useCallback } from "react";
3
- export function useAsyncFetcher() {
4
- const [isPending, setPending] = useState(false);
5
- const controllerRef = useRef(null);
6
- const startFetch = useCallback(async ({ url, options }) => {
7
- if (isPending || !url)
8
- return;
9
- const controller = new AbortController();
10
- controllerRef.current = controller;
11
- setPending(true);
12
- try {
13
- const response = await fetch(url, {
14
- signal: controller.signal,
15
- ...options,
16
- });
17
- const datas = await response.json();
18
- return datas;
19
- }
20
- catch (error) {
21
- console.error("useAsyncFetche startFetch error:", error);
22
- return { status: false, error: error };
23
- }
24
- finally {
25
- setPending(false);
26
- }
27
- }, [isPending]);
28
- const cancelFetch = () => {
29
- controllerRef.current?.abort();
30
- setPending(false);
31
- };
32
- useEffect(() => {
33
- return () => controllerRef.current?.abort();
34
- }, []);
35
- return {
36
- pending: isPending,
37
- cancel: cancelFetch,
38
- fetcher: startFetch
39
- };
40
- }
@@ -1,6 +0,0 @@
1
- export declare function useCookies(): {
2
- setCookies: (name: string, value: string, days?: number) => void;
3
- getCookies: (name: string) => string | null;
4
- updateCookies: (name: string, value: string, days?: number) => false | void;
5
- deleteCookies: (name: string) => void;
6
- };
@@ -1,24 +0,0 @@
1
- "use client";
2
- //wade 2024.12.06
3
- export function useCookies() {
4
- const setCookies = (name, value, days = 7) => {
5
- const date = new Date();
6
- date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
7
- const expires = `expires=${date.toUTCString()}`;
8
- document.cookie = `${name}=${encodeURIComponent(value)}; ${expires}; path=/`;
9
- };
10
- const getCookies = (name) => {
11
- const cookies = document.cookie.split("; ");
12
- for (const cookie of cookies) {
13
- const [key, value] = cookie.split("=");
14
- if (key === name)
15
- return decodeURIComponent(value);
16
- }
17
- return null; // 如果找不到,返回 null
18
- };
19
- const updateCookies = (name, value, days = 7) => getCookies(name) !== null && setCookies(name, value, days);
20
- const deleteCookies = (name) => {
21
- document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/`;
22
- };
23
- return { setCookies, getCookies, updateCookies, deleteCookies };
24
- }
@@ -1,7 +0,0 @@
1
- export interface DebounceTypes {
2
- callback: () => any;
3
- dependency: any[];
4
- delay?: number;
5
- active?: boolean;
6
- }
7
- export declare function useDebounce({ callback, dependency, delay, active, }: DebounceTypes): void;
@@ -1,16 +0,0 @@
1
- "use client";
2
- import { useEffect, useRef } from "react";
3
- export function useDebounce({ callback, dependency = [], delay = 500, active = true, }) {
4
- if (!active || !callback)
5
- return;
6
- const timerRef = useRef(null);
7
- useEffect(() => {
8
- if (timerRef.current)
9
- clearTimeout(timerRef.current);
10
- timerRef.current = setTimeout(callback, delay);
11
- return () => {
12
- if (timerRef.current)
13
- clearTimeout(timerRef.current);
14
- };
15
- }, [...dependency]);
16
- }
@@ -1 +0,0 @@
1
- export declare function useDebounceValue<T>(value: T, delay?: number): T;
@@ -1,17 +0,0 @@
1
- "use client";
2
- import { useEffect, useRef, useState } from "react";
3
- export function useDebounceValue(value, delay = 500) {
4
- const [debounceValue, setDebounceValue] = useState(value);
5
- const timerRef = useRef(undefined);
6
- useEffect(() => {
7
- if (timerRef.current)
8
- clearTimeout(timerRef.current);
9
- timerRef.current = setTimeout(() => setDebounceValue(value), delay);
10
- return () => {
11
- if (timerRef.current)
12
- clearTimeout(timerRef.current);
13
- };
14
- }, [value, delay]);
15
- return debounceValue;
16
- }
17
- ;
@@ -1,19 +0,0 @@
1
- export interface ResizeTypes {
2
- width?: number | string;
3
- height?: number | string;
4
- }
5
- export interface DragResizePropsTypes {
6
- active?: boolean;
7
- direction?: "width" | "height";
8
- minWidth?: number;
9
- maxWidth?: number;
10
- onInit?: (size: ResizeTypes) => void;
11
- onResizeStart?: (size: ResizeTypes) => void;
12
- onResizing?: (size: ResizeTypes) => void;
13
- onResizeEnd?: (size: ResizeTypes) => void;
14
- }
15
- export type DragResizeTypes = {
16
- dragRef: React.RefObject<HTMLDivElement | null>;
17
- resizeRef: React.RefObject<HTMLDivElement | null>;
18
- };
19
- export declare function useDragResize({ active, direction, minWidth, maxWidth, onInit, onResizeStart, onResizing, onResizeEnd }: DragResizePropsTypes): DragResizeTypes;
@@ -1,63 +0,0 @@
1
- "use client";
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 }) {
5
- const dragRef = useRef(null);
6
- const resizeRef = useRef(null);
7
- const getResizeSizeValue = () => {
8
- if (!resizeRef.current)
9
- return;
10
- const { width: w, height: h } = resizeRef.current.style;
11
- const width = Number(w.replace("px", "")) ?? "inherit";
12
- const height = Number(h.replace("px", "")) ?? "inherit";
13
- return { width };
14
- };
15
- const setResizeValue = (clientX, clientY) => {
16
- if (!resizeRef.current)
17
- return;
18
- const rect = resizeRef.current.getBoundingClientRect();
19
- const resizeWidth = clientX - rect.left;
20
- const resizeHeight = clientY - rect.top;
21
- if (resizeWidth <= minWidth || resizeWidth >= maxWidth)
22
- return;
23
- resizeRef.current.style.width = resizeWidth + "px";
24
- return { width: resizeWidth };
25
- };
26
- const onInitCallback = () => {
27
- const resizeValue = getResizeSizeValue();
28
- resizeValue && onInit?.(resizeValue);
29
- };
30
- const removeEventListeners = () => {
31
- document.removeEventListener("mousemove", onMouseMove);
32
- document.removeEventListener("mouseup", onMouseUp);
33
- };
34
- const onMouseMove = (e) => {
35
- const resizeValue = setResizeValue(e.clientX, e.clientY);
36
- resizeValue && onResizing?.(resizeValue);
37
- };
38
- const onMouseUp = () => {
39
- const resizeValue = getResizeSizeValue();
40
- resizeValue && onResizeEnd?.(resizeValue);
41
- removeEventListeners();
42
- };
43
- const onDragRefMouseDown = (e) => {
44
- e.preventDefault();
45
- const resizeValue = getResizeSizeValue();
46
- resizeValue && onResizeStart?.(resizeValue);
47
- document.addEventListener("mousemove", onMouseMove);
48
- document.addEventListener("mouseup", onMouseUp);
49
- };
50
- useEffect(() => {
51
- if (active && dragRef.current && resizeRef.current) {
52
- dragRef.current.onmousedown = onDragRefMouseDown;
53
- onInit && onInitCallback();
54
- }
55
- return () => {
56
- if (!dragRef?.current)
57
- return;
58
- dragRef.current.onmousedown = null;
59
- removeEventListeners();
60
- };
61
- }, [active]);
62
- return { dragRef, resizeRef };
63
- }
package/dist/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export * from "./components";
2
- export * from "./hooks";
3
- export * from "./utils";
4
- export * from "./types";
package/dist/index.js DELETED
@@ -1,4 +0,0 @@
1
- export * from "./components";
2
- export * from "./hooks";
3
- export * from "./utils";
4
- export * from "./types";
@@ -1,27 +0,0 @@
1
- export type SitesTypes = {
2
- id: number | string;
3
- index: string;
4
- name: string;
5
- route: string;
6
- sites: SitesLagnuageTypes[];
7
- };
8
- export type SitesLagnuageTypes = {
9
- id: number | string;
10
- index: string;
11
- name: string;
12
- route: string;
13
- };
14
- export type SitesNavsMenusTypes = {
15
- id: number | string;
16
- index: string;
17
- name: string;
18
- route: string;
19
- navs: SitesNavsTypes[];
20
- active?: boolean;
21
- };
22
- export type SitesNavsTypes = {
23
- id: number | string;
24
- index: string;
25
- name: string;
26
- route: string;
27
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,16 +0,0 @@
1
- export type ParamsTypes = {
2
- sites?: string;
3
- units?: string;
4
- contents?: string;
5
- };
6
- export type SearchParamsTypes = {
7
- [key: string]: string | string[] | undefined;
8
- };
9
- export type CacheTypes = number | false | undefined;
10
- export type PermissionTypes = "read" | "edit" | "create";
11
- export type ConfirmEndTypes = "REMOTE" | "LOCAL";
12
- export type DatasetsEndTypes = "REMOTE" | "LOCAL";
13
- export type ReduceBaseActionTypes<S, T extends keyof S, P = S[T]> = {
14
- type: T;
15
- payload: P;
16
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,9 +0,0 @@
1
- type AsTypes<T extends React.ElementType = "div"> = {
2
- as?: T;
3
- };
4
- type AsPropsToOmit<T extends React.ElementType, P> = keyof (AsTypes<T> & P);
5
- export type AsPropsTypes<T extends React.ElementType, P = {}> = P & AsTypes<T> & Omit<React.ComponentPropsWithoutRef<T>, AsPropsToOmit<T, P>>;
6
- export type SlotsPropsTypes = {
7
- [key: number]: string;
8
- };
9
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,4 +0,0 @@
1
- export * from "./commons.type";
2
- export * from "./components.type";
3
- export * from "./utils.type";
4
- export * from "./cms.type";
@@ -1,4 +0,0 @@
1
- export * from "./commons.type";
2
- export * from "./components.type";
3
- export * from "./utils.type";
4
- export * from "./cms.type";
@@ -1 +0,0 @@
1
- export type MergeAll<M> = M[keyof M];
@@ -1 +0,0 @@
1
- export {};
@@ -1,13 +0,0 @@
1
- export declare const regexParse: (regexString: string, flags?: string) => RegExp | String;
2
- export declare const regexReplaceEach: (currentValue: string, replace: {
3
- pattern: string;
4
- flags?: string;
5
- }[]) => string;
6
- export declare const mediaRatio: (width: number, height: number) => string;
7
- export declare const sleep: (time: number) => Promise<void>;
8
- export declare const querySearchWord: (str: string) => string;
9
- export declare const lockBody: (active: boolean, stillScrollHTMLElement?: HTMLElement | HTMLElement[] | null | undefined) => void;
10
- export declare const mergeClassName: (...argements: (string | number | boolean)[]) => string;
11
- export declare const getSearchParams: (searchParams: URLSearchParams) => any;
12
- export declare const getDomTransTime: (target: HTMLElement) => number;
13
- export declare const getURLSearchParams: (searchParams: URLSearchParams) => URLSearchParams;
@@ -1,55 +0,0 @@
1
- import { lock, clearBodyLocks } from "tua-body-scroll-lock";
2
- export const regexParse = (regexString, flags) => {
3
- const regex = regexString.replace(/\\\\/g, "\\");
4
- try {
5
- return new RegExp(regex);
6
- }
7
- catch (e) {
8
- console.error("Invalid regular expression:", regexString, e);
9
- return regexString;
10
- }
11
- };
12
- export const regexReplaceEach = (currentValue, replace) => replace.reduce((current, regexs) => {
13
- const regexPattern = regexParse(regexs.pattern, regexs.flags);
14
- return regexPattern instanceof RegExp
15
- ? current.replace(regexPattern, "")
16
- : current;
17
- }, currentValue);
18
- export const mediaRatio = (width, height) => Number(width) && Number(height)
19
- ? Math.round(height / width * 10000) / 100 + "%"
20
- : "100%";
21
- export const sleep = (time) => new Promise((resolve) => {
22
- let timer = setTimeout(() => {
23
- clearTimeout(timer);
24
- return resolve();
25
- }, time);
26
- });
27
- export const querySearchWord = (str) => str.trim().toLowerCase();
28
- export const lockBody = (active, stillScrollHTMLElement) => {
29
- document.body.style.overflow = active ? "visible" : "";
30
- active ? lock(stillScrollHTMLElement) : clearBodyLocks();
31
- };
32
- export const mergeClassName = (...argements) => argements.toString().replace(/,/g, " ").replace(/\s+/g, " ").trim();
33
- export const getSearchParams = (searchParams) => {
34
- const params = {};
35
- searchParams.forEach((value, key) => { params[key] = value; });
36
- return params;
37
- };
38
- export const getDomTransTime = (target) => {
39
- const computedStyle = window.getComputedStyle(target);
40
- const transNumber = (time) => {
41
- if (time.endsWith("ms"))
42
- return parseFloat(time);
43
- if (time.endsWith("s"))
44
- return parseFloat(time) * 1000;
45
- return 0;
46
- };
47
- const durations = computedStyle.transitionDuration.split(',').map(transNumber);
48
- const delays = computedStyle.transitionDelay.split(',').map(transNumber);
49
- return Math.max(...durations.map((d, i) => d + (delays[i] || 0)));
50
- };
51
- export const getURLSearchParams = (searchParams) => {
52
- const params = {};
53
- searchParams.forEach((value, key) => { params[key] = value; });
54
- return new URLSearchParams({ ...params });
55
- };