@tiny-codes/react-easy 1.7.5 → 1.7.7
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 +30 -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 +29 -17
- package/es/components/ColumnSetting/index.js.map +1 -1
- package/es/components/ConfigProvider/context.d.ts +38 -0
- package/es/components/ConfigProvider/context.js +2 -1
- package/es/components/ConfigProvider/context.js.map +1 -1
- package/es/components/ConfigProvider/index.d.ts +22 -4
- package/es/components/ConfigProvider/index.js +22 -10
- package/es/components/ConfigProvider/index.js.map +1 -1
- package/es/components/ConfigProvider/style/index.js +1 -1
- package/es/components/ConfigProvider/style/index.js.map +1 -1
- package/es/components/ContextMenu/index.d.ts +16 -0
- package/es/components/ContextMenu/index.js +3 -2
- package/es/components/ContextMenu/index.js.map +1 -1
- package/es/components/ContextMenu/style/index.js.map +1 -1
- package/es/components/DeleteConfirmAction/withDeleteConfirmAction.d.ts +3 -3
- 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 +3 -2
- package/es/components/EditableText/index.js.map +1 -1
- package/es/components/FloatDrawer/index.d.ts +10 -0
- package/es/components/FloatDrawer/index.js +3 -2
- package/es/components/FloatDrawer/index.js.map +1 -1
- package/es/components/FloatDrawer/style/index.js +1 -1
- package/es/components/FloatDrawer/style/index.js.map +1 -1
- package/es/components/Iconfont/createIconfont.d.ts +28 -0
- package/es/components/Iconfont/createIconfont.js +57 -0
- package/es/components/Iconfont/createIconfont.js.map +1 -0
- package/es/components/Iconfont/index.d.ts +1 -0
- package/es/components/Iconfont/index.js +2 -0
- package/es/components/Iconfont/index.js.map +1 -0
- package/es/components/Loading/index.js +3 -2
- package/es/components/Loading/index.js.map +1 -1
- package/es/components/Loading/style/index.js +1 -1
- package/es/components/Loading/style/index.js.map +1 -1
- package/es/components/OverflowTags/index.d.ts +2 -0
- package/es/components/OverflowTags/index.js +3 -2
- package/es/components/OverflowTags/index.js.map +1 -1
- package/es/components/OverflowTags/style/index.js +1 -1
- package/es/components/OverflowTags/style/index.js.map +1 -1
- package/es/components/index.d.ts +1 -0
- package/es/components/index.js +1 -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/style/useSplitter.d.ts +3 -0
- package/es/hooks/style/useSplitter.js +40 -0
- package/es/hooks/style/useSplitter.js.map +1 -0
- 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/hooks/useSplitter.d.ts +52 -9
- package/es/hooks/useSplitter.js +69 -39
- package/es/hooks/useSplitter.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 +20 -15
- package/lib/components/ColumnSetting/index.js.map +3 -3
- package/lib/components/ConfigProvider/context.d.ts +38 -0
- package/lib/components/ConfigProvider/context.js +2 -1
- package/lib/components/ConfigProvider/context.js.map +2 -2
- package/lib/components/ConfigProvider/index.d.ts +22 -4
- package/lib/components/ConfigProvider/index.js +17 -6
- package/lib/components/ConfigProvider/index.js.map +2 -2
- package/lib/components/ConfigProvider/style/index.js +1 -1
- package/lib/components/ConfigProvider/style/index.js.map +2 -2
- package/lib/components/ContextMenu/index.d.ts +16 -0
- package/lib/components/ContextMenu/index.js +2 -1
- package/lib/components/ContextMenu/index.js.map +3 -3
- package/lib/components/ContextMenu/style/index.js.map +2 -2
- package/lib/components/DeleteConfirmAction/withDeleteConfirmAction.d.ts +3 -3
- 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 +3 -2
- package/lib/components/EditableText/index.js.map +3 -3
- package/lib/components/FloatDrawer/index.d.ts +10 -0
- package/lib/components/FloatDrawer/index.js +3 -2
- package/lib/components/FloatDrawer/index.js.map +3 -3
- package/lib/components/FloatDrawer/style/index.js +1 -1
- package/lib/components/FloatDrawer/style/index.js.map +2 -2
- package/lib/components/Iconfont/createIconfont.d.ts +28 -0
- package/lib/components/Iconfont/createIconfont.js +65 -0
- package/lib/components/Iconfont/createIconfont.js.map +7 -0
- package/lib/components/Iconfont/index.d.ts +1 -0
- package/lib/components/Iconfont/index.js +24 -0
- package/lib/components/Iconfont/index.js.map +7 -0
- package/lib/components/Loading/index.js +3 -2
- package/lib/components/Loading/index.js.map +3 -3
- package/lib/components/Loading/style/index.js +1 -1
- package/lib/components/Loading/style/index.js.map +2 -2
- package/lib/components/OverflowTags/index.d.ts +2 -0
- package/lib/components/OverflowTags/index.js +3 -2
- package/lib/components/OverflowTags/index.js.map +3 -3
- package/lib/components/OverflowTags/style/index.js +1 -1
- package/lib/components/OverflowTags/style/index.js.map +2 -2
- package/lib/components/index.d.ts +1 -0
- package/lib/components/index.js +3 -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/style/useSplitter.d.ts +3 -0
- package/lib/hooks/style/useSplitter.js +72 -0
- package/lib/hooks/style/useSplitter.js.map +7 -0
- 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/hooks/useSplitter.d.ts +52 -9
- package/lib/hooks/useSplitter.js +56 -26
- package/lib/hooks/useSplitter.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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hooks/useMovable.ts"],
|
|
4
|
-
"sourcesContent": ["import { type RefObject, useEffect, useRef, useState } from 'react';\nimport
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA4D;AAC5D,
|
|
6
|
-
"names": ["useRefValue", "useRefFunction"]
|
|
4
|
+
"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"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA4D;AAC5D,6BAA4B;AAC5B,4BAA2B;AAC3B,yBAAwB;AA6BxB,IAAM,aAAa,CAAC,UAA2B;AAC7C,QAAM,EAAE,SAAS,cAAc,iBAAiB,WAAW,IAAI;AAE/D,QAAM,oBAAgB,mBAAAA,SAAY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AACA,QAAI,SAAS;AACX,aAAO,iBAAiB,eAAe,MAAM;AAC7C,aAAO,iBAAiB,aAAa,IAAI;AACzC,aAAO,iBAAiB,iBAAiB,IAAI;AAAA,IAC/C;AACA,WAAO,MAAM;AACX,aAAO,oBAAoB,eAAe,MAAM;AAChD,aAAO,oBAAoB,aAAa,IAAI;AAC5C,aAAO,oBAAoB,iBAAiB,IAAI;AAAA,IAClD;AAAA,EACF,GAAG,CAAC,OAAO,CAAC;AAEZ,SAAO;AAAA,IACL,eAAe;AAAA,IACf;AAAA,EACF;AACF;AAOA,IAAO,qBAAQ;",
|
|
6
|
+
"names": ["useRefValue", "useLocalStorage", "useRefFunction"]
|
|
7
7
|
}
|
|
@@ -2,40 +2,41 @@ import { type CSSProperties } from 'react';
|
|
|
2
2
|
export interface UseSplitterProps {
|
|
3
3
|
/**
|
|
4
4
|
* - **EN:** Split direction. vertical = left/right; horizontal = top/bottom.
|
|
5
|
-
* - **
|
|
5
|
+
* - **CN:** 分割方向。vertical 表示左右分割;horizontal 表示上下分割。
|
|
6
6
|
*
|
|
7
7
|
* @default 'vertical'
|
|
8
8
|
*/
|
|
9
9
|
direction?: 'vertical' | 'horizontal';
|
|
10
10
|
/**
|
|
11
|
-
* - **EN:**
|
|
12
|
-
*
|
|
11
|
+
* - **EN:** Parent container element. If not specified, the parent container of the `dom` element
|
|
12
|
+
* will be used automatically.
|
|
13
|
+
* - **CN:** 父容器元素,如果不指定,则自动使用 `dom` 元素的父容器
|
|
13
14
|
*/
|
|
14
|
-
container
|
|
15
|
+
container?: HTMLDivElement | null | undefined;
|
|
15
16
|
/**
|
|
16
17
|
* - **EN:** Default ratio of the left/top pane (0~1).
|
|
17
|
-
* - **
|
|
18
|
+
* - **CN:** 左侧/顶部面板的默认比例 (0~1)。
|
|
18
19
|
*
|
|
19
20
|
* @default 0.32
|
|
20
21
|
*/
|
|
21
22
|
defaultRatio?: number;
|
|
22
23
|
/**
|
|
23
24
|
* - **EN:** Minimum ratio of the left/top pane (0~1).
|
|
24
|
-
* - **
|
|
25
|
+
* - **CN:** 左侧/顶部面板的最小比例 (0~1)。
|
|
25
26
|
*
|
|
26
27
|
* @default 0.15
|
|
27
28
|
*/
|
|
28
29
|
minRatio?: number;
|
|
29
30
|
/**
|
|
30
31
|
* - **EN:** Maximum ratio of the left/top pane (0~1).
|
|
31
|
-
* - **
|
|
32
|
+
* - **CN:** 左侧/顶部面板的最大比例 (0~1)。
|
|
32
33
|
*
|
|
33
34
|
* @default 0.85
|
|
34
35
|
*/
|
|
35
36
|
maxRatio?: number;
|
|
36
37
|
/**
|
|
37
38
|
* - **EN:** Width of the splitter in pixels.
|
|
38
|
-
* - **
|
|
39
|
+
* - **CN:** 分割条的宽度,单位为像素。
|
|
39
40
|
*
|
|
40
41
|
* @default 2
|
|
41
42
|
*/
|
|
@@ -44,9 +45,51 @@ export interface UseSplitterProps {
|
|
|
44
45
|
className?: string;
|
|
45
46
|
/** Additional style for the splitter element */
|
|
46
47
|
style?: CSSProperties;
|
|
48
|
+
/**
|
|
49
|
+
* - **EN:** Custom prefix for the component's CSS class.
|
|
50
|
+
* - **CN:** 组件的自定义 CSS 类前缀。
|
|
51
|
+
*/
|
|
52
|
+
prefixCls?: string;
|
|
53
|
+
/**
|
|
54
|
+
* - **EN:** Semantic class names
|
|
55
|
+
* - **CN:** 语义化类名
|
|
56
|
+
*/
|
|
57
|
+
classNames?: {
|
|
58
|
+
/**
|
|
59
|
+
* - **EN:** Class name applied when the splitter is hovered.
|
|
60
|
+
* - **CN:** 分割条悬停时应用的类名。
|
|
61
|
+
*/
|
|
62
|
+
hover?: string;
|
|
63
|
+
/**
|
|
64
|
+
* - **EN:** Class name applied when the splitter is being dragged.
|
|
65
|
+
* - **CN:** 分割条拖动时应用的类名。
|
|
66
|
+
*/
|
|
67
|
+
dragging?: string;
|
|
68
|
+
/**
|
|
69
|
+
* - **EN:** Class name applied to the splitter handle.
|
|
70
|
+
* - **CN:** 分割条手柄的类名。
|
|
71
|
+
*/
|
|
72
|
+
handle?: string;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* - **EN:** Semantic styles
|
|
76
|
+
* - **CN:** 语义化样式
|
|
77
|
+
*/
|
|
78
|
+
styles?: {
|
|
79
|
+
/**
|
|
80
|
+
* - **EN:** Custom styles for the splitter handle.
|
|
81
|
+
* - **CN:** 分割条手柄的自定义样式。
|
|
82
|
+
*/
|
|
83
|
+
handle?: CSSProperties;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* - **EN:** Callback function when the splitter ratio changes.
|
|
87
|
+
* - **CN:** 分割比例变化时的回调函数。
|
|
88
|
+
*/
|
|
89
|
+
onChange?: (ratio?: number) => void;
|
|
47
90
|
}
|
|
48
91
|
declare const useSplitter: (props: UseSplitterProps) => {
|
|
49
|
-
dom: import("react
|
|
92
|
+
dom: import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
50
93
|
percent: number | undefined;
|
|
51
94
|
width: number | undefined;
|
|
52
95
|
dragging: boolean;
|
package/lib/hooks/useSplitter.js
CHANGED
|
@@ -33,23 +33,34 @@ __export(useSplitter_exports, {
|
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(useSplitter_exports);
|
|
35
35
|
var import_react = require("react");
|
|
36
|
-
var
|
|
36
|
+
var import_classnames = __toESM(require("classnames"));
|
|
37
|
+
var import_components = require("../components");
|
|
38
|
+
var import_useSplitter = __toESM(require("./style/useSplitter"));
|
|
37
39
|
var import_useRefValue = __toESM(require("./useRefValue"));
|
|
38
40
|
var useSplitter = (props) => {
|
|
39
41
|
const {
|
|
40
|
-
container,
|
|
42
|
+
container: containerFromProps,
|
|
41
43
|
defaultRatio,
|
|
42
44
|
minRatio = 0.15,
|
|
43
45
|
maxRatio = 1 - minRatio,
|
|
44
46
|
direction = "vertical",
|
|
45
|
-
splitterWidth =
|
|
47
|
+
splitterWidth = 1,
|
|
46
48
|
className,
|
|
47
|
-
|
|
49
|
+
classNames,
|
|
50
|
+
styles,
|
|
51
|
+
prefixCls: prefixClsInProps,
|
|
52
|
+
style,
|
|
53
|
+
onChange
|
|
48
54
|
} = props || {};
|
|
49
|
-
const {
|
|
55
|
+
const { getPrefixCls } = (0, import_react.useContext)(import_components.ConfigProvider.ConfigContext);
|
|
56
|
+
const prefixCls = getPrefixCls("splitter", prefixClsInProps);
|
|
57
|
+
const [wrapCSSVar, hashId, cssVarCls] = (0, import_useSplitter.default)(prefixCls);
|
|
50
58
|
const directionRef = (0, import_useRefValue.default)(direction);
|
|
59
|
+
const [splitterRef, setSplitterRef] = (0, import_react.useState)(null);
|
|
60
|
+
const [container, setContainer] = (0, import_react.useState)(containerFromProps);
|
|
51
61
|
const [percent, setPercent] = (0, import_react.useState)(defaultRatio);
|
|
52
62
|
const percentRef = (0, import_useRefValue.default)(percent);
|
|
63
|
+
const onChangeRef = (0, import_useRefValue.default)(onChange);
|
|
53
64
|
const [width, setWidth] = (0, import_react.useState)(
|
|
54
65
|
container && defaultRatio ? ((container == null ? void 0 : container.clientWidth) || 0) * defaultRatio : void 0
|
|
55
66
|
);
|
|
@@ -61,6 +72,7 @@ var useSplitter = (props) => {
|
|
|
61
72
|
if (!dragging)
|
|
62
73
|
return;
|
|
63
74
|
const onMove = (e) => {
|
|
75
|
+
var _a, _b;
|
|
64
76
|
const el = container;
|
|
65
77
|
if (!el)
|
|
66
78
|
return;
|
|
@@ -70,11 +82,13 @@ var useSplitter = (props) => {
|
|
|
70
82
|
const ratio = Math.max(minRatioRef.current, Math.min(maxRatioRef.current, x / rect.width));
|
|
71
83
|
setPercent(ratio);
|
|
72
84
|
setWidth(x);
|
|
85
|
+
(_a = onChangeRef.current) == null ? void 0 : _a.call(onChangeRef, ratio);
|
|
73
86
|
} else {
|
|
74
87
|
const y = e.clientY - rect.top;
|
|
75
88
|
const ratio = Math.max(minRatioRef.current, Math.min(maxRatioRef.current, y / rect.height));
|
|
76
89
|
setPercent(ratio);
|
|
77
90
|
setWidth(y);
|
|
91
|
+
(_b = onChangeRef.current) == null ? void 0 : _b.call(onChangeRef, ratio);
|
|
78
92
|
}
|
|
79
93
|
e.preventDefault();
|
|
80
94
|
};
|
|
@@ -87,39 +101,55 @@ var useSplitter = (props) => {
|
|
|
87
101
|
};
|
|
88
102
|
}, [container, dragging, direction, minRatioRef, maxRatioRef]);
|
|
89
103
|
(0, import_react.useEffect)(() => {
|
|
104
|
+
const containerDom = containerFromProps ?? (splitterRef == null ? void 0 : splitterRef.parentElement) ?? void 0;
|
|
105
|
+
setContainer(containerDom);
|
|
106
|
+
}, [containerFromProps, splitterRef]);
|
|
107
|
+
(0, import_react.useEffect)(() => {
|
|
108
|
+
var _a, _b;
|
|
90
109
|
if (defaultRatio && container && percentRef.current == null) {
|
|
91
110
|
const rect = container.getBoundingClientRect();
|
|
92
111
|
setPercent(defaultRatio);
|
|
93
112
|
if (directionRef.current === "vertical") {
|
|
94
113
|
setWidth(rect.width * defaultRatio);
|
|
114
|
+
(_a = onChangeRef.current) == null ? void 0 : _a.call(onChangeRef, defaultRatio);
|
|
95
115
|
} else {
|
|
96
116
|
setWidth(rect.height * defaultRatio);
|
|
117
|
+
(_b = onChangeRef.current) == null ? void 0 : _b.call(onChangeRef, defaultRatio);
|
|
97
118
|
}
|
|
98
119
|
}
|
|
99
120
|
}, [defaultRatio, container]);
|
|
100
121
|
const vertical = direction === "vertical";
|
|
101
|
-
const dom =
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
122
|
+
const dom = wrapCSSVar(
|
|
123
|
+
/* @__PURE__ */ React.createElement(
|
|
124
|
+
"div",
|
|
125
|
+
{
|
|
126
|
+
ref: setSplitterRef,
|
|
127
|
+
className: (0, import_classnames.default)(
|
|
128
|
+
hashId,
|
|
129
|
+
cssVarCls,
|
|
130
|
+
prefixCls,
|
|
131
|
+
className,
|
|
132
|
+
isOver ? (0, import_classnames.default)(`${prefixCls}-hover`, classNames == null ? void 0 : classNames.hover) : void 0,
|
|
133
|
+
dragging ? (0, import_classnames.default)(`${prefixCls}-dragging`, classNames == null ? void 0 : classNames.dragging) : void 0,
|
|
134
|
+
{
|
|
135
|
+
[`${prefixCls}-vertical`]: vertical,
|
|
136
|
+
[`${prefixCls}-horizontal`]: !vertical
|
|
137
|
+
}
|
|
138
|
+
),
|
|
139
|
+
style: {
|
|
140
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
141
|
+
[`--splitter-width`]: splitterWidth ? `${splitterWidth}px` : void 0,
|
|
142
|
+
...style
|
|
143
|
+
},
|
|
144
|
+
onMouseDown: () => setDragging(true),
|
|
145
|
+
onMouseEnter: () => setIsOver(true),
|
|
146
|
+
onMouseLeave: () => setIsOver(false),
|
|
147
|
+
role: "separator",
|
|
148
|
+
"aria-orientation": vertical ? "vertical" : "horizontal",
|
|
149
|
+
"aria-label": "Resize"
|
|
115
150
|
},
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
onMouseLeave: () => setIsOver(false),
|
|
119
|
-
role: "separator",
|
|
120
|
-
"aria-orientation": vertical ? "vertical" : "horizontal",
|
|
121
|
-
"aria-label": "Resize"
|
|
122
|
-
}
|
|
151
|
+
/* @__PURE__ */ React.createElement("div", { className: (0, import_classnames.default)(`${prefixCls}-handle`, classNames == null ? void 0 : classNames.handle), style: styles == null ? void 0 : styles.handle })
|
|
152
|
+
)
|
|
123
153
|
);
|
|
124
154
|
return {
|
|
125
155
|
dom,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hooks/useSplitter.tsx"],
|
|
4
|
-
"sourcesContent": ["import { type CSSProperties, useEffect, useState } from 'react';\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
6
|
-
"names": ["useRefValue"]
|
|
4
|
+
"sourcesContent": ["import { type CSSProperties, useContext, useEffect, useState } from 'react';\nimport names from 'classnames';\nimport { ConfigProvider } from '../components';\nimport useStyle from './style/useSplitter';\nimport useRefValue from './useRefValue';\n\nexport interface UseSplitterProps {\n /**\n * - **EN:** Split direction. vertical = left/right; horizontal = top/bottom.\n * - **CN:** 分割方向。vertical 表示左右分割;horizontal 表示上下分割。\n *\n * @default 'vertical'\n */\n direction?: 'vertical' | 'horizontal';\n /**\n * - **EN:** Parent container element. If not specified, the parent container of the `dom` element\n * will be used automatically.\n * - **CN:** 父容器元素,如果不指定,则自动使用 `dom` 元素的父容器\n */\n container?: HTMLDivElement | null | undefined;\n /**\n * - **EN:** Default ratio of the left/top pane (0~1).\n * - **CN:** 左侧/顶部面板的默认比例 (0~1)。\n *\n * @default 0.32\n */\n defaultRatio?: number;\n /**\n * - **EN:** Minimum ratio of the left/top pane (0~1).\n * - **CN:** 左侧/顶部面板的最小比例 (0~1)。\n *\n * @default 0.15\n */\n minRatio?: number;\n /**\n * - **EN:** Maximum ratio of the left/top pane (0~1).\n * - **CN:** 左侧/顶部面板的最大比例 (0~1)。\n *\n * @default 0.85\n */\n maxRatio?: number;\n /**\n * - **EN:** Width of the splitter in pixels.\n * - **CN:** 分割条的宽度,单位为像素。\n *\n * @default 2\n */\n splitterWidth?: number;\n /** Additional class name for the splitter element */\n className?: string;\n /** Additional style for the splitter element */\n style?: CSSProperties;\n /**\n * - **EN:** Custom prefix for the component's CSS class.\n * - **CN:** 组件的自定义 CSS 类前缀。\n */\n prefixCls?: string;\n /**\n * - **EN:** Semantic class names\n * - **CN:** 语义化类名\n */\n classNames?: {\n /**\n * - **EN:** Class name applied when the splitter is hovered.\n * - **CN:** 分割条悬停时应用的类名。\n */\n hover?: string;\n /**\n * - **EN:** Class name applied when the splitter is being dragged.\n * - **CN:** 分割条拖动时应用的类名。\n */\n dragging?: string;\n /**\n * - **EN:** Class name applied to the splitter handle.\n * - **CN:** 分割条手柄的类名。\n */\n handle?: string;\n };\n /**\n * - **EN:** Semantic styles\n * - **CN:** 语义化样式\n */\n styles?: {\n /**\n * - **EN:** Custom styles for the splitter handle.\n * - **CN:** 分割条手柄的自定义样式。\n */\n handle?: CSSProperties;\n };\n /**\n * - **EN:** Callback function when the splitter ratio changes.\n * - **CN:** 分割比例变化时的回调函数。\n */\n onChange?: (ratio?: number) => void;\n}\n\nconst useSplitter = (props: UseSplitterProps) => {\n const {\n container: containerFromProps,\n defaultRatio,\n minRatio = 0.15,\n maxRatio = 1 - minRatio,\n direction = 'vertical',\n splitterWidth = 1,\n className,\n classNames,\n styles,\n prefixCls: prefixClsInProps,\n style,\n onChange,\n } = props || {};\n const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);\n const prefixCls = getPrefixCls('splitter', prefixClsInProps);\n const [wrapCSSVar, hashId, cssVarCls] = useStyle(prefixCls);\n const directionRef = useRefValue(direction);\n const [splitterRef, setSplitterRef] = useState<HTMLDivElement | null>(null);\n const [container, setContainer] = useState(containerFromProps);\n const [percent, setPercent] = useState(defaultRatio);\n const percentRef = useRefValue(percent);\n const onChangeRef = useRefValue(onChange);\n const [width, setWidth] = useState(\n container && defaultRatio ? (container?.clientWidth || 0) * defaultRatio : undefined\n );\n const [dragging, setDragging] = useState(false);\n const minRatioRef = useRefValue(minRatio);\n const maxRatioRef = useRefValue(maxRatio);\n const [isOver, setIsOver] = useState(false);\n\n useEffect(() => {\n if (!dragging) return;\n const onMove = (e: MouseEvent) => {\n const el = container;\n if (!el) return;\n const rect = el.getBoundingClientRect();\n if (direction === 'vertical') {\n const x = e.clientX - rect.left;\n const ratio = Math.max(minRatioRef.current, Math.min(maxRatioRef.current, x / rect.width));\n setPercent(ratio);\n setWidth(x);\n onChangeRef.current?.(ratio);\n } else {\n const y = e.clientY - rect.top;\n const ratio = Math.max(minRatioRef.current, Math.min(maxRatioRef.current, y / rect.height));\n setPercent(ratio);\n setWidth(y);\n onChangeRef.current?.(ratio);\n }\n // prevent text selection while dragging\n e.preventDefault();\n };\n const onUp = () => setDragging(false);\n window.addEventListener('mousemove', onMove);\n window.addEventListener('mouseup', onUp, { once: true });\n\n return () => {\n window.removeEventListener('mousemove', onMove);\n window.removeEventListener('mouseup', onUp);\n };\n }, [container, dragging, direction, minRatioRef, maxRatioRef]);\n\n useEffect(() => {\n const containerDom = containerFromProps ?? (splitterRef?.parentElement as HTMLDivElement | undefined) ?? undefined;\n setContainer(containerDom);\n }, [containerFromProps, splitterRef]);\n\n // Initialize percent and width on mount\n useEffect(() => {\n if (defaultRatio && container && percentRef.current == null) {\n const rect = container.getBoundingClientRect();\n setPercent(defaultRatio);\n if (directionRef.current === 'vertical') {\n setWidth(rect.width * defaultRatio);\n onChangeRef.current?.(defaultRatio);\n } else {\n setWidth(rect.height * defaultRatio);\n onChangeRef.current?.(defaultRatio);\n }\n }\n }, [defaultRatio, container]);\n\n const vertical = direction === 'vertical';\n const dom = wrapCSSVar(\n <div\n ref={setSplitterRef}\n className={names(\n hashId,\n cssVarCls,\n prefixCls,\n className,\n isOver ? names(`${prefixCls}-hover`, classNames?.hover) : undefined,\n dragging ? names(`${prefixCls}-dragging`, classNames?.dragging) : undefined,\n {\n [`${prefixCls}-vertical`]: vertical,\n [`${prefixCls}-horizontal`]: !vertical,\n }\n )}\n style={{\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n [`--splitter-width` as any]: splitterWidth ? `${splitterWidth}px` : undefined,\n ...style,\n }}\n onMouseDown={() => setDragging(true)}\n onMouseEnter={() => setIsOver(true)}\n onMouseLeave={() => setIsOver(false)}\n role=\"separator\"\n aria-orientation={vertical ? 'vertical' : 'horizontal'}\n aria-label=\"Resize\"\n >\n <div className={names(`${prefixCls}-handle`, classNames?.handle)} style={styles?.handle}></div>\n </div>\n );\n\n return {\n dom,\n percent,\n width,\n dragging,\n direction,\n };\n};\n\nexport default useSplitter;\n"],
|
|
5
|
+
"mappings": ";;;;;;;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F,GAAG,CAAC,cAAc,SAAS,CAAC;AAE5B,QAAM,WAAW,cAAc;AAC/B,QAAM,MAAM;AAAA,IACV;AAAA,MAAC;AAAA;AAAA,QACC,KAAK;AAAA,QACL,eAAW,kBAAAC;AAAA,UACT;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA,aAAS,kBAAAA,SAAM,GAAG,mBAAmB,yCAAY,KAAK,IAAI;AAAA,UAC1D,eAAW,kBAAAA,SAAM,GAAG,sBAAsB,yCAAY,QAAQ,IAAI;AAAA,UAClE;AAAA,YACE,CAAC,GAAG,oBAAoB,GAAG;AAAA,YAC3B,CAAC,GAAG,sBAAsB,GAAG,CAAC;AAAA,UAChC;AAAA,QACF;AAAA,QACA,OAAO;AAAA;AAAA,UAEL,CAAC,kBAAyB,GAAG,gBAAgB,GAAG,oBAAoB;AAAA,UACpE,GAAG;AAAA,QACL;AAAA,QACA,aAAa,MAAM,YAAY,IAAI;AAAA,QACnC,cAAc,MAAM,UAAU,IAAI;AAAA,QAClC,cAAc,MAAM,UAAU,KAAK;AAAA,QACnC,MAAK;AAAA,QACL,oBAAkB,WAAW,aAAa;AAAA,QAC1C,cAAW;AAAA;AAAA,MAEX,oCAAC,SAAI,eAAW,kBAAAA,SAAM,GAAG,oBAAoB,yCAAY,MAAM,GAAG,OAAO,iCAAQ,QAAQ;AAAA,IAC3F;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEA,IAAO,sBAAQ;",
|
|
6
|
+
"names": ["useStyle", "useRefValue", "names"]
|
|
7
7
|
}
|
package/lib/locales/index.js
CHANGED
package/lib/locales/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/locales/index.ts"],
|
|
4
|
-
"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"],
|
|
4
|
+
"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"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA0C;AAC1C,mBAAiB;AACjB,mBAAiB;AAEV,IAAM,QAAQ,CAAC,MAAM,SAAS,OAAO;AAIrC,IAAM,YAAY;AAAA,EACvB,IAAI,EAAE,aAAa,aAAAA,QAAK;AAAA,EACxB,SAAS,EAAE,aAAa,aAAAA,QAAK;AAAA,EAC7B,SAAS,EAAE,aAAa,aAAAC,QAAK;AAC/B;AAEA,IAAM,oBAAsB,+BAAe,CAAC,CAAC;AAE7C,cAAc,KAAK;AAAA,EACjB,KAAK;AAAA,EACL;AACF,CAAC;AAEM,IAAM,IAAgB,IAAI,SAAS;AACxC,SAAO,cAAc,EAAE,GAAG,IAAI;AAChC;AAEA,IAAO,kBAAQ;",
|
|
6
6
|
"names": ["enUS", "zhCN"]
|
|
7
7
|
}
|
package/lib/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;
|
package/lib/utils/math.js
CHANGED
|
@@ -24,26 +24,33 @@ __export(math_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(math_exports);
|
|
25
25
|
function random(min, max) {
|
|
26
26
|
var _a;
|
|
27
|
+
if (min == null && max == null) {
|
|
28
|
+
return randomLikeMath();
|
|
29
|
+
}
|
|
30
|
+
if (min == null || max == null) {
|
|
31
|
+
throw new TypeError("Both min and max must be provided");
|
|
32
|
+
}
|
|
27
33
|
if (!Number.isFinite(min) || !Number.isFinite(max)) {
|
|
28
34
|
throw new TypeError("min and max must be finite numbers");
|
|
29
35
|
}
|
|
30
36
|
if (Math.floor(min) !== min || Math.floor(max) !== max) {
|
|
31
37
|
throw new TypeError("min and max must be integers");
|
|
32
38
|
}
|
|
39
|
+
const globalThat2 = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : {};
|
|
33
40
|
if (min > max) {
|
|
34
41
|
[min, max] = [max, min];
|
|
35
42
|
}
|
|
36
|
-
let
|
|
43
|
+
let nodeCrypto2;
|
|
37
44
|
if (typeof process !== "undefined" && ((_a = process.versions) == null ? void 0 : _a.node)) {
|
|
38
45
|
try {
|
|
39
|
-
|
|
40
|
-
} catch {
|
|
46
|
+
nodeCrypto2 = require("crypto");
|
|
47
|
+
} catch (error) {
|
|
41
48
|
}
|
|
42
49
|
}
|
|
43
|
-
if (
|
|
44
|
-
return
|
|
50
|
+
if (nodeCrypto2 == null ? void 0 : nodeCrypto2.randomInt) {
|
|
51
|
+
return nodeCrypto2.randomInt(min, max + 1);
|
|
45
52
|
}
|
|
46
|
-
const webCrypto =
|
|
53
|
+
const webCrypto = globalThat2.crypto || (nodeCrypto2 == null ? void 0 : nodeCrypto2.webcrypto);
|
|
47
54
|
if (webCrypto == null ? void 0 : webCrypto.getRandomValues) {
|
|
48
55
|
const range = max - min + 1;
|
|
49
56
|
if (range <= 0)
|
|
@@ -58,8 +65,36 @@ function random(min, max) {
|
|
|
58
65
|
} while (v >= limit);
|
|
59
66
|
return min + v % range;
|
|
60
67
|
}
|
|
61
|
-
|
|
62
|
-
|
|
68
|
+
return randomLikeMath();
|
|
69
|
+
}
|
|
70
|
+
function randomLikeMath() {
|
|
71
|
+
var _a;
|
|
72
|
+
const globalThat = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : {};
|
|
73
|
+
const cryptoObj = globalThat.crypto;
|
|
74
|
+
if (cryptoObj == null ? void 0 : cryptoObj.getRandomValues) {
|
|
75
|
+
const buf = new Uint32Array(2);
|
|
76
|
+
cryptoObj.getRandomValues(buf);
|
|
77
|
+
const high = buf[0] >>> 5;
|
|
78
|
+
const low = buf[1] >>> 6;
|
|
79
|
+
return (high * 67108864 + low) / 9007199254740992;
|
|
80
|
+
}
|
|
81
|
+
const req = typeof process !== "undefined" && ((_a = process.versions) == null ? void 0 : _a.node) && typeof globalThat.require === "function" ? globalThat.require : (() => {
|
|
82
|
+
try {
|
|
83
|
+
return eval("require");
|
|
84
|
+
} catch (error) {
|
|
85
|
+
return void 0;
|
|
86
|
+
}
|
|
87
|
+
})();
|
|
88
|
+
if (!req) {
|
|
89
|
+
throw new Error("No secure random source available in this environment");
|
|
90
|
+
}
|
|
91
|
+
const nodeCrypto = req("crypto");
|
|
92
|
+
if (typeof nodeCrypto.randomBytes !== "function") {
|
|
93
|
+
throw new Error("No secure random source available in this environment");
|
|
94
|
+
}
|
|
95
|
+
const b = nodeCrypto.randomBytes(7);
|
|
96
|
+
const x = (b[0] & 31) * 2 ** 48 + b[1] * 2 ** 40 + b[2] * 2 ** 32 + b[3] * 2 ** 24 + b[4] * 2 ** 16 + b[5] * 2 ** 8 + b[6];
|
|
97
|
+
return x / 9007199254740992;
|
|
63
98
|
}
|
|
64
99
|
// Annotate the CommonJS export names for ESM import in node:
|
|
65
100
|
0 && (module.exports = {
|
package/lib/utils/math.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/math.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * **EN**: Generate a random number within a specified range (inclusive on both ends)\n *\n * **CN**:
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["/**\n * **EN**: Generate a random decimal number between 0 and 1\n *\n * **CN**: 生成一个0~1之间的小数\n *\n * @returns The generated random number | 生成的随机数\n */\nexport function random(): number;\n/**\n * **EN**: Generate a random integer within a specified range (inclusive on both ends)\n *\n * **CN**: 生成指定范围(两端包含)内的随机整数\n *\n * @param min The minimum value (inclusive) | 最小值(包含)\n * @param max The maximum value (inclusive) | 最大值(包含)\n *\n * @returns The generated random integer | 生成的随机整数\n */\nexport function random(min: number, max: number): number;\nexport function random(min?: number, max?: number): number {\n if (min == null && max == null) {\n return randomLikeMath();\n }\n if (min == null || max == null) {\n throw new TypeError('Both min and max must be provided');\n }\n if (!Number.isFinite(min) || !Number.isFinite(max)) {\n throw new TypeError('min and max must be finite numbers');\n }\n if (Math.floor(min) !== min || Math.floor(max) !== max) {\n throw new TypeError('min and max must be integers');\n }\n const globalThat =\n typeof globalThis !== 'undefined'\n ? globalThis\n : typeof window !== 'undefined'\n ? window\n : typeof global !== 'undefined'\n ? global\n : ({} as typeof globalThis);\n if (min > max) {\n [min, max] = [max, min];\n }\n\n // Try to require Node.js crypto\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let nodeCrypto: any;\n if (typeof process !== 'undefined' && process.versions?.node) {\n try {\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n nodeCrypto = require('crypto');\n } catch (error) {\n // ignore\n }\n }\n\n // 1. Node.js crypto.randomInt\n if (nodeCrypto?.randomInt) {\n return nodeCrypto.randomInt(min, max + 1);\n }\n\n // 2. Web Crypto (Browsers or Node 19+ webcrypto)\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const webCrypto: Crypto | undefined = globalThat.crypto || nodeCrypto?.webcrypto;\n\n if (webCrypto?.getRandomValues) {\n const range = max - min + 1;\n if (range <= 0) return min;\n\n // Use rejection sampling to avoid the slight bias caused by (2^32 % range).\n const maxUint32 = 0xffffffff;\n const limit = Math.floor((maxUint32 + 1) / range) * range;\n const arr = new Uint32Array(1);\n let v: number;\n do {\n webCrypto.getRandomValues(arr);\n v = arr[0];\n } while (v >= limit);\n return min + (v % range);\n }\n\n // 3. Fallback\n return randomLikeMath();\n}\n\nfunction randomLikeMath(): number {\n const globalThat =\n typeof globalThis !== 'undefined'\n ? globalThis\n : typeof window !== 'undefined'\n ? window\n : typeof global !== 'undefined'\n ? global\n : ({} as typeof globalThis);\n // Browser / Node(with webcrypto)\n const cryptoObj = globalThat.crypto;\n if (cryptoObj?.getRandomValues) {\n const buf = new Uint32Array(2);\n cryptoObj.getRandomValues(buf);\n\n // 53-bit precision, mapped to [0, 1)\n const high = buf[0] >>> 5; // 27 bits\n const low = buf[1] >>> 6; // 26 bits\n return (high * 67108864 + low) / 9007199254740992; // 2^53\n }\n\n // Old Node fallback (No webcrypto)\n // Use eval('require') to avoid \"require is not defined\" error during browser bundling\n const req: NodeRequire | undefined =\n typeof process !== 'undefined' &&\n process.versions?.node &&\n typeof (globalThat as unknown as { require?: unknown }).require === 'function'\n ? (globalThat as unknown as { require: NodeRequire }).require\n : (() => {\n try {\n // eslint-disable-next-line no-eval\n return eval('require') as NodeRequire;\n } catch (error) {\n return undefined;\n }\n })();\n\n if (!req) {\n throw new Error('No secure random source available in this environment');\n }\n\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const nodeCrypto = req('crypto') as { randomBytes?: (size: number) => Uint8Array };\n if (typeof nodeCrypto.randomBytes !== 'function') {\n throw new Error('No secure random source available in this environment');\n }\n\n const b = nodeCrypto.randomBytes(7); // 56 bits\n const x =\n (b[0] & 0x1f) * 2 ** 48 + b[1] * 2 ** 40 + b[2] * 2 ** 32 + b[3] * 2 ** 24 + b[4] * 2 ** 16 + b[5] * 2 ** 8 + b[6];\n\n return x / 9007199254740992; // 2^53 => [0,1)\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAmBO,SAAS,OAAO,KAAc,KAAsB;AAnB3D;AAoBE,MAAI,OAAO,QAAQ,OAAO,MAAM;AAC9B,WAAO,eAAe;AAAA,EACxB;AACA,MAAI,OAAO,QAAQ,OAAO,MAAM;AAC9B,UAAM,IAAI,UAAU,mCAAmC;AAAA,EACzD;AACA,MAAI,CAAC,OAAO,SAAS,GAAG,KAAK,CAAC,OAAO,SAAS,GAAG,GAAG;AAClD,UAAM,IAAI,UAAU,oCAAoC;AAAA,EAC1D;AACA,MAAI,KAAK,MAAM,GAAG,MAAM,OAAO,KAAK,MAAM,GAAG,MAAM,KAAK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O,WAAW,OAAO;AAAA,EACnC;AAIA,QAAM,MACJ,OAAO,YAAY,iBACnB,aAAQ,aAAR,mBAAkB,SAClB,OAAQ,WAAgD,YAAY,aAC/D,WAAmD,WACnD,MAAM;AACL,QAAI;AAEF,aAAO,KAAK,SAAS;AAAA,IACvB,SAAS,OAAP;AACA,aAAO;AAAA,IACT;AAAA,EACF,GAAG;AAET,MAAI,CAAC,KAAK;AACR,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AAGA,QAAM,aAAa,IAAI,QAAQ;AAC/B,MAAI,OAAO,WAAW,gBAAgB,YAAY;AAChD,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AAEA,QAAM,IAAI,WAAW,YAAY,CAAC;AAClC,QAAM,KACH,EAAE,CAAC,IAAI,MAAQ,KAAK,KAAK,EAAE,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;AAEnH,SAAO,IAAI;AACb;",
|
|
6
|
+
"names": ["globalThat", "nodeCrypto"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiny-codes/react-easy",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.7",
|
|
4
4
|
"description": "Simplify React and AntDesign development with practical components and hooks",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -33,9 +33,11 @@
|
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build": "run-s build-core correct-sourcemap",
|
|
35
35
|
"build-core": "father build",
|
|
36
|
+
"build-storybook": "storybook build",
|
|
36
37
|
"correct-sourcemap": "tsx scripts/correct-sourcemap.ts",
|
|
37
38
|
"prepare": "husky",
|
|
38
|
-
"prepublishOnly": "npm run build"
|
|
39
|
+
"prepublishOnly": "npm run build",
|
|
40
|
+
"storybook": "storybook dev -p 6006"
|
|
39
41
|
},
|
|
40
42
|
"dependencies": {
|
|
41
43
|
"@lexical/react": "^0.33.1",
|
|
@@ -44,12 +46,14 @@
|
|
|
44
46
|
"crypto-js": "^4.2.0",
|
|
45
47
|
"lexical": "^0.33.1",
|
|
46
48
|
"react-contexify": "^6.0.0",
|
|
47
|
-
"react-use": "^17.6.0",
|
|
48
49
|
"sockjs-client": "^1.6.1"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
52
|
+
"@storybook/addon-docs": "^10.2.12",
|
|
53
|
+
"@storybook/addon-links": "^10.2.12",
|
|
54
|
+
"@storybook/react-vite": "^10.2.12",
|
|
51
55
|
"@tiny-codes/code-style-all-in-one": "^1.1.5",
|
|
52
|
-
"@tiny-codes/eslint-plugin-react-hooks": "^
|
|
56
|
+
"@tiny-codes/eslint-plugin-react-hooks": "^5.2.0",
|
|
53
57
|
"@types/crypto-js": "^4.2.2",
|
|
54
58
|
"@types/jest": "^29.5.14",
|
|
55
59
|
"@types/node": "^22.15.32",
|
|
@@ -57,16 +61,19 @@
|
|
|
57
61
|
"@types/react-dom": "^19.0.4",
|
|
58
62
|
"@types/react-is": "^19.0.0",
|
|
59
63
|
"@types/sockjs-client": "^1.5.4",
|
|
60
|
-
"antd": "^5.
|
|
64
|
+
"antd": "^5.29.3",
|
|
65
|
+
"eslint-plugin-storybook": "10.2.13",
|
|
61
66
|
"father": "^4.5.2",
|
|
62
67
|
"jest": "^29.7.0",
|
|
63
|
-
"npm-run-all2": "^
|
|
68
|
+
"npm-run-all2": "^8.0.4",
|
|
64
69
|
"react": "^19.0.0",
|
|
65
70
|
"react-dom": "^19.0.0",
|
|
66
71
|
"react-is": "^19.0.0",
|
|
72
|
+
"storybook": "^10.2.12",
|
|
67
73
|
"ts-jest": "^29.3.0",
|
|
68
74
|
"tsx": "^4.20.5",
|
|
69
|
-
"typescript": "^5.8.2"
|
|
75
|
+
"typescript": "^5.8.2",
|
|
76
|
+
"vite": "^7.3.1"
|
|
70
77
|
},
|
|
71
78
|
"peerDependencies": {
|
|
72
79
|
"antd": ">=5.1.0",
|