@tiny-codes/react-easy 1.4.16 → 1.4.18

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/CHANGELOG.md CHANGED
@@ -2,6 +2,26 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ## 1.4.18
6
+
7
+ 2025-9-23
8
+
9
+ ### Features
10
+
11
+ #### `FloatDrawer`
12
+
13
+ - ✨ add `destroyOnClose` prop to control whether to destroy the drawer content when closed
14
+
15
+ ## 1.4.17
16
+
17
+ 2025-9-23
18
+
19
+ ### Features
20
+
21
+ #### `useDebounce`
22
+
23
+ - ✨ enhance `useDebounce` with `cancel`, `disable`, `enable`, and `isDisabled` methods
24
+
5
25
  ## 1.4.16
6
26
 
7
27
  2025-9-18
@@ -60,6 +60,11 @@ export interface FloatDrawerProps {
60
60
  * - **CN:** 抽屉是否可调整大小, 默认`true`。
61
61
  */
62
62
  resizable?: boolean;
63
+ /**
64
+ * - **EN:** Whether to destroy the drawer content when closed, default is `false`.
65
+ * - **CN:** 抽屉关闭时是否销毁内容,默认`false`。
66
+ */
67
+ destroyOnClose?: boolean;
63
68
  /**
64
69
  * - **EN:** Cache key for storing the drawer size in localStorage. If not set, the size will not be
65
70
  * cached.
@@ -44,6 +44,8 @@ var FloatDrawer = function FloatDrawer(props) {
44
44
  showToggle = _props$showToggle === void 0 ? true : _props$showToggle,
45
45
  _props$resizable = props.resizable,
46
46
  resizable = _props$resizable === void 0 ? true : _props$resizable,
47
+ _props$destroyOnClose = props.destroyOnClose,
48
+ destroyOnClose = _props$destroyOnClose === void 0 ? false : _props$destroyOnClose,
47
49
  onOpenChange = props.onOpenChange,
48
50
  onResize = props.onResize,
49
51
  onClick = props.onClick;
@@ -179,7 +181,7 @@ var FloatDrawer = function FloatDrawer(props) {
179
181
  className: classNames("".concat(prefixCls, "-card"), classNamesInProps === null || classNamesInProps === void 0 ? void 0 : classNamesInProps.card),
180
182
  style: styles === null || styles === void 0 ? void 0 : styles.card
181
183
  }, cardProps), {}, {
182
- children: children
184
+ children: !destroyOnClose || isOpen ? children : null
183
185
  }))
184
186
  }), showToggle && /*#__PURE__*/_jsx("div", {
185
187
  className: classNames("".concat(prefixCls, "-toggle"), classNamesInProps === null || classNamesInProps === void 0 ? void 0 : classNamesInProps.toggle),
@@ -1 +1 @@
1
- {"version":3,"names":["useContext","useEffect","useMemo","useRef","useState","Card","ConfigProvider","classNames","DownOutlined","LeftOutlined","RightOutlined","UpOutlined","useRefFunction","useStyle","jsx","_jsx","jsxs","_jsxs","FloatDrawer","props","prefixClsInProps","prefixCls","open","_props$position","position","cardProps","children","className","classNamesInProps","style","styles","cacheKey","defaultSize","_props$minSize","minSize","_props$maxSize","maxSize","Infinity","edgeOffset","_props$showToggle","showToggle","_props$resizable","resizable","onOpenChange","onResize","onClick","_useContext","ConfigContext","getPrefixCls","_useStyle","_useStyle2","_slicedToArray","wrapCSSVar","hashId","cssVarCls","_useState","_useState2","drawerRef","setDrawerRef","_useState3","localStorage","getItem","Number","_useState4","size","setSize","sizeMap","type","_defineProperty","_useState5","_useState6","isOpen","setIsOpen","_useState7","_useState8","isDragging","setIsDragging","dragStartPos","dragStartSize","classString","concat","closeIcon","openIcon","toggleDrawer","handleResizeStart","e","current","clientY","clientX","preventDefault","handleResize","newSize","setItem","String","handleResizeEnd","undefined","rect","getBoundingClientRect","width","height","window","addEventListener","removeEventListener","_objectSpread","ref","drawer","resizeHandle","onMouseDown","content","bordered","variant","card","toggle","handleIcon"],"sources":["../../../src/components/FloatDrawer/index.tsx"],"sourcesContent":["import type { CSSProperties, FC, ReactNode } from 'react';\nimport { useContext, useEffect, useMemo, useRef, useState } from 'react';\nimport type { CardProps } from 'antd';\nimport { Card, ConfigProvider } from 'antd';\nimport classNames from 'classnames';\nimport { DownOutlined, LeftOutlined, RightOutlined, UpOutlined } from '@ant-design/icons';\nimport useRefFunction from '../../hooks/useRefFunction';\nimport useStyle from './style';\n\nexport interface FloatDrawerProps {\n prefixCls?: string;\n /**\n * - **EN:** Whether the drawer is open\n * - **CN:** 抽屉是否打开\n */\n open?: boolean;\n /**\n * - **EN:** Position of the drawer\n * - **CN:** 抽屉的位置\n *\n * @default 'right'\n */\n position?: 'left' | 'right' | 'top' | 'bottom';\n /**\n * - **EN:** Default size of the drawer. If the drawer is placed on the left or right, this is the\n * width, otherwise it is the height. If not set, the drawer will adapt to the content size.\n * - **CN:** 抽屉的默认宽度。如果抽屉放在左侧或右侧,则为宽度,否则为高度。不设置时,抽屉会根据内容自适应大小。\n */\n defaultSize?: number;\n /**\n * - **EN:** Minimum size of the drawer\n * - **CN:** 抽屉的最小宽度\n *\n * @default 0\n */\n minSize?: number;\n /**\n * - **EN:** Maximum size of the drawer\n * - **CN:** 抽屉的最大宽度\n *\n * @default Infinity\n */\n maxSize?: number;\n /**\n * - **EN:** Offset of the drawer from the edge of the screen, supports all CSS length units,\n * default is `0`.\n *\n * > The drawer will be hidden outside the parent container's edge, but since the parent container\n * > may have padding or border, the drawer may not be completely hidden. You can adjust the\n * > `edgeOffset` to ensure the drawer is completely hidden outside the parent container.\n *\n * - **CN:** 抽屉距离屏幕边缘的偏移量,支持所有的CSS长度单位, 默认`0`。\n *\n * > 抽屉会隐藏在父容器的外边缘, 但由于父容器可能有padding或border, 导致抽屉不能完全隐藏, 因此可以通过设置 `edgeOffset` 来调整抽屉的偏移量,\n * > 以确保抽屉完全隐藏在父容器之外。\n *\n * @default 0\n */\n edgeOffset?: CSSProperties['width'];\n /**\n * - **EN:** Whether to show the toggle button, default is `true`.\n * - **CN:** 是否显示展开/收起按钮,默认`true`。\n */\n showToggle?: boolean;\n /**\n * - **EN:** Whether the drawer is resizable, default is `true`.\n * - **CN:** 抽屉是否可调整大小, 默认`true`。\n */\n resizable?: boolean;\n /**\n * - **EN:** Cache key for storing the drawer size in localStorage. If not set, the size will not be\n * cached.\n * - **CN:** 指定一个localStorage缓存键,用于记忆抽屉宽度。如果不设置,则不使用缓存。\n */\n cacheKey?: string;\n /**\n * - **EN:** Custom class name for the root element\n * - **CN:** 根元素的自定义类名\n */\n className?: string;\n /**\n * - **EN:** Custom class names for specific elements\n * - **CN:** 特定元素的自定义类名\n */\n classNames?: {\n /**\n * - **EN:** Class name for the drawer element\n * - **CN:** 抽屉元素的类名\n */\n drawer?: string;\n /**\n * - **EN:** Class name for the expand handle\n * - **CN:** 展开手柄的类名\n */\n toggle?: string;\n /**\n * - **EN:** Class name for the resize handle\n * - **CN:** 调整大小手柄的类名\n */\n resizeHandle?: string;\n /**\n * - **EN:** Class name for the handle icon\n * - **CN:** 手柄图标的类名\n */\n handleIcon?: string;\n /**\n * - **EN:** Class name for the content area\n * - **CN:** 内容区域的类名\n */\n content?: string;\n /**\n * - **EN:** Class name for the card element\n * - **CN:** 卡片元素的类名\n */\n card?: string;\n };\n /**\n * - **EN:** Custom styles for the root element\n * - **CN:** 根元素的自定义样式\n */\n style?: CSSProperties;\n /**\n * - **EN:** Custom styles for specific elements\n * - **CN:** 特定元素的自定义样式\n */\n styles?: {\n /**\n * - **EN:** Styles for the drawer element\n * - **CN:** 抽屉元素的样式\n */\n drawer?: CSSProperties;\n /**\n * - **EN:** Styles for the expand handle\n * - **CN:** 展开手柄的样式\n */\n toggle?: CSSProperties;\n /**\n * - **EN:** Styles for the resize handle\n * - **CN:** 调整大小手柄的样式\n */\n resizeHandle?: CSSProperties;\n /**\n * - **EN:** Styles for the handle icon\n * - **CN:** 手柄图标的样式\n */\n handleIcon?: CSSProperties;\n /**\n * - **EN:** Styles for the content area\n * - **CN:** 内容区域的样式\n */\n content?: CSSProperties;\n /**\n * - **EN:** Styles for the card element\n * - **CN:** 卡片元素的样式\n */\n card?: CSSProperties;\n };\n /**\n * - **EN:** Custom properties for the card element\n * - **CN:** 卡片元素的自定义属性\n */\n cardProps?: Omit<CardProps, 'children'>;\n /**\n * - **EN:** Content to be rendered inside the drawer\n * - **CN:** 抽屉内容\n */\n children?: ReactNode;\n /**\n * - **EN:** Callback function when the open state changes\n * - **CN:** 打开状态变化时的回调函数\n */\n onOpenChange?: (open: boolean) => void;\n /**\n * - **EN:** Callback function when the drawer is resized\n * - **CN:** 抽屉调整大小时的回调函数\n */\n onResize?: (size: number) => void;\n /**\n * - **EN:** Event handler for click events on the drawer container and its internal elements\n * - **CN:** 点击抽屉容器及内部元素时的事件\n */\n onClick?: (e: React.MouseEvent<HTMLDivElement>) => void;\n}\n\n/**\n * - **EN:** FloatDrawer component for creating a draggable, resizable drawer\n * - **CN:** FloatDrawer组件,用于创建可拖动、可调整大小的抽屉\n */\nconst FloatDrawer: FC<FloatDrawerProps> = (props) => {\n const {\n prefixCls: prefixClsInProps,\n open,\n position = 'right',\n cardProps,\n children,\n className,\n classNames: classNamesInProps,\n style,\n styles,\n cacheKey,\n defaultSize,\n minSize = 0,\n maxSize = +Infinity,\n edgeOffset,\n showToggle = true,\n resizable = true,\n onOpenChange,\n onResize,\n onClick,\n } = props;\n const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);\n const prefixCls = getPrefixCls('easy-float-drawer', prefixClsInProps);\n const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls);\n const [drawerRef, setDrawerRef] = useState<HTMLDivElement | null>(null);\n const [size, setSize] = useState(\n cacheKey && localStorage.getItem(cacheKey) ? Number(localStorage.getItem(cacheKey)) || defaultSize : defaultSize\n );\n const sizeMap = useMemo(() => {\n const type = position === 'left' || position === 'right' ? 'width' : 'height';\n return {\n [type]: size,\n };\n }, [position, size]);\n const [isOpen, setIsOpen] = useState<boolean>();\n const [isDragging, setIsDragging] = useState(false);\n const dragStartPos = useRef<number>(0);\n const dragStartSize = useRef<number>(size);\n const classString = classNames(\n prefixCls,\n className,\n {\n [`${prefixCls}-open`]: isOpen,\n [`${prefixCls}-closed`]: !isOpen,\n [`${prefixCls}-${position}`]: position,\n },\n hashId,\n cssVarCls\n );\n const closeIcon = useMemo(() => {\n return position === 'left' ? (\n <RightOutlined />\n ) : position === 'top' ? (\n <DownOutlined />\n ) : position === 'bottom' ? (\n <UpOutlined />\n ) : (\n <LeftOutlined />\n );\n }, [position]);\n const openIcon = useMemo(() => {\n return position === 'left' ? (\n <LeftOutlined />\n ) : position === 'top' ? (\n <UpOutlined />\n ) : position === 'bottom' ? (\n <DownOutlined />\n ) : (\n <RightOutlined />\n );\n }, [position]);\n\n // Handle drawer visibility\n const toggleDrawer = () => {\n setIsOpen(!isOpen);\n onOpenChange?.(!isOpen);\n };\n\n // Handle resize events\n const handleResizeStart = useRefFunction((e: React.MouseEvent) => {\n setIsDragging(true);\n if (position === 'top' || position === 'bottom') {\n dragStartPos.current = e.clientY;\n } else {\n dragStartPos.current = e.clientX;\n }\n dragStartSize.current = size;\n e.preventDefault();\n });\n const handleResize = useRefFunction((e: MouseEvent) => {\n if (isDragging && dragStartSize.current) {\n let newSize: number;\n if (position === 'left') {\n newSize = dragStartSize.current - (dragStartPos.current - e.clientX);\n } else if (position === 'top') {\n newSize = dragStartSize.current - (dragStartPos.current - e.clientY);\n } else if (position === 'bottom') {\n newSize = dragStartSize.current - (e.clientY - dragStartPos.current);\n } else {\n newSize = dragStartSize.current - (e.clientX - dragStartPos.current);\n }\n if (newSize >= minSize && newSize <= maxSize) {\n setSize(newSize);\n if (cacheKey) {\n localStorage.setItem(cacheKey, String(newSize));\n }\n onResize?.(newSize);\n }\n }\n });\n const handleResizeEnd = useRefFunction(() => {\n setIsDragging(false);\n });\n\n // Monitor drawer ref, calculate size if not set\n // This is useful for initial rendering when size is not provided\n useEffect(() => {\n if (drawerRef && size === undefined) {\n const rect = drawerRef.getBoundingClientRect();\n setSize(position === 'left' || position === 'right' ? rect.width : rect.height);\n }\n }, [drawerRef, position, size]);\n\n // Controlled open state\n useEffect(() => {\n setIsOpen(open);\n }, [open]);\n\n // Handle global events\n useEffect(() => {\n if (isDragging) {\n window.addEventListener('mousemove', handleResize);\n window.addEventListener('mouseup', handleResizeEnd);\n } else {\n window.removeEventListener('mousemove', handleResize);\n window.removeEventListener('mouseup', handleResizeEnd);\n }\n return () => {\n window.removeEventListener('mousemove', handleResize);\n window.removeEventListener('mouseup', handleResizeEnd);\n };\n }, [isDragging]);\n\n return wrapCSSVar(\n <div\n className={classString}\n style={{\n // @ts-expect-error: because of dynamic CSS variables\n '--edge-offset': typeof edgeOffset === 'number' ? `${edgeOffset}px` : edgeOffset,\n ...style,\n }}\n onClick={onClick}\n >\n <div\n ref={setDrawerRef}\n className={classNames(`${prefixCls}-drawer`, classNamesInProps?.drawer)}\n style={{ ...sizeMap, ...styles?.drawer }}\n >\n {resizable && (\n <div\n className={classNames(\n `${prefixCls}-resize-handle`,\n isDragging && `${prefixCls}-resize-handle-dragging`,\n classNamesInProps?.resizeHandle\n )}\n style={styles?.resizeHandle}\n onMouseDown={handleResizeStart}\n />\n )}\n <div className={classNames(`${prefixCls}-content`, classNamesInProps?.content)} style={styles?.content}>\n <Card\n bordered={false}\n variant=\"borderless\"\n className={classNames(`${prefixCls}-card`, classNamesInProps?.card)}\n style={styles?.card}\n {...cardProps}\n >\n {children}\n </Card>\n </div>\n {showToggle && (\n <div\n className={classNames(`${prefixCls}-toggle`, classNamesInProps?.toggle)}\n style={styles?.toggle}\n onClick={toggleDrawer}\n >\n <div\n className={classNames(`${prefixCls}-handle-icon`, classNamesInProps?.handleIcon)}\n style={styles?.handleIcon}\n >\n {isOpen ? openIcon : closeIcon}\n </div>\n </div>\n )}\n </div>\n </div>\n );\n};\n\nexport default FloatDrawer;\n"],"mappings":";;;;;;;;;;;;AACA,SAASA,UAAU,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAExE,SAASC,IAAI,EAAEC,cAAc,QAAQ,MAAM;AAC3C,OAAOC,UAAU,MAAM,YAAY;AACnC,SAASC,YAAY,EAAEC,YAAY,EAAEC,aAAa,EAAEC,UAAU,QAAQ,mBAAmB;AACzF,OAAOC,cAAc;AACrB,OAAOC,QAAQ;AAAgB,SAAAC,GAAA,IAAAC,IAAA;AAAA,SAA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,SAAS,EAAEpB,UAAU,IAAAyE,MAAA,CAAI3D,SAAS,YAASO,iBAAiB,aAAjBA,iBAAiB,uBAAjBA,iBAAiB,CAAEmF,IAAI,CAAE;UACpElF,KAAK,EAAEC,MAAM,aAANA,MAAM,uBAANA,MAAM,CAAEiF;QAAK,GAChBtF,SAAS;UAAAC,QAAA,EAEZA;QAAQ,EACL;MAAC,CACJ,CAAC,EACLc,UAAU,iBACTzB,IAAA;QACEY,SAAS,EAAEpB,UAAU,IAAAyE,MAAA,CAAI3D,SAAS,cAAWO,iBAAiB,aAAjBA,iBAAiB,uBAAjBA,iBAAiB,CAAEoF,MAAM,CAAE;QACxEnF,KAAK,EAAEC,MAAM,aAANA,MAAM,uBAANA,MAAM,CAAEkF,MAAO;QACtBnE,OAAO,EAAEsC,YAAa;QAAAzD,QAAA,eAEtBX,IAAA;UACEY,SAAS,EAAEpB,UAAU,IAAAyE,MAAA,CAAI3D,SAAS,mBAAgBO,iBAAiB,aAAjBA,iBAAiB,uBAAjBA,iBAAiB,CAAEqF,UAAU,CAAE;UACjFpF,KAAK,EAAEC,MAAM,aAANA,MAAM,uBAANA,MAAM,CAAEmF,UAAW;UAAAvF,QAAA,EAEzB6C,MAAM,GAAGW,QAAQ,GAAGD;QAAS,CAC3B;MAAC,CACH,CACN;IAAA,CACE;EAAC,CACH,CACP,CAAC;AACH,CAAC;AAED,eAAe/D,WAAW"}
1
+ {"version":3,"names":["useContext","useEffect","useMemo","useRef","useState","Card","ConfigProvider","classNames","DownOutlined","LeftOutlined","RightOutlined","UpOutlined","useRefFunction","useStyle","jsx","_jsx","jsxs","_jsxs","FloatDrawer","props","prefixClsInProps","prefixCls","open","_props$position","position","cardProps","children","className","classNamesInProps","style","styles","cacheKey","defaultSize","_props$minSize","minSize","_props$maxSize","maxSize","Infinity","edgeOffset","_props$showToggle","showToggle","_props$resizable","resizable","_props$destroyOnClose","destroyOnClose","onOpenChange","onResize","onClick","_useContext","ConfigContext","getPrefixCls","_useStyle","_useStyle2","_slicedToArray","wrapCSSVar","hashId","cssVarCls","_useState","_useState2","drawerRef","setDrawerRef","_useState3","localStorage","getItem","Number","_useState4","size","setSize","sizeMap","type","_defineProperty","_useState5","_useState6","isOpen","setIsOpen","_useState7","_useState8","isDragging","setIsDragging","dragStartPos","dragStartSize","classString","concat","closeIcon","openIcon","toggleDrawer","handleResizeStart","e","current","clientY","clientX","preventDefault","handleResize","newSize","setItem","String","handleResizeEnd","undefined","rect","getBoundingClientRect","width","height","window","addEventListener","removeEventListener","_objectSpread","ref","drawer","resizeHandle","onMouseDown","content","bordered","variant","card","toggle","handleIcon"],"sources":["../../../src/components/FloatDrawer/index.tsx"],"sourcesContent":["import type { CSSProperties, FC, ReactNode } from 'react';\nimport { useContext, useEffect, useMemo, useRef, useState } from 'react';\nimport type { CardProps } from 'antd';\nimport { Card, ConfigProvider } from 'antd';\nimport classNames from 'classnames';\nimport { DownOutlined, LeftOutlined, RightOutlined, UpOutlined } from '@ant-design/icons';\nimport useRefFunction from '../../hooks/useRefFunction';\nimport useStyle from './style';\n\nexport interface FloatDrawerProps {\n prefixCls?: string;\n /**\n * - **EN:** Whether the drawer is open\n * - **CN:** 抽屉是否打开\n */\n open?: boolean;\n /**\n * - **EN:** Position of the drawer\n * - **CN:** 抽屉的位置\n *\n * @default 'right'\n */\n position?: 'left' | 'right' | 'top' | 'bottom';\n /**\n * - **EN:** Default size of the drawer. If the drawer is placed on the left or right, this is the\n * width, otherwise it is the height. If not set, the drawer will adapt to the content size.\n * - **CN:** 抽屉的默认宽度。如果抽屉放在左侧或右侧,则为宽度,否则为高度。不设置时,抽屉会根据内容自适应大小。\n */\n defaultSize?: number;\n /**\n * - **EN:** Minimum size of the drawer\n * - **CN:** 抽屉的最小宽度\n *\n * @default 0\n */\n minSize?: number;\n /**\n * - **EN:** Maximum size of the drawer\n * - **CN:** 抽屉的最大宽度\n *\n * @default Infinity\n */\n maxSize?: number;\n /**\n * - **EN:** Offset of the drawer from the edge of the screen, supports all CSS length units,\n * default is `0`.\n *\n * > The drawer will be hidden outside the parent container's edge, but since the parent container\n * > may have padding or border, the drawer may not be completely hidden. You can adjust the\n * > `edgeOffset` to ensure the drawer is completely hidden outside the parent container.\n *\n * - **CN:** 抽屉距离屏幕边缘的偏移量,支持所有的CSS长度单位, 默认`0`。\n *\n * > 抽屉会隐藏在父容器的外边缘, 但由于父容器可能有padding或border, 导致抽屉不能完全隐藏, 因此可以通过设置 `edgeOffset` 来调整抽屉的偏移量,\n * > 以确保抽屉完全隐藏在父容器之外。\n *\n * @default 0\n */\n edgeOffset?: CSSProperties['width'];\n /**\n * - **EN:** Whether to show the toggle button, default is `true`.\n * - **CN:** 是否显示展开/收起按钮,默认`true`。\n */\n showToggle?: boolean;\n /**\n * - **EN:** Whether the drawer is resizable, default is `true`.\n * - **CN:** 抽屉是否可调整大小, 默认`true`。\n */\n resizable?: boolean;\n /**\n * - **EN:** Whether to destroy the drawer content when closed, default is `false`.\n * - **CN:** 抽屉关闭时是否销毁内容,默认`false`。\n */\n destroyOnClose?: boolean;\n /**\n * - **EN:** Cache key for storing the drawer size in localStorage. If not set, the size will not be\n * cached.\n * - **CN:** 指定一个localStorage缓存键,用于记忆抽屉宽度。如果不设置,则不使用缓存。\n */\n cacheKey?: string;\n /**\n * - **EN:** Custom class name for the root element\n * - **CN:** 根元素的自定义类名\n */\n className?: string;\n /**\n * - **EN:** Custom class names for specific elements\n * - **CN:** 特定元素的自定义类名\n */\n classNames?: {\n /**\n * - **EN:** Class name for the drawer element\n * - **CN:** 抽屉元素的类名\n */\n drawer?: string;\n /**\n * - **EN:** Class name for the expand handle\n * - **CN:** 展开手柄的类名\n */\n toggle?: string;\n /**\n * - **EN:** Class name for the resize handle\n * - **CN:** 调整大小手柄的类名\n */\n resizeHandle?: string;\n /**\n * - **EN:** Class name for the handle icon\n * - **CN:** 手柄图标的类名\n */\n handleIcon?: string;\n /**\n * - **EN:** Class name for the content area\n * - **CN:** 内容区域的类名\n */\n content?: string;\n /**\n * - **EN:** Class name for the card element\n * - **CN:** 卡片元素的类名\n */\n card?: string;\n };\n /**\n * - **EN:** Custom styles for the root element\n * - **CN:** 根元素的自定义样式\n */\n style?: CSSProperties;\n /**\n * - **EN:** Custom styles for specific elements\n * - **CN:** 特定元素的自定义样式\n */\n styles?: {\n /**\n * - **EN:** Styles for the drawer element\n * - **CN:** 抽屉元素的样式\n */\n drawer?: CSSProperties;\n /**\n * - **EN:** Styles for the expand handle\n * - **CN:** 展开手柄的样式\n */\n toggle?: CSSProperties;\n /**\n * - **EN:** Styles for the resize handle\n * - **CN:** 调整大小手柄的样式\n */\n resizeHandle?: CSSProperties;\n /**\n * - **EN:** Styles for the handle icon\n * - **CN:** 手柄图标的样式\n */\n handleIcon?: CSSProperties;\n /**\n * - **EN:** Styles for the content area\n * - **CN:** 内容区域的样式\n */\n content?: CSSProperties;\n /**\n * - **EN:** Styles for the card element\n * - **CN:** 卡片元素的样式\n */\n card?: CSSProperties;\n };\n /**\n * - **EN:** Custom properties for the card element\n * - **CN:** 卡片元素的自定义属性\n */\n cardProps?: Omit<CardProps, 'children'>;\n /**\n * - **EN:** Content to be rendered inside the drawer\n * - **CN:** 抽屉内容\n */\n children?: ReactNode;\n /**\n * - **EN:** Callback function when the open state changes\n * - **CN:** 打开状态变化时的回调函数\n */\n onOpenChange?: (open: boolean) => void;\n /**\n * - **EN:** Callback function when the drawer is resized\n * - **CN:** 抽屉调整大小时的回调函数\n */\n onResize?: (size: number) => void;\n /**\n * - **EN:** Event handler for click events on the drawer container and its internal elements\n * - **CN:** 点击抽屉容器及内部元素时的事件\n */\n onClick?: (e: React.MouseEvent<HTMLDivElement>) => void;\n}\n\n/**\n * - **EN:** FloatDrawer component for creating a draggable, resizable drawer\n * - **CN:** FloatDrawer组件,用于创建可拖动、可调整大小的抽屉\n */\nconst FloatDrawer: FC<FloatDrawerProps> = (props) => {\n const {\n prefixCls: prefixClsInProps,\n open,\n position = 'right',\n cardProps,\n children,\n className,\n classNames: classNamesInProps,\n style,\n styles,\n cacheKey,\n defaultSize,\n minSize = 0,\n maxSize = +Infinity,\n edgeOffset,\n showToggle = true,\n resizable = true,\n destroyOnClose = false,\n onOpenChange,\n onResize,\n onClick,\n } = props;\n const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);\n const prefixCls = getPrefixCls('easy-float-drawer', prefixClsInProps);\n const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls);\n const [drawerRef, setDrawerRef] = useState<HTMLDivElement | null>(null);\n const [size, setSize] = useState(\n cacheKey && localStorage.getItem(cacheKey) ? Number(localStorage.getItem(cacheKey)) || defaultSize : defaultSize\n );\n const sizeMap = useMemo(() => {\n const type = position === 'left' || position === 'right' ? 'width' : 'height';\n return {\n [type]: size,\n };\n }, [position, size]);\n const [isOpen, setIsOpen] = useState<boolean>();\n const [isDragging, setIsDragging] = useState(false);\n const dragStartPos = useRef<number>(0);\n const dragStartSize = useRef<number>(size);\n const classString = classNames(\n prefixCls,\n className,\n {\n [`${prefixCls}-open`]: isOpen,\n [`${prefixCls}-closed`]: !isOpen,\n [`${prefixCls}-${position}`]: position,\n },\n hashId,\n cssVarCls\n );\n const closeIcon = useMemo(() => {\n return position === 'left' ? (\n <RightOutlined />\n ) : position === 'top' ? (\n <DownOutlined />\n ) : position === 'bottom' ? (\n <UpOutlined />\n ) : (\n <LeftOutlined />\n );\n }, [position]);\n const openIcon = useMemo(() => {\n return position === 'left' ? (\n <LeftOutlined />\n ) : position === 'top' ? (\n <UpOutlined />\n ) : position === 'bottom' ? (\n <DownOutlined />\n ) : (\n <RightOutlined />\n );\n }, [position]);\n\n // Handle drawer visibility\n const toggleDrawer = () => {\n setIsOpen(!isOpen);\n onOpenChange?.(!isOpen);\n };\n\n // Handle resize events\n const handleResizeStart = useRefFunction((e: React.MouseEvent) => {\n setIsDragging(true);\n if (position === 'top' || position === 'bottom') {\n dragStartPos.current = e.clientY;\n } else {\n dragStartPos.current = e.clientX;\n }\n dragStartSize.current = size;\n e.preventDefault();\n });\n const handleResize = useRefFunction((e: MouseEvent) => {\n if (isDragging && dragStartSize.current) {\n let newSize: number;\n if (position === 'left') {\n newSize = dragStartSize.current - (dragStartPos.current - e.clientX);\n } else if (position === 'top') {\n newSize = dragStartSize.current - (dragStartPos.current - e.clientY);\n } else if (position === 'bottom') {\n newSize = dragStartSize.current - (e.clientY - dragStartPos.current);\n } else {\n newSize = dragStartSize.current - (e.clientX - dragStartPos.current);\n }\n if (newSize >= minSize && newSize <= maxSize) {\n setSize(newSize);\n if (cacheKey) {\n localStorage.setItem(cacheKey, String(newSize));\n }\n onResize?.(newSize);\n }\n }\n });\n const handleResizeEnd = useRefFunction(() => {\n setIsDragging(false);\n });\n\n // Monitor drawer ref, calculate size if not set\n // This is useful for initial rendering when size is not provided\n useEffect(() => {\n if (drawerRef && size === undefined) {\n const rect = drawerRef.getBoundingClientRect();\n setSize(position === 'left' || position === 'right' ? rect.width : rect.height);\n }\n }, [drawerRef, position, size]);\n\n // Controlled open state\n useEffect(() => {\n setIsOpen(open);\n }, [open]);\n\n // Handle global events\n useEffect(() => {\n if (isDragging) {\n window.addEventListener('mousemove', handleResize);\n window.addEventListener('mouseup', handleResizeEnd);\n } else {\n window.removeEventListener('mousemove', handleResize);\n window.removeEventListener('mouseup', handleResizeEnd);\n }\n return () => {\n window.removeEventListener('mousemove', handleResize);\n window.removeEventListener('mouseup', handleResizeEnd);\n };\n }, [isDragging]);\n\n return wrapCSSVar(\n <div\n className={classString}\n style={{\n // @ts-expect-error: because of dynamic CSS variables\n '--edge-offset': typeof edgeOffset === 'number' ? `${edgeOffset}px` : edgeOffset,\n ...style,\n }}\n onClick={onClick}\n >\n <div\n ref={setDrawerRef}\n className={classNames(`${prefixCls}-drawer`, classNamesInProps?.drawer)}\n style={{ ...sizeMap, ...styles?.drawer }}\n >\n {resizable && (\n <div\n className={classNames(\n `${prefixCls}-resize-handle`,\n isDragging && `${prefixCls}-resize-handle-dragging`,\n classNamesInProps?.resizeHandle\n )}\n style={styles?.resizeHandle}\n onMouseDown={handleResizeStart}\n />\n )}\n <div className={classNames(`${prefixCls}-content`, classNamesInProps?.content)} style={styles?.content}>\n <Card\n bordered={false}\n variant=\"borderless\"\n className={classNames(`${prefixCls}-card`, classNamesInProps?.card)}\n style={styles?.card}\n {...cardProps}\n >\n {!destroyOnClose || isOpen ? children : null}\n </Card>\n </div>\n {showToggle && (\n <div\n className={classNames(`${prefixCls}-toggle`, classNamesInProps?.toggle)}\n style={styles?.toggle}\n onClick={toggleDrawer}\n >\n <div\n className={classNames(`${prefixCls}-handle-icon`, classNamesInProps?.handleIcon)}\n style={styles?.handleIcon}\n >\n {isOpen ? openIcon : closeIcon}\n </div>\n </div>\n )}\n </div>\n </div>\n );\n};\n\nexport default FloatDrawer;\n"],"mappings":";;;;;;;;;;;;AACA,SAASA,UAAU,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAExE,SAASC,IAAI,EAAEC,cAAc,QAAQ,MAAM;AAC3C,OAAOC,UAAU,MAAM,YAAY;AACnC,SAASC,YAAY,EAAEC,YAAY,EAAEC,aAAa,EAAEC,UAAU,QAAQ,mBAAmB;AACzF,OAAOC,cAAc;AACrB,OAAOC,QAAQ;AAAgB,SAAAC,GAAA,IAAAC,IAAA;AAAA,SAAAC,IAAA,IAAAC,KAAA;AAsL/B;AACA;AACA;AACA;AACA,IAAMC,WAAiC,GAAG,SAApCA,WAAiCA,CAAIC,KAAK,EAAK;EACnD,IACaC,gBAAgB,GAoBzBD,KAAK,CApBPE,SAAS;IACTC,IAAI,GAmBFH,KAAK,CAnBPG,IAAI;IAAAC,eAAA,GAmBFJ,KAAK,CAlBPK,QAAQ;IAARA,QAAQ,GAAAD,eAAA,cAAG,OAAO,GAAAA,eAAA;IAClBE,SAAS,GAiBPN,KAAK,CAjBPM,SAAS;IACTC,QAAQ,GAgBNP,KAAK,CAhBPO,QAAQ;IACRC,SAAS,GAePR,KAAK,CAfPQ,SAA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BACTzB,IAAA;QACEY,SAAS,EAAEpB,UAAU,IAAA2E,MAAA,CAAI7D,SAAS,cAAWO,iBAAiB,aAAjBA,iBAAiB,uBAAjBA,iBAAiB,CAAEsF,MAAM,CAAE;QACxErF,KAAK,EAAEC,MAAM,aAANA,MAAM,uBAANA,MAAM,CAAEoF,MAAO;QACtBnE,OAAO,EAAEsC,YAAa;QAAA3D,QAAA,eAEtBX,IAAA;UACEY,SAAS,EAAEpB,UAAU,IAAA2E,MAAA,CAAI7D,SAAS,mBAAgBO,iBAAiB,aAAjBA,iBAAiB,uBAAjBA,iBAAiB,CAAEuF,UAAU,CAAE;UACjFtF,KAAK,EAAEC,MAAM,aAANA,MAAM,uBAANA,MAAM,CAAEqF,UAAW;UAAAzF,QAAA,EAEzB+C,MAAM,GAAGW,QAAQ,GAAGD;QAAS,CAC3B;MAAC,CACH,CACN;IAAA,CACE;EAAC,CACH,CACP,CAAC;AACH,CAAC;AAED,eAAejE,WAAW"}
@@ -1,27 +1,27 @@
1
1
  /// <reference types="react" />
2
2
  export interface UseDebounceOptions {
3
3
  /**
4
- * - **EN** Whether to execute at the start of the wait period. Default is `false`.
5
- * - **CN** 是否在等待周期开始时执行,默认值为 `false`
4
+ * - **EN:** Whether to execute at the start of the wait period. Default is `false`.
5
+ * - **CN:** 是否在等待周期开始时执行,默认值为 `false`
6
6
  */
7
7
  leading?: boolean;
8
8
  /**
9
- * - **EN** Regular debounce interval in milliseconds. Default is `0`, meaning no debounce.
10
- * - **CN** 常规防抖间隔 (ms),默认值为 `0`, 表示不进行防抖
9
+ * - **EN:** Regular debounce interval in milliseconds. Default is `0`, meaning no debounce.
10
+ * - **CN:** 常规防抖间隔 (ms),默认值为 `0`, 表示不进行防抖
11
11
  */
12
12
  wait?: number;
13
13
  /**
14
- * - **EN** Maximum wait time in milliseconds. Default is `0`, meaning no maximum wait.
15
- * - **CN** 最大等待时间 (ms),默认值为 `0`, 表示不限制最大等待时间
14
+ * - **EN:** Maximum wait time in milliseconds. Default is `0`, meaning no maximum wait.
15
+ * - **CN:** 最大等待时间 (ms),默认值为 `0`, 表示不限制最大等待时间
16
16
  */
17
17
  maxWait?: number;
18
18
  }
19
19
  /**
20
- * - **EN** Debounce Hook with dual trigger mechanisms:
20
+ * - **EN:** Debounce Hook with dual trigger mechanisms:
21
21
  *
22
22
  * 1. Traditional debounce: Executes after a specified interval without new calls.
23
23
  * 2. Max wait: Forces execution after exceeding a specified maximum wait time.
24
- * - **CN** 防抖 Hook:具有两种触发机制:
24
+ * - **CN:** 防抖 Hook:具有两种触发机制:
25
25
  *
26
26
  * 1. 传统防抖:等待指定时间内无新调用后执行
27
27
  * 2. 最大等待:超过指定最大等待时间后强制执行
@@ -33,5 +33,33 @@ export interface UseDebounceOptions {
33
33
  *
34
34
  * @returns The debounced function | 防抖处理后的函数
35
35
  */
36
- declare function useDebounce<T extends (...args: any[]) => unknown>(fn: T, deps: React.DependencyList, options?: UseDebounceOptions): (...args: Parameters<T>) => void;
36
+ declare function useDebounce<T extends (...args: any[]) => unknown>(fn: T, deps: React.DependencyList, options?: UseDebounceOptions): DebouncedFunc<T>;
37
+ export interface DebouncedFunc<T extends (...args: any[]) => unknown> {
38
+ /**
39
+ * - **EN:** The debounced function.
40
+ * - **CN:** 防抖处理后的函数
41
+ */
42
+ (...args: Parameters<T>): ReturnType<T>;
43
+ /**
44
+ * - **EN:** Cancel any pending execution of the debounced function.
45
+ * - **CN:** 取消防抖函数的任何待执行操作
46
+ */
47
+ cancel: () => void;
48
+ /**
49
+ * - **EN:** Disable the debounce functionality. Once disabled, subsequent calls to the function
50
+ * will have no effect until re-enabled.
51
+ * - **CN:** 禁用此防抖函数,一旦被禁用,再次调用改函数将不会有任何效果,除非重新启用
52
+ */
53
+ disable: () => void;
54
+ /**
55
+ * - **EN:** Re-enable the debounce functionality after it has been disabled.
56
+ * - **CN:** 重新启用此防抖函数
57
+ */
58
+ enable: () => void;
59
+ /**
60
+ * - **EN:** Check if the debounce functionality is currently disabled.
61
+ * - **CN:** 检查此防抖函数当前是否被禁用
62
+ */
63
+ isDisabled(): boolean;
64
+ }
37
65
  export default useDebounce;
@@ -5,12 +5,13 @@ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symb
5
5
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6
6
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
7
7
  import { useCallback, useEffect, useRef } from 'react';
8
+ import useRefFunction from "./useRefFunction";
8
9
  /**
9
- * - **EN** Debounce Hook with dual trigger mechanisms:
10
+ * - **EN:** Debounce Hook with dual trigger mechanisms:
10
11
  *
11
12
  * 1. Traditional debounce: Executes after a specified interval without new calls.
12
13
  * 2. Max wait: Forces execution after exceeding a specified maximum wait time.
13
- * - **CN** 防抖 Hook:具有两种触发机制:
14
+ * - **CN:** 防抖 Hook:具有两种触发机制:
14
15
  *
15
16
  * 1. 传统防抖:等待指定时间内无新调用后执行
16
17
  * 2. 最大等待:超过指定最大等待时间后强制执行
@@ -34,6 +35,7 @@ function useDebounce(fn, deps) {
34
35
  var fnRef = useRef(fn);
35
36
  var lastExecutedTimeRef = useRef(0); // The last execution timestamp
36
37
  var lastArgsRef = useRef([]); // The last call arguments
38
+ var isDisabledRef = useRef(false); // Whether debounce is disabled
37
39
 
38
40
  // Update the latest function reference
39
41
  useEffect(function () {
@@ -58,7 +60,10 @@ function useDebounce(fn, deps) {
58
60
  }, []);
59
61
 
60
62
  // The debounced function
61
- return useCallback(function () {
63
+ var debouncedFunction = useRefFunction(function () {
64
+ if (isDisabledRef.current) {
65
+ return;
66
+ }
62
67
  var now = Date.now();
63
68
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
64
69
  args[_key] = arguments[_key];
@@ -85,8 +90,23 @@ function useDebounce(fn, deps) {
85
90
 
86
91
  // 3. Set a new debounce timer
87
92
  timeoutRef.current = setTimeout(executeFunction, wait);
88
- }, // eslint-disable-next-line @tiny-codes/react-hooks/exhaustive-deps
89
- [wait, maxWait, executeFunction, leading].concat(_toConsumableArray(deps)));
93
+ });
94
+ debouncedFunction.cancel = function () {
95
+ if (timeoutRef.current) {
96
+ clearTimeout(timeoutRef.current);
97
+ timeoutRef.current = null;
98
+ }
99
+ };
100
+ debouncedFunction.disable = function () {
101
+ isDisabledRef.current = true;
102
+ };
103
+ debouncedFunction.enable = function () {
104
+ isDisabledRef.current = false;
105
+ };
106
+ debouncedFunction.isDisabled = function () {
107
+ return isDisabledRef.current;
108
+ };
109
+ return debouncedFunction;
90
110
  }
91
111
  export default useDebounce;
92
112
  //# sourceMappingURL=useDebounce.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["useCallback","useEffect","useRef","useDebounce","fn","deps","options","arguments","length","undefined","_options$wait","wait","_options$maxWait","maxWait","_options$leading","leading","timeoutRef","fnRef","lastExecutedTimeRef","lastArgsRef","current","clearTimeout","executeFunction","Date","now","apply","_toConsumableArray","_len","args","Array","_key","setTimeout","concat"],"sources":["../../src/hooks/useDebounce.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from 'react';\n\nexport interface UseDebounceOptions {\n /**\n * - **EN** Whether to execute at the start of the wait period. Default is `false`.\n * - **CN** 是否在等待周期开始时执行,默认值为 `false`\n */\n leading?: boolean;\n /**\n * - **EN** Regular debounce interval in milliseconds. Default is `0`, meaning no debounce.\n * - **CN** 常规防抖间隔 (ms),默认值为 `0`, 表示不进行防抖\n */\n wait?: number;\n /**\n * - **EN** Maximum wait time in milliseconds. Default is `0`, meaning no maximum wait.\n * - **CN** 最大等待时间 (ms),默认值为 `0`, 表示不限制最大等待时间\n */\n maxWait?: number;\n}\n/**\n * - **EN** Debounce Hook with dual trigger mechanisms:\n *\n * 1. Traditional debounce: Executes after a specified interval without new calls.\n * 2. Max wait: Forces execution after exceeding a specified maximum wait time.\n * - **CN** 防抖 Hook:具有两种触发机制:\n *\n * 1. 传统防抖:等待指定时间内无新调用后执行\n * 2. 最大等待:超过指定最大等待时间后强制执行\n *\n * @param fn The function to debounce | 需要防抖的函数\n * @param deps Dependency array, re-creates the debounced function when dependencies change |\n * 依赖项数组,当依赖变化时重新创建防抖函数\n * @param options Configuration options | 配置选项\n *\n * @returns The debounced function | 防抖处理后的函数\n */\nfunction useDebounce<T extends (...args: any[]) => unknown>(\n fn: T,\n deps: React.DependencyList,\n options: UseDebounceOptions = {}\n): (...args: Parameters<T>) => void {\n const { wait = 0, maxWait = 0, leading = false } = options;\n const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const fnRef = useRef<T>(fn);\n const lastExecutedTimeRef = useRef<number>(0); // The last execution timestamp\n const lastArgsRef = useRef<unknown[]>([]); // The last call arguments\n\n // Update the latest function reference\n useEffect(() => {\n fnRef.current = fn;\n }, [fn]);\n\n // Cleanup on unmount\n useEffect(() => {\n return () => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n timeoutRef.current = null;\n }\n };\n }, []);\n\n // The actual execution function\n const executeFunction = useCallback(() => {\n timeoutRef.current = null;\n lastExecutedTimeRef.current = Date.now();\n fnRef.current(...lastArgsRef.current);\n }, []);\n\n // The debounced function\n return useCallback(\n (...args: Parameters<T>) => {\n const now = Date.now();\n lastArgsRef.current = args;\n\n // If leading is true and it's the first call, execute immediately\n if (leading && timeoutRef.current === null && now - lastExecutedTimeRef.current >= wait) {\n executeFunction();\n return;\n }\n\n // 1. Clear the existing timer\n if (timeoutRef.current !== null) {\n clearTimeout(timeoutRef.current);\n timeoutRef.current = null;\n }\n\n // 2. Check if the maximum wait time has been exceeded, if so, execute immediately\n if (maxWait > 0 && now - lastExecutedTimeRef.current >= maxWait) {\n executeFunction();\n return;\n }\n\n // 3. Set a new debounce timer\n timeoutRef.current = setTimeout(executeFunction, wait);\n },\n // eslint-disable-next-line @tiny-codes/react-hooks/exhaustive-deps\n [wait, maxWait, executeFunction, leading, ...deps]\n );\n}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EA,eAAeF,WAAW"}
1
+ {"version":3,"names":["useCallback","useEffect","useRef","useRefFunction","useDebounce","fn","deps","options","arguments","length","undefined","_options$wait","wait","_options$maxWait","maxWait","_options$leading","leading","timeoutRef","fnRef","lastExecutedTimeRef","lastArgsRef","isDisabledRef","current","clearTimeout","executeFunction","Date","now","apply","_toConsumableArray","debouncedFunction","_len","args","Array","_key","setTimeout","cancel","disable","enable","isDisabled"],"sources":["../../src/hooks/useDebounce.ts"],"sourcesContent":["import { useCallback, useEffect, useRef } from 'react';\nimport useRefFunction from './useRefFunction';\n\nexport interface UseDebounceOptions {\n /**\n * - **EN:** Whether to execute at the start of the wait period. Default is `false`.\n * - **CN:** 是否在等待周期开始时执行,默认值为 `false`\n */\n leading?: boolean;\n /**\n * - **EN:** Regular debounce interval in milliseconds. Default is `0`, meaning no debounce.\n * - **CN:** 常规防抖间隔 (ms),默认值为 `0`, 表示不进行防抖\n */\n wait?: number;\n /**\n * - **EN:** Maximum wait time in milliseconds. Default is `0`, meaning no maximum wait.\n * - **CN:** 最大等待时间 (ms),默认值为 `0`, 表示不限制最大等待时间\n */\n maxWait?: number;\n}\n/**\n * - **EN:** Debounce Hook with dual trigger mechanisms:\n *\n * 1. Traditional debounce: Executes after a specified interval without new calls.\n * 2. Max wait: Forces execution after exceeding a specified maximum wait time.\n * - **CN:** 防抖 Hook:具有两种触发机制:\n *\n * 1. 传统防抖:等待指定时间内无新调用后执行\n * 2. 最大等待:超过指定最大等待时间后强制执行\n *\n * @param fn The function to debounce | 需要防抖的函数\n * @param deps Dependency array, re-creates the debounced function when dependencies change |\n * 依赖项数组,当依赖变化时重新创建防抖函数\n * @param options Configuration options | 配置选项\n *\n * @returns The debounced function | 防抖处理后的函数\n */\nfunction useDebounce<T extends (...args: any[]) => unknown>(\n fn: T,\n deps: React.DependencyList,\n options: UseDebounceOptions = {}\n): DebouncedFunc<T> {\n const { wait = 0, maxWait = 0, leading = false } = options;\n const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const fnRef = useRef<T>(fn);\n const lastExecutedTimeRef = useRef<number>(0); // The last execution timestamp\n const lastArgsRef = useRef<unknown[]>([]); // The last call arguments\n const isDisabledRef = useRef<boolean>(false); // Whether debounce is disabled\n\n // Update the latest function reference\n useEffect(() => {\n fnRef.current = fn;\n }, [fn]);\n\n // Cleanup on unmount\n useEffect(() => {\n return () => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n timeoutRef.current = null;\n }\n };\n }, []);\n\n // The actual execution function\n const executeFunction = useCallback(() => {\n timeoutRef.current = null;\n lastExecutedTimeRef.current = Date.now();\n fnRef.current(...lastArgsRef.current);\n }, []);\n\n // The debounced function\n const debouncedFunction = useRefFunction((...args: Parameters<T>) => {\n if (isDisabledRef.current) {\n return;\n }\n const now = Date.now();\n lastArgsRef.current = args;\n\n // If leading is true and it's the first call, execute immediately\n if (leading && timeoutRef.current === null && now - lastExecutedTimeRef.current >= wait) {\n executeFunction();\n return;\n }\n\n // 1. Clear the existing timer\n if (timeoutRef.current !== null) {\n clearTimeout(timeoutRef.current);\n timeoutRef.current = null;\n }\n\n // 2. Check if the maximum wait time has been exceeded, if so, execute immediately\n if (maxWait > 0 && now - lastExecutedTimeRef.current >= maxWait) {\n executeFunction();\n return;\n }\n\n // 3. Set a new debounce timer\n timeoutRef.current = setTimeout(executeFunction, wait);\n }) as DebouncedFunc<T>;\n debouncedFunction.cancel = () => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n timeoutRef.current = null;\n }\n };\n debouncedFunction.disable = () => {\n isDisabledRef.current = true;\n };\n debouncedFunction.enable = () => {\n isDisabledRef.current = false;\n };\n debouncedFunction.isDisabled = () => isDisabledRef.current;\n return debouncedFunction;\n}\n\nexport interface DebouncedFunc<T extends (...args: any[]) => unknown> {\n /**\n * - **EN:** The debounced function.\n * - **CN:** 防抖处理后的函数\n */\n (...args: Parameters<T>): ReturnType<T>;\n /**\n * - **EN:** Cancel any pending execution of the debounced function.\n * - **CN:** 取消防抖函数的任何待执行操作\n */\n cancel: () => void;\n /**\n * - **EN:** Disable the debounce functionality. Once disabled, subsequent calls to the function\n * will have no effect until re-enabled.\n * - **CN:** 禁用此防抖函数,一旦被禁用,再次调用改函数将不会有任何效果,除非重新启用\n */\n disable: () => void;\n /**\n * - **EN:** Re-enable the debounce functionality after it has been disabled.\n * - **CN:** 重新启用此防抖函数\n */\n enable: () => void;\n /**\n * - **EN:** Check if the debounce functionality is currently disabled.\n * - **CN:** 检查此防抖函数当前是否被禁用\n */\n isDisabled(): boolean;\n}\n\nexport default useDebounce;\n"],"mappings":";;;;;;AAAA,SAASA,WAAW,EAAEC,SAAS,EAAEC,MAAM,QAAQ,OAAO;AACtD,OAAOC,cAAc;AAmBrB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,WAAWA,CAClBC,EAAK,EACLC,IAA0B,EAER;EAAA,IADlBC,OAA2B,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAEhC,IAAAG,aAAA,GAAmDJ,OAAO,CAAlDK,IAAI;IAAJA,IAAI,GAAAD,aAAA,cAAG,CAAC,GAAAA,aAAA;IAAAE,gBAAA,GAAmCN,OAAO,CAAxCO,OAAO;IAAPA,OAAO,GAAAD,gBAAA,cAAG,CAAC,GAAAA,gBAAA;IAAAE,gBAAA,GAAsBR,OAAO,CAA3BS,OAAO;IAAPA,OAAO,GAAAD,gBAAA,cAAG,KAAK,GAAAA,gBAAA;EAC9C,IAAME,UAAU,GAAGf,MAAM,CAAuC,IAAI,CAAC;EACrE,IAAMgB,KAAK,GAAGhB,MAAM,CAAIG,EAAE,CAAC;EAC3B,IAAMc,mBAAmB,GAAGjB,MAAM,CAAS,CAAC,CAAC,CAAC,CAAC;EAC/C,IAAMkB,WAAW,GAAGlB,MAAM,CAAY,EAAE,CAAC,CAAC,CAAC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B;IACF;;IAEA;IACA,IAAIP,UAAU,CAACK,OAAO,KAAK,IAAI,EAAE;MAC/BC,YAAY,CAACN,UAAU,CAACK,OAAO,CAAC;MAChCL,UAAU,CAACK,OAAO,GAAG,IAAI;IAC3B;;IAEA;IACA,IAAIR,OAAO,GAAG,CAAC,IAAIY,GAAG,GAAGP,mBAAmB,CAACG,OAAO,IAAIR,OAAO,EAAE;MAC/DU,eAAe,CAAC,CAAC;MACjB;IACF;;IAEA;IACAP,UAAU,CAACK,OAAO,GAAGY,UAAU,CAACV,eAAe,EAAEZ,IAAI,CAAC;EACxD,CAAC,CAAqB;EACtBiB,iBAAiB,CAACM,MAAM,GAAG,YAAM;IAC/B,IAAIlB,UAAU,CAACK,OAAO,EAAE;MACtBC,YAAY,CAACN,UAAU,CAACK,OAAO,CAAC;MAChCL,UAAU,CAACK,OAAO,GAAG,IAAI;IAC3B;EACF,CAAC;EACDO,iBAAiB,CAACO,OAAO,GAAG,YAAM;IAChCf,aAAa,CAACC,OAAO,GAAG,IAAI;EAC9B,CAAC;EACDO,iBAAiB,CAACQ,MAAM,GAAG,YAAM;IAC/BhB,aAAa,CAACC,OAAO,GAAG,KAAK;EAC/B,CAAC;EACDO,iBAAiB,CAACS,UAAU,GAAG;IAAA,OAAMjB,aAAa,CAACC,OAAO;EAAA;EAC1D,OAAOO,iBAAiB;AAC1B;AA+BA,eAAezB,WAAW"}
@@ -60,6 +60,11 @@ export interface FloatDrawerProps {
60
60
  * - **CN:** 抽屉是否可调整大小, 默认`true`。
61
61
  */
62
62
  resizable?: boolean;
63
+ /**
64
+ * - **EN:** Whether to destroy the drawer content when closed, default is `false`.
65
+ * - **CN:** 抽屉关闭时是否销毁内容,默认`false`。
66
+ */
67
+ destroyOnClose?: boolean;
63
68
  /**
64
69
  * - **EN:** Cache key for storing the drawer size in localStorage. If not set, the size will not be
65
70
  * cached.
@@ -56,6 +56,7 @@ var FloatDrawer = (props) => {
56
56
  edgeOffset,
57
57
  showToggle = true,
58
58
  resizable = true,
59
+ destroyOnClose = false,
59
60
  onOpenChange,
60
61
  onResize,
61
62
  onClick
@@ -194,7 +195,7 @@ var FloatDrawer = (props) => {
194
195
  style: styles == null ? void 0 : styles.card,
195
196
  ...cardProps
196
197
  },
197
- children
198
+ !destroyOnClose || isOpen ? children : null
198
199
  )),
199
200
  showToggle && /* @__PURE__ */ React.createElement(
200
201
  "div",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/FloatDrawer/index.tsx"],
4
- "sourcesContent": ["import type { CSSProperties, FC, ReactNode } from 'react';\nimport { useContext, useEffect, useMemo, useRef, useState } from 'react';\nimport type { CardProps } from 'antd';\nimport { Card, ConfigProvider } from 'antd';\nimport classNames from 'classnames';\nimport { DownOutlined, LeftOutlined, RightOutlined, UpOutlined } from '@ant-design/icons';\nimport useRefFunction from '../../hooks/useRefFunction';\nimport useStyle from './style';\n\nexport interface FloatDrawerProps {\n prefixCls?: string;\n /**\n * - **EN:** Whether the drawer is open\n * - **CN:** 抽屉是否打开\n */\n open?: boolean;\n /**\n * - **EN:** Position of the drawer\n * - **CN:** 抽屉的位置\n *\n * @default 'right'\n */\n position?: 'left' | 'right' | 'top' | 'bottom';\n /**\n * - **EN:** Default size of the drawer. If the drawer is placed on the left or right, this is the\n * width, otherwise it is the height. If not set, the drawer will adapt to the content size.\n * - **CN:** 抽屉的默认宽度。如果抽屉放在左侧或右侧,则为宽度,否则为高度。不设置时,抽屉会根据内容自适应大小。\n */\n defaultSize?: number;\n /**\n * - **EN:** Minimum size of the drawer\n * - **CN:** 抽屉的最小宽度\n *\n * @default 0\n */\n minSize?: number;\n /**\n * - **EN:** Maximum size of the drawer\n * - **CN:** 抽屉的最大宽度\n *\n * @default Infinity\n */\n maxSize?: number;\n /**\n * - **EN:** Offset of the drawer from the edge of the screen, supports all CSS length units,\n * default is `0`.\n *\n * > The drawer will be hidden outside the parent container's edge, but since the parent container\n * > may have padding or border, the drawer may not be completely hidden. You can adjust the\n * > `edgeOffset` to ensure the drawer is completely hidden outside the parent container.\n *\n * - **CN:** 抽屉距离屏幕边缘的偏移量,支持所有的CSS长度单位, 默认`0`。\n *\n * > 抽屉会隐藏在父容器的外边缘, 但由于父容器可能有padding或border, 导致抽屉不能完全隐藏, 因此可以通过设置 `edgeOffset` 来调整抽屉的偏移量,\n * > 以确保抽屉完全隐藏在父容器之外。\n *\n * @default 0\n */\n edgeOffset?: CSSProperties['width'];\n /**\n * - **EN:** Whether to show the toggle button, default is `true`.\n * - **CN:** 是否显示展开/收起按钮,默认`true`。\n */\n showToggle?: boolean;\n /**\n * - **EN:** Whether the drawer is resizable, default is `true`.\n * - **CN:** 抽屉是否可调整大小, 默认`true`。\n */\n resizable?: boolean;\n /**\n * - **EN:** Cache key for storing the drawer size in localStorage. If not set, the size will not be\n * cached.\n * - **CN:** 指定一个localStorage缓存键,用于记忆抽屉宽度。如果不设置,则不使用缓存。\n */\n cacheKey?: string;\n /**\n * - **EN:** Custom class name for the root element\n * - **CN:** 根元素的自定义类名\n */\n className?: string;\n /**\n * - **EN:** Custom class names for specific elements\n * - **CN:** 特定元素的自定义类名\n */\n classNames?: {\n /**\n * - **EN:** Class name for the drawer element\n * - **CN:** 抽屉元素的类名\n */\n drawer?: string;\n /**\n * - **EN:** Class name for the expand handle\n * - **CN:** 展开手柄的类名\n */\n toggle?: string;\n /**\n * - **EN:** Class name for the resize handle\n * - **CN:** 调整大小手柄的类名\n */\n resizeHandle?: string;\n /**\n * - **EN:** Class name for the handle icon\n * - **CN:** 手柄图标的类名\n */\n handleIcon?: string;\n /**\n * - **EN:** Class name for the content area\n * - **CN:** 内容区域的类名\n */\n content?: string;\n /**\n * - **EN:** Class name for the card element\n * - **CN:** 卡片元素的类名\n */\n card?: string;\n };\n /**\n * - **EN:** Custom styles for the root element\n * - **CN:** 根元素的自定义样式\n */\n style?: CSSProperties;\n /**\n * - **EN:** Custom styles for specific elements\n * - **CN:** 特定元素的自定义样式\n */\n styles?: {\n /**\n * - **EN:** Styles for the drawer element\n * - **CN:** 抽屉元素的样式\n */\n drawer?: CSSProperties;\n /**\n * - **EN:** Styles for the expand handle\n * - **CN:** 展开手柄的样式\n */\n toggle?: CSSProperties;\n /**\n * - **EN:** Styles for the resize handle\n * - **CN:** 调整大小手柄的样式\n */\n resizeHandle?: CSSProperties;\n /**\n * - **EN:** Styles for the handle icon\n * - **CN:** 手柄图标的样式\n */\n handleIcon?: CSSProperties;\n /**\n * - **EN:** Styles for the content area\n * - **CN:** 内容区域的样式\n */\n content?: CSSProperties;\n /**\n * - **EN:** Styles for the card element\n * - **CN:** 卡片元素的样式\n */\n card?: CSSProperties;\n };\n /**\n * - **EN:** Custom properties for the card element\n * - **CN:** 卡片元素的自定义属性\n */\n cardProps?: Omit<CardProps, 'children'>;\n /**\n * - **EN:** Content to be rendered inside the drawer\n * - **CN:** 抽屉内容\n */\n children?: ReactNode;\n /**\n * - **EN:** Callback function when the open state changes\n * - **CN:** 打开状态变化时的回调函数\n */\n onOpenChange?: (open: boolean) => void;\n /**\n * - **EN:** Callback function when the drawer is resized\n * - **CN:** 抽屉调整大小时的回调函数\n */\n onResize?: (size: number) => void;\n /**\n * - **EN:** Event handler for click events on the drawer container and its internal elements\n * - **CN:** 点击抽屉容器及内部元素时的事件\n */\n onClick?: (e: React.MouseEvent<HTMLDivElement>) => void;\n}\n\n/**\n * - **EN:** FloatDrawer component for creating a draggable, resizable drawer\n * - **CN:** FloatDrawer组件,用于创建可拖动、可调整大小的抽屉\n */\nconst FloatDrawer: FC<FloatDrawerProps> = (props) => {\n const {\n prefixCls: prefixClsInProps,\n open,\n position = 'right',\n cardProps,\n children,\n className,\n classNames: classNamesInProps,\n style,\n styles,\n cacheKey,\n defaultSize,\n minSize = 0,\n maxSize = +Infinity,\n edgeOffset,\n showToggle = true,\n resizable = true,\n onOpenChange,\n onResize,\n onClick,\n } = props;\n const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);\n const prefixCls = getPrefixCls('easy-float-drawer', prefixClsInProps);\n const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls);\n const [drawerRef, setDrawerRef] = useState<HTMLDivElement | null>(null);\n const [size, setSize] = useState(\n cacheKey && localStorage.getItem(cacheKey) ? Number(localStorage.getItem(cacheKey)) || defaultSize : defaultSize\n );\n const sizeMap = useMemo(() => {\n const type = position === 'left' || position === 'right' ? 'width' : 'height';\n return {\n [type]: size,\n };\n }, [position, size]);\n const [isOpen, setIsOpen] = useState<boolean>();\n const [isDragging, setIsDragging] = useState(false);\n const dragStartPos = useRef<number>(0);\n const dragStartSize = useRef<number>(size);\n const classString = classNames(\n prefixCls,\n className,\n {\n [`${prefixCls}-open`]: isOpen,\n [`${prefixCls}-closed`]: !isOpen,\n [`${prefixCls}-${position}`]: position,\n },\n hashId,\n cssVarCls\n );\n const closeIcon = useMemo(() => {\n return position === 'left' ? (\n <RightOutlined />\n ) : position === 'top' ? (\n <DownOutlined />\n ) : position === 'bottom' ? (\n <UpOutlined />\n ) : (\n <LeftOutlined />\n );\n }, [position]);\n const openIcon = useMemo(() => {\n return position === 'left' ? (\n <LeftOutlined />\n ) : position === 'top' ? (\n <UpOutlined />\n ) : position === 'bottom' ? (\n <DownOutlined />\n ) : (\n <RightOutlined />\n );\n }, [position]);\n\n // Handle drawer visibility\n const toggleDrawer = () => {\n setIsOpen(!isOpen);\n onOpenChange?.(!isOpen);\n };\n\n // Handle resize events\n const handleResizeStart = useRefFunction((e: React.MouseEvent) => {\n setIsDragging(true);\n if (position === 'top' || position === 'bottom') {\n dragStartPos.current = e.clientY;\n } else {\n dragStartPos.current = e.clientX;\n }\n dragStartSize.current = size;\n e.preventDefault();\n });\n const handleResize = useRefFunction((e: MouseEvent) => {\n if (isDragging && dragStartSize.current) {\n let newSize: number;\n if (position === 'left') {\n newSize = dragStartSize.current - (dragStartPos.current - e.clientX);\n } else if (position === 'top') {\n newSize = dragStartSize.current - (dragStartPos.current - e.clientY);\n } else if (position === 'bottom') {\n newSize = dragStartSize.current - (e.clientY - dragStartPos.current);\n } else {\n newSize = dragStartSize.current - (e.clientX - dragStartPos.current);\n }\n if (newSize >= minSize && newSize <= maxSize) {\n setSize(newSize);\n if (cacheKey) {\n localStorage.setItem(cacheKey, String(newSize));\n }\n onResize?.(newSize);\n }\n }\n });\n const handleResizeEnd = useRefFunction(() => {\n setIsDragging(false);\n });\n\n // Monitor drawer ref, calculate size if not set\n // This is useful for initial rendering when size is not provided\n useEffect(() => {\n if (drawerRef && size === undefined) {\n const rect = drawerRef.getBoundingClientRect();\n setSize(position === 'left' || position === 'right' ? rect.width : rect.height);\n }\n }, [drawerRef, position, size]);\n\n // Controlled open state\n useEffect(() => {\n setIsOpen(open);\n }, [open]);\n\n // Handle global events\n useEffect(() => {\n if (isDragging) {\n window.addEventListener('mousemove', handleResize);\n window.addEventListener('mouseup', handleResizeEnd);\n } else {\n window.removeEventListener('mousemove', handleResize);\n window.removeEventListener('mouseup', handleResizeEnd);\n }\n return () => {\n window.removeEventListener('mousemove', handleResize);\n window.removeEventListener('mouseup', handleResizeEnd);\n };\n }, [isDragging]);\n\n return wrapCSSVar(\n <div\n className={classString}\n style={{\n // @ts-expect-error: because of dynamic CSS variables\n '--edge-offset': typeof edgeOffset === 'number' ? `${edgeOffset}px` : edgeOffset,\n ...style,\n }}\n onClick={onClick}\n >\n <div\n ref={setDrawerRef}\n className={classNames(`${prefixCls}-drawer`, classNamesInProps?.drawer)}\n style={{ ...sizeMap, ...styles?.drawer }}\n >\n {resizable && (\n <div\n className={classNames(\n `${prefixCls}-resize-handle`,\n isDragging && `${prefixCls}-resize-handle-dragging`,\n classNamesInProps?.resizeHandle\n )}\n style={styles?.resizeHandle}\n onMouseDown={handleResizeStart}\n />\n )}\n <div className={classNames(`${prefixCls}-content`, classNamesInProps?.content)} style={styles?.content}>\n <Card\n bordered={false}\n variant=\"borderless\"\n className={classNames(`${prefixCls}-card`, classNamesInProps?.card)}\n style={styles?.card}\n {...cardProps}\n >\n {children}\n </Card>\n </div>\n {showToggle && (\n <div\n className={classNames(`${prefixCls}-toggle`, classNamesInProps?.toggle)}\n style={styles?.toggle}\n onClick={toggleDrawer}\n >\n <div\n className={classNames(`${prefixCls}-handle-icon`, classNamesInProps?.handleIcon)}\n style={styles?.handleIcon}\n >\n {isOpen ? openIcon : closeIcon}\n </div>\n </div>\n )}\n </div>\n </div>\n );\n};\n\nexport default FloatDrawer;\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAiE;AAEjE,kBAAqC;AACrC,wBAAuB;AACvB,mBAAsE;AACtE,4BAA2B;AAC3B,mBAAqB;AAqLrB,IAAM,cAAoC,CAAC,UAAU;AACnD,QAAM;AAAA,IACJ,WAAW;AAAA,IACX;AAAA,IACA,WAAW;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,IACA,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV,UAAU;AAAA,IACV;AAAA,IACA,aAAa;AAAA,IACb,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AACJ,QAAM,EAAE,aAAa,QAAI,yBAAW,2BAAe,aAAa;AAChE,QAAM,YAAY,aAAa,qBAAqB,gBAAgB;AACpE,QAAM,CAAC,YAAY,QAAQ,SAAS,QAAI,aAAAA,SAAS,SAAS;AAC1D,QAAM,CAAC,WAAW,YAAY,QAAI,uBAAgC,IAAI;AACtE,QAAM,CAAC,MAAM,OAAO,QAAI;AAAA,IACtB,YAAY,aAAa,QAAQ,QAAQ,IAAI,OAAO,aAAa,QAAQ,QAAQ,CAAC,KAAK,cAAc;AAAA,EACvG;AACA,QAAM,cAAU,sBAAQ,MAAM;AAC5B,UAAM,OAAO,aAAa,UAAU,aAAa,UAAU,UAAU;AACrE,WAAO;AAAA,MACL,CAAC,IAAI,GAAG;AAAA,IACV;AAAA,EACF,GAAG,CA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AAe,WAAW,GAAG,iBAAiB;AAAA,UACtE,GAAG;AAAA,QACL;AAAA,QACA;AAAA;AAAA,MAEA;AAAA,QAAC;AAAA;AAAA,UACC,KAAK;AAAA,UACL,eAAW,kBAAAD,SAAW,GAAG,oBAAoB,uDAAmB,MAAM;AAAA,UACtE,OAAO,EAAE,GAAG,SAAS,GAAG,iCAAQ,OAAO;AAAA;AAAA,QAEtC,aACC;AAAA,UAAC;AAAA;AAAA,YACC,eAAW,kBAAAA;AAAA,cACT,GAAG;AAAA,cACH,cAAc,GAAG;AAAA,cACjB,uDAAmB;AAAA,YACrB;AAAA,YACA,OAAO,iCAAQ;AAAA,YACf,aAAa;AAAA;AAAA,QACf;AAAA,QAEF,oCAAC,SAAI,eAAW,kBAAAA,SAAW,GAAG,qBAAqB,uDAAmB,OAAO,GAAG,OAAO,iCAAQ,WAC7F;AAAA,UAAC;AAAA;AAAA,YACC,UAAU;AAAA,YACV,SAAQ;AAAA,YACR,eAAW,kBAAAA,SAAW,GAAG,kBAAkB,uDAAmB,IAAI;AAAA,YAClE,OAAO,iCAAQ;AAAA,YACd,GAAG;AAAA;AAAA,UAEH;AAAA,QACH,CACF;AAAA,QACC,cACC;AAAA,UAAC;AAAA;AAAA,YACC,eAAW,kBAAAA,SAAW,GAAG,oBAAoB,uDAAmB,MAAM;AAAA,YACtE,OAAO,iCAAQ;AAAA,YACf,SAAS;AAAA;AAAA,UAET;AAAA,YAAC;AAAA;AAAA,cACC,eAAW,kBAAAA,SAAW,GAAG,yBAAyB,uDAAmB,UAAU;AAAA,cAC/E,OAAO,iCAAQ;AAAA;AAAA,YAEd,SAAS,WAAW;AAAA,UACvB;AAAA,QACF;AAAA,MAEJ;AAAA,IACF;AAAA,EACF;AACF;AAEA,IAAO,sBAAQ;",
4
+ "sourcesContent": ["import type { CSSProperties, FC, ReactNode } from 'react';\nimport { useContext, useEffect, useMemo, useRef, useState } from 'react';\nimport type { CardProps } from 'antd';\nimport { Card, ConfigProvider } from 'antd';\nimport classNames from 'classnames';\nimport { DownOutlined, LeftOutlined, RightOutlined, UpOutlined } from '@ant-design/icons';\nimport useRefFunction from '../../hooks/useRefFunction';\nimport useStyle from './style';\n\nexport interface FloatDrawerProps {\n prefixCls?: string;\n /**\n * - **EN:** Whether the drawer is open\n * - **CN:** 抽屉是否打开\n */\n open?: boolean;\n /**\n * - **EN:** Position of the drawer\n * - **CN:** 抽屉的位置\n *\n * @default 'right'\n */\n position?: 'left' | 'right' | 'top' | 'bottom';\n /**\n * - **EN:** Default size of the drawer. If the drawer is placed on the left or right, this is the\n * width, otherwise it is the height. If not set, the drawer will adapt to the content size.\n * - **CN:** 抽屉的默认宽度。如果抽屉放在左侧或右侧,则为宽度,否则为高度。不设置时,抽屉会根据内容自适应大小。\n */\n defaultSize?: number;\n /**\n * - **EN:** Minimum size of the drawer\n * - **CN:** 抽屉的最小宽度\n *\n * @default 0\n */\n minSize?: number;\n /**\n * - **EN:** Maximum size of the drawer\n * - **CN:** 抽屉的最大宽度\n *\n * @default Infinity\n */\n maxSize?: number;\n /**\n * - **EN:** Offset of the drawer from the edge of the screen, supports all CSS length units,\n * default is `0`.\n *\n * > The drawer will be hidden outside the parent container's edge, but since the parent container\n * > may have padding or border, the drawer may not be completely hidden. You can adjust the\n * > `edgeOffset` to ensure the drawer is completely hidden outside the parent container.\n *\n * - **CN:** 抽屉距离屏幕边缘的偏移量,支持所有的CSS长度单位, 默认`0`。\n *\n * > 抽屉会隐藏在父容器的外边缘, 但由于父容器可能有padding或border, 导致抽屉不能完全隐藏, 因此可以通过设置 `edgeOffset` 来调整抽屉的偏移量,\n * > 以确保抽屉完全隐藏在父容器之外。\n *\n * @default 0\n */\n edgeOffset?: CSSProperties['width'];\n /**\n * - **EN:** Whether to show the toggle button, default is `true`.\n * - **CN:** 是否显示展开/收起按钮,默认`true`。\n */\n showToggle?: boolean;\n /**\n * - **EN:** Whether the drawer is resizable, default is `true`.\n * - **CN:** 抽屉是否可调整大小, 默认`true`。\n */\n resizable?: boolean;\n /**\n * - **EN:** Whether to destroy the drawer content when closed, default is `false`.\n * - **CN:** 抽屉关闭时是否销毁内容,默认`false`。\n */\n destroyOnClose?: boolean;\n /**\n * - **EN:** Cache key for storing the drawer size in localStorage. If not set, the size will not be\n * cached.\n * - **CN:** 指定一个localStorage缓存键,用于记忆抽屉宽度。如果不设置,则不使用缓存。\n */\n cacheKey?: string;\n /**\n * - **EN:** Custom class name for the root element\n * - **CN:** 根元素的自定义类名\n */\n className?: string;\n /**\n * - **EN:** Custom class names for specific elements\n * - **CN:** 特定元素的自定义类名\n */\n classNames?: {\n /**\n * - **EN:** Class name for the drawer element\n * - **CN:** 抽屉元素的类名\n */\n drawer?: string;\n /**\n * - **EN:** Class name for the expand handle\n * - **CN:** 展开手柄的类名\n */\n toggle?: string;\n /**\n * - **EN:** Class name for the resize handle\n * - **CN:** 调整大小手柄的类名\n */\n resizeHandle?: string;\n /**\n * - **EN:** Class name for the handle icon\n * - **CN:** 手柄图标的类名\n */\n handleIcon?: string;\n /**\n * - **EN:** Class name for the content area\n * - **CN:** 内容区域的类名\n */\n content?: string;\n /**\n * - **EN:** Class name for the card element\n * - **CN:** 卡片元素的类名\n */\n card?: string;\n };\n /**\n * - **EN:** Custom styles for the root element\n * - **CN:** 根元素的自定义样式\n */\n style?: CSSProperties;\n /**\n * - **EN:** Custom styles for specific elements\n * - **CN:** 特定元素的自定义样式\n */\n styles?: {\n /**\n * - **EN:** Styles for the drawer element\n * - **CN:** 抽屉元素的样式\n */\n drawer?: CSSProperties;\n /**\n * - **EN:** Styles for the expand handle\n * - **CN:** 展开手柄的样式\n */\n toggle?: CSSProperties;\n /**\n * - **EN:** Styles for the resize handle\n * - **CN:** 调整大小手柄的样式\n */\n resizeHandle?: CSSProperties;\n /**\n * - **EN:** Styles for the handle icon\n * - **CN:** 手柄图标的样式\n */\n handleIcon?: CSSProperties;\n /**\n * - **EN:** Styles for the content area\n * - **CN:** 内容区域的样式\n */\n content?: CSSProperties;\n /**\n * - **EN:** Styles for the card element\n * - **CN:** 卡片元素的样式\n */\n card?: CSSProperties;\n };\n /**\n * - **EN:** Custom properties for the card element\n * - **CN:** 卡片元素的自定义属性\n */\n cardProps?: Omit<CardProps, 'children'>;\n /**\n * - **EN:** Content to be rendered inside the drawer\n * - **CN:** 抽屉内容\n */\n children?: ReactNode;\n /**\n * - **EN:** Callback function when the open state changes\n * - **CN:** 打开状态变化时的回调函数\n */\n onOpenChange?: (open: boolean) => void;\n /**\n * - **EN:** Callback function when the drawer is resized\n * - **CN:** 抽屉调整大小时的回调函数\n */\n onResize?: (size: number) => void;\n /**\n * - **EN:** Event handler for click events on the drawer container and its internal elements\n * - **CN:** 点击抽屉容器及内部元素时的事件\n */\n onClick?: (e: React.MouseEvent<HTMLDivElement>) => void;\n}\n\n/**\n * - **EN:** FloatDrawer component for creating a draggable, resizable drawer\n * - **CN:** FloatDrawer组件,用于创建可拖动、可调整大小的抽屉\n */\nconst FloatDrawer: FC<FloatDrawerProps> = (props) => {\n const {\n prefixCls: prefixClsInProps,\n open,\n position = 'right',\n cardProps,\n children,\n className,\n classNames: classNamesInProps,\n style,\n styles,\n cacheKey,\n defaultSize,\n minSize = 0,\n maxSize = +Infinity,\n edgeOffset,\n showToggle = true,\n resizable = true,\n destroyOnClose = false,\n onOpenChange,\n onResize,\n onClick,\n } = props;\n const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);\n const prefixCls = getPrefixCls('easy-float-drawer', prefixClsInProps);\n const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls);\n const [drawerRef, setDrawerRef] = useState<HTMLDivElement | null>(null);\n const [size, setSize] = useState(\n cacheKey && localStorage.getItem(cacheKey) ? Number(localStorage.getItem(cacheKey)) || defaultSize : defaultSize\n );\n const sizeMap = useMemo(() => {\n const type = position === 'left' || position === 'right' ? 'width' : 'height';\n return {\n [type]: size,\n };\n }, [position, size]);\n const [isOpen, setIsOpen] = useState<boolean>();\n const [isDragging, setIsDragging] = useState(false);\n const dragStartPos = useRef<number>(0);\n const dragStartSize = useRef<number>(size);\n const classString = classNames(\n prefixCls,\n className,\n {\n [`${prefixCls}-open`]: isOpen,\n [`${prefixCls}-closed`]: !isOpen,\n [`${prefixCls}-${position}`]: position,\n },\n hashId,\n cssVarCls\n );\n const closeIcon = useMemo(() => {\n return position === 'left' ? (\n <RightOutlined />\n ) : position === 'top' ? (\n <DownOutlined />\n ) : position === 'bottom' ? (\n <UpOutlined />\n ) : (\n <LeftOutlined />\n );\n }, [position]);\n const openIcon = useMemo(() => {\n return position === 'left' ? (\n <LeftOutlined />\n ) : position === 'top' ? (\n <UpOutlined />\n ) : position === 'bottom' ? (\n <DownOutlined />\n ) : (\n <RightOutlined />\n );\n }, [position]);\n\n // Handle drawer visibility\n const toggleDrawer = () => {\n setIsOpen(!isOpen);\n onOpenChange?.(!isOpen);\n };\n\n // Handle resize events\n const handleResizeStart = useRefFunction((e: React.MouseEvent) => {\n setIsDragging(true);\n if (position === 'top' || position === 'bottom') {\n dragStartPos.current = e.clientY;\n } else {\n dragStartPos.current = e.clientX;\n }\n dragStartSize.current = size;\n e.preventDefault();\n });\n const handleResize = useRefFunction((e: MouseEvent) => {\n if (isDragging && dragStartSize.current) {\n let newSize: number;\n if (position === 'left') {\n newSize = dragStartSize.current - (dragStartPos.current - e.clientX);\n } else if (position === 'top') {\n newSize = dragStartSize.current - (dragStartPos.current - e.clientY);\n } else if (position === 'bottom') {\n newSize = dragStartSize.current - (e.clientY - dragStartPos.current);\n } else {\n newSize = dragStartSize.current - (e.clientX - dragStartPos.current);\n }\n if (newSize >= minSize && newSize <= maxSize) {\n setSize(newSize);\n if (cacheKey) {\n localStorage.setItem(cacheKey, String(newSize));\n }\n onResize?.(newSize);\n }\n }\n });\n const handleResizeEnd = useRefFunction(() => {\n setIsDragging(false);\n });\n\n // Monitor drawer ref, calculate size if not set\n // This is useful for initial rendering when size is not provided\n useEffect(() => {\n if (drawerRef && size === undefined) {\n const rect = drawerRef.getBoundingClientRect();\n setSize(position === 'left' || position === 'right' ? rect.width : rect.height);\n }\n }, [drawerRef, position, size]);\n\n // Controlled open state\n useEffect(() => {\n setIsOpen(open);\n }, [open]);\n\n // Handle global events\n useEffect(() => {\n if (isDragging) {\n window.addEventListener('mousemove', handleResize);\n window.addEventListener('mouseup', handleResizeEnd);\n } else {\n window.removeEventListener('mousemove', handleResize);\n window.removeEventListener('mouseup', handleResizeEnd);\n }\n return () => {\n window.removeEventListener('mousemove', handleResize);\n window.removeEventListener('mouseup', handleResizeEnd);\n };\n }, [isDragging]);\n\n return wrapCSSVar(\n <div\n className={classString}\n style={{\n // @ts-expect-error: because of dynamic CSS variables\n '--edge-offset': typeof edgeOffset === 'number' ? `${edgeOffset}px` : edgeOffset,\n ...style,\n }}\n onClick={onClick}\n >\n <div\n ref={setDrawerRef}\n className={classNames(`${prefixCls}-drawer`, classNamesInProps?.drawer)}\n style={{ ...sizeMap, ...styles?.drawer }}\n >\n {resizable && (\n <div\n className={classNames(\n `${prefixCls}-resize-handle`,\n isDragging && `${prefixCls}-resize-handle-dragging`,\n classNamesInProps?.resizeHandle\n )}\n style={styles?.resizeHandle}\n onMouseDown={handleResizeStart}\n />\n )}\n <div className={classNames(`${prefixCls}-content`, classNamesInProps?.content)} style={styles?.content}>\n <Card\n bordered={false}\n variant=\"borderless\"\n className={classNames(`${prefixCls}-card`, classNamesInProps?.card)}\n style={styles?.card}\n {...cardProps}\n >\n {!destroyOnClose || isOpen ? children : null}\n </Card>\n </div>\n {showToggle && (\n <div\n className={classNames(`${prefixCls}-toggle`, classNamesInProps?.toggle)}\n style={styles?.toggle}\n onClick={toggleDrawer}\n >\n <div\n className={classNames(`${prefixCls}-handle-icon`, classNamesInProps?.handleIcon)}\n style={styles?.handleIcon}\n >\n {isOpen ? openIcon : closeIcon}\n </div>\n </div>\n )}\n </div>\n </div>\n );\n};\n\nexport default FloatDrawer;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;A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AA;AAAA,cACT,GAAG;AAAA,cACH,cAAc,GAAG;AAAA,cACjB,uDAAmB;AAAA,YACrB;AAAA,YACA,OAAO,iCAAQ;AAAA,YACf,aAAa;AAAA;AAAA,QACf;AAAA,QAEF,oCAAC,SAAI,eAAW,kBAAAA,SAAW,GAAG,qBAAqB,uDAAmB,OAAO,GAAG,OAAO,iCAAQ,WAC7F;AAAA,UAAC;AAAA;AAAA,YACC,UAAU;AAAA,YACV,SAAQ;AAAA,YACR,eAAW,kBAAAA,SAAW,GAAG,kBAAkB,uDAAmB,IAAI;AAAA,YAClE,OAAO,iCAAQ;AAAA,YACd,GAAG;AAAA;AAAA,UAEH,CAAC,kBAAkB,SAAS,WAAW;AAAA,QAC1C,CACF;AAAA,QACC,cACC;AAAA,UAAC;AAAA;AAAA,YACC,eAAW,kBAAAA,SAAW,GAAG,oBAAoB,uDAAmB,MAAM;AAAA,YACtE,OAAO,iCAAQ;AAAA,YACf,SAAS;AAAA;AAAA,UAET;AAAA,YAAC;AAAA;AAAA,cACC,eAAW,kBAAAA,SAAW,GAAG,yBAAyB,uDAAmB,UAAU;AAAA,cAC/E,OAAO,iCAAQ;AAAA;AAAA,YAEd,SAAS,WAAW;AAAA,UACvB;AAAA,QACF;AAAA,MAEJ;AAAA,IACF;AAAA,EACF;AACF;AAEA,IAAO,sBAAQ;",
6
6
  "names": ["useStyle", "classNames", "useRefFunction"]
7
7
  }
@@ -1,27 +1,27 @@
1
1
  /// <reference types="react" />
2
2
  export interface UseDebounceOptions {
3
3
  /**
4
- * - **EN** Whether to execute at the start of the wait period. Default is `false`.
5
- * - **CN** 是否在等待周期开始时执行,默认值为 `false`
4
+ * - **EN:** Whether to execute at the start of the wait period. Default is `false`.
5
+ * - **CN:** 是否在等待周期开始时执行,默认值为 `false`
6
6
  */
7
7
  leading?: boolean;
8
8
  /**
9
- * - **EN** Regular debounce interval in milliseconds. Default is `0`, meaning no debounce.
10
- * - **CN** 常规防抖间隔 (ms),默认值为 `0`, 表示不进行防抖
9
+ * - **EN:** Regular debounce interval in milliseconds. Default is `0`, meaning no debounce.
10
+ * - **CN:** 常规防抖间隔 (ms),默认值为 `0`, 表示不进行防抖
11
11
  */
12
12
  wait?: number;
13
13
  /**
14
- * - **EN** Maximum wait time in milliseconds. Default is `0`, meaning no maximum wait.
15
- * - **CN** 最大等待时间 (ms),默认值为 `0`, 表示不限制最大等待时间
14
+ * - **EN:** Maximum wait time in milliseconds. Default is `0`, meaning no maximum wait.
15
+ * - **CN:** 最大等待时间 (ms),默认值为 `0`, 表示不限制最大等待时间
16
16
  */
17
17
  maxWait?: number;
18
18
  }
19
19
  /**
20
- * - **EN** Debounce Hook with dual trigger mechanisms:
20
+ * - **EN:** Debounce Hook with dual trigger mechanisms:
21
21
  *
22
22
  * 1. Traditional debounce: Executes after a specified interval without new calls.
23
23
  * 2. Max wait: Forces execution after exceeding a specified maximum wait time.
24
- * - **CN** 防抖 Hook:具有两种触发机制:
24
+ * - **CN:** 防抖 Hook:具有两种触发机制:
25
25
  *
26
26
  * 1. 传统防抖:等待指定时间内无新调用后执行
27
27
  * 2. 最大等待:超过指定最大等待时间后强制执行
@@ -33,5 +33,33 @@ export interface UseDebounceOptions {
33
33
  *
34
34
  * @returns The debounced function | 防抖处理后的函数
35
35
  */
36
- declare function useDebounce<T extends (...args: any[]) => unknown>(fn: T, deps: React.DependencyList, options?: UseDebounceOptions): (...args: Parameters<T>) => void;
36
+ declare function useDebounce<T extends (...args: any[]) => unknown>(fn: T, deps: React.DependencyList, options?: UseDebounceOptions): DebouncedFunc<T>;
37
+ export interface DebouncedFunc<T extends (...args: any[]) => unknown> {
38
+ /**
39
+ * - **EN:** The debounced function.
40
+ * - **CN:** 防抖处理后的函数
41
+ */
42
+ (...args: Parameters<T>): ReturnType<T>;
43
+ /**
44
+ * - **EN:** Cancel any pending execution of the debounced function.
45
+ * - **CN:** 取消防抖函数的任何待执行操作
46
+ */
47
+ cancel: () => void;
48
+ /**
49
+ * - **EN:** Disable the debounce functionality. Once disabled, subsequent calls to the function
50
+ * will have no effect until re-enabled.
51
+ * - **CN:** 禁用此防抖函数,一旦被禁用,再次调用改函数将不会有任何效果,除非重新启用
52
+ */
53
+ disable: () => void;
54
+ /**
55
+ * - **EN:** Re-enable the debounce functionality after it has been disabled.
56
+ * - **CN:** 重新启用此防抖函数
57
+ */
58
+ enable: () => void;
59
+ /**
60
+ * - **EN:** Check if the debounce functionality is currently disabled.
61
+ * - **CN:** 检查此防抖函数当前是否被禁用
62
+ */
63
+ isDisabled(): boolean;
64
+ }
37
65
  export default useDebounce;
@@ -1,6 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
4
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
7
  var __export = (target, all) => {
6
8
  for (var name in all)
@@ -14,6 +16,14 @@ var __copyProps = (to, from, except, desc) => {
14
16
  }
15
17
  return to;
16
18
  };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
17
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
28
 
19
29
  // src/hooks/useDebounce.ts
@@ -23,12 +33,14 @@ __export(useDebounce_exports, {
23
33
  });
24
34
  module.exports = __toCommonJS(useDebounce_exports);
25
35
  var import_react = require("react");
36
+ var import_useRefFunction = __toESM(require("./useRefFunction"));
26
37
  function useDebounce(fn, deps, options = {}) {
27
38
  const { wait = 0, maxWait = 0, leading = false } = options;
28
39
  const timeoutRef = (0, import_react.useRef)(null);
29
40
  const fnRef = (0, import_react.useRef)(fn);
30
41
  const lastExecutedTimeRef = (0, import_react.useRef)(0);
31
42
  const lastArgsRef = (0, import_react.useRef)([]);
43
+ const isDisabledRef = (0, import_react.useRef)(false);
32
44
  (0, import_react.useEffect)(() => {
33
45
  fnRef.current = fn;
34
46
  }, [fn]);
@@ -45,27 +57,40 @@ function useDebounce(fn, deps, options = {}) {
45
57
  lastExecutedTimeRef.current = Date.now();
46
58
  fnRef.current(...lastArgsRef.current);
47
59
  }, []);
48
- return (0, import_react.useCallback)(
49
- (...args) => {
50
- const now = Date.now();
51
- lastArgsRef.current = args;
52
- if (leading && timeoutRef.current === null && now - lastExecutedTimeRef.current >= wait) {
53
- executeFunction();
54
- return;
55
- }
56
- if (timeoutRef.current !== null) {
57
- clearTimeout(timeoutRef.current);
58
- timeoutRef.current = null;
59
- }
60
- if (maxWait > 0 && now - lastExecutedTimeRef.current >= maxWait) {
61
- executeFunction();
62
- return;
63
- }
64
- timeoutRef.current = setTimeout(executeFunction, wait);
65
- },
66
- // eslint-disable-next-line @tiny-codes/react-hooks/exhaustive-deps
67
- [wait, maxWait, executeFunction, leading, ...deps]
68
- );
60
+ const debouncedFunction = (0, import_useRefFunction.default)((...args) => {
61
+ if (isDisabledRef.current) {
62
+ return;
63
+ }
64
+ const now = Date.now();
65
+ lastArgsRef.current = args;
66
+ if (leading && timeoutRef.current === null && now - lastExecutedTimeRef.current >= wait) {
67
+ executeFunction();
68
+ return;
69
+ }
70
+ if (timeoutRef.current !== null) {
71
+ clearTimeout(timeoutRef.current);
72
+ timeoutRef.current = null;
73
+ }
74
+ if (maxWait > 0 && now - lastExecutedTimeRef.current >= maxWait) {
75
+ executeFunction();
76
+ return;
77
+ }
78
+ timeoutRef.current = setTimeout(executeFunction, wait);
79
+ });
80
+ debouncedFunction.cancel = () => {
81
+ if (timeoutRef.current) {
82
+ clearTimeout(timeoutRef.current);
83
+ timeoutRef.current = null;
84
+ }
85
+ };
86
+ debouncedFunction.disable = () => {
87
+ isDisabledRef.current = true;
88
+ };
89
+ debouncedFunction.enable = () => {
90
+ isDisabledRef.current = false;
91
+ };
92
+ debouncedFunction.isDisabled = () => isDisabledRef.current;
93
+ return debouncedFunction;
69
94
  }
70
95
  var useDebounce_default = useDebounce;
71
96
  //# sourceMappingURL=useDebounce.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/hooks/useDebounce.ts"],
4
- "sourcesContent": ["import { useCallback, useEffect, useRef } from 'react';\n\nexport interface UseDebounceOptions {\n /**\n * - **EN** Whether to execute at the start of the wait period. Default is `false`.\n * - **CN** 是否在等待周期开始时执行,默认值为 `false`\n */\n leading?: boolean;\n /**\n * - **EN** Regular debounce interval in milliseconds. Default is `0`, meaning no debounce.\n * - **CN** 常规防抖间隔 (ms),默认值为 `0`, 表示不进行防抖\n */\n wait?: number;\n /**\n * - **EN** Maximum wait time in milliseconds. Default is `0`, meaning no maximum wait.\n * - **CN** 最大等待时间 (ms),默认值为 `0`, 表示不限制最大等待时间\n */\n maxWait?: number;\n}\n/**\n * - **EN** Debounce Hook with dual trigger mechanisms:\n *\n * 1. Traditional debounce: Executes after a specified interval without new calls.\n * 2. Max wait: Forces execution after exceeding a specified maximum wait time.\n * - **CN** 防抖 Hook:具有两种触发机制:\n *\n * 1. 传统防抖:等待指定时间内无新调用后执行\n * 2. 最大等待:超过指定最大等待时间后强制执行\n *\n * @param fn The function to debounce | 需要防抖的函数\n * @param deps Dependency array, re-creates the debounced function when dependencies change |\n * 依赖项数组,当依赖变化时重新创建防抖函数\n * @param options Configuration options | 配置选项\n *\n * @returns The debounced function | 防抖处理后的函数\n */\nfunction useDebounce<T extends (...args: any[]) => unknown>(\n fn: T,\n deps: React.DependencyList,\n options: UseDebounceOptions = {}\n): (...args: Parameters<T>) => void {\n const { wait = 0, maxWait = 0, leading = false } = options;\n const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const fnRef = useRef<T>(fn);\n const lastExecutedTimeRef = useRef<number>(0); // The last execution timestamp\n const lastArgsRef = useRef<unknown[]>([]); // The last call arguments\n\n // Update the latest function reference\n useEffect(() => {\n fnRef.current = fn;\n }, [fn]);\n\n // Cleanup on unmount\n useEffect(() => {\n return () => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n timeoutRef.current = null;\n }\n };\n }, []);\n\n // The actual execution function\n const executeFunction = useCallback(() => {\n timeoutRef.current = null;\n lastExecutedTimeRef.current = Date.now();\n fnRef.current(...lastArgsRef.current);\n }, []);\n\n // The debounced function\n return useCallback(\n (...args: Parameters<T>) => {\n const now = Date.now();\n lastArgsRef.current = args;\n\n // If leading is true and it's the first call, execute immediately\n if (leading && timeoutRef.current === null && now - lastExecutedTimeRef.current >= wait) {\n executeFunction();\n return;\n }\n\n // 1. Clear the existing timer\n if (timeoutRef.current !== null) {\n clearTimeout(timeoutRef.current);\n timeoutRef.current = null;\n }\n\n // 2. Check if the maximum wait time has been exceeded, if so, execute immediately\n if (maxWait > 0 && now - lastExecutedTimeRef.current >= maxWait) {\n executeFunction();\n return;\n }\n\n // 3. Set a new debounce timer\n timeoutRef.current = setTimeout(executeFunction, wait);\n },\n // eslint-disable-next-line @tiny-codes/react-hooks/exhaustive-deps\n [wait, maxWait, executeFunction, leading, ...deps]\n );\n}\n\nexport default useDebounce;\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA+C;AAoC/C,SAAS,YACP,IACA,MACA,UAA8B,CAAC,GACG;AAClC,QAAM,EAAE,OAAO,GAAG,UAAU,GAAG,UAAU,MAAM,IAAI;AACnD,QAAM,iBAAa,qBAA6C,IAAI;AACpE,QAAM,YAAQ,qBAAU,EAAE;AAC1B,QAAM,0BAAsB,qBAAe,CAAC;AAC5C,QAAM,kBAAc,qBAAkB,CAAC,CAAC;AAGxC,8BAAU,MAAM;AACd,UAAM,UAAU;AAAA,EAClB,GAAG,CAAC,EAAE,CAAC;AAGP,8BAAU,MAAM;AACd,WAAO,MAAM;AACX,UAAI,WAAW,SAAS;AACtB,qBAAa,WAAW,OAAO;AAC/B,mBAAW,UAAU;AAAA,MACvB;AAAA,IACF;AAAA,EACF,GAAG,CAAC,CAAC;AAGL,QAAM,sBAAkB,0BAAY,MAAM;AACxC,eAAW,UAAU;AACrB,wBAAoB,UAAU,KAAK,IAAI;AACvC,UAAM,QAAQ,GAAG,YAAY,OAAO;AAAA,EACtC,GAAG,CAAC,CAAC;AAGL,aAAO;AAAA,IACL,IAAI,SAAwB;AAC1B,YAAM,MAAM,KAAK,IAAI;AACrB,kBAAY,UAAU;AAGtB,UAAI,WAAW,WAAW,YAAY,QAAQ,MAAM,oBAAoB,WAAW,MAAM;AACvF,wBAAgB;AAChB;AAAA,MACF;AAGA,UAAI,WAAW,YAAY,MAAM;AAC/B,qBAAa,WAAW,OAAO;AAC/B,mBAAW,UAAU;AAAA,MACvB;AAGA,UAAI,UAAU,KAAK,MAAM,oBAAoB,WAAW,SAAS;AAC/D,wBAAgB;AAChB;AAAA,MACF;AAGA,iBAAW,UAAU,WAAW,iBAAiB,IAAI;AAAA,IACvD;AAAA;AAAA,IAEA,CAAC,MAAM,SAAS,iBAAiB,SAAS,GAAG,IAAI;AAAA,EACnD;AACF;AAEA,IAAO,sBAAQ;",
6
- "names": []
4
+ "sourcesContent": ["import { useCallback, useEffect, useRef } from 'react';\nimport useRefFunction from './useRefFunction';\n\nexport interface UseDebounceOptions {\n /**\n * - **EN:** Whether to execute at the start of the wait period. Default is `false`.\n * - **CN:** 是否在等待周期开始时执行,默认值为 `false`\n */\n leading?: boolean;\n /**\n * - **EN:** Regular debounce interval in milliseconds. Default is `0`, meaning no debounce.\n * - **CN:** 常规防抖间隔 (ms),默认值为 `0`, 表示不进行防抖\n */\n wait?: number;\n /**\n * - **EN:** Maximum wait time in milliseconds. Default is `0`, meaning no maximum wait.\n * - **CN:** 最大等待时间 (ms),默认值为 `0`, 表示不限制最大等待时间\n */\n maxWait?: number;\n}\n/**\n * - **EN:** Debounce Hook with dual trigger mechanisms:\n *\n * 1. Traditional debounce: Executes after a specified interval without new calls.\n * 2. Max wait: Forces execution after exceeding a specified maximum wait time.\n * - **CN:** 防抖 Hook:具有两种触发机制:\n *\n * 1. 传统防抖:等待指定时间内无新调用后执行\n * 2. 最大等待:超过指定最大等待时间后强制执行\n *\n * @param fn The function to debounce | 需要防抖的函数\n * @param deps Dependency array, re-creates the debounced function when dependencies change |\n * 依赖项数组,当依赖变化时重新创建防抖函数\n * @param options Configuration options | 配置选项\n *\n * @returns The debounced function | 防抖处理后的函数\n */\nfunction useDebounce<T extends (...args: any[]) => unknown>(\n fn: T,\n deps: React.DependencyList,\n options: UseDebounceOptions = {}\n): DebouncedFunc<T> {\n const { wait = 0, maxWait = 0, leading = false } = options;\n const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const fnRef = useRef<T>(fn);\n const lastExecutedTimeRef = useRef<number>(0); // The last execution timestamp\n const lastArgsRef = useRef<unknown[]>([]); // The last call arguments\n const isDisabledRef = useRef<boolean>(false); // Whether debounce is disabled\n\n // Update the latest function reference\n useEffect(() => {\n fnRef.current = fn;\n }, [fn]);\n\n // Cleanup on unmount\n useEffect(() => {\n return () => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n timeoutRef.current = null;\n }\n };\n }, []);\n\n // The actual execution function\n const executeFunction = useCallback(() => {\n timeoutRef.current = null;\n lastExecutedTimeRef.current = Date.now();\n fnRef.current(...lastArgsRef.current);\n }, []);\n\n // The debounced function\n const debouncedFunction = useRefFunction((...args: Parameters<T>) => {\n if (isDisabledRef.current) {\n return;\n }\n const now = Date.now();\n lastArgsRef.current = args;\n\n // If leading is true and it's the first call, execute immediately\n if (leading && timeoutRef.current === null && now - lastExecutedTimeRef.current >= wait) {\n executeFunction();\n return;\n }\n\n // 1. Clear the existing timer\n if (timeoutRef.current !== null) {\n clearTimeout(timeoutRef.current);\n timeoutRef.current = null;\n }\n\n // 2. Check if the maximum wait time has been exceeded, if so, execute immediately\n if (maxWait > 0 && now - lastExecutedTimeRef.current >= maxWait) {\n executeFunction();\n return;\n }\n\n // 3. Set a new debounce timer\n timeoutRef.current = setTimeout(executeFunction, wait);\n }) as DebouncedFunc<T>;\n debouncedFunction.cancel = () => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n timeoutRef.current = null;\n }\n };\n debouncedFunction.disable = () => {\n isDisabledRef.current = true;\n };\n debouncedFunction.enable = () => {\n isDisabledRef.current = false;\n };\n debouncedFunction.isDisabled = () => isDisabledRef.current;\n return debouncedFunction;\n}\n\nexport interface DebouncedFunc<T extends (...args: any[]) => unknown> {\n /**\n * - **EN:** The debounced function.\n * - **CN:** 防抖处理后的函数\n */\n (...args: Parameters<T>): ReturnType<T>;\n /**\n * - **EN:** Cancel any pending execution of the debounced function.\n * - **CN:** 取消防抖函数的任何待执行操作\n */\n cancel: () => void;\n /**\n * - **EN:** Disable the debounce functionality. Once disabled, subsequent calls to the function\n * will have no effect until re-enabled.\n * - **CN:** 禁用此防抖函数,一旦被禁用,再次调用改函数将不会有任何效果,除非重新启用\n */\n disable: () => void;\n /**\n * - **EN:** Re-enable the debounce functionality after it has been disabled.\n * - **CN:** 重新启用此防抖函数\n */\n enable: () => void;\n /**\n * - **EN:** Check if the debounce functionality is currently disabled.\n * - **CN:** 检查此防抖函数当前是否被禁用\n */\n isDisabled(): boolean;\n}\n\nexport default useDebounce;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA+C;AAC/C,4BAA2B;AAoC3B,SAAS,YACP,IACA,MACA,UAA8B,CAAC,GACb;AAClB,QAAM,EAAE,OAAO,GAAG,UAAU,GAAG,UAAU,MAAM,IAAI;AACnD,QAAM,iBAAa,qBAA6C,IAAI;AACpE,QAAM,YAAQ,qBA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ACnD,SAAO;AACT;AA+BA,IAAO,sBAAQ;",
6
+ "names": ["useRefFunction"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiny-codes/react-easy",
3
- "version": "1.4.16",
3
+ "version": "1.4.18",
4
4
  "description": "Simplify React and AntDesign development with practical components and hooks",
5
5
  "keywords": [
6
6
  "react",