@tiny-codes/react-easy 1.7.4 → 1.7.6
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 +25 -0
- package/es/components/Animation/Pulse/index.d.ts +18 -2
- package/es/components/Animation/Pulse/index.js +1 -1
- package/es/components/Animation/Pulse/index.js.map +1 -1
- package/es/components/BreakLines/index.d.ts +7 -7
- package/es/components/BreakLines/index.js.map +1 -1
- package/es/components/ColumnSetting/index.d.ts +7 -2
- package/es/components/ColumnSetting/index.js +27 -16
- package/es/components/ColumnSetting/index.js.map +1 -1
- package/es/components/ConfigProvider/context.d.ts +2 -0
- package/es/components/ConfigProvider/context.js +1 -1
- package/es/components/ConfigProvider/context.js.map +1 -1
- package/es/components/ConfigProvider/index.d.ts +17 -1
- package/es/components/ConfigProvider/index.js +15 -8
- package/es/components/ConfigProvider/index.js.map +1 -1
- package/es/components/ContextMenu/index.d.ts +16 -0
- package/es/components/ContextMenu/index.js.map +1 -1
- package/es/components/EditableText/form.d.ts +4 -0
- package/es/components/EditableText/form.js.map +1 -1
- package/es/components/EditableText/index.d.ts +6 -2
- package/es/components/EditableText/index.js.map +1 -1
- package/es/components/EllipsisTypography/EllipsisLink.d.ts +19 -0
- package/es/components/EllipsisTypography/EllipsisLink.js +19 -0
- package/es/components/EllipsisTypography/EllipsisLink.js.map +1 -0
- package/es/components/FloatDrawer/index.d.ts +10 -0
- package/es/components/FloatDrawer/index.js.map +1 -1
- package/es/components/OverflowTags/index.d.ts +2 -0
- package/es/components/OverflowTags/index.js.map +1 -1
- package/es/components/index.d.ts +2 -0
- package/es/components/index.js +2 -0
- package/es/components/index.js.map +1 -1
- package/es/hooks/index.d.ts +2 -0
- package/es/hooks/index.js +2 -0
- package/es/hooks/index.js.map +1 -1
- package/es/hooks/useLocalStorage.d.ts +16 -0
- package/es/hooks/useLocalStorage.js +115 -0
- package/es/hooks/useLocalStorage.js.map +1 -0
- package/es/hooks/useMovable.js +2 -2
- package/es/hooks/useMovable.js.map +1 -1
- package/es/locales/index.js +1 -1
- package/es/locales/index.js.map +1 -1
- package/es/utils/math.d.ts +11 -3
- package/es/utils/math.js +62 -9
- package/es/utils/math.js.map +1 -1
- package/lib/components/Animation/Pulse/index.d.ts +18 -2
- package/lib/components/Animation/Pulse/index.js +0 -5
- package/lib/components/Animation/Pulse/index.js.map +2 -2
- package/lib/components/BreakLines/index.d.ts +7 -7
- package/lib/components/BreakLines/index.js.map +1 -1
- package/lib/components/ColumnSetting/index.d.ts +7 -2
- package/lib/components/ColumnSetting/index.js +18 -14
- package/lib/components/ColumnSetting/index.js.map +3 -3
- package/lib/components/ConfigProvider/context.d.ts +2 -0
- package/lib/components/ConfigProvider/context.js +1 -1
- package/lib/components/ConfigProvider/context.js.map +2 -2
- package/lib/components/ConfigProvider/index.d.ts +17 -1
- package/lib/components/ConfigProvider/index.js +13 -6
- package/lib/components/ConfigProvider/index.js.map +2 -2
- package/lib/components/ContextMenu/index.d.ts +16 -0
- package/lib/components/ContextMenu/index.js.map +2 -2
- package/lib/components/EditableText/form.d.ts +4 -0
- package/lib/components/EditableText/form.js.map +2 -2
- package/lib/components/EditableText/index.d.ts +6 -2
- package/lib/components/EditableText/index.js.map +2 -2
- package/lib/components/EllipsisTypography/EllipsisLink.d.ts +19 -0
- package/lib/components/EllipsisTypography/EllipsisLink.js +39 -0
- package/lib/components/EllipsisTypography/EllipsisLink.js.map +7 -0
- package/lib/components/FloatDrawer/index.d.ts +10 -0
- package/lib/components/FloatDrawer/index.js.map +2 -2
- package/lib/components/OverflowTags/index.d.ts +2 -0
- package/lib/components/OverflowTags/index.js.map +2 -2
- package/lib/components/index.d.ts +2 -0
- package/lib/components/index.js +6 -1
- package/lib/components/index.js.map +2 -2
- package/lib/hooks/index.d.ts +2 -0
- package/lib/hooks/index.js +5 -0
- package/lib/hooks/index.js.map +2 -2
- package/lib/hooks/useLocalStorage.d.ts +16 -0
- package/lib/hooks/useLocalStorage.js +120 -0
- package/lib/hooks/useLocalStorage.js.map +7 -0
- package/lib/hooks/useMovable.js +2 -2
- package/lib/hooks/useMovable.js.map +3 -3
- package/lib/locales/index.js +1 -1
- package/lib/locales/index.js.map +1 -1
- package/lib/utils/math.d.ts +11 -3
- package/lib/utils/math.js +43 -8
- package/lib/utils/math.js.map +3 -3
- package/package.json +14 -7
|
@@ -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","_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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,"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 /**\n * - **EN:** Custom prefix for the component's CSS class.\n * - **CN:** 组件的自定义 CSS 类前缀。\n */\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 * @default true\n */\n showToggle?: boolean;\n /**\n * - **EN:** Whether the drawer is resizable, default is `true`.\n * - **CN:** 抽屉是否可调整大小, 默认`true`。\n *\n * @default true\n */\n resizable?: boolean;\n /**\n * - **EN:** Whether to destroy the drawer content when closed, default is `false`.\n * - **CN:** 抽屉关闭时是否销毁内容,默认`false`。\n *\n * @default 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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EgF,OAAQ;QAAApF,QAAA,eACrGX,IAAA,CAACV,IAAI,EAAAoG,aAAA,CAAAA,aAAA;UACHM,QAAQ,EAAE,KAAM;UAChBC,OAAO,EAAC,YAAY;UACpBrF,SAAS,EAAEpB,UAAU,IAAA2E,MAAA,CAAI7D,SAAS,YAASO,iBAAiB,aAAjBA,iBAAiB,uBAAjBA,iBAAiB,CAAEqF,IAAI,CAAE;UACpEpF,KAAK,EAAEC,MAAM,aAANA,MAAM,uBAANA,MAAM,CAAEmF;QAAK,GAChBxF,SAAS;UAAAC,QAAA,EAEZ,CAACkB,cAAc,IAAI6B,MAAM,GAAG/C,QAAQ,GAAG;QAAI,EACxC;MAAC,CACJ,CAAC,EACLc,UAAU,iBACTzB,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"}
|
|
@@ -55,6 +55,8 @@ export interface OverflowTagsProps<T> extends Omit<OverflowProps<T>, 'renderItem
|
|
|
55
55
|
* contain a `color` property to specify the color, and the latter takes precedence.
|
|
56
56
|
*
|
|
57
57
|
* **CN**: 是否使用随机颜色,默认`false`。注意,tag对象还可以包含`color`属性来指定颜色,而且后者优先级更高。
|
|
58
|
+
*
|
|
59
|
+
* @default false
|
|
58
60
|
*/
|
|
59
61
|
randomColors?: boolean;
|
|
60
62
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useCallback","useContext","useMemo","ConfigProvider","Dropdown","Tag","theme","PresetColors","classNames","Overflow","random","useStyle","jsx","_jsx","jsxs","_jsxs","OverflowTags","props","_props$tags","tags","randomColors","getTagNameInProps","getTagName","getTagKey","tagProps","ellipsisTagProps","ellipsisDropdownProps","className","prefixClsInProps","prefixCls","restProps","_objectWithoutProperties","_excluded","_theme$useToken","useToken","token","_useContext","ConfigContext","getPrefixCls","_useStyle","_useStyle2","_slicedToArray","wrapCSSVar","hashId","cssVarCls","colors","filter","c","includes","map","color","concat","getValue","tag","field","_typeof","record","undefined","_ref","_getValue","toString","renderTag","item","_objectSpread","icon","length","children","data","maxCount","renderItem","renderRest","omittedItems","menu","items","_ref2","_getValue2","type","key","label","allTags"],"sources":["../../../src/components/OverflowTags/index.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\nimport { useCallback, useContext, useMemo } from 'react';\nimport type { DropdownProps, TagProps } from 'antd';\nimport { ConfigProvider, Dropdown, Tag, theme } from 'antd';\nimport { PresetColors } from 'antd/es/theme/internal';\nimport classNames from 'classnames';\nimport type { OverflowProps } from 'rc-overflow';\nimport Overflow from 'rc-overflow';\nimport { random } from '../../utils/math';\nimport useStyle from './style';\n\nexport interface OverflowTagsProps<T> extends Omit<OverflowProps<T>, 'renderItem'> {\n /**\n * **CN**: 标签集合的数据\n *\n * **EN**: Data collection of tags\n */\n tags: T[] | undefined;\n /**\n * **EN**: Function to get the tag name, default is `tag.label` or `tag.name`\n *\n * **CN**: 获取标签名称的函数,默认取`tag.label`或`tag.name`\n */\n getTagName?: (tag: T) => ReactNode;\n /**\n * **EN**: Function to get the unique identifier of the tag, default is `tag.value` or `tag.id`\n *\n * **CN**: 获取标签唯一标识的函数,默认取`tag.value`或`tag.id`\n */\n getTagKey?: (tag: T) => React.Key;\n\n /**\n * **EN**: Custom tag rendering function\n *\n * **CN**: 标签渲染函数\n */\n renderTag?: OverflowProps<T>['renderItem'];\n /**\n * **EN**: Custom properties for the tag component\n *\n * **CN**: 自定义标签的组件属性\n */\n tagProps?: TagProps | ((tag: T, options: { tags: T[] }) => TagProps);\n /**\n * **EN**: When the number of tags exceeds the maximum display count, an ellipsis tag will be\n * shown. This property is used to set the style of the ellipsis tag.\n *\n * **CN**: 当标签数量超过最大显示数量时,会显示省略号的标签,此属性用于设置省略号标签的样式\n */\n ellipsisTagProps?: TagProps | ((tag: T, options: { omittedItems: T[]; allTags: T[] }) => TagProps);\n /**\n * **EN**: Custom properties for the dropdown component when tags are overflowed\n *\n * **CN**: 当标签溢出时,下拉菜单的自定义属性\n */\n ellipsisDropdownProps?: DropdownProps;\n /**\n * **EN**: Whether to use random colors, default is `false`. Note that the tag object can also\n * contain a `color` property to specify the color, and the latter takes precedence.\n *\n * **CN**: 是否使用随机颜色,默认`false`。注意,tag对象还可以包含`color`属性来指定颜色,而且后者优先级更高。\n */\n randomColors?: boolean;\n}\n\n/**\n * - **EN:** Overflow tags component, used to display a collection of tags that can overflow and be\n * truncated. It supports displaying tags in a dropdown when the number of tags exceeds the\n * maximum display count. It also supports custom tag rendering and properties.\n * - **CN:** 溢出标签组件,用于显示一组可以溢出和截断的标签集合。当标签数量超过最大显示数量时,支持在下拉菜单中显示标签。还支持自定义标签渲染和属性。\n *\n * @example\n * <OverflowTags\n * tags={[\n * { value: 1, label: 'Tag1', icon: <Icon1 /> },\n * { value: 2, label: 'Tag2', icon: <Icon2 /> },\n * ]}\n * tagProps={{ color: 'blue' }}\n * ellipsisTagProps={{ color: 'grey' }}\n * />;\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst OverflowTags = <T,>(props: OverflowTagsProps<T>) => {\n const {\n tags = [],\n randomColors,\n getTagName: getTagNameInProps,\n getTagKey,\n tagProps,\n ellipsisTagProps,\n ellipsisDropdownProps,\n className,\n prefixCls: prefixClsInProps,\n ...restProps\n } = props;\n const { token } = theme.useToken();\n const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);\n const prefixCls = getPrefixCls('easy-overflow-tags', prefixClsInProps);\n const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls);\n\n const colors = useMemo(\n () => PresetColors.filter((c) => !['lime', 'yellow', 'magenta'].includes(c)).map((color) => token[`${color}-3`]),\n [token]\n );\n const getValue = useCallback((tag: T | undefined, field: string) => {\n if (tag != null && typeof tag === 'object') {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const record = tag as Record<string, any>;\n return record[field];\n }\n return undefined;\n }, []);\n const getTagName = useCallback(\n (tag: T) => {\n return getTagNameInProps\n ? getTagNameInProps(tag)\n : (getValue(tag, 'label') ?? getValue(tag, 'name') ?? tag?.toString());\n },\n [getTagNameInProps, getValue]\n );\n const renderTag = (item: T) => {\n return (\n <Tag\n icon={getValue(item, 'icon')}\n color={randomColors ? colors[random(0, colors.length - 1)] : getValue(item, 'color') || 'default'}\n {...(typeof tagProps === 'function' ? tagProps(item, { tags }) : tagProps)}\n >\n {getTagName(item)}\n </Tag>\n );\n };\n\n return wrapCSSVar(\n <Overflow<T>\n className={classNames(hashId, cssVarCls, prefixCls, className)}\n data={tags}\n maxCount=\"responsive\"\n renderItem={renderTag}\n renderRest={(omittedItems) => (\n <Dropdown\n {...ellipsisDropdownProps}\n menu={{\n items: omittedItems.map((tag) => ({\n type: 'item',\n key: getTagKey ? getTagKey(tag) : (getValue(tag, 'value') ?? getValue(tag, 'id') ?? getTagName(tag)),\n label: getTagName(tag),\n })),\n ...ellipsisDropdownProps?.menu,\n }}\n >\n <Tag\n {...(typeof ellipsisTagProps === 'function'\n ? ellipsisTagProps(omittedItems[0], { omittedItems, allTags: tags })\n : ellipsisTagProps)}\n >\n + {omittedItems.length}...\n </Tag>\n </Dropdown>\n )}\n {...restProps}\n />\n );\n};\n\nex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AAA,UAAA,GAAIvB,QAAQ,CAACC,GAAG,EAAE,IAAI,CAAC,cAAAqB,KAAA,cAAAA,KAAA,GAAIpD,UAAU,CAAC+B,GAAG,CAAE;cACpGyB,KAAK,EAAExD,UAAU,CAAC+B,GAAG;YACvB,CAAC;UAAA,CAAC;QAAC,GACA3B,qBAAqB,aAArBA,qBAAqB,uBAArBA,qBAAqB,CAAE8C,IAAI,CAC9B;QAAAN,QAAA,eAEFnD,KAAA,CAACV,GAAG,EAAA0D,aAAA,CAAAA,aAAA,KACG,OAAOtC,gBAAgB,KAAK,UAAU,GACvCA,gBAAgB,CAAC8C,YAAY,CAAC,CAAC,CAAC,EAAE;UAAEA,YAAY,EAAZA,YAAY;UAAEQ,OAAO,EAAE5D;QAAK,CAAC,CAAC,GAClEM,gBAAgB;UAAAyC,QAAA,GACrB,IACG,EAACK,YAAY,CAACN,MAAM,EAAC,KACzB;QAAA,EAAK;MAAC,EACE,CAAC;IAAA;EACX,GACEnC,SAAS,CACd,CACH,CAAC;AACH,CAAC;AAED,eAAed,YAAY"}
|
|
1
|
+
{"version":3,"names":["useCallback","useContext","useMemo","ConfigProvider","Dropdown","Tag","theme","PresetColors","classNames","Overflow","random","useStyle","jsx","_jsx","jsxs","_jsxs","OverflowTags","props","_props$tags","tags","randomColors","getTagNameInProps","getTagName","getTagKey","tagProps","ellipsisTagProps","ellipsisDropdownProps","className","prefixClsInProps","prefixCls","restProps","_objectWithoutProperties","_excluded","_theme$useToken","useToken","token","_useContext","ConfigContext","getPrefixCls","_useStyle","_useStyle2","_slicedToArray","wrapCSSVar","hashId","cssVarCls","colors","filter","c","includes","map","color","concat","getValue","tag","field","_typeof","record","undefined","_ref","_getValue","toString","renderTag","item","_objectSpread","icon","length","children","data","maxCount","renderItem","renderRest","omittedItems","menu","items","_ref2","_getValue2","type","key","label","allTags"],"sources":["../../../src/components/OverflowTags/index.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\nimport { useCallback, useContext, useMemo } from 'react';\nimport type { DropdownProps, TagProps } from 'antd';\nimport { ConfigProvider, Dropdown, Tag, theme } from 'antd';\nimport { PresetColors } from 'antd/es/theme/internal';\nimport classNames from 'classnames';\nimport type { OverflowProps } from 'rc-overflow';\nimport Overflow from 'rc-overflow';\nimport { random } from '../../utils/math';\nimport useStyle from './style';\n\nexport interface OverflowTagsProps<T> extends Omit<OverflowProps<T>, 'renderItem'> {\n /**\n * **CN**: 标签集合的数据\n *\n * **EN**: Data collection of tags\n */\n tags: T[] | undefined;\n /**\n * **EN**: Function to get the tag name, default is `tag.label` or `tag.name`\n *\n * **CN**: 获取标签名称的函数,默认取`tag.label`或`tag.name`\n */\n getTagName?: (tag: T) => ReactNode;\n /**\n * **EN**: Function to get the unique identifier of the tag, default is `tag.value` or `tag.id`\n *\n * **CN**: 获取标签唯一标识的函数,默认取`tag.value`或`tag.id`\n */\n getTagKey?: (tag: T) => React.Key;\n\n /**\n * **EN**: Custom tag rendering function\n *\n * **CN**: 标签渲染函数\n */\n renderTag?: OverflowProps<T>['renderItem'];\n /**\n * **EN**: Custom properties for the tag component\n *\n * **CN**: 自定义标签的组件属性\n */\n tagProps?: TagProps | ((tag: T, options: { tags: T[] }) => TagProps);\n /**\n * **EN**: When the number of tags exceeds the maximum display count, an ellipsis tag will be\n * shown. This property is used to set the style of the ellipsis tag.\n *\n * **CN**: 当标签数量超过最大显示数量时,会显示省略号的标签,此属性用于设置省略号标签的样式\n */\n ellipsisTagProps?: TagProps | ((tag: T, options: { omittedItems: T[]; allTags: T[] }) => TagProps);\n /**\n * **EN**: Custom properties for the dropdown component when tags are overflowed\n *\n * **CN**: 当标签溢出时,下拉菜单的自定义属性\n */\n ellipsisDropdownProps?: DropdownProps;\n /**\n * **EN**: Whether to use random colors, default is `false`. Note that the tag object can also\n * contain a `color` property to specify the color, and the latter takes precedence.\n *\n * **CN**: 是否使用随机颜色,默认`false`。注意,tag对象还可以包含`color`属性来指定颜色,而且后者优先级更高。\n *\n * @default false\n */\n randomColors?: boolean;\n}\n\n/**\n * - **EN:** Overflow tags component, used to display a collection of tags that can overflow and be\n * truncated. It supports displaying tags in a dropdown when the number of tags exceeds the\n * maximum display count. It also supports custom tag rendering and properties.\n * - **CN:** 溢出标签组件,用于显示一组可以溢出和截断的标签集合。当标签数量超过最大显示数量时,支持在下拉菜单中显示标签。还支持自定义标签渲染和属性。\n *\n * @example\n * <OverflowTags\n * tags={[\n * { value: 1, label: 'Tag1', icon: <Icon1 /> },\n * { value: 2, label: 'Tag2', icon: <Icon2 /> },\n * ]}\n * tagProps={{ color: 'blue' }}\n * ellipsisTagProps={{ color: 'grey' }}\n * />;\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst OverflowTags = <T,>(props: OverflowTagsProps<T>) => {\n const {\n tags = [],\n randomColors,\n getTagName: getTagNameInProps,\n getTagKey,\n tagProps,\n ellipsisTagProps,\n ellipsisDropdownProps,\n className,\n prefixCls: prefixClsInProps,\n ...restProps\n } = props;\n const { token } = theme.useToken();\n const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);\n const prefixCls = getPrefixCls('easy-overflow-tags', prefixClsInProps);\n const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls);\n\n const colors = useMemo(\n () => PresetColors.filter((c) => !['lime', 'yellow', 'magenta'].includes(c)).map((color) => token[`${color}-3`]),\n [token]\n );\n const getValue = useCallback((tag: T | undefined, field: string) => {\n if (tag != null && typeof tag === 'object') {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const record = tag as Record<string, any>;\n return record[field];\n }\n return undefined;\n }, []);\n const getTagName = useCallback(\n (tag: T) => {\n return getTagNameInProps\n ? getTagNameInProps(tag)\n : (getValue(tag, 'label') ?? getValue(tag, 'name') ?? tag?.toString());\n },\n [getTagNameInProps, getValue]\n );\n const renderTag = (item: T) => {\n return (\n <Tag\n icon={getValue(item, 'icon')}\n color={randomColors ? colors[random(0, colors.length - 1)] : getValue(item, 'color') || 'default'}\n {...(typeof tagProps === 'function' ? tagProps(item, { tags }) : tagProps)}\n >\n {getTagName(item)}\n </Tag>\n );\n };\n\n return wrapCSSVar(\n <Overflow<T>\n className={classNames(hashId, cssVarCls, prefixCls, className)}\n data={tags}\n maxCount=\"responsive\"\n renderItem={renderTag}\n renderRest={(omittedItems) => (\n <Dropdown\n {...ellipsisDropdownProps}\n menu={{\n items: omittedItems.map((tag) => ({\n type: 'item',\n key: getTagKey ? getTagKey(tag) : (getValue(tag, 'value') ?? getValue(tag, 'id') ?? getTagName(tag)),\n label: getTagName(tag),\n })),\n ...ellipsisDropdownProps?.menu,\n }}\n >\n <Tag\n {...(typeof ellipsisTagProps === 'function'\n ? ellipsisTagProps(omittedItems[0], { omittedItems, allTags: tags })\n : ellipsisTagProps)}\n >\n + {omittedItems.length}...\n </Tag>\n </Dropdown>\n )}\n {...restProps}\n />\n );\n};\n\nexport default OverflowTags;\n"],"mappings":";;;;;;;;;;;;;;;AACA,SAASA,WAAW,EAAEC,UAAU,EAAEC,OAAO,QAAQ,OAAO;AAExD,SAASC,cAAc,EAAEC,QAAQ,EAAEC,GAAG,EAAEC,KAAK,QAAQ,MAAM;AAC3D,SAASC,YAAY,QAAQ,wBAAwB;AACrD,OAAOC,UAAU,MAAM,YAAY;AAEnC,OAAOC,QAAQ,MAAM,aAAa;AAClC,SAASC,MAAM;AACf,OAAOC,QAAQ;AAAgB,SAAAC,GAAA,IAAAC,IAAA;AAAA,SAAAC,IAAA,IAAAC,KAAA;AA0D/B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAMC,YAAY,GAAG,SAAfA,YAAYA,CAAQC,KAA2B,EAAK;EACxD,IAAAC,WAAA,GAWID,KAAK,CAVPE,IAAI;IAAJA,IAAI,GAAAD,WAAA,cAAG,EAAE,GAAAA,WAAA;IACTE,YAAY,GASVH,KAAK,CATPG,YAAY;IACAC,iBAAiB,GAQ3BJ,KAAK,CARPK,UAAU;IACVC,SAAS,G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 export * from './EllipsisTypography/EllipsisText';
|
|
|
22
22
|
export { default as EllipsisText } from './EllipsisTypography/EllipsisText';
|
|
23
23
|
export * from './EllipsisTypography/EllipsisTitle';
|
|
24
24
|
export { default as EllipsisTitle } from './EllipsisTypography/EllipsisTitle';
|
|
25
|
+
export * from './EllipsisTypography/EllipsisLink';
|
|
26
|
+
export { default as EllipsisLink } from './EllipsisTypography/EllipsisLink';
|
|
25
27
|
export type { FloatDrawerProps } from './FloatDrawer';
|
|
26
28
|
export { default as FloatDrawer } from './FloatDrawer';
|
|
27
29
|
export type { FormItemControlProps } from './FormItemControl';
|
package/es/components/index.js
CHANGED
|
@@ -17,6 +17,8 @@ export * from "./EllipsisTypography/EllipsisText";
|
|
|
17
17
|
export { default as EllipsisText } from "./EllipsisTypography/EllipsisText";
|
|
18
18
|
export * from "./EllipsisTypography/EllipsisTitle";
|
|
19
19
|
export { default as EllipsisTitle } from "./EllipsisTypography/EllipsisTitle";
|
|
20
|
+
export * from "./EllipsisTypography/EllipsisLink";
|
|
21
|
+
export { default as EllipsisLink } from "./EllipsisTypography/EllipsisLink";
|
|
20
22
|
export { default as FloatDrawer } from "./FloatDrawer";
|
|
21
23
|
export { default as FormItemControl } from "./FormItemControl";
|
|
22
24
|
export { default as Loading } from "./Loading";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["default","BreakLines","ColumnSetting","ConfigProvider","ReactEasyContext","withDefaultConfirmActionProps","withConfirmAction","ConfirmAction","ContextMenu","DeleteConfirmAction","withDeleteConfirmAction","EditableText","EllipsisParagraph","EllipsisText","EllipsisTitle","FloatDrawer","FormItemControl","Loading","withDefaultModalActionProps","withModalAction","ModalAction","OverflowTags","PulseAnimation"],"sources":["../../src/components/index.tsx"],"sourcesContent":["export type { BreakLinesProps } from './BreakLines';\nexport { default as BreakLines } from './BreakLines';\n\nexport type { ColumnSettingProps } from './ColumnSetting';\nexport { default as ColumnSetting } from './ColumnSetting';\n\nexport type { ConfigProviderProps } from './ConfigProvider';\nexport { default as ConfigProvider } from './ConfigProvider';\nexport type { ReactEasyContextProps } from './ConfigProvider/context';\nexport { default as ReactEasyContext } from './ConfigProvider/context';\n\nexport type { ConfirmActionProps, ConfirmActionTrigger, ConfirmActionRef, ActionCompConstraint } from './ConfirmAction';\nexport { withDefaultConfirmActionProps } from './ConfirmAction';\nexport { default as withConfirmAction } from './ConfirmAction/withConfirmAction';\nexport { default as ConfirmAction } from './ConfirmAction';\n\nexport type {\n ContextMenuProps,\n ContextMenuItem,\n ContextMenuSeparator,\n ContextMenuSubmenu,\n ContextMenuRef,\n} from './ContextMenu';\nexport { default as ContextMenu } from './ContextMenu';\n\n// export * from './DeleteConfirmAction';\nexport { default as DeleteConfirmAction } from './DeleteConfirmAction';\nexport { default as withDeleteConfirmAction } from './DeleteConfirmAction/withDeleteConfirmAction';\n\nexport type { EditableTextProps } from './EditableText';\nexport { default as EditableText } from './EditableText';\n\nexport * from './EllipsisTypography/EllipsisParagraph';\nexport { default as EllipsisParagraph } from './EllipsisTypography/EllipsisParagraph';\n\nexport * from './EllipsisTypography/EllipsisText';\nexport { default as EllipsisText } from './EllipsisTypography/EllipsisText';\n\nexport * from './EllipsisTypography/EllipsisTitle';\nexport { default as EllipsisTitle } from './EllipsisTypography/EllipsisTitle';\n\nexport type { FloatDrawerProps } from './FloatDrawer';\nexport { default as FloatDrawer } from './FloatDrawer';\n\nexport type { FormItemControlProps } from './FormItemControl';\nexport { default as FormItemControl } from './FormItemControl';\n\nexport type { LoadingProps } from './Loading';\nexport { default as Loading } from './Loading';\n\nexport type { ModalActionProps, FormCompPropsConstraint, ModalActionTrigger, ModalActionRef } from './ModalAction';\nexport { withDefaultModalActionProps, withModalAction } from './ModalAction';\nexport { default as ModalAction } from './ModalAction';\n\nexport type { OverflowTagsProps } from './OverflowTags';\nexport { default as OverflowTags } from './OverflowTags';\n\nexport type { PulseAnimationProps } from './Animation/Pulse';\nexport { default as PulseAnimation } from './Animation/Pulse';\n"],"mappings":"AACA,SAASA,OAAO,IAAIC,UAAU;AAG9B,SAASD,OAAO,IAAIE,aAAa;AAGjC,SAASF,OAAO,IAAIG,cAAc;AAElC,SAASH,OAAO,IAAII,gBAAgB;AAGpC,SAASC,6BAA6B;AACtC,SAASL,OAAO,IAAIM,iBAAiB;AACrC,SAASN,OAAO,IAAIO,aAAa;AASjC,SAASP,OAAO,IAAIQ,WAAW;;AAE/B;AACA,SAASR,OAAO,IAAIS,mBAAmB;AACvC,SAAST,OAAO,IAAIU,uBAAuB;AAG3C,SAASV,OAAO,IAAIW,YAAY;AAEhC;AACA,SAASX,OAAO,IAAIY,iBAAiB;AAErC;AACA,SAASZ,OAAO,IAAIa,YAAY;AAEhC;AACA,SAASb,OAAO,IAAIc,aAAa;
|
|
1
|
+
{"version":3,"names":["default","BreakLines","ColumnSetting","ConfigProvider","ReactEasyContext","withDefaultConfirmActionProps","withConfirmAction","ConfirmAction","ContextMenu","DeleteConfirmAction","withDeleteConfirmAction","EditableText","EllipsisParagraph","EllipsisText","EllipsisTitle","EllipsisLink","FloatDrawer","FormItemControl","Loading","withDefaultModalActionProps","withModalAction","ModalAction","OverflowTags","PulseAnimation"],"sources":["../../src/components/index.tsx"],"sourcesContent":["export type { BreakLinesProps } from './BreakLines';\nexport { default as BreakLines } from './BreakLines';\n\nexport type { ColumnSettingProps } from './ColumnSetting';\nexport { default as ColumnSetting } from './ColumnSetting';\n\nexport type { ConfigProviderProps } from './ConfigProvider';\nexport { default as ConfigProvider } from './ConfigProvider';\nexport type { ReactEasyContextProps } from './ConfigProvider/context';\nexport { default as ReactEasyContext } from './ConfigProvider/context';\n\nexport type { ConfirmActionProps, ConfirmActionTrigger, ConfirmActionRef, ActionCompConstraint } from './ConfirmAction';\nexport { withDefaultConfirmActionProps } from './ConfirmAction';\nexport { default as withConfirmAction } from './ConfirmAction/withConfirmAction';\nexport { default as ConfirmAction } from './ConfirmAction';\n\nexport type {\n ContextMenuProps,\n ContextMenuItem,\n ContextMenuSeparator,\n ContextMenuSubmenu,\n ContextMenuRef,\n} from './ContextMenu';\nexport { default as ContextMenu } from './ContextMenu';\n\n// export * from './DeleteConfirmAction';\nexport { default as DeleteConfirmAction } from './DeleteConfirmAction';\nexport { default as withDeleteConfirmAction } from './DeleteConfirmAction/withDeleteConfirmAction';\n\nexport type { EditableTextProps } from './EditableText';\nexport { default as EditableText } from './EditableText';\n\nexport * from './EllipsisTypography/EllipsisParagraph';\nexport { default as EllipsisParagraph } from './EllipsisTypography/EllipsisParagraph';\n\nexport * from './EllipsisTypography/EllipsisText';\nexport { default as EllipsisText } from './EllipsisTypography/EllipsisText';\n\nexport * from './EllipsisTypography/EllipsisTitle';\nexport { default as EllipsisTitle } from './EllipsisTypography/EllipsisTitle';\n\nexport * from './EllipsisTypography/EllipsisLink';\nexport { default as EllipsisLink } from './EllipsisTypography/EllipsisLink';\n\nexport type { FloatDrawerProps } from './FloatDrawer';\nexport { default as FloatDrawer } from './FloatDrawer';\n\nexport type { FormItemControlProps } from './FormItemControl';\nexport { default as FormItemControl } from './FormItemControl';\n\nexport type { LoadingProps } from './Loading';\nexport { default as Loading } from './Loading';\n\nexport type { ModalActionProps, FormCompPropsConstraint, ModalActionTrigger, ModalActionRef } from './ModalAction';\nexport { withDefaultModalActionProps, withModalAction } from './ModalAction';\nexport { default as ModalAction } from './ModalAction';\n\nexport type { OverflowTagsProps } from './OverflowTags';\nexport { default as OverflowTags } from './OverflowTags';\n\nexport type { PulseAnimationProps } from './Animation/Pulse';\nexport { default as PulseAnimation } from './Animation/Pulse';\n"],"mappings":"AACA,SAASA,OAAO,IAAIC,UAAU;AAG9B,SAASD,OAAO,IAAIE,aAAa;AAGjC,SAASF,OAAO,IAAIG,cAAc;AAElC,SAASH,OAAO,IAAII,gBAAgB;AAGpC,SAASC,6BAA6B;AACtC,SAASL,OAAO,IAAIM,iBAAiB;AACrC,SAASN,OAAO,IAAIO,aAAa;AASjC,SAASP,OAAO,IAAIQ,WAAW;;AAE/B;AACA,SAASR,OAAO,IAAIS,mBAAmB;AACvC,SAAST,OAAO,IAAIU,uBAAuB;AAG3C,SAASV,OAAO,IAAIW,YAAY;AAEhC;AACA,SAASX,OAAO,IAAIY,iBAAiB;AAErC;AACA,SAASZ,OAAO,IAAIa,YAAY;AAEhC;AACA,SAASb,OAAO,IAAIc,aAAa;AAEjC;AACA,SAASd,OAAO,IAAIe,YAAY;AAGhC,SAASf,OAAO,IAAIgB,WAAW;AAG/B,SAAShB,OAAO,IAAIiB,eAAe;AAGnC,SAASjB,OAAO,IAAIkB,OAAO;AAG3B,SAASC,2BAA2B,EAAEC,eAAe;AACrD,SAASpB,OAAO,IAAIqB,WAAW;AAG/B,SAASrB,OAAO,IAAIsB,YAAY;AAGhC,SAAStB,OAAO,IAAIuB,cAAc"}
|
package/es/hooks/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { default as useAudioPlayer } from './useAudioPlayer';
|
|
2
2
|
export { default as useDebounce } from './useDebounce';
|
|
3
|
+
export * from './useLocalStorage';
|
|
4
|
+
export { default as useLocalStorage } from './useLocalStorage';
|
|
3
5
|
export * from './useMovable';
|
|
4
6
|
export { default as useMovable } from './useMovable';
|
|
5
7
|
export * from './useProcessingText';
|
package/es/hooks/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { default as useAudioPlayer } from "./useAudioPlayer";
|
|
2
2
|
export { default as useDebounce } from "./useDebounce";
|
|
3
|
+
export * from "./useLocalStorage";
|
|
4
|
+
export { default as useLocalStorage } from "./useLocalStorage";
|
|
3
5
|
export * from "./useMovable";
|
|
4
6
|
export { default as useMovable } from "./useMovable";
|
|
5
7
|
export * from "./useProcessingText";
|
package/es/hooks/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["default","useAudioPlayer","useDebounce","useMovable","useProcessingText","useRefValue","useRefFunction","useSplitter","useSSE","useStompSocket","useUserMedia","useValidators","useValidator","useValidatorBuilder"],"sources":["../../src/hooks/index.ts"],"sourcesContent":["export { default as useAudioPlayer } from './useAudioPlayer';\n\nexport { default as useDebounce } from './useDebounce';\n\nexport * from './useMovable';\nexport { default as useMovable } from './useMovable';\n\nexport * from './useProcessingText';\nexport { default as useProcessingText } from './useProcessingText';\n\nexport { default as useRefValue } from './useRefValue';\n\nexport { default as useRefFunction } from './useRefFunction';\n\nexport * from './useSplitter';\nexport { default as useSplitter } from './useSplitter';\n\nexport * from './useSSE';\nexport { default as useSSE } from './useSSE';\n\nexport * from './useStompSocket';\nexport { default as useStompSocket } from './useStompSocket';\n\nexport * from './useUserMedia';\nexport { default as useUserMedia } from './useUserMedia';\n\nexport type { ValidatorRuleMap } from './useValidators';\nexport { default as useValidators } from './useValidators';\n\nexport { default as useValidator } from './useValidator';\n\nexport type { Validator, RuleRegExpFlags, ValidatorRule, BuilderOptions } from './useValidatorBuilder';\nexport { default as useValidatorBuilder } from './useValidatorBuilder';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,cAAc;AAElC,SAASD,OAAO,IAAIE,WAAW;AAE/B;AACA,SAASF,OAAO,IAAIG,
|
|
1
|
+
{"version":3,"names":["default","useAudioPlayer","useDebounce","useLocalStorage","useMovable","useProcessingText","useRefValue","useRefFunction","useSplitter","useSSE","useStompSocket","useUserMedia","useValidators","useValidator","useValidatorBuilder"],"sources":["../../src/hooks/index.ts"],"sourcesContent":["export { default as useAudioPlayer } from './useAudioPlayer';\n\nexport { default as useDebounce } from './useDebounce';\n\nexport * from './useLocalStorage';\nexport { default as useLocalStorage } from './useLocalStorage';\n\nexport * from './useMovable';\nexport { default as useMovable } from './useMovable';\n\nexport * from './useProcessingText';\nexport { default as useProcessingText } from './useProcessingText';\n\nexport { default as useRefValue } from './useRefValue';\n\nexport { default as useRefFunction } from './useRefFunction';\n\nexport * from './useSplitter';\nexport { default as useSplitter } from './useSplitter';\n\nexport * from './useSSE';\nexport { default as useSSE } from './useSSE';\n\nexport * from './useStompSocket';\nexport { default as useStompSocket } from './useStompSocket';\n\nexport * from './useUserMedia';\nexport { default as useUserMedia } from './useUserMedia';\n\nexport type { ValidatorRuleMap } from './useValidators';\nexport { default as useValidators } from './useValidators';\n\nexport { default as useValidator } from './useValidator';\n\nexport type { Validator, RuleRegExpFlags, ValidatorRule, BuilderOptions } from './useValidatorBuilder';\nexport { default as useValidatorBuilder } from './useValidatorBuilder';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,cAAc;AAElC,SAASD,OAAO,IAAIE,WAAW;AAE/B;AACA,SAASF,OAAO,IAAIG,eAAe;AAEnC;AACA,SAASH,OAAO,IAAII,UAAU;AAE9B;AACA,SAASJ,OAAO,IAAIK,iBAAiB;AAErC,SAASL,OAAO,IAAIM,WAAW;AAE/B,SAASN,OAAO,IAAIO,cAAc;AAElC;AACA,SAASP,OAAO,IAAIQ,WAAW;AAE/B;AACA,SAASR,OAAO,IAAIS,MAAM;AAE1B;AACA,SAAST,OAAO,IAAIU,cAAc;AAElC;AACA,SAASV,OAAO,IAAIW,YAAY;AAGhC,SAASX,OAAO,IAAIY,aAAa;AAEjC,SAASZ,OAAO,IAAIa,YAAY;AAGhC,SAASb,OAAO,IAAIc,mBAAmB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
type SetStateAction<T> = T | ((prev: T) => T);
|
|
2
|
+
export interface UseLocalStorageOptions<T> {
|
|
3
|
+
/** When true, listen to `storage` events and keep state in sync across tabs. Defaults to true. */
|
|
4
|
+
sync?: boolean;
|
|
5
|
+
/** Custom serializer. Defaults to JSON.stringify. */
|
|
6
|
+
serialize?: (value: T) => string;
|
|
7
|
+
/** Custom deserializer. Defaults to JSON.parse. */
|
|
8
|
+
deserialize?: (raw: string) => T;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* useLocalStorage
|
|
12
|
+
*
|
|
13
|
+
* - If `key` is empty/falsy, behaves like useState and does not touch localStorage.
|
|
14
|
+
*/
|
|
15
|
+
declare function useLocalStorage<T>(key?: string | null, initialValue?: T | (() => T), options?: UseLocalStorageOptions<T>): [T, (action: SetStateAction<T>) => void, () => void];
|
|
16
|
+
export default useLocalStorage;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
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; }
|
|
5
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
8
|
+
function isBrowser() {
|
|
9
|
+
return typeof window !== 'undefined' && typeof window.localStorage !== 'undefined';
|
|
10
|
+
}
|
|
11
|
+
function defaultSerialize(value) {
|
|
12
|
+
return JSON.stringify(value);
|
|
13
|
+
}
|
|
14
|
+
function defaultDeserialize(raw) {
|
|
15
|
+
return JSON.parse(raw);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* useLocalStorage
|
|
20
|
+
*
|
|
21
|
+
* - If `key` is empty/falsy, behaves like useState and does not touch localStorage.
|
|
22
|
+
*/
|
|
23
|
+
function useLocalStorage(key, initialValue, options) {
|
|
24
|
+
var _options$sync, _options$serialize, _options$deserialize;
|
|
25
|
+
var storageKey = (key !== null && key !== void 0 ? key : '').trim();
|
|
26
|
+
var enabled = storageKey.length > 0;
|
|
27
|
+
var sync = (_options$sync = options === null || options === void 0 ? void 0 : options.sync) !== null && _options$sync !== void 0 ? _options$sync : true;
|
|
28
|
+
var serialize = (_options$serialize = options === null || options === void 0 ? void 0 : options.serialize) !== null && _options$serialize !== void 0 ? _options$serialize : defaultSerialize;
|
|
29
|
+
var deserialize = (_options$deserialize = options === null || options === void 0 ? void 0 : options.deserialize) !== null && _options$deserialize !== void 0 ? _options$deserialize : defaultDeserialize;
|
|
30
|
+
var initialValueRef = useRef(initialValue);
|
|
31
|
+
initialValueRef.current = initialValue;
|
|
32
|
+
var getInitial = useCallback(function () {
|
|
33
|
+
var fallback = function () {
|
|
34
|
+
var v = initialValueRef.current;
|
|
35
|
+
return typeof v === 'function' ? v() : v;
|
|
36
|
+
}();
|
|
37
|
+
if (!enabled || !isBrowser()) return fallback;
|
|
38
|
+
try {
|
|
39
|
+
var _raw = window.localStorage.getItem(storageKey);
|
|
40
|
+
if (_raw == null) return fallback;
|
|
41
|
+
return deserialize(_raw);
|
|
42
|
+
} catch (_unused) {
|
|
43
|
+
return fallback;
|
|
44
|
+
}
|
|
45
|
+
}, [deserialize, enabled, storageKey]);
|
|
46
|
+
var _useState = useState(getInitial),
|
|
47
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
48
|
+
value = _useState2[0],
|
|
49
|
+
setValueState = _useState2[1];
|
|
50
|
+
var writeStorage = useCallback(function (nextValue) {
|
|
51
|
+
if (!enabled || !isBrowser()) return;
|
|
52
|
+
try {
|
|
53
|
+
window.localStorage.setItem(storageKey, serialize(nextValue));
|
|
54
|
+
} catch (_unused2) {
|
|
55
|
+
// ignore write errors (e.g., quota exceeded, blocked storage)
|
|
56
|
+
}
|
|
57
|
+
}, [enabled, serialize, storageKey]);
|
|
58
|
+
var setValue = useCallback(function (action) {
|
|
59
|
+
setValueState(function (prev) {
|
|
60
|
+
var next = typeof action === 'function' ? action(prev) : action;
|
|
61
|
+
writeStorage(next);
|
|
62
|
+
return next;
|
|
63
|
+
});
|
|
64
|
+
}, [writeStorage]);
|
|
65
|
+
var remove = useCallback(function () {
|
|
66
|
+
// If key is empty/falsy, just reset to initial value.
|
|
67
|
+
var next = function () {
|
|
68
|
+
var v = initialValueRef.current;
|
|
69
|
+
return typeof v === 'function' ? v() : v;
|
|
70
|
+
}();
|
|
71
|
+
setValueState(next);
|
|
72
|
+
if (!enabled || !isBrowser()) return;
|
|
73
|
+
try {
|
|
74
|
+
window.localStorage.removeItem(storageKey);
|
|
75
|
+
} catch (_unused3) {
|
|
76
|
+
// ignore
|
|
77
|
+
}
|
|
78
|
+
}, [enabled, storageKey]);
|
|
79
|
+
|
|
80
|
+
// Keep state updated if key changes.
|
|
81
|
+
useEffect(function () {
|
|
82
|
+
setValueState(getInitial());
|
|
83
|
+
}, [getInitial]);
|
|
84
|
+
|
|
85
|
+
// Cross-tab sync.
|
|
86
|
+
useEffect(function () {
|
|
87
|
+
if (!enabled || !sync || !isBrowser()) return;
|
|
88
|
+
var onStorage = function onStorage(e) {
|
|
89
|
+
if (e.storageArea !== window.localStorage) return;
|
|
90
|
+
if (e.key !== storageKey) return;
|
|
91
|
+
|
|
92
|
+
// When removed, fall back to initial.
|
|
93
|
+
if (e.newValue == null) {
|
|
94
|
+
setValueState(getInitial());
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
setValueState(deserialize(e.newValue));
|
|
99
|
+
} catch (_unused4) {
|
|
100
|
+
// ignore parse errors
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
window.addEventListener('storage', onStorage);
|
|
104
|
+
return function () {
|
|
105
|
+
return window.removeEventListener('storage', onStorage);
|
|
106
|
+
};
|
|
107
|
+
}, [deserialize, enabled, getInitial, storageKey, sync]);
|
|
108
|
+
|
|
109
|
+
// Stable tuple identity.
|
|
110
|
+
return useMemo(function () {
|
|
111
|
+
return [value, setValue, remove];
|
|
112
|
+
}, [remove, setValue, value]);
|
|
113
|
+
}
|
|
114
|
+
export default useLocalStorage;
|
|
115
|
+
//# sourceMappingURL=useLocalStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useCallback","useEffect","useMemo","useRef","useState","isBrowser","window","localStorage","defaultSerialize","value","JSON","stringify","defaultDeserialize","raw","parse","useLocalStorage","key","initialValue","options","_options$sync","_options$serialize","_options$deserialize","storageKey","trim","enabled","length","sync","serialize","deserialize","initialValueRef","current","getInitial","fallback","v","getItem","_unused","_useState","_useState2","_slicedToArray","setValueState","writeStorage","nextValue","setItem","_unused2","setValue","action","prev","next","remove","removeItem","_unused3","onStorage","e","storageArea","newValue","_unused4","addEventListener","removeEventListener"],"sources":["../../src/hooks/useLocalStorage.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from 'react';\n\ntype SetStateAction<T> = T | ((prev: T) => T);\n\nexport interface UseLocalStorageOptions<T> {\n /** When true, listen to `storage` events and keep state in sync across tabs. Defaults to true. */\n sync?: boolean;\n /** Custom serializer. Defaults to JSON.stringify. */\n serialize?: (value: T) => string;\n /** Custom deserializer. Defaults to JSON.parse. */\n deserialize?: (raw: string) => T;\n}\n\nfunction isBrowser() {\n return typeof window !== 'undefined' && typeof window.localStorage !== 'undefined';\n}\n\nfunction defaultSerialize<T>(value: T) {\n return JSON.stringify(value);\n}\n\nfunction defaultDeserialize<T>(raw: string) {\n return JSON.parse(raw) as T;\n}\n\n/**\n * useLocalStorage\n *\n * - If `key` is empty/falsy, behaves like useState and does not touch localStorage.\n */\nfunction useLocalStorage<T>(\n key?: string | null,\n initialValue?: T | (() => T),\n options?: UseLocalStorageOptions<T>\n): [T, (action: SetStateAction<T>) => void, () => void] {\n const storageKey = (key ?? '').trim();\n const enabled = storageKey.length > 0;\n const sync = options?.sync ?? true;\n const serialize = options?.serialize ?? defaultSerialize;\n const deserialize = options?.deserialize ?? defaultDeserialize;\n\n const initialValueRef = useRef(initialValue);\n initialValueRef.current = initialValue;\n\n const getInitial = useCallback((): T => {\n const fallback = (() => {\n const v = initialValueRef.current;\n return (typeof v === 'function' ? (v as () => T)() : (v as T)) as T;\n })();\n\n if (!enabled || !isBrowser()) return fallback;\n\n try {\n const raw = window.localStorage.getItem(storageKey);\n if (raw == null) return fallback;\n return deserialize(raw);\n } catch {\n return fallback;\n }\n }, [deserialize, enabled, storageKey]);\n\n const [value, setValueState] = useState<T>(getInitial);\n\n const writeStorage = useCallback(\n (nextValue: T) => {\n if (!enabled || !isBrowser()) return;\n try {\n window.localStorage.setItem(storageKey, serialize(nextValue));\n } catch {\n // ignore write errors (e.g., quota exceeded, blocked storage)\n }\n },\n [enabled, serialize, storageKey]\n );\n\n const setValue = useCallback(\n (action: SetStateAction<T>) => {\n setValueState((prev) => {\n const next = typeof action === 'function' ? (action as (p: T) => T)(prev) : action;\n writeStorage(next);\n return next;\n });\n },\n [writeStorage]\n );\n\n const remove = useCallback(() => {\n // If key is empty/falsy, just reset to initial value.\n const next = (() => {\n const v = initialValueRef.current;\n return (typeof v === 'function' ? (v as () => T)() : (v as T)) as T;\n })();\n\n setValueState(next);\n\n if (!enabled || !isBrowser()) return;\n try {\n window.localStorage.removeItem(storageKey);\n } catch {\n // ignore\n }\n }, [enabled, storageKey]);\n\n // Keep state updated if key changes.\n useEffect(() => {\n setValueState(getInitial());\n }, [getInitial]);\n\n // Cross-tab sync.\n useEffect(() => {\n if (!enabled || !sync || !isBrowser()) return;\n\n const onStorage = (e: StorageEvent) => {\n if (e.storageArea !== window.localStorage) return;\n if (e.key !== storageKey) return;\n\n // When removed, fall back to initial.\n if (e.newValue == null) {\n setValueState(getInitial());\n return;\n }\n\n try {\n setValueState(deserialize(e.newValue));\n } catch {\n // ignore parse errors\n }\n };\n\n window.addEventListener('storage', onStorage);\n return () => window.removeEventListener('storage', onStorage);\n }, [deserialize, enabled, getInitial, storageKey, sync]);\n\n // Stable tuple identity.\n return useMemo(() => [value, setValue, remove] as const, [remove, setValue, value]);\n}\n\nexport default useLocalStorage;\n"],"mappings":";;;;;;AAAA,SAASA,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAazE,SAASC,SAASA,CAAA,EAAG;EACnB,OAAO,OAAOC,MAAM,KAAK,WAAW,IAAI,OAAOA,MAAM,CAACC,YAAY,KAAK,WAAW;AACpF;AAEA,SAASC,gBAAgBA,CAAIC,KAAQ,EAAE;EACrC,OAAOC,IAAI,CAACC,SAAS,CAACF,KAAK,CAAC;AAC9B;AAEA,SAASG,kBAAkBA,CAAIC,GAAW,EAAE;EAC1C,OAAOH,IAAI,CAACI,KAAK,CAACD,GAAG,CAAC;AACxB;;AAEA;AACA;AACA;AACA;AACA;AACA,SAASE,eAAeA,CACtBC,GAAmB,EACnBC,YAA4B,EAC5BC,OAAmC,EACmB;EAAA,IAAAC,aAAA,EAAAC,kBAAA,EAAAC,oBAAA;EACtD,IAAMC,UAAU,GAAG,CAACN,GAAG,aAAHA,GAAG,cAAHA,GAAG,GAAI,EAAE,EAAEO,IAAI,CAAC,CAAC;EACrC,IAAMC,OAAO,GAAGF,UAAU,CAACG,MAAM,GAAG,CAAC;EACrC,IAAMC,IAAI,IAAAP,aAAA,GAAGD,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEQ,IAAI,cAAAP,aAAA,cAAAA,aAAA,GAAI,IAAI;EAClC,IAAMQ,SAAS,IAAAP,kBAAA,GAAG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rB,SAAS,CAAC,CAAC,EAAE;IAEvC,IAAM8C,SAAS,GAAG,SAAZA,SAASA,CAAIC,CAAe,EAAK;MACrC,IAAIA,CAAC,CAACC,WAAW,KAAK/C,MAAM,CAACC,YAAY,EAAE;MAC3C,IAAI6C,CAAC,CAACpC,GAAG,KAAKM,UAAU,EAAE;;MAE1B;MACA,IAAI8B,CAAC,CAACE,QAAQ,IAAI,IAAI,EAAE;QACtBf,aAAa,CAACR,UAAU,CAAC,CAAC,CAAC;QAC3B;MACF;MAEA,IAAI;QACFQ,aAAa,CAACX,WAAW,CAACwB,CAAC,CAACE,QAAQ,CAAC,CAAC;MACxC,CAAC,CAAC,OAAAC,QAAA,EAAM;QACN;MAAA;IAEJ,CAAC;IAEDjD,MAAM,CAACkD,gBAAgB,CAAC,SAAS,EAAEL,SAAS,CAAC;IAC7C,OAAO;MAAA,OAAM7C,MAAM,CAACmD,mBAAmB,CAAC,SAAS,EAAEN,SAAS,CAAC;IAAA;EAC/D,CAAC,EAAE,CAACvB,WAAW,EAAEJ,OAAO,EAAEO,UAAU,EAAET,UAAU,EAAEI,IAAI,CAAC,CAAC;;EAExD;EACA,OAAOxB,OAAO,CAAC;IAAA,OAAM,CAACO,KAAK,EAAEmC,QAAQ,EAAEI,MAAM,CAAC;EAAA,CAAS,EAAE,CAACA,MAAM,EAAEJ,QAAQ,EAAEnC,KAAK,CAAC,CAAC;AACrF;AAEA,eAAeM,eAAe"}
|
package/es/hooks/useMovable.js
CHANGED
|
@@ -5,7 +5,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
5
5
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
6
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
7
|
import { useEffect, useRef, useState } from 'react';
|
|
8
|
-
import
|
|
8
|
+
import useLocalStorage from "./useLocalStorage";
|
|
9
9
|
import useRefFunction from "./useRefFunction";
|
|
10
10
|
import useRefValue from "./useRefValue";
|
|
11
11
|
/**
|
|
@@ -66,7 +66,7 @@ var useMovable = function useMovable(props) {
|
|
|
66
66
|
e.preventDefault();
|
|
67
67
|
});
|
|
68
68
|
|
|
69
|
-
//
|
|
69
|
+
// Automatically adjust the position during window resize to prevent it from exceeding the visible area.
|
|
70
70
|
useEffect(function () {
|
|
71
71
|
var clampToViewport = function clampToViewport() {
|
|
72
72
|
var _containerRef$current3;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useEffect","useRef","useState","useLocalStorage","useRefFunction","useRefValue","useMovable","props","enabled","containerRef","ignoreSelectors","storageKey","storageKeyRef","_useLocalStorage","_useLocalStorage2","_slicedToArray","savedPosition","savePosition","savePositionRef","_useState","undefined","_useState2","position","setPosition","positionRef","draggingRef","dragOffsetRef","x","y","sizeRef","w","h","handlePointerDown","e","_position$left","_position$top","target","closest","join","current","rect","getBoundingClientRect","width","height","currentLeft","left","currentTop","top","clientX","clientY","_containerRef$current","_containerRef$current2","setPointerCapture","call","pointerId","_unused","preventDefault","clampToViewport","_containerRef$current3","pos","maxLeft","Math","max","window","innerWidth","maxTop","innerHeight","clampedLeft","min","clampedTop","next","addEventListener","removeEventListener","onMove","newLeft","newTop","onUp","onPointerDown"],"sources":["../../src/hooks/useMovable.ts"],"sourcesContent":["import { type RefObject, useEffect, useRef, useState } from 'react';\nimport { useLocalStorage } from 'react-use';\nimport useRefFunction from './useRefFunction';\nimport useRefValue from './useRefValue';\n\nexport interface UseMovableProps {\n /**\n * - **EN:** Whether dragging is enabled, default is `true`\n * - **CN:** 是否启用拖动,默认`true`\n */\n enabled?: boolean;\n /**\n * - **EN:** The ref of the container element\n * - **CN:** 容器元素的ref\n */\n containerRef: RefObject<HTMLElement>;\n /**\n * - **EN:** Selectors of elements that should not trigger dragging, e.g., interactive controls\n * - **CN:** 不应触发拖动的元素的选择器,例如交互控件\n */\n ignoreSelectors?: string[];\n /**\n * - **EN:** Key for storing position in localStorage; if not provided, position won't be saved\n * - **CN:** 用于在 localStorage 中存储位置的键;如果未提供,则不会保存位置\n */\n storageKey?: string;\n}\n\n/**\n * - **EN:** Hook to make an element movable by dragging, with position persistence using localStorage\n * - **CN:** 通过拖动使元素可移动的钩子,并使用 localStorage 持久化位置\n */\nconst useMovable = (props: UseMovableProps) => {\n const { enabled, containerRef, ignoreSelectors, storageKey } = props;\n\n const storageKeyRef = useRefValue(storageKey);\n const [savedPosition, savePosition] = useLocalStorage<MovePosition>(storageKey ?? '');\n const savePositionRef = useRefValue(savePosition);\n const [position, setPosition] = useState<MovePosition | undefined>(savedPosition ?? undefined);\n const positionRef = useRefValue(position);\n const draggingRef = useRef(false);\n const dragOffsetRef = useRef({ x: 0, y: 0 });\n const sizeRef = useRef({ w: 0, h: 0 });\n\n // Drag start (exclude interactive controls)\n const handlePointerDown = useRefFunction((e: React.PointerEvent<HTMLDivElement>) => {\n const target = e.target as HTMLElement;\n // Set the selector for elements that do not trigger dragging\n if (ignoreSelectors && target.closest(ignoreSelectors.join(','))) return;\n\n if (!containerRef.current) return;\n const rect = containerRef.current.getBoundingClientRect();\n sizeRef.current = { w: rect.width, h: rect.height };\n const currentLeft = position?.left ?? rect.left;\n const currentTop = position?.top ?? rect.top;\n\n dragOffsetRef.current = { x: e.clientX - currentLeft, y: e.clientY - currentTop };\n draggingRef.current = true;\n try {\n containerRef.current.setPointerCapture?.(e.pointerId);\n } catch {\n // do nothing\n }\n e.preventDefault();\n });\n\n // 调整:在窗口 resize 时自动收敛位置,防止超出可视区域\n useEffect(() => {\n const clampToViewport = () => {\n const pos = positionRef.current;\n if (!pos) return;\n\n // Refresh the container size before each convergence to ensure accurate boundaries.\n const rect = containerRef.current?.getBoundingClientRect();\n if (rect) {\n sizeRef.current = { w: rect.width, h: rect.height };\n }\n\n const maxLeft = Math.max(0, window.innerWidth - sizeRef.current.w);\n const maxTop = Math.max(0, window.innerHeight - sizeRef.current.h);\n const clampedLeft = Math.min(Math.max(0, pos.left), maxLeft);\n const clampedTop = Math.min(Math.max(0, pos.top), maxTop);\n\n if (clampedLeft !== pos.left || clampedTop !== pos.top) {\n const next = { left: clampedLeft, top: clampedTop };\n setPosition(next);\n if (storageKeyRef.current) {\n savePositionRef.current(next);\n }\n }\n };\n\n window.addEventListener('resize', clampToViewport);\n // Calibrate immediately after the first mount/position change.\n clampToViewport();\n\n return () => {\n window.removeEventListener('resize', clampToViewport);\n };\n }, [containerRef]);\n\n // Update position during dragging; restrict within the visible area.\n useEffect(() => {\n const onMove = (e: PointerEvent) => {\n if (!draggingRef.current) return;\n const newLeft = e.clientX - dragOffsetRef.current.x;\n const newTop = e.clientY - dragOffsetRef.current.y;\n const maxLeft = Math.max(0, window.innerWidth - sizeRef.current.w);\n const maxTop = Math.max(0, window.innerHeight - sizeRef.current.h);\n const clampedLeft = Math.min(Math.max(0, newLeft), maxLeft);\n const clampedTop = Math.min(Math.max(0, newTop), maxTop);\n const pos = { left: clampedLeft, top: clampedTop };\n setPosition(pos);\n if (storageKeyRef.current) {\n savePositionRef.current(pos);\n }\n };\n const onUp = () => {\n if (draggingRef.current) draggingRef.current = false;\n };\n if (enabled) {\n window.addEventListener('pointermove', onMove);\n window.addEventListener('pointerup', onUp);\n window.addEventListener('pointercancel', onUp);\n }\n return () => {\n window.removeEventListener('pointermove', onMove);\n window.removeEventListener('pointerup', onUp);\n window.removeEventListener('pointercancel', onUp);\n };\n }, [enabled]);\n\n return {\n onPointerDown: handlePointerDown,\n position,\n };\n};\n\nexport interface MovePosition {\n left: number;\n top: number;\n}\n\nexport default useMovable;\n"],"mappings":";;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CAACoC,GAAG,CAAC;MAChB,IAAI/C,aAAa,CAAC2B,OAAO,EAAE;QACzBrB,eAAe,CAACqB,OAAO,CAACoB,GAAG,CAAC;MAC9B;IACF,CAAC;IACD,IAAMiB,IAAI,GAAG,SAAPA,IAAIA,CAAA,EAAS;MACjB,IAAInD,WAAW,CAACc,OAAO,EAAEd,WAAW,CAACc,OAAO,GAAG,KAAK;IACtD,CAAC;IACD,IAAI/B,OAAO,EAAE;MACXuD,MAAM,CAACQ,gBAAgB,CAAC,aAAa,EAAEE,MAAM,CAAC;MAC9CV,MAAM,CAACQ,gBAAgB,CAAC,WAAW,EAAEK,IAAI,CAAC;MAC1Cb,MAAM,CAACQ,gBAAgB,CAAC,eAAe,EAAEK,IAAI,CAAC;IAChD;IACA,OAAO,YAAM;MACXb,MAAM,CAACS,mBAAmB,CAAC,aAAa,EAAEC,MAAM,CAAC;MACjDV,MAAM,CAACS,mBAAmB,CAAC,WAAW,EAAEI,IAAI,CAAC;MAC7Cb,MAAM,CAACS,mBAAmB,CAAC,eAAe,EAAEI,IAAI,CAAC;IACnD,CAAC;EACH,CAAC,EAAE,CAACpE,OAAO,CAAC,CAAC;EAEb,OAAO;IACLqE,aAAa,EAAE7C,iBAAiB;IAChCV,QAAQ,EAARA;EACF,CAAC;AACH,CAAC;AAOD,eAAehB,UAAU"}
|
|
1
|
+
{"version":3,"names":["useEffect","useRef","useState","useLocalStorage","useRefFunction","useRefValue","useMovable","props","enabled","containerRef","ignoreSelectors","storageKey","storageKeyRef","_useLocalStorage","_useLocalStorage2","_slicedToArray","savedPosition","savePosition","savePositionRef","_useState","undefined","_useState2","position","setPosition","positionRef","draggingRef","dragOffsetRef","x","y","sizeRef","w","h","handlePointerDown","e","_position$left","_position$top","target","closest","join","current","rect","getBoundingClientRect","width","height","currentLeft","left","currentTop","top","clientX","clientY","_containerRef$current","_containerRef$current2","setPointerCapture","call","pointerId","_unused","preventDefault","clampToViewport","_containerRef$current3","pos","maxLeft","Math","max","window","innerWidth","maxTop","innerHeight","clampedLeft","min","clampedTop","next","addEventListener","removeEventListener","onMove","newLeft","newTop","onUp","onPointerDown"],"sources":["../../src/hooks/useMovable.ts"],"sourcesContent":["import { type RefObject, useEffect, useRef, useState } from 'react';\nimport useLocalStorage from './useLocalStorage';\nimport useRefFunction from './useRefFunction';\nimport useRefValue from './useRefValue';\n\nexport interface UseMovableProps {\n /**\n * - **EN:** Whether dragging is enabled, default is `true`\n * - **CN:** 是否启用拖动,默认`true`\n */\n enabled?: boolean;\n /**\n * - **EN:** The ref of the container element\n * - **CN:** 容器元素的ref\n */\n containerRef: RefObject<HTMLElement>;\n /**\n * - **EN:** Selectors of elements that should not trigger dragging, e.g., interactive controls\n * - **CN:** 不应触发拖动的元素的选择器,例如交互控件\n */\n ignoreSelectors?: string[];\n /**\n * - **EN:** Key for storing position in localStorage; if not provided, position won't be saved\n * - **CN:** 用于在 localStorage 中存储位置的键;如果未提供,则不会保存位置\n */\n storageKey?: string;\n}\n\n/**\n * - **EN:** Hook to make an element movable by dragging, with position persistence using localStorage\n * - **CN:** 通过拖动使元素可移动的钩子,并使用 localStorage 持久化位置\n */\nconst useMovable = (props: UseMovableProps) => {\n const { enabled, containerRef, ignoreSelectors, storageKey } = props;\n\n const storageKeyRef = useRefValue(storageKey);\n const [savedPosition, savePosition] = useLocalStorage<MovePosition>(storageKey ?? '');\n const savePositionRef = useRefValue(savePosition);\n const [position, setPosition] = useState<MovePosition | undefined>(savedPosition ?? undefined);\n const positionRef = useRefValue(position);\n const draggingRef = useRef(false);\n const dragOffsetRef = useRef({ x: 0, y: 0 });\n const sizeRef = useRef({ w: 0, h: 0 });\n\n // Drag start (exclude interactive controls)\n const handlePointerDown = useRefFunction((e: React.PointerEvent<HTMLDivElement>) => {\n const target = e.target as HTMLElement;\n // Set the selector for elements that do not trigger dragging\n if (ignoreSelectors && target.closest(ignoreSelectors.join(','))) return;\n\n if (!containerRef.current) return;\n const rect = containerRef.current.getBoundingClientRect();\n sizeRef.current = { w: rect.width, h: rect.height };\n const currentLeft = position?.left ?? rect.left;\n const currentTop = position?.top ?? rect.top;\n\n dragOffsetRef.current = { x: e.clientX - currentLeft, y: e.clientY - currentTop };\n draggingRef.current = true;\n try {\n containerRef.current.setPointerCapture?.(e.pointerId);\n } catch {\n // do nothing\n }\n e.preventDefault();\n });\n\n // Automatically adjust the position during window resize to prevent it from exceeding the visible area.\n useEffect(() => {\n const clampToViewport = () => {\n const pos = positionRef.current;\n if (!pos) return;\n\n // Refresh the container size before each convergence to ensure accurate boundaries.\n const rect = containerRef.current?.getBoundingClientRect();\n if (rect) {\n sizeRef.current = { w: rect.width, h: rect.height };\n }\n\n const maxLeft = Math.max(0, window.innerWidth - sizeRef.current.w);\n const maxTop = Math.max(0, window.innerHeight - sizeRef.current.h);\n const clampedLeft = Math.min(Math.max(0, pos.left), maxLeft);\n const clampedTop = Math.min(Math.max(0, pos.top), maxTop);\n\n if (clampedLeft !== pos.left || clampedTop !== pos.top) {\n const next = { left: clampedLeft, top: clampedTop };\n setPosition(next);\n if (storageKeyRef.current) {\n savePositionRef.current(next);\n }\n }\n };\n\n window.addEventListener('resize', clampToViewport);\n // Calibrate immediately after the first mount/position change.\n clampToViewport();\n\n return () => {\n window.removeEventListener('resize', clampToViewport);\n };\n }, [containerRef]);\n\n // Update position during dragging; restrict within the visible area.\n useEffect(() => {\n const onMove = (e: PointerEvent) => {\n if (!draggingRef.current) return;\n const newLeft = e.clientX - dragOffsetRef.current.x;\n const newTop = e.clientY - dragOffsetRef.current.y;\n const maxLeft = Math.max(0, window.innerWidth - sizeRef.current.w);\n const maxTop = Math.max(0, window.innerHeight - sizeRef.current.h);\n const clampedLeft = Math.min(Math.max(0, newLeft), maxLeft);\n const clampedTop = Math.min(Math.max(0, newTop), maxTop);\n const pos = { left: clampedLeft, top: clampedTop };\n setPosition(pos);\n if (storageKeyRef.current) {\n savePositionRef.current(pos);\n }\n };\n const onUp = () => {\n if (draggingRef.current) draggingRef.current = false;\n };\n if (enabled) {\n window.addEventListener('pointermove', onMove);\n window.addEventListener('pointerup', onUp);\n window.addEventListener('pointercancel', onUp);\n }\n return () => {\n window.removeEventListener('pointermove', onMove);\n window.removeEventListener('pointerup', onUp);\n window.removeEventListener('pointercancel', onUp);\n };\n }, [enabled]);\n\n return {\n onPointerDown: handlePointerDown,\n position,\n };\n};\n\nexport interface MovePosition {\n left: number;\n top: number;\n}\n\nexport default useMovable;\n"],"mappings":";;;;;;AAAA,SAAyBA,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AACnE,OAAOC,eAAe;AACtB,OAAOC,cAAc;AACrB,OAAOC,WAAW;AAyBlB;AACA;AACA;AACA;AACA,IAAMC,UAAU,GAAG,SAAbA,UAAUA,CAAIC,KAAsB,EAAK;EAC7C,IAAQC,OAAO,GAAgDD,KAAK,CAA5DC,OAAO;IAAEC,YAAY,GAAkCF,KAAK,CAAnDE,YAAY;IAAEC,eAAe,GAAiBH,KAAK,CAArCG,eAAe;IAAEC,UAAU,GAAKJ,KAAK,CAApBI,UAAU;EAE1D,IAAMC,aAAa,GAAGP,WAAW,CAACM,UAAU,CAAC;EAC7C,IAAAE,gBAAA,GAAsCV,eAAe,CAAeQ,UAAU,aAAVA,UAAU,cAAVA,UAAU,GAAI,EAAE,CAAC;IAAAG,iBAAA,GAAAC,cAAA,CAAAF,gBAAA;IAA9EG,aAAa,GAAAF,iBAAA;IAAEG,YAAY,GAAAH,iBAAA;EAClC,IAAMI,eAAe,GAAGb,WAAW,CAACY,YAAY,CAAC;EACjD,IAAAE,SAAA,GAAgCjB,QAAQ,CAA2Bc,aAAa,aAAbA,aAAa,cAAbA,aAAa,GAAII,SAAS,CAAC;IAAAC,UAAA,GAAAN,cAAA,CAAAI,SAAA;IAAvFG,QAAQ,GAAAD,UAAA;IAAEE,WAAW,GAAAF,UAAA;EAC5B,IAAMG,WAAW,GAAGnB,WAAW,CAACiB,QAAQ,CAAC;EACzC,IAAMG,WAAW,GAAGxB,MAAM,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C,EAAEY,OAAO,CAAC,EAAEd,OAAO,CAAC;MAC3D,IAAMS,UAAU,GAAGR,IAAI,CAACO,GAAG,CAACP,IAAI,CAACC,GAAG,CAAC,CAAC,EAAEa,MAAM,CAAC,EAAEV,MAAM,CAAC;MACxD,IAAMN,GAAG,GAAG;QAAEd,IAAI,EAAEsB,WAAW;QAAEpB,GAAG,EAAEsB;MAAW,CAAC;MAClD9C,WAAW,CAACoC,GAAG,CAAC;MAChB,IAAI/C,aAAa,CAAC2B,OAAO,EAAE;QACzBrB,eAAe,CAACqB,OAAO,CAACoB,GAAG,CAAC;MAC9B;IACF,CAAC;IACD,IAAMiB,IAAI,GAAG,SAAPA,IAAIA,CAAA,EAAS;MACjB,IAAInD,WAAW,CAACc,OAAO,EAAEd,WAAW,CAACc,OAAO,GAAG,KAAK;IACtD,CAAC;IACD,IAAI/B,OAAO,EAAE;MACXuD,MAAM,CAACQ,gBAAgB,CAAC,aAAa,EAAEE,MAAM,CAAC;MAC9CV,MAAM,CAACQ,gBAAgB,CAAC,WAAW,EAAEK,IAAI,CAAC;MAC1Cb,MAAM,CAACQ,gBAAgB,CAAC,eAAe,EAAEK,IAAI,CAAC;IAChD;IACA,OAAO,YAAM;MACXb,MAAM,CAACS,mBAAmB,CAAC,aAAa,EAAEC,MAAM,CAAC;MACjDV,MAAM,CAACS,mBAAmB,CAAC,WAAW,EAAEI,IAAI,CAAC;MAC7Cb,MAAM,CAACS,mBAAmB,CAAC,eAAe,EAAEI,IAAI,CAAC;IACnD,CAAC;EACH,CAAC,EAAE,CAACpE,OAAO,CAAC,CAAC;EAEb,OAAO;IACLqE,aAAa,EAAE7C,iBAAiB;IAChCV,QAAQ,EAARA;EACF,CAAC;AACH,CAAC;AAOD,eAAehB,UAAU"}
|
package/es/locales/index.js
CHANGED
package/es/locales/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createInstance","enUS","zhCN","langs","resources","en","translation","reactEasyI18n","init","lng","t","apply","arguments"],"sources":["../../src/locales/index.ts"],"sourcesContent":["import { createInstance, type i18n } from 'i18next';\nimport enUS from './langs/en-US';\nimport zhCN from './langs/zh-CN';\n\nexport const langs = ['en', 'en-US', 'zh-CN'] as const;\n\nexport type Langs = (typeof langs)[number];\n\nexport const resources = {\n en: { translation: enUS },\n 'en-US': { translation: enUS },\n 'zh-CN': { translation: zhCN },\n} as const;\n\nconst reactEasyI18n: i18n = createInstance({});\n\nreactEasyI18n.init({\n lng: 'en',\n resources,\n});\n\nexport const t: i18n['t'] = ((...args) => {\n return reactEasyI18n.t(...args);\n}) as i18n['t'];\n\nexport default reactEasyI18n;\n"],"mappings":"AAAA,SAASA,cAAc,QAAmB,SAAS;AACnD,OAAOC,IAAI;AACX,OAAOC,IAAI;AAEX,OAAO,IAAMC,KAAK,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAU;AAItD,OAAO,IAAMC,SAAS,GAAG;EACvBC,EAAE,EAAE;IAAEC,WAAW,EAAEL;EAAK,CAAC;EACzB,OAAO,EAAE;IAAEK,WAAW,EAAEL;EAAK,CAAC;EAC9B,OAAO,EAAE;IAAEK,WAAW,EAAEJ;EAAK;AAC/B,CAAU;AAEV,IAAMK,aAAmB,GAAGP,cAAc,CAAC,CAAC,CAAC,CAAC;AAE9CO,aAAa,CAACC,IAAI,CAAC;EACjBC,GAAG,EAAE,
|
|
1
|
+
{"version":3,"names":["createInstance","enUS","zhCN","langs","resources","en","translation","reactEasyI18n","init","lng","t","apply","arguments"],"sources":["../../src/locales/index.ts"],"sourcesContent":["import { createInstance, type i18n } from 'i18next';\nimport enUS from './langs/en-US';\nimport zhCN from './langs/zh-CN';\n\nexport const langs = ['en', 'en-US', 'zh-CN'] as const;\n\nexport type Langs = (typeof langs)[number];\n\nexport const resources = {\n en: { translation: enUS },\n 'en-US': { translation: enUS },\n 'zh-CN': { translation: zhCN },\n} as const;\n\nconst reactEasyI18n: i18n = createInstance({});\n\nreactEasyI18n.init({\n lng: 'en-US',\n resources,\n});\n\nexport const t: i18n['t'] = ((...args) => {\n return reactEasyI18n.t(...args);\n}) as i18n['t'];\n\nexport default reactEasyI18n;\n"],"mappings":"AAAA,SAASA,cAAc,QAAmB,SAAS;AACnD,OAAOC,IAAI;AACX,OAAOC,IAAI;AAEX,OAAO,IAAMC,KAAK,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAU;AAItD,OAAO,IAAMC,SAAS,GAAG;EACvBC,EAAE,EAAE;IAAEC,WAAW,EAAEL;EAAK,CAAC;EACzB,OAAO,EAAE;IAAEK,WAAW,EAAEL;EAAK,CAAC;EAC9B,OAAO,EAAE;IAAEK,WAAW,EAAEJ;EAAK;AAC/B,CAAU;AAEV,IAAMK,aAAmB,GAAGP,cAAc,CAAC,CAAC,CAAC,CAAC;AAE9CO,aAAa,CAACC,IAAI,CAAC;EACjBC,GAAG,EAAE,OAAO;EACZL,SAAS,EAATA;AACF,CAAC,CAAC;AAEF,OAAO,IAAMM,CAAY,GAAI,SAAhBA,CAAYA,CAAA,EAAiB;EACxC,OAAOH,aAAa,CAACG,CAAC,CAAAC,KAAA,CAAfJ,aAAa,EAAAK,SAAU,CAAC;AACjC,CAAe;AAEf,eAAeL,aAAa"}
|
package/es/utils/math.d.ts
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* **EN**: Generate a random number
|
|
2
|
+
* **EN**: Generate a random decimal number between 0 and 1
|
|
3
3
|
*
|
|
4
|
-
* **CN**:
|
|
4
|
+
* **CN**: 生成一个0~1之间的小数
|
|
5
|
+
*
|
|
6
|
+
* @returns The generated random number | 生成的随机数
|
|
7
|
+
*/
|
|
8
|
+
export declare function random(): number;
|
|
9
|
+
/**
|
|
10
|
+
* **EN**: Generate a random integer within a specified range (inclusive on both ends)
|
|
11
|
+
*
|
|
12
|
+
* **CN**: 生成指定范围(两端包含)内的随机整数
|
|
5
13
|
*
|
|
6
14
|
* @param min The minimum value (inclusive) | 最小值(包含)
|
|
7
15
|
* @param max The maximum value (inclusive) | 最大值(包含)
|
|
8
16
|
*
|
|
9
|
-
* @returns The generated random
|
|
17
|
+
* @returns The generated random integer | 生成的随机整数
|
|
10
18
|
*/
|
|
11
19
|
export declare function random(min: number, max: number): number;
|