@tiny-codes/react-easy 1.7.6 → 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 +15 -1
- package/es/components/ColumnSetting/index.js +2 -1
- package/es/components/ColumnSetting/index.js.map +1 -1
- package/es/components/ConfigProvider/context.d.ts +36 -0
- package/es/components/ConfigProvider/context.js +1 -0
- package/es/components/ConfigProvider/context.js.map +1 -1
- package/es/components/ConfigProvider/index.d.ts +5 -3
- package/es/components/ConfigProvider/index.js +13 -8
- 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.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/index.js +3 -2
- package/es/components/EditableText/index.js.map +1 -1
- 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.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/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/useSplitter.d.ts +52 -9
- package/es/hooks/useSplitter.js +69 -39
- package/es/hooks/useSplitter.js.map +1 -1
- package/lib/components/ColumnSetting/index.js +2 -1
- package/lib/components/ColumnSetting/index.js.map +3 -3
- package/lib/components/ConfigProvider/context.d.ts +36 -0
- package/lib/components/ConfigProvider/context.js +1 -0
- package/lib/components/ConfigProvider/context.js.map +2 -2
- package/lib/components/ConfigProvider/index.d.ts +5 -3
- package/lib/components/ConfigProvider/index.js +6 -2
- 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.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/index.js +3 -2
- package/lib/components/EditableText/index.js.map +3 -3
- 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.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/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/useSplitter.d.ts +52 -9
- package/lib/hooks/useSplitter.js +56 -26
- package/lib/hooks/useSplitter.js.map +3 -3
- package/package.json +1 -1
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/hooks/style/useSplitter.ts
|
|
20
|
+
var useSplitter_exports = {};
|
|
21
|
+
__export(useSplitter_exports, {
|
|
22
|
+
default: () => useSplitter_default
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(useSplitter_exports);
|
|
25
|
+
var import_internal = require("antd/es/theme/internal");
|
|
26
|
+
var genStyle = (token) => {
|
|
27
|
+
const { componentCls, EasySplitter: { splitterDefaultWidth = 1 } = {} } = token;
|
|
28
|
+
return {
|
|
29
|
+
[componentCls]: {
|
|
30
|
+
flex: "none",
|
|
31
|
+
userSelect: "none",
|
|
32
|
+
[`&${componentCls}-vertical`]: {
|
|
33
|
+
cursor: "col-resize",
|
|
34
|
+
padding: "0 4px",
|
|
35
|
+
height: "100%",
|
|
36
|
+
[`${componentCls}-handle`]: {
|
|
37
|
+
width: `var(--splitter-width, ${splitterDefaultWidth}px)`,
|
|
38
|
+
height: "100%"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
[`&${componentCls}-horizontal`]: {
|
|
42
|
+
cursor: "row-resize",
|
|
43
|
+
padding: "4px 0",
|
|
44
|
+
width: "100%",
|
|
45
|
+
[`${componentCls}-handle`]: {
|
|
46
|
+
width: "100%",
|
|
47
|
+
height: `var(--splitter-width, ${splitterDefaultWidth}px)`
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"&:hover": {
|
|
51
|
+
[`${componentCls}-handle`]: {
|
|
52
|
+
background: token.colorPrimaryActive
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
[`&${componentCls}-dragging`]: {
|
|
56
|
+
[`${componentCls}-handle`]: {
|
|
57
|
+
background: token.colorPrimaryHover
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
[`&${componentCls}-hover`]: {
|
|
61
|
+
[`${componentCls}-handle`]: {
|
|
62
|
+
background: token.colorPrimaryActive
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
[`${componentCls}-handle`]: {
|
|
66
|
+
background: token.colorBorder
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
var useSplitter_default = (0, import_internal.genStyleHooks)("EasySplitter", genStyle);
|
|
72
|
+
//# sourceMappingURL=useSplitter.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/hooks/style/useSplitter.ts"],
|
|
4
|
+
"sourcesContent": ["import { genStyleHooks } from 'antd/es/theme/internal';\nimport type { AliasToken, GenerateStyle } from 'antd/es/theme/internal';\nimport type { CSSObject } from '@ant-design/cssinjs';\nimport type { FullToken } from '@ant-design/cssinjs-utils';\n\ntype UseSplitterToken = FullToken<\n {\n EasySplitter?: {\n splitterDefaultWidth?: number;\n };\n },\n AliasToken,\n 'EasySplitter'\n>;\n\nconst genStyle: GenerateStyle<UseSplitterToken> = (token): CSSObject => {\n const { componentCls, EasySplitter: { splitterDefaultWidth = 1 } = {} } = token;\n return {\n [componentCls]: {\n flex: 'none',\n userSelect: 'none',\n [`&${componentCls}-vertical`]: {\n cursor: 'col-resize',\n padding: '0 4px',\n height: '100%',\n [`${componentCls}-handle`]: {\n width: `var(--splitter-width, ${splitterDefaultWidth}px)`,\n height: '100%',\n },\n },\n [`&${componentCls}-horizontal`]: {\n cursor: 'row-resize',\n padding: '4px 0',\n width: '100%',\n [`${componentCls}-handle`]: {\n width: '100%',\n height: `var(--splitter-width, ${splitterDefaultWidth}px)`,\n },\n },\n '&:hover': {\n [`${componentCls}-handle`]: {\n background: token.colorPrimaryActive,\n },\n },\n [`&${componentCls}-dragging`]: {\n [`${componentCls}-handle`]: {\n background: token.colorPrimaryHover,\n },\n },\n [`&${componentCls}-hover`]: {\n [`${componentCls}-handle`]: {\n background: token.colorPrimaryActive,\n },\n },\n [`${componentCls}-handle`]: {\n background: token.colorBorder,\n },\n },\n };\n};\n\nexport default genStyleHooks('EasySplitter' as never, genStyle);\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA8B;AAe9B,IAAM,WAA4C,CAAC,UAAqB;AACtE,QAAM,EAAE,cAAc,cAAc,EAAE,uBAAuB,EAAE,IAAI,CAAC,EAAE,IAAI;AAC1E,SAAO;AAAA,IACL,CAAC,YAAY,GAAG;AAAA,MACd,MAAM;AAAA,MACN,YAAY;AAAA,MACZ,CAAC,IAAI,uBAAuB,GAAG;AAAA,QAC7B,QAAQ;AAAA,QACR,SAAS;AAAA,QACT,QAAQ;AAAA,QACR,CAAC,GAAG,qBAAqB,GAAG;AAAA,UAC1B,OAAO,yBAAyB;AAAA,UAChC,QAAQ;AAAA,QACV;AAAA,MACF;AAAA,MACA,CAAC,IAAI,yBAAyB,GAAG;AAAA,QAC/B,QAAQ;AAAA,QACR,SAAS;AAAA,QACT,OAAO;AAAA,QACP,CAAC,GAAG,qBAAqB,GAAG;AAAA,UAC1B,OAAO;AAAA,UACP,QAAQ,yBAAyB;AAAA,QACnC;AAAA,MACF;AAAA,MACA,WAAW;AAAA,QACT,CAAC,GAAG,qBAAqB,GAAG;AAAA,UAC1B,YAAY,MAAM;AAAA,QACpB;AAAA,MACF;AAAA,MACA,CAAC,IAAI,uBAAuB,GAAG;AAAA,QAC7B,CAAC,GAAG,qBAAqB,GAAG;AAAA,UAC1B,YAAY,MAAM;AAAA,QACpB;AAAA,MACF;AAAA,MACA,CAAC,IAAI,oBAAoB,GAAG;AAAA,QAC1B,CAAC,GAAG,qBAAqB,GAAG;AAAA,UAC1B,YAAY,MAAM;AAAA,QACpB;AAAA,MACF;AAAA,MACA,CAAC,GAAG,qBAAqB,GAAG;AAAA,QAC1B,YAAY,MAAM;AAAA,MACpB;AAAA,IACF;AAAA,EACF;AACF;AAEA,IAAO,0BAAQ,+BAAc,gBAAyB,QAAQ;",
|
|
6
|
+
"names": []
|
|
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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAoE;AACpE,wBAAkB;AAClB,wBAA+B;AAC/B,yBAAqB;AACrB,yBAAwB;AA4FxB,IAAM,cAAc,CAAC,UAA4B;AAC/C,QAAM;AAAA,IACJ,WAAW;AAAA,IACX;AAAA,IACA,WAAW;AAAA,IACX,WAAW,IAAI;AAAA,IACf,YAAY;AAAA,IACZ,gBAAgB;AAAA,IAChB;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX;AAAA,IACA;AAAA,EACF,IAAI,SAAS,CAAC;AACd,QAAM,EAAE,aAAa,QAAI,yBAAW,iCAAe,aAAa;AAChE,QAAM,YAAY,aAAa,YAAY,gBAAgB;AAC3D,QAAM,CAAC,YAAY,QAAQ,SAAS,QAAI,mBAAAA,SAAS,SAAS;AAC1D,QAAM,mBAAe,mBAAAC,SAAY,SAAS;AAC1C,QAAM,CAAC,aAAa,cAAc,QAAI,uBAAgC,IAAI;AAC1E,QAAM,CAAC,WAAW,YAAY,QAAI,uBAAS,kBAAkB;AAC7D,QAAM,CAAC,SAAS,UAAU,QAAI,uBAAS,YAAY;AACnD,QAAM,iBAAa,mBAAAA,S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